threeML.plugins.XYLike module

class threeML.plugins.XYLike.XYLike(name: str, x: ndarray, y: ndarray, yerr: Optional[ndarray] = None, poisson_data: bool = False, exposure: Optional[float] = None, quiet: bool = False, source_name: Optional[str] = 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)


source_name – name of the source (must be contained in the likelihood model)



fit(function: Function, minimizer: str = 'minuit', verbose: bool = False) JointLikelihood[source]

Fit the data with the provided function (an astromodels function)

  • function – astromodels function

  • minimizer – the minimizer to use

  • verbose – print every step of the fit procedure


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

  • 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


a XYLike instance

classmethod from_function(name: str, function: Function, x: ndarray, yerr: Optional[ndarray] = None, exposure: Optional[float] = None, **kwargs) XYLike[source]

Generate an XYLike plugin from an astromodels function instance

  • 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


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)

  • name – the name for the new instance

  • filename – path to the file


get_log_like() float[source]

Return the value of the log-likelihood with the current values for the parameters

get_model() ndarray[source]
get_number_of_data_points() int[source]

returns the number of active data points :return:

get_simulated_dataset(new_name: Optional[str] = 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

  • n_iterations – number of Monte Carlo simulations to generate

  • continue_of_failure – whether to continue or not if a fit fails (default: False)


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
plot(x_label='x', y_label='y', x_scale='linear', y_scale='linear', ax=None)[source]
set_model(likelihood_model_instance: Model) None[source]

Set the model to be used in the joint minimization. Must be a LikelihoodModel instance.


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



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


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)


filename – Name of the output file



property x: ndarray
property y: Optional[ndarray]
property yerr: Optional[ndarray]