Module input
Structure and loading of input files.
- class multifit.input.Config(data: DataConfig, model: ModelConfig, fit: FitConfig)
Bases:
objectClass holding the full multifit configuration.
See attribute classes for more detail.
- data
Configuration for reading the data.
- Type:
- model
Configuration of the model.
- Type:
- classmethod from_yaml(file: TextIO | Path | str, error_if_incomplete=True)
Initialize configuration from yaml configuration file.
- Parameters:
file (TextIO or path or str) – Configuration file to read.
error_if_incomplete (bool, default True) – If true, raise an error when the configuration file is incomplete. If false, issue a warning.
- class multifit.input.DataConfig(directory, files, bin_width: float, column: int = 0, delimiter: str = None)
Bases:
objectClass for configuration of the input data.
Data should be in the form of histograms with equal width bins.
- directory
Directory from which to read the data files.
- Type:
path
- files
List of data files relative to directory
- Type:
list of path
- bin_width
Bin width of the data histograms.
- Type:
float
- column
Column of the data file containing the histogram content.
- Type:
int
- delimiter
Column delimiter for data stored in a text file.
- Type:
str
- class multifit.input.ModelConfig(module, function: str, number_of_peaks: int, spectrum_params: list[str], peak_params: list[str], kwargs: dict)
Bases:
objectClass for configuration of the model
The model consists of a cumulative density function describing a single peak structure. The function may be repeated to model several peak structures. Each function parameter may be shared by all peaks in a spectrum or all instances of a peak across spectra.
- module
Path to the python module where the model function is defined.
- Type:
path
- function
Name of the function defining the model.
- Type:
str
- number_of_peaks
Number of peak structures to model for each spectrum.
- Type:
int
- spectrum_params
Name of parameters to be shared by all peaks in a spectrum.
- Type:
list of str
- peak_params
Name of parameters to be shared by all instances of the same peak across spectra.
- Type:
list of str
- kwargs
Additional keyword arguments required by the function.
- Type:
dict
- class multifit.input.FitConfig(range: tuple | list[tuple], parameter_ranges, initial_values: dict[float])
Bases:
objectClass for configuration of the fit.
- range
Range of data to fit. A single tuple is read as a range. A list of tuples is read as a union of ranges.
- Type:
tuple or list of tuple
- parameter_ranges
Allowed range for each fit parameter.
- Type:
dict of tuple
- initial_values
Initial values for each fit parameter.
- Type:
dict[float]
- multifit.input.fetch_data(config: DataConfig, cls, sorting_key=0, npy=True) list[Spectrum | CoincidenceMatrix]
Read data files.
WARNING: This function will be depracated in the future.
- Parameters:
config (DataConfig) – Data configuration object.
cls ({Spectrum, CoincidenceMatrix}) – Class to read the data into.
sorting_key – key to use when sorting the data object list. May be a constant or a callable taking the file name as a positional argument.
npy (bool) – If true, try to read the data from a .npy file. If such a file doesn’t exist, generate it. (default True)
- Returns:
Sorted list of data objects read from each file.
- Return type:
list of cls
- multifit.input.import_cdf(path: Path, function: str) callable
Import a function from an arbitrary module.
- Parameters:
path (path) – Path to the python module containing the function.
function (str) – Name of the function to import.
- Returns:
The imported function.
- Return type:
callable