threeML.plugins.XYLike module¶
-
class
threeML.plugins.XYLike.
XYLike
(name, x, y, yerr=None, poisson_data=False, exposure=None, quiet=False, source_name=None)[source]¶ Bases:
threeML.plugin_prototype.PluginPrototype
-
assign_to_source
(source_name)[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, minimizer='minuit', verbose=False)[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, dataframe, x_column='x', y_column='y', err_column='yerr', poisson=False)[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, function, x, yerr=None, exposure=None, **kwargs)[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)[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
()[source]¶ Return the value of the log-likelihood with the current values for the parameters
-
goodness_of_fit
(n_iterations=1000, continue_of_failure=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
¶
-
inner_fit
()[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
¶
-
set_model
(likelihood_model_instance)[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)[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
()[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)[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
¶
-
property
y
¶
-
property
yerr
¶
-