mla package
Submodules
mla.analysis module
Docstring
- class mla.analysis.SingleSourceLLHAnalysis(config: dict, minimizer_class: ~typing.Type[~mla.minimizers.Minimizer], sob_term_factories: ~typing.List[~mla.sob_terms.SoBTermFactory] = <property object>, data_handler_source: ~typing.Tuple[~mla.data_handlers.DataHandler, ~mla.sources.PointSource] = <property object>)
Bases:
objectDocstring
- config: dict
- property data_handler_source: Tuple[DataHandler, PointSource]
Docstring
- classmethod generate_default_config(minimizer_class: Type[Minimizer]) dict
Docstring
- generate_params() Params
Docstring
- minimizer_class: Type[Minimizer]
- produce_and_minimize(params: Params, fitting_params: List[str], n_signal: float = 0) tuple
Docstring
- property sob_term_factories: List[SoBTermFactory]
Docstring
- property test_statistic_factory: LLHTestStatisticFactory
Docstring
- property trial_generator: SingleSourceTrialGenerator
Docstring
mla.injectors module
mla.models module
mla.spectral module
mla.time_profiles module
The classes in this file are example time profiles that can be used in the analysis classes. There is also GenericProfile, an abstract parent class to inherit from to create other time profiles.
- class mla.time_profiles.CustomProfile(config: dict, dist: ~typing.Callable[[~numpy.ndarray, ~typing.Tuple[float, float]], ~numpy.ndarray] = <property object>)
Bases:
GenericProfileTime profile class for a custom binned distribution.
This time profile uses a binned pdf defined between 0 and 1. Normalization is handled internally and not required beforehand.
- pdf
The distribution function. This function needs to accept an array of bin centers and a time window as a tuple, and it needs to return an array of probability densities at the given bin centers.
- Type:
Callable[[np.array, Tuple[float, float]], np.array]
- dist
The histogrammed version of the distribution function.
- Type:
scipy.stats.rv_histogram
- exposure
- Type:
float
- range
The range of allowed times for for events injected using this time profile.
- Type:
Tuple[Optional[float], Optional[float]]
- default_params
A dictionary of fitting parameters for this time profile.
- Type:
Dict[str, float]
- param_dtype
The numpy dytpe for the fitting parameters.
- Type:
List[Tuple[str, str]]
- bounds(time_profile: GenericProfile) List[Tuple[Optional[float], Optional[float]]]
Given some other profile, returns allowable ranges for parameters.
- Parameters:
time_profile – Another time profile to use to get the bounds.
- Returns:
The fitting bounds for the parameters of this time profile.
- cdf(times: ndarray) ndarray
Docstring
- property dist: rv_histogram
Docstring
- property exposure: float
Docstring
- classmethod generate_config() dict
Docstring
- inverse_transform_sample(start_times: ndarray, stop_times: ndarray) ndarray
Docstring
- logpdf(times: ndarray) ndarray
Calculates the log(probability) for each time.
- Parameters:
times – An array of times to evaluate.
- Returns:
An array of the log(probability density) for the given times.
- property offset: float
- property param_bounds: dict
Docstring
- property param_dtype: dtype
Returns the parameter names and datatypes formatted for numpy dtypes.
- property params: dict
Docstring
- pdf(times: ndarray) ndarray
Calculates the probability density for each time.
- Parameters:
times – An array of times to evaluate.
- Returns:
An array of probability densities at the given times.
- random(size: int = 1) ndarray
Returns random values following the uniform distribution.
- Parameters:
size – The number of random values to return.
- Returns:
An array of random values sampled from the histogram distribution.
- property range: Tuple[Optional[float], Optional[float]]
Gets the maximum and minimum values for the times in this profile.
- x0(times: ndarray) Tuple[float, float]
Gives a guess of the parameters of this type of time profile.
- Parameters:
times – An array of times to use to guess the parameters.
- Returns:
The guessed start and end times of the distribution that generated the given times.
- class mla.time_profiles.GaussProfile(config: dict)
Bases:
GenericProfileTime profile class for a gaussian distribution.
Use this to produce gaussian-distributed times for your source.
- mean
The center of the distribution.
- Type:
float
- sigma
The spread of the distribution.
- Type:
float
- scipy_dist
- Type:
scipy.stats.rv_continuous
- exposure
- Type:
float
- range
The range of allowed times for for events injected using this time profile.
- Type:
Tuple[Optional[float], Optional[float]]
- default_params
A dictionary of fitting parameters for this time profile.
- Type:
Dict[str, float]
- param_dtype
The numpy dytpe for the fitting parameters.
- Type:
List[Tuple[str, str]]
- bounds(time_profile: GenericProfile) List[tuple]
Returns good bounds for this time profile given another time profile.
Limits the mean to be within the range of the other profile and limits the sigma to be >= 0 and <= the width of the other profile.
- Parameters:
time_profile – Another time profile to use to define the parameter bounds of this time profile.
- Returns:
A list of tuples of bounds for fitting the parameters in this time profile.
- cdf(times: ndarray) ndarray
Docstring
- property exposure: float
Docstring
- classmethod generate_config() dict
Docstring
- inverse_transform_sample(start_times: ndarray, stop_times: ndarray) ndarray
Docstring
- logpdf(times: ndarray) ndarray
Calculates the log(probability) for each time.
- Parameters:
times – A numpy list of times to evaluate.
- Returns:
A numpy array of log(probability) at the given times.
- property param_bounds: dict
Docstring
- property param_dtype: dtype
Returns the parameter names and datatypes formatted for numpy dtypes.
- property params: dict
Docstring
- pdf(times: ndarray) ndarray
Calculates the probability for each time.
- Parameters:
times – A numpy list of times to evaluate.
- Returns:
A numpy array of probability amplitudes at the given times.
- random(size: int = 1) ndarray
Returns random values following the gaussian distribution.
- Parameters:
size – The number of random values to return.
- Returns:
An array of times.
- property range: Tuple[float, float]
Gets the maximum and minimum values for the times in this profile.
- scipy_dist: rv_frozen
- x0(times: ndarray) tuple
Returns good guesses for mean and sigma based on given times.
- Parameters:
times – A numpy list of times to evaluate.
- Returns:
A tuple of mean and sigma guesses.
- class mla.time_profiles.GenericProfile(config: dict)
Bases:
ConfigurableA generic base class to standardize the methods for the time profiles.
While I’m only currently using scipy-based probability distributions, you can write your own if you want. Just be sure to define these methods and ensure that the PDF is normalized!
- exposure
- Type:
float
- range
The range of allowed times for for events injected using this time profile.
- Type:
Tuple[Optional[float], Optional[float]]
- default_params
A dictionary of fitting parameters for this time profile.
- Type:
Dict[str, float]
- param_dtype
The numpy dytpe for the fitting parameters.
- Type:
List[Tuple[str, str]]
- abstract bounds(time_profile: GenericProfile) List[Tuple[Optional[float], Optional[float]]]
Get a list of tuples of bounds for the parameters of this profile.
Uses another time profile to constrain the bounds. This is usually needed to constrain the bounds of a signal time profile given a background time profile.
- Parameters:
time_profile – Another time profile to constrain from.
- Returns:
A list of tuples of bounds for fitting the parameters of this time profile.
- abstract cdf(times: ndarray) ndarray
Docstring
- config: dict
- abstract property default_params: Dict[str, float]
Returns the initial parameters formatted for ts calculation output.
- abstract property exposure: float
Docstring
- abstract inverse_transform_sample(start_times: ndarray, stop_times: ndarray) ndarray
Docstring
- abstract logpdf(times: ndarray) ndarray
Get the log(probability) given a time for this time profile.
- Parameters:
times – An array of times to get the log(probability) of.
- Returns:
A numpy array of log(probability) at the given times.
- abstract property param_bounds: dict
Docstring
- abstract property param_dtype: dtype
Returns the parameter names and datatypes formatted for numpy dtypes.
- abstract property params: dict
Docstring
- abstract pdf(times: ndarray) ndarray
Get the probability amplitude given a time for this time profile.
- Parameters:
times – An array of event times to get the probability amplitude for.
- Returns:
A numpy array of probability amplitudes at the given times.
- abstract random(size: int) ndarray
Get random times sampled from the pdf of this time profile.
- Parameters:
size – The number of times to return.
- Returns:
An array of times.
- abstract property range: Tuple[float, float]
Gets the maximum and minimum values for the times in this profile.
- abstract x0(times: ndarray) Tuple
Gets a tuple of initial guess to use when fitting parameters.
The guesses are arrived at by simple approximations using the given times.
- Parameters:
times – An array of times to use to approximate the fitting parameters of this time profile.
- Returns:
A tuple of approximate parameters.
- class mla.time_profiles.UniformProfile(config: dict)
Bases:
GenericProfileTime profile class for a uniform distribution.
Use this for background or if you want to assume a steady signal from your source.
- exposure
- Type:
float
- range
The range of allowed times for for events injected using this time profile.
- Type:
Tuple[Optional[float], Optional[float]]
- default_params
A dictionary of fitting parameters for this time profile.
- Type:
Dict[str, float]
- param_dtype
The numpy dytpe for the fitting parameters.
- Type:
List[Tuple[str, str]]
- bounds(time_profile: GenericProfile) List[Tuple[Optional[float], Optional[float]]]
Given some other profile, returns allowable ranges for parameters.
- Parameters:
time_profile – Another time profile used to get the limits of start and length.
- Returns:
A list of tuples of bounds for fitting.
- cdf(times: ndarray) ndarray
Docstring
- property exposure: float
Docstring
- classmethod generate_config() dict
Docstring
- inverse_transform_sample(start_times: ndarray, stop_times: ndarray) ndarray
Docstring
- logpdf(times: ndarray) ndarray
Calculates the log(probability) for each time.
- Parameters:
times – A numpy list of times to evaluate.
- Returns:
A numpy array of log(probability) at the given times.
- property param_bounds: dict
Docstring
- property param_dtype: dtype
Returns the parameter names and datatypes formatted for numpy dtypes.
- property params: dict
Docstring
- pdf(times: ndarray) ndarray
Calculates the probability for each time.
- Parameters:
times – A numpy list of times to evaluate.
- Returns:
A numpy array of probability amplitudes at the given times.
- random(size: int = 1) ndarray
Returns random values following the uniform distribution.
- Parameters:
size – The number of random values to return.
- Returns:
An array of times.
- property range: Tuple[float, float]
Gets the maximum and minimum values for the times in this profile.
- x0(times: ndarray) Tuple[float, float]
Returns good guesses for start and stop based on given times.
- Parameters:
times – A numpy list of times to evaluate.
- Returns:
A tuple of start and stop guesses.
mla.tools module
Module contents
__init__.py