threeML.plugins.XYLike module
- class threeML.plugins.XYLike.XYLike(name: str, x: ndarray, y: ndarray, yerr: ndarray | None = None, poisson_data: bool = False, exposure: float | None = None, quiet: bool = False, source_name: str | None = None)[source]
Bases:
PluginPrototype
- assign_to_source(source_name: str) None [source]
Assign these data to the given source (instead of to the sum of all sources, which is the default)
- Parameters:
source_name – name of the source (must be contained in the likelihood model)
- Returns:
none
- fit(function: Function, minimizer: str = 'minuit', verbose: bool = False) _AnalysisResults [source]
Fit the data with the provided function (an astromodels function)
- Parameters:
function – astromodels function
minimizer – the minimizer to use
verbose – print every step of the fit procedure
- Returns:
best fit results
- classmethod from_dataframe(name: str, dataframe: DataFrame, x_column: str = 'x', y_column: str = 'y', err_column: str = 'yerr', poisson: bool = False) XYLike [source]
Generate a XYLike instance from a Pandas.DataFrame instance
- Parameters:
name – the name for the XYLike instance
dataframe – the input data frame
x_column – name of the column to be used as x (default: ‘x’)
y_column – name of the column to be used as y (default: ‘y’)
err_column – name of the column to be used as error on y (default: ‘yerr’)
poisson – if True, then the err_column is ignored and data are treated as Poisson distributed
- Returns:
a XYLike instance
- classmethod from_function(name: str, function: Function, x: ndarray, yerr: ndarray | None = None, exposure: float | None = None, **kwargs) XYLike [source]
Generate an XYLike plugin from an astromodels function instance
- Parameters:
name – name of plugin
function – astromodels function instance
x – where to simulate
yerr – y errors or None for Poisson data
kwargs – kwargs from xylike constructor
- Returns:
XYLike plugin
- classmethod from_text_file(name, filename) XYLike [source]
Instance the plugin starting from a text file generated with the .to_txt() method. Note that a more general way of creating a XYLike instance from a text file is to read the file using pandas.DataFrame.from_csv, and then use the .from_dataframe method of the XYLike plugin:
> df = pd.DataFrame.from_csv(filename, …) > xyl = XYLike.from_dataframe(“my instance”, df)
- Parameters:
name – the name for the new instance
filename – path to the file
- Returns:
- get_log_like() float [source]
Return the value of the log-likelihood with the current values for the parameters
- get_simulated_dataset(new_name: str | None = None) XYLike [source]
return a simulated XYLike plugin
- goodness_of_fit(n_iterations: int = 1000, continue_of_failure: bool = False)[source]
Returns the goodness of fit of the performed fit
- Parameters:
n_iterations – number of Monte Carlo simulations to generate
continue_of_failure – whether to continue or not if a fit fails (default: False)
- Returns:
tuple (goodness of fit, frame with all results, frame with all likelihood values)
- property has_errors: bool
- inner_fit() float [source]
This is used for the profile likelihood. Keeping fixed all parameters in the LikelihoodModel, this method minimize the logLike over the remaining nuisance parameters, i.e., the parameters belonging only to the model for this particular detector. If there are no nuisance parameters, simply return the logLike value.
- property is_poisson: bool
- property likelihood_model: Model
- set_model(likelihood_model_instance: Model) None [source]
Set the model to be used in the joint minimization. Must be a LikelihoodModel instance.
- Parameters:
likelihood_model_instance (astromodels.Model) – instance of Model
- to_csv(*args, **kwargs) None [source]
Save the data in a comma-separated-values file (CSV) file. All keywords arguments are passed to the pandas.DataFrame.to_csv method (see the documentation from pandas for all possibilities). This gives a very high control on the format of the output
All arguments are forwarded to pandas.DataFrame.to_csv
- Returns:
none
- to_dataframe() DataFrame [source]
Returns a pandas.DataFrame instance with the data in the ‘x’, ‘y’, and ‘yerr’ column. If the data are Poisson, the yerr column will be -99 for every entry
- Returns:
a pandas.DataFrame instance
- to_txt(filename: str) None [source]
Save the dataset in a text file. You can read the content back in a dataframe using:
> df = pandas.DataFrame.from_csv(filename, sep=’ ‘)
and recreate the XYLike instance as:
> xyl = XYLike.from_dataframe(df)
- Parameters:
filename – Name of the output file
- Returns:
none
- property x: ndarray
- property y: ndarray | None
- property yerr: ndarray | None