threeML package¶
Subpackages¶
- threeML.bayesian package
- threeML.catalogs package
- threeML.classicMLE package
- threeML.config package
- threeML.exceptions package
- threeML.io package
- Subpackages
- threeML.io.cern_root_utils package
- threeML.io.plotting package
- Submodules
- threeML.io.plotting.cmap_cycle module
- threeML.io.plotting.data_residual_plot module
- threeML.io.plotting.light_curve_plots module
- threeML.io.plotting.model_plot module
- threeML.io.plotting.plot_style module
- threeML.io.plotting.post_process_data_plots module
- threeML.io.plotting.step_plot module
- Module contents
- Submodules
- threeML.io.calculate_flux module
- threeML.io.configuration module
- threeML.io.detect_notebook module
- threeML.io.dict_with_pretty_print module
- threeML.io.download_from_ftp module
- threeML.io.download_from_http module
- threeML.io.file_utils module
- threeML.io.fits_file module
- threeML.io.get_heasarc_table_as_pandas module
- threeML.io.network module
- threeML.io.package_data module
- threeML.io.progress_bar module
- threeML.io.results_table module
- threeML.io.rich_display module
- threeML.io.serialization module
- threeML.io.suppress_stdout module
- threeML.io.table module
- threeML.io.uncertainty_formatter module
- Module contents
- Subpackages
- threeML.minimizer package
- Submodules
- threeML.minimizer.ROOT_minimizer module
- threeML.minimizer.grid_minimizer module
- threeML.minimizer.minimization module
- threeML.minimizer.minuit_minimizer module
- threeML.minimizer.multinest_minimizer module
- threeML.minimizer.pagmo_minimizer module
- threeML.minimizer.scipy_minimizer module
- threeML.minimizer.tutorial_material module
- Module contents
- threeML.parallel package
- threeML.plugins package
- Subpackages
- Submodules
- threeML.plugins.DispersionSpectrumLike module
- threeML.plugins.FermiLATLike module
- threeML.plugins.FermipyLike module
- threeML.plugins.HAWCLike module
- threeML.plugins.OGIPLike module
- threeML.plugins.PhotometryLike module
- threeML.plugins.SpectrumLike module
- threeML.plugins.SwiftXRTLike module
- threeML.plugins.XYLike module
- threeML.plugins.gammaln module
- Module contents
- threeML.test package
- Submodules
- threeML.test.conftest module
- threeML.test.generate_pha module
- threeML.test.test_AAA_against_xspec module
- threeML.test.test_FermipyLike module
- threeML.test.test_XYLike module
- threeML.test.test_analysis_results module
- threeML.test.test_basic module
- threeML.test.test_bayesian module
- threeML.test.test_catalogs module
- threeML.test.test_configuration module
- threeML.test.test_download_GBM_data module
- threeML.test.test_download_LAT_data module
- threeML.test.test_event_list module
- threeML.test.test_fits_file module
- threeML.test.test_fitted_point_sources module
- threeML.test.test_generic module
- threeML.test.test_get_package_data module
- threeML.test.test_goodness_of_fit module
- threeML.test.test_hawc module
- threeML.test.test_histogram module
- threeML.test.test_joint_likelihood_set module
- threeML.test.test_minimizers module
- threeML.test.test_ogip module
- threeML.test.test_photometry_utils module
- threeML.test.test_plot_style module
- threeML.test.test_plotting module
- threeML.test.test_plugin_loading module
- threeML.test.test_power_of_two_utils module
- threeML.test.test_response module
- threeML.test.test_spectrum_class module
- threeML.test.test_spectrumlike module
- threeML.test.test_time_energy_fit module
- threeML.test.test_time_interval module
- threeML.test.test_time_series module
- Module contents
- threeML.utils package
- Subpackages
- threeML.utils.OGIP package
- threeML.utils.data_builders package
- threeML.utils.data_download package
- threeML.utils.fitted_objects package
- threeML.utils.photometry package
- threeML.utils.spectrum package
- threeML.utils.statistics package
- threeML.utils.time_series package
- Submodules
- threeML.utils.bayesian_blocks module
- threeML.utils.binner module
- threeML.utils.cartesian module
- threeML.utils.differentiation module
- threeML.utils.fermi_relative_mission_time module
- threeML.utils.histogram module
- threeML.utils.interval module
- threeML.utils.power_of_two_utils module
- threeML.utils.step_parameter_generator module
- threeML.utils.string_utils module
- threeML.utils.time_interval module
- threeML.utils.unique_deterministic_tag module
- Module contents
- Subpackages
Submodules¶
threeML.analysis_results module¶
-
class
threeML.analysis_results.
ANALYSIS_RESULTS
(analysis_results)[source]¶ Bases:
threeML.io.fits_file.FITSExtension
Represents the ANALYSIS_RESULTS extension of a FITS file encoding the results of an analysis
- Parameters
analysis_results (_AnalysisResults) –
-
class
threeML.analysis_results.
ANALYSIS_RESULTS_HDF
(analysis_results, hdf_obj)[source]¶ Bases:
object
-
class
threeML.analysis_results.
AnalysisResultsFITS
(*analysis_results, **kwargs)[source]¶ Bases:
threeML.io.fits_file.FITSFile
A FITS file for storing one or more results from 3ML analysis
-
class
threeML.analysis_results.
AnalysisResultsSet
(results)[source]¶ Bases:
collections.abc.Sequence
A container for results which behaves like a list (but you cannot add/remove elements).
You can index (analysis_set[0]), iterate (for item in analysis_set) and measure with len()
-
characterize_sequence
(name, data_tuple)[source]¶ Characterize the sequence of these results. The provided data frame will be saved along with the results in the “SEQUENCE” extension to allow the interpretation of the results.
This method is completely general, and allow for a lot of flexibility.
If this is a binned analysis and you only want to save the lower and upper bound of the bins, use set_bins instead.
If you only want to associate one quantity for each entry, use set_x.
-
set_bins
(name, lower_bounds, upper_bounds, unit=None)[source]¶ Associate the provided bins with these results. These bins will be written in the SEQUENCE extension when saving these results to a FITS file
- Parameters
name – a name for these bins (for example, “time” or “energy”). Please use only letters and numbers
(no special characters) :param lower_bounds: :param upper_bounds: :param unit: unit for the boundaries (like “s” for seconds, or a astropy.units.Unit instance) :return:
-
set_x
(name, x, unit=None)[source]¶ Associate the provided x with these results. The values in x will be written in the SEQUENCE extension when saving these results to a FITS file.
- Parameters
name – a name for this sequence (for example, “time” or “energy”). Please use only letters and numbers
(no special characters) :param x: :param unit: unit for x (like “s” for seconds, or a astropy.units.Unit instance) :return:
-
-
class
threeML.analysis_results.
BayesianResults
(optimized_model, samples, posterior_values, statistical_measures)[source]¶ Bases:
threeML.analysis_results._AnalysisResults
Store results of a Bayesian analysis (i.e., the samples) and allow for computation with them and “error propagation”
- Parameters
optimized_model – a Model instance with the MAP values of the parameters. A clone will be stored within
the class, so there is no need to clone it before hand :type optimized_model: astromodels.Model :param samples: the samples for the parameters :type samples: np.ndarray :param posterior_values: a dictionary containing the posterior values for the different datasets at the HPD :type posterior_values: dict
-
comparison_corner_plot
(*other_fits, **kwargs)[source]¶ Create a corner plot from many different fits which allow for co-plotting of parameters marginals.
- Parameters
other_fits – other fitted results
parameters – parameters to plot
renamed_parameters – a python dictionary of parameters to rename. Useful when e.g. spectral indices in models have different names but you wish to compare them. Format is {‘old label’: ‘new label’}
names – (optional) name for each chain first name is this chain followed by each added chain
kwargs – chain consumer kwargs
- Returns
Returns:
-
convergence_plots
(n_samples_in_each_subset, n_subsets)[source]¶ Compute the mean and variance for subsets of the samples, and plot them. They should all be around the same values if the MCMC has converged to the posterior distribution.
The subsamples are taken with two different strategies: the first is to slide a fixed-size window, the second is to take random samples from the chain (bootstrap)
- Parameters
n_samples_in_each_subset – number of samples in each subset
n_subsets – number of subsets to take for each strategy
- Returns
a matplotlib.figure instance
-
corner_plot
(renamed_parameters=None, **kwargs)[source]¶ Produce the corner plot showing the marginal distributions in one and two directions.
- Parameters
renamed_parameters – a python dictionary of parameters to rename. Useful when e.g. spectral indices in models have different names but you wish to compare them. Format is {‘old label’: ‘new label’}, where ‘old label’ is the full path of the parameter
kwargs – arguments to be passed to the corner function
- Returns
a matplotlib.figure instance
-
corner_plot_cc
(parameters=None, renamed_parameters=None, **cc_kwargs)[source]¶ Corner plots using chainconsumer which allows for nicer plotting of marginals see: https://samreay.github.io/ChainConsumer/chain_api.html#chainconsumer.ChainConsumer.configure for all options :param parameters: list of parameters to plot :param renamed_parameters: a python dictionary of parameters to rename.
Useful when e.g. spectral indices in models have different names but you wish to compare them. Format is {‘old label’: ‘new label’}
- Parameters
**cc_kwargs –
chainconsumer general keyword arguments
- Return fig
-
static
freedman_diaconis_rule
(data)[source]¶ Returns the number of bins from the Freedman-Diaconis rule for a histogram of the given data
- Parameters
data – an array of data
- Returns
the optimal number of bins
-
get_correlation_matrix
()[source]¶ Estimate the covariance matrix from the samples
- Returns
the correlation matrix
-
class
threeML.analysis_results.
MLEResults
(optimized_model, covariance_matrix, likelihood_values, n_samples=5000, statistical_measures=None)[source]¶ Bases:
threeML.analysis_results._AnalysisResults
Build the _AnalysisResults object starting from a covariance matrix.
- Parameters
optimized_model – best fit model
:type optimized_model:astromodels.Model :param covariance_matrix: :type covariance_matrix: np.ndarray :param likelihood_values: :type likelihood_values: dict :param n_samples: Number of samples to use :type n_samples: int :return: an _AnalysisResults instance
-
property
covariance_matrix
¶ Returns the covariance matrix.
- Returns
covariance matrix or None (if the class was built from samples. Use estimate_covariance_matrix in that case)
-
class
threeML.analysis_results.
SEQUENCE
(name, data_tuple)[source]¶ Bases:
threeML.io.fits_file.FITSExtension
Represents the SEQUENCE extension of a FITS file containing a set of results from a set of analysis
-
threeML.analysis_results.
load_analysis_results
(fits_file: str)[source]¶ Load the results of one or more analysis from a FITS file produced by 3ML
- Parameters
fits_file – path to the FITS file containing the results, as output by MLEResults or BayesianResults
- Returns
a new instance of either MLEResults or Bayesian results dending on the type of the input FITS file
-
threeML.analysis_results.
load_analysis_results_hdf
(hdf_file: str)[source]¶ Load the results of one or more analysis from a FITS file produced by 3ML
- Parameters
fits_file – path to the FITS file containing the results, as output by MLEResults or BayesianResults
- Returns
a new instance of either MLEResults or Bayesian results dending on the type of the input FITS file
threeML.data_list module¶
threeML.plugin_prototype module¶
Define the interface for a plugin class.
-
class
threeML.plugin_prototype.
PluginPrototype
(name, nuisance_parameters)[source]¶ Bases:
object
-
abstract
get_log_like
()[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
-
abstract
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
name
¶ Returns the name of this instance
- Returns
a string (this is enforced to be a valid python identifier)
-
property
nuisance_parameters
¶ Returns a dictionary containing the nuisance parameters for this dataset
- Returns
a dictionary
-
abstract
set_model
(likelihood_model_instance)[source]¶ Set the model to be used in the joint minimization. Must be a LikelihoodModel instance.
-
property
tag
¶ Gets/sets the tag for this instance, as (independent variable, start, [end])
-
abstract
threeML.random_variates module¶
-
class
threeML.random_variates.
RandomVariates
(input_array, value=None)[source]¶ Bases:
numpy.ndarray
A subclass of np.array which is meant to contain samples for one parameter. This class contains methods to easily compute properties for the parameter (errors and so on)
-
property
average
¶ Returns average value
-
equal_tail_interval
(cl=0.68)[source]¶ Returns the equal tail interval, i.e., an interval centered on the median of the distribution with the same probability on the right and on the left of the mean.
If the distribution of the parameter is Gaussian and cl=0.68, this is equivalent to the 1 sigma confidence interval.
- Parameters
cl – confidence level (0 < cl < 1)
- Returns
(low_bound, hi_bound)
-
highest_posterior_density_interval
(cl=0.68)[source]¶ Returns the Highest Posterior Density interval (HPD) for the parameter, for the given credibility level.
NOTE: the returned interval is the HPD only if the posterior is not multimodal. If it is multimodal, you should probably report the full posterior, not only an interval.
- Parameters
cl – credibility level (0 < cl < 1)
- Returns
(low_bound, hi_bound)
-
property
median
¶ Returns median value
-
property
samples
¶
-
property
std
¶ Returns sample std value
-
property
value
¶
-
property
var
¶ Returns sample variance value
-
property