HDF5_BLS_treat.Treat_backend
- class HDF5_BLS_treat.Treat_backend(frequency: ndarray, PSD: ndarray, frequency_sample_dimension=None)[source]
Bases:
objectThis class is the base class for all the treat classes. Its purpose is to provide the basic silent functions to open, create and save algorithms, and to store the different steps of the treatment and their effects on the data.
Notes
The philosophy of this class is to rely on 2 fixed attributes:
frequency: the array of frequency axis corresponding to the PSD
PSD: the array of power spectral density to be treated
And to update the following attributes: - shift: the shift array obtained after the treatment - shift_var: the array of standard deviation of the shift array obtained after the treatment - linewidth: the linewidth array obtained after the treatment - linewidth_var: the array of standard deviation of the linewidth array obtained after the treatment - amplitude: the amplitude array obtained after the treatment - amplitude_var: the array of standard deviation of the amplitude array obtained after the treatment
The treatment itself is stored in the _algorithm attribute and each change to a classe’s attribute is stored in the _history attribute:
_algorithm: a dictionary that stores the name of the algorithm, its version, the author, and a description
_record_algorithm: a boolean that indicates whether the algorithm should be recorded or not while running the functions of the class
When a treatment fails or is identified as not well fitted, the class stores the information in the following attributes:
point_errors: the list of points that are not well fitted
Additionally, the class uses sub-attributes to test the treatment on particular spectra. These sub-attributes are:
frequency_sample: A 1-D sampled frequency array
PSD_sample: A 1-D sampled PSD array
offset_sample: A list of offset values obtained on the sampled PSD array (size of lists corresponds to number of peaks analysed)
shift_sample: A list of shift values obtained on the sampled PSD array(size of lists corresponds to number of peaks analysed)
shift_err_sample: A list of the standard deviation on the shift values obtained on the sampled PSD array(size of lists corresponds to number of peaks analysed)
linewidth_sample: A list of linewidth values obtained on the sampled PSD array(size of lists corresponds to number of peaks analysed)
linewidth_err_sample: A list of the standard deviation on the linewidth values obtained on the sampled PSD array(size of lists corresponds to number of peaks analysed)
amplitude_sample: A list of amplitude values obtained on the sampled PSD array (size of lists corresponds to number of peaks analysed)
amplitude_err_sample: A list of the standard deviation on the amplitude values obtained on the sampled PSD array(size of lists corresponds to number of peaks analysed)
For treating these samples, the class offers an argument to store the steps of the treatment. This is stored in the _history attribute. - _history: a list that stores the evolution of the attributes
To switch the class between the treatment of all the PSD array, sampled PSD arrays or error points, we use the attribute:
- _treat_selection: a string that directs the treatment towards the whole PSD array, sampled PSD arrays or error points with the following options:
all: the whole PSD array is treated
sampled: the sampled PSD arrays are treated
errors: the error points are treated
Note that the _history attribute is implemented only if _treat_selection is set to “sampled”.
- __init__(frequency: ndarray, PSD: ndarray, frequency_sample_dimension=None)[source]
Initializes the class by storing the PSD and frequency arrays. Also initializes the sample sub-arrays using the frequency_sample_dimension parameter.
- Parameters:
frequency (np.ndarray) – An array corresponding to the frequency axis of the PSD
PSD (np.ndarray) – An array corresponding to the power spectral density to treat
frequency_sample_dimension (tuple, optional) – The tuple leading to the 1-D array to use as frequency axis. By default, the first dimension of the frequency is used.
Methods
__init__(frequency, PSD[, ...])Initializes the class by storing the PSD and frequency arrays.
Clears the list of points and the list of windows.
silent_create_algorithm([algorithm_name, ...])Creates a new JSON algorithm with the given name, version, author and description.
silent_move_step(step, new_step)Moves a step from one position to another in the _algorithm attribute.
silent_open_algorithm([filepath])Opens an existing JSON algorithm and stores it in the _algorithm attribute.
silent_remove_step([step])Removes the step from the _history attribute of the class.
Returns a string representation of the algorithm stored in the _algorithm attribute of the class.
silent_run_algorithm([step, algorithm])Runs an algorithm.
silent_save_algorithm([filepath, ...])Saves the algorithm to a JSON file with or without the parameters used.
- silent_create_algorithm(algorithm_name: str = 'Unnamed Algorithm', version: str = '0.1', author: str = 'Unknown', description: str = '', new_algorithm=False)[source]
Creates a new JSON algorithm with the given name, version, author and description. This algorithm is stored in the _algorithm attribute. This function also creates an empty history. for the software.
- Parameters:
algorithm_name (str, optional) – The name of the algorithm, by default “Unnamed Algorithm”
version (str, optional) – The version of the algorithm, by default “0.1”
author (str, optional) – The author of the algorithm, by default “Unknown”
description (str, optional) – The description of the algorithm, by default “”
- silent_move_step(step: int, new_step: int)[source]
Moves a step from one position to another in the _algorithm attribute. Deletes the elements of the _history attribute that are after the moved step (included)
- Parameters:
step (int) – The position of the function to move in the _algorithm attribute.
new_step (int) – The new position to move the function to.
- silent_open_algorithm(filepath: str = None)[source]
Opens an existing JSON algorithm and stores it in the _algorithm attribute. This function also creates an empty history.
- Parameters:
filepath (str, optional) – The filepath to the JSON algorithm, by default None
- silent_remove_step(step: int = None)[source]
Removes the step from the _history attribute of the class. If no step is given, removes the last step.
- Parameters:
step (int, optional) – The number of the function up to which the algorithm has to be run. Default is None, means that the last step is removed.
- silent_return_string_algorithm()[source]
Returns a string representation of the algorithm stored in the _algorithm attribute of the class.
- Returns:
The string representation of the algorithm.
- Return type:
str
- silent_run_algorithm(step: int = None, algorithm: dict = None)[source]
Runs an algorithm. By default, the algorithm run is the one stored in the _algorithm attribute of the class. This function can also run other algorithms if specified. The function runs the algorithm up to the given step (included). If no step is given, the algorithm is run up to the last step (included).
- Parameters:
step (int, optional) – The number of the function up to which the algorithm has to be run (included), by default None means that all the steps of the algorithm are run.
algorithm (dict, optional) – The algorithm to be run. If None, the algorithm stored in the _algorithm attribute is used. Default is None.
- silent_save_algorithm(filepath: str = 'algorithm.json', save_parameters: bool = False)[source]
Saves the algorithm to a JSON file with or without the parameters used. If the parameters are not saved, their value is set to a default value proper to their type.
- Parameters:
filepath (str, optional) – The filepath to save the algorithm to. Default is “algorithm.json”.
save_parameters (bool, optional) – Whether to save the parameters of the functions. Default is False.