threeML.plugins package

Subpackages

Submodules

threeML.plugins.BinnedProfileLike module

threeML.plugins.DispersionSpectrumLike module

class threeML.plugins.DispersionSpectrumLike.DispersionSpectrumLike(name: str, observation: BinnedSpectrumWithDispersion, background: Optional[Union[BinnedSpectrum, SpectrumLike, XYLike]] = None, background_exposure: Optional[float] = None, verbose: bool = True, tstart: Optional[float] = None, tstop: Optional[float] = None)[source]

Bases: SpectrumLike

display_rsp()[source]

Display the currently loaded full response matrix, i.e., RMF and ARF convolved :return:

classmethod from_function(name: str, source_function, response, source_errors=None, source_sys_errors=None, background_function=None, background_errors=None, background_sys_errors=None, exposure=1.0, scale_factor=1.0) DispersionSpectrumLike[source]

Construct a simulated spectrum from a given source function and (optional) background function. If source and/or background errors are not supplied, the likelihood is assumed to be Poisson.

Parameters:
  • name – simulated data set name

  • source_function – astromodels function

  • response – 3ML Instrument response

  • source_errors – (optional) gaussian source errors

  • source_sys_errors – (optional) systematic source errors

  • background_function – (optional) astromodels background function

  • background_errors – (optional) gaussian background errors

  • background_sys_errors – (optional) background systematic errors

  • exposure – the exposure to assume

  • scale_factor – the scale factor between source exposure / bkg exposure

Returns:

simulated DispersionSpectrumLike plugin

get_pha_files()[source]
get_simulated_dataset(new_name=None, **kwargs)[source]

Returns another DispersionSpectrumLike instance where data have been obtained by randomizing the current expectation from the model, as well as from the background (depending on the respective noise models)

Returns:

a DispersionSpectrumLike simulated instance

property response: InstrumentResponse
set_model(likelihoodModel: Model) None[source]

Set the model to be used in the joint minimization.

set_model_integrate_method(method: str)[source]

Change the integrate method for the model integration :param method: (str) which method should be used (simpson or trapz)

write_pha(filename: str, overwrite: bool = False, force_rsp_write: bool = False) None[source]

Writes the observation, background and (optional) rsp to PHAII fits files

Parameters:
  • filename – base file name to write out

  • overwrite – if you would like to force overwriting of the files

  • force_rsp_write – force the writing of an rsp even if not required

threeML.plugins.FermiLATLike module

threeML.plugins.FermipyLike module

class threeML.plugins.FermipyLike.FermipyLike(*args, **kwargs)[source]

Bases: PluginPrototype

Plugin for the data of the Fermi Large Area Telescope, based on fermipy (http://fermipy.readthedocs.io/)

property configuration

Returns the loaded configuration

Returns:

a dictionary containing the active configuration

display_model(data_color: str = 'k', model_cmap: str = 'Set1', model_color: Optional[str] = None, total_model_color: str = 'k', background_color: str = 'b', show_data: bool = True, primary_sources: Optional[Union[str, List[str]]] = None, show_background_sources: bool = True, shade_fixed_sources: bool = True, shade_secondary_source: bool = False, fixed_sources_color: str = 'grey', secondary_sources_color: str = 'k', show_residuals: bool = True, ratio_residuals: bool = False, show_legend: bool = True, model_label: Optional[str] = None, model_kwargs: Optional[Dict[str, Any]] = None, data_kwargs: Optional[Dict[str, Any]] = None, background_kwargs: Optional[Dict[str, Any]] = None, **kwargs) ResidualPlot[source]

Plot the current model with or without the data and the residuals. Multiple models can be plotted by supplying a previous axis to ‘model_subplot’.

Example usage:

fig = data.display_model()

fig2 = data2.display_model(model_subplot=fig.axes)

Parameters:
  • data_color – the color of the data

  • model_color – the color of the model

  • show_data – (bool) show_the data with the model

  • show_residuals – (bool) shoe the residuals

  • ratio_residuals – (bool) use model ratio instead of residuals

  • show_legend – (bool) show legend

  • model_label – (optional) the label to use for the model default is plugin name

  • model_kwargs – plotting kwargs affecting the plotting of the model

  • data_kwargs – plotting kwargs affecting the plotting of the data and residuls

  • background_kwargs – plotting kwargs affecting the plotting of the background

Returns:

static get_basic_config(evfile, scfile, ra, dec, emin=100.0, emax=100000.0, zmax=100.0, evclass=128, evtype=3, filter='DATA_QUAL>0 && LAT_CONFIG==1', fermipy_verbosity=2, fermitools_chatter=2)[source]
get_log_like()[source]

Return the value of the log-likelihood with the current values for the parameters stored in the ModelManager instance

get_number_of_data_points()[source]

Return the number of spatial/energy bins

Returns:

number of bins

get_observation_duration()[source]
property gta
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.

set_inner_minimization(flag: bool) None[source]

Turn on the minimization of the internal Fermi parameters

Parameters:

flag (bool) – turing on and off the minimization of the Fermipy internal parameters

Returns:

set_model(likelihood_model_instance)[source]

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

set_nuisance_parameter_value(paramName, value)[source]

threeML.plugins.HAWCLike module

threeML.plugins.OGIPLike module

class threeML.plugins.OGIPLike.OGIPLike(name: str, observation: Union[str, Path, PHASpectrum, PHAII], background: Optional[Union[str, Path, PHASpectrum, PHAII, SpectrumLike, XYLike]] = None, response: Optional[str] = None, arf_file: Optional[str] = None, spectrum_number: Optional[int] = None, verbose: bool = True)[source]

Bases: DispersionSpectrumLike

classmethod from_general_dispersion_spectrum(dispersion_like: DispersionSpectrumLike) OGIPLike[source]

Build on OGIPLike from a dispersion like. This makes it easy to write a dispersion like to a pha file

Parameters:

dispersion_like

Returns:

get_simulated_dataset(new_name: Optional[str] = None, spectrum_number: int = 1, **kwargs) OGIPLike[source]

Returns another OGIPLike instance where data have been obtained by randomizing the current expectation from the model, as well as from the background (depending on the respective noise models)

Parameters:
  • new_name – name of the simulated plugin

  • spectrum_number – spectrum number (default is 1)

  • kwargs – keywords to pass back up to parents

Returns:

a DispersionSpectrumLike simulated instance

property grouping
write_pha(file_name: str, overwrite: bool = False, force_rsp_write: bool = False) None[source]

Create a pha file of the current pha selections

Parameters:
  • file_name – output file name (excluding extension)

  • overwrite – overwrite the files

  • force_rsp_write – for an rsp to be saved

Returns:

None

threeML.plugins.PhotometryLike module

class threeML.plugins.PhotometryLike.BandNode(name, index, value, mask)[source]

Bases: object

property off

‘p.off = True’ or ‘p.off = False’.

Type:

Turn on or off the band. Use booleans, like

property on

‘p.on = True’ or ‘p.on = False’.

Type:

Turn on or off the band. Use booleans, like

class threeML.plugins.PhotometryLike.PhotometryLike(name: str, filters: Union[FilterSequence, FilterResponse], observation: PhotometericObservation)[source]

Bases: XYLike

display_filters()[source]

display the filter transmission curves

Returns:

classmethod from_file(name: str, filters: Union[FilterResponse, FilterSequence], file_name: str)[source]

Create the a PhotometryLike plugin from a saved HDF5 data file

Parameters:
  • name – plugin name

  • filters – speclite filters

  • file_name – name of the observation file

classmethod from_kwargs(name, filters, **kwargs)[source]

Example:

grond = PhotometryLike.from_kwargs(‘GROND’,

filters=threeML_filter_library.ESO.GROND, g=(20.93,.23), r=(20.6,0.12), i=(20.4,.07), z=(20.3,.04), J=(20.0,.03), H=(19.8,.03), K=(19.7,.04))

Magnitudes and errors are entered as keyword arguments where the key is the filter name and the argument is a tuple containing the data. You can exclude data for individual filters and they will be ignored during the fit.

NOTE: PhotometryLike expects apparent AB magnitudes. Please calibrate your data to this system

Parameters:
  • name – plugin name

  • filters – speclite filters

  • kwargs – keyword args of band name and tuple(mag, mag error)

property magnitude_errors
property magnitudes
property observation: PhotometericObservation
plot(data_color: str = 'r', model_color: str = 'blue', show_data: bool = True, show_residuals: bool = True, show_legend: bool = True, model_label: Optional[str] = None, model_kwargs: Optional[Dict[str, Any]] = None, data_kwargs: Optional[Dict[str, Any]] = None, **kwargs) ResidualPlot[source]

TODO describe function

Parameters:
  • data_color (str) –

  • model_color (str) –

  • show_data (bool) –

  • show_residuals (bool) –

  • show_legend (bool) –

  • model_label (Optional[str]) –

  • model_kwargs (Optional[Dict[str, Any]]) –

  • data_kwargs (Optional[Dict[str, Any]]) –

Returns:

set_model(likelihood_model)[source]

set the likelihood model :param likelihood_model: :return:

threeML.plugins.SpectrumLike module

class threeML.plugins.SpectrumLike.SpectrumLike(name: str, observation: BinnedSpectrum, background: Optional[Union[BinnedSpectrum, SpectrumLike, XYLike]] = None, verbose: bool = True, background_exposure=None, tstart: Optional[Union[float, int]] = None, tstop: Optional[Union[float, int]] = None)[source]

Bases: PluginPrototype

property area_ratio: float

ratio between source and background area

Type:

return

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

property background_count_errors: Optional[ndarray]

the observed background count errors

Type:

return

property background_counts: Optional[ndarray]

the observed background counts

Type:

return

property background_exposure: float

Exposure of the background spectrum, if present

property background_integrate_method: str

The method used to integrate the_background across the response matrix

property background_noise_model: str

Sets/gets the noise model for the background spectrum

property background_plugin
property background_scale_factor: float

The background scale factor

Returns:

property background_spectrum: BinnedSpectrum
property current_background_count_errors: Optional[ndarray]
property current_background_counts: Optional[ndarray]
property current_observed_count_errors: Optional[ndarray]
property current_observed_counts: ndarray
property current_scaled_background_counts: Optional[ndarray]
display()[source]
display_model(data_color: str = 'k', model_color: str = 'r', background_color: str = 'b', step: bool = True, show_data: bool = True, show_residuals: bool = True, ratio_residuals: bool = False, show_legend: bool = True, min_rate: Union[int, float] = 1e-99, model_label: Optional[str] = None, model_kwargs: Optional[Dict[str, Any]] = None, data_kwargs: Optional[Dict[str, Any]] = None, background_label: Optional[str] = None, background_kwargs: Optional[Dict[str, Any]] = None, source_only: bool = True, show_background: bool = False, **kwargs) ResidualPlot[source]

Plot the current model with or without the data and the residuals. Multiple models can be plotted by supplying a previous axis to ‘model_subplot’.

Example usage:

fig = data.display_model()

fig2 = data2.display_model(model_subplot=fig.axes)

Parameters:
  • data_color – the color of the data

  • model_color – the color of the model

  • step – (bool) create a step count histogram or interpolate the model

  • show_data – (bool) show_the data with the model

  • show_residuals – (bool) shoe the residuals

  • ratio_residuals – (bool) use model ratio instead of residuals

  • show_legend – (bool) show legend

  • min_rate – the minimum rate per bin

  • model_label – (optional) the label to use for the model default is plugin name

  • model_subplot – (optional) axis or list of axes to plot to

  • model_kwargs – plotting kwargs affecting the plotting of the model

  • data_kwargs – plotting kwargs affecting the plotting of the data and residuls

Returns:

property energy_boundaries: Tuple[float]

Energy boundaries of channels currently in use (rebinned, if a rebinner is active)

Returns:

(energy_min, energy_max)

property expected_model_rate: ndarray
property exposure: float

Exposure of the source spectrum

property exposure_ratio: float

ratio between source and background exposure

Type:

return

fix_effective_area_correction(value: Union[int, float] = 1) None[source]

Fix the multiplicative factor (see use_effective_area_correction) to the provided value (default: 1)

Parameters:

value – new value (default: 1, i.e., no correction)

Returns:

classmethod from_background(name: str, spectrum_like, verbose: bool = True)[source]

Extract a SpectrumLike plugin from the background of another SpectrumLike (or subclass) instance

Parameters:
  • name – name of the extracted_plugin

  • spectrum_like – plugin with background to extract

  • verbose – if the plugin should be verbose

Returns:

SpectrumLike instance from the background

classmethod from_function(name: str, source_function, energy_min, energy_max, source_errors=None, source_sys_errors=None, background_function=None, background_errors=None, background_sys_errors=None, exposure=1.0, scale_factor=1.0, **kwargs)[source]

Construct a simulated spectrum from a given source function and (optional) background function. If source and/or background errors are not supplied, the likelihood is assumed to be Poisson.

Parameters:
  • name – simulkated data set name

  • source_function – astromodels function

  • energy_min – array of low energy bin edges

  • energy_max – array of high energy bin edges

  • source_errors – (optional) gaussian source errors

  • source_sys_errors – (optional) systematic source errors

  • background_function – (optional) astromodels background function

  • background_errors – (optional) gaussian background errors

  • background_sys_errors – (optional) background systematic errors

  • exposure – the exposure to assume

  • scale_factor – the scale factor between source exposure / bkg exposure

Returns:

simulated SpectrumLike plugin

get_background_model(without_mask: bool = False) ndarray[source]

The background model integrated over the energy bins. Note that it only returns the model for the currently active channels/measurements

Returns:

array of folded model

get_log_like(precalc_fluxes: Optional[ndarray] = None) float[source]

Calls the likelihood from the pre-setup likelihood evaluator that “knows” of the currently set noise models

Returns:

get_model(precalc_fluxes: Optional[array] = None) ndarray[source]

The model integrated over the energy bins. Note that it only returns the model for the currently active channels/measurements

Returns:

array of folded model

get_number_of_data_points() int[source]

returns the number of active data bins :return:

get_pha_files() Dict[str, BinnedSpectrum][source]
get_simulated_dataset(new_name: Optional[str] = None, store_model: Optional[bool] = True, **kwargs) SpectrumLike[source]

Returns another Binned instance where data have been obtained by randomizing the current expectation from the model, as well as from the background (depending on the respective noise models)

Parameters:
  • new_name – the base line name

  • store_model – to store the model configuration used to simulate the data set

Returns:

an BinnedSpectrum or child instance

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 likelihood_model: Model
property mask: ndarray

The channel mask :return:

property model_integrate_method: str

The method used to integrate the model across the response matrix

property n_data_points: int
property observation_noise_model: str

Sets/gets the noise model for the background spectrum

property observed_count_errors: Optional[ndarray]

the observed counts errors

Type:

return

property observed_counts: ndarray

the observed counts

Type:

return

property observed_spectrum: BinnedSpectrum
property quality: Quality
rebin_on_background(min_number_of_counts: float) None[source]

Rebin the spectrum guaranteeing the provided minimum number of counts in each background bin. This is usually required for spectra with very few background counts to make the Poisson profile likelihood meaningful. Of course this is not relevant if you treat the background as ideal, nor if the background spectrum has Gaussian errors.

The observed spectrum will be rebinned in the same fashion as the background spectrum.

To neutralize this completely, use “remove_rebinning”

Parameters:

min_number_of_counts – the minimum number of counts in each bin

Returns:

none

rebin_on_source(min_number_of_counts: int) None[source]

Rebin the spectrum guaranteeing the provided minimum number of counts in each source bin.

To neutralize this completely, use “remove_rebinning”

Parameters:

min_number_of_counts – the minimum number of counts in each bin

Returns:

none

remove_rebinning() None[source]

Remove the rebinning scheme set with rebin_on_background.

Returns:

property scale_factor: float

Ratio between the source and the background exposure and area

Returns:

set_active_measurements(*args, **kwargs) None[source]

Set the measurements to be used during the analysis. Use as many ranges as you need, and you can specify either energies or channels to be used.

NOTE to Xspec users: while XSpec uses integers and floats to distinguish between energies and channels specifications, 3ML does not, as it would be error-prone when writing scripts. Read the following documentation to know how to achieve the same functionality.

  • Energy selections:

They are specified as ‘emin-emax’. Energies are in keV. Example:

set_active_measurements(‘10-12.5’,’56.0-100.0’)

which will set the energy range 10-12.5 keV and 56-100 keV to be used in the analysis. Note that there is no difference in saying 10 or 10.0.

  • Channel selections:

They are specified as ‘c[channel min]-c[channel max]’. Example:

set_active_measurements(‘c10-c12’,’c56-c100’)

This will set channels 10-12 and 56-100 as active channels to be used in the analysis

  • Mixed channel and energy selections:

You can also specify mixed energy/channel selections, for example to go from 0.2 keV to channel 20 and from channel 50 to 10 keV:

set_active_measurements(‘0.2-c10’,’c50-10’)

  • Use all measurements (i.e., reset to initial state):

Use ‘all’ to select all measurements, as in:

set_active_measurements(‘all’)

Use ‘reset’ to return to native PHA quality from file, as in:

set_active_measurements(‘reset’)

  • Exclude measurements:

Excluding measurements work as selecting measurements, but with the “exclude” keyword set to the energies and/or channels to be excluded. To exclude between channel 10 and 20 keV and 50 keV to channel 120 do:

set_active_measurements(exclude=[“c10-20”, “50-c120”])

  • Select and exclude:

Call this method more than once if you need to select and exclude. For example, to select between 0.2 keV and channel 10, but exclude channel 30-50 and energy , do:

set_active_measurements(“0.2-c10”,exclude=[“c30-c50”])

  • Using native PHA quality:

To simply add or exclude channels from the native PHA, one can use the use_quailty option:

set_active_measurements(

“0.2-c10”,exclude=[“c30-c50”], use_quality=True)

This translates to including the channels from 0.2 keV - channel 10, exluding channels 30-50 and any channels flagged BAD in the PHA file will also be excluded.

Parameters:
  • args

  • exclude – (list) exclude the provided channel/energy ranges

  • use_quality – (bool) use the native quality on the PHA file (default=False)

Returns:

set_background_integrate_method(method: str) None[source]

Change the integrate method for the background integration :param method: (str) which method should be used (simpson or trapz)

set_model(likelihoodModel: Model) None[source]

Set the model to be used in the joint minimization.

set_model_integrate_method(method: str) None[source]

Change the integrate method for the model integration :param method: (str) which method should be used (simpson or trapz)

property significance: float

the significance of the data over background

Type:

return

property significance_per_channel: ndarray

the significance of the data over background per channel

Type:

return

property simulated_parameters: Model

Return the simulated dataset parameters :return: a likelihood model copy

property source_rate: ndarray

The source rate of the model. If there is background or a background background plugin present, the source is background subtracted, but only for visual purposes. If no background is present, then, this is just the observed rate.

Returns:

the source rate

property source_rate_error: ndarray

The source rate error of the model. If there is background or a background background plugin present, the source is background subtracted, but only for visual purposes. If no background is present, then, this is just the observed rate.

Returns:

the source rate error

property tstart: float
property tstop: float
use_effective_area_correction(min_value: Union[int, float] = 0.8, max_value: Union[int, float] = 1.2, use_gaussian_prior: bool = False, mu: float = 1, sigma: float = 0.1) None[source]

Activate the use of the effective area correction, which is a multiplicative factor in front of the model which might be used to mitigate the effect of intercalibration mismatch between different instruments.

NOTE: do not use this is you are using only one detector, as the multiplicative constant will be completely degenerate with the normalization of the model.

NOTE2: always keep at least one multiplicative constant fixed to one (its default value), when using this with other OGIPLike-type detectors

Parameters:
  • min_value – minimum allowed value (default: 0.8, corresponding to a 20% - effect)

  • max_value – maximum allowed value (default: 1.2, corresponding to a 20% + effect)

  • use_gaussian_prior – use a gaussian prior on the constant

  • mu – the center of the gaussian

  • sigma – the spread of the gaussian

Returns:

view_count_spectrum(plot_errors: bool = True, show_bad_channels: bool = True, show_warn_channels: bool = False, significance_level: Optional[bool] = None, scale_background: bool = True) Figure[source]

View the count and background spectrum. Useful to check energy selections. :param plot_errors: plot errors on the counts :param show_bad_channels: (bool) show which channels are bad in the native PHA quality :return:

write_pha()[source]

threeML.plugins.SwiftXRTLike module

class threeML.plugins.SwiftXRTLike.SwiftXRTLike(name: str, observation: Union[str, Path, PHASpectrum, PHAII], background: Optional[Union[str, Path, PHASpectrum, PHAII, SpectrumLike, XYLike]] = None, response: Optional[str] = None, arf_file: Optional[str] = None, spectrum_number: Optional[int] = None, verbose: bool = True)[source]

Bases: OGIPLike

threeML.plugins.UnbinnedPoissonLike module

class threeML.plugins.UnbinnedPoissonLike.EventObservation(events: ndarray, exposure: float, start: Union[float, ndarray], stop: Union[float, ndarray], for_timeseries: bool = False)[source]

Bases: object

property events: ndarray
property exposure: float
property for_timeseries: bool
property is_multi_interval: bool
property n_events: int
property start: Union[float, ndarray]
property stop: Union[float, ndarray]
class threeML.plugins.UnbinnedPoissonLike.UnbinnedPoissonLike(name: str, observation: EventObservation, source_name: Optional[str] = None)[source]

Bases: PluginPrototype

get_log_like() float[source]

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

get_number_of_data_points()[source]

This returns the number of data points that are used to evaluate the likelihood. For binned measurements, this is the number of active bins used in the fit. For unbinned measurements, this would be the number of photons/particles that are evaluated on the likelihood

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.

set_model(model: Model) None[source]

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

threeML.plugins.UnresolvedExtendedXYLike module

class threeML.plugins.UnresolvedExtendedXYLike.UnresolvedExtendedXYLike(name, x, y, yerr=None, exposure=None, poisson_data=False, quiet=False, source_name=None)[source]

Bases: XYLike

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

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

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)

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: Optional[ndarray] = None, exposure: Optional[float] = 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_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

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
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.

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: Optional[ndarray]
property yerr: Optional[ndarray]

Module contents