HDF5_BLS_treat.Treat
- class HDF5_BLS_treat.Treat(frequency: ndarray, PSD: ndarray)[source]
Bases:
Treat_backendThis class is a class inherited from the Treat_backend class used to define functions to treat the data. Each function is meant to perform the minimum of operation so as to give the user a total control over the treatment.
- __init__(frequency: ndarray, PSD: ndarray)[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.
add_point([position_center_window, ...])Adds a single point to the list of points together with a window to the list of windows with its type.
add_window([position_center_window, ...])Adds a single window to the list of windows together with the central point (with type "Window") to the list of windows.
adjust_treatment_on_errors([position, ...])Reapplies the treatment on the point error located at the position "position" with the new parameters "new_parameters".
Takes all the steps of the algorithm up to the moment this function is called and applies the steps to each individual spectrum in the dataset.
blind_deconvolution([default_width])Subtracts a constant width to all the linewidth array and recomputes the BLT array.
combine_results_FSR([FSR, ...])Combines the results of the algorithm to have a value for frequency shift based on a known Free Spectral Range (FSR) value.
define_model([model, elastic_correction])Defines the model to be used to fit the data.
estimate_width_inelastic_peaks([max_width_guess])Estimates the full width at half maximum of the inelastic peaks stored in self.points.
fit_all_inelastic_of_curve([default_width, ...])Fits a lineshape to each of the inelastic peaks using the points stored as Stokes or Anti-Stokes peaks in the points attribute.
mark_errors_BLT([min_BLT, max_BLT])Marks the points that present a value of BLT above or below given thresholds.
mark_errors_linewidth([min_linewidth, ...])Marks the points that present a value of linewidth above or below given thresholds.
mark_errors_shift([min_shift, max_shift])Marks the points that present a value of shift above or below given thresholds.
mark_errors_std_BLT([max_error_BLT_variance])Marks the points that present a variance of the BLT greater than a certain threshold.
mark_errors_std_linewidth([...])Marks the points that present a variance of the linewidth greater than a certain threshold.
mark_errors_std_shift([max_error_shift_variance])Marks the points that present a variance of the shift greater than a certain threshold.
mark_point_error(position)Forces a point located at the position "position" to be considered as an error.
multi_fit_all_inelastic([default_width, ...])Fits all inelastically scattered peak as a single curve.
normalize_data([threshold_noise])Normalizes the data by identifying the regions corresponding to noise, substracting the average of these regions from the data, and dividing by the average of the amplitude of all peaks that are not of type elastic.
silent_clear_points()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.
silent_return_string_algorithm()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.
single_fit_all_inelastic([default_width, ...])Fits each inelastically scattered peak individually.
- add_point(position_center_window: float = None, window_width: float = None, type_pnt: str = 'Other')[source]
Adds a single point to the list of points together with a window to the list of windows with its type. Each point is an intensity extremum obtained by fitting a quadratic polynomial to the windowed data. The point is given as a value on the frequency axis (not a position on this axis). The “position_center_window” parameter is the center of the window surrounding the peak. The “window_width” parameter is the width of the window surrounding the peak (full width). The “type_pnt” parameter is the type of the peak. It can be either “Stokes”, “Anti-Stokes”, “Elastic” or “Other”.
- Parameters:
position_center_window (float) – A value on the self.x axis corresponding to the center of a window surrounding a peak
window_width (float or 2-tuple of float) – A value on the self.x axis corresponding to the width of a window surrounding a peak. If a tuple is given, the first element is the lower bound of the window and the second element is the upper bound given in absolute value from center point.
type_pnt (str) – The nature of the peak. Must be one of the following: “Other”,”Stokes”, “Anti-Stokes” or “Elastic”
- add_window(position_center_window: float = None, window_width: float = None)[source]
Adds a single window to the list of windows together with the central point (with type “Window”) to the list of windows. The positions are given as values on the frequency axis (not a position). The “position_center_window” parameter is the center of the window surrounding the peak. The “window_width” parameter is the width of the window surrounding the peak (full width).
- Parameters:
position_center_window (float) – A value on the self.x axis corresponding to the center of a window surrounding a peak
window (float) – A value on the self.x axis corresponding to the width of a window surrounding a peak
- adjust_treatment_on_errors(position=None, new_parameters=None)[source]
Reapplies the treatment on the point error located at the position “position” with the new parameters “new_parameters”.
- Parameters:
position (list, optional) – The position of the point error to be adjusted. Default is None.
new_parameters (list of dictionnaries, optional) – The list of new parameters to be applied to re-run the treatment on the errors. Each element is either None (if we don’t change the parameters) or a dictionnary of the parameters to be passed to the function. Default is None, means that all the parameters used earlier are used.
- apply_algorithm_on_all()[source]
Takes all the steps of the algorithm up to the moment this function is called and applies the steps to each individual spectrum in the dataset. This function updates the global attributes of the class concerning the shift, the linewidth and the amplitude together with their variance, taking into account error propagation. If a spectrum could not be fitted, its value is set to 0 in the global attributes. All the points where the spectra could not be fitted are marked with the “fit_error_marker” parameter in the global attributes (shift, linewidth, amplitude, shift_var, linewidth_var, amplitude_var) and their coordinates are stored in the “point_error” list. The “point_error_type” attribute is also updated with the type of error returned by the fit function (see scipy.optimize.curve_fit documentation). The function returns the number of spectra that could not be fitted.
- blind_deconvolution(default_width: float = None)[source]
Subtracts a constant width to all the linewidth array and recomputes the BLT array. If default_width is not specified, the width is estimated by fitting a Lorentzian to the most proeminent elastic peak. If no elastic peak are specified, and default_width is not specified, no deconvolution is performed.
- Parameters:
default_width (float, optional) – The value of the width to subtract to the linewidth array, by default None. If None, the width is estimated by fitting a Lorentzian to the most proeminent elastic peak.
- combine_results_FSR(FSR: float = 15, keep_max_amplitude: bool = False, amplitude_weight: bool = False, shift_err_weight: bool = False, position: list = None)[source]
Combines the results of the algorithm to have a value for frequency shift based on a known Free Spectral Range (FSR) value. The end shift value is obtained by “moving” the peak by a FSR value until the peak is within the [-FSR/2, FSR/2] range. Then the absolute value of the shift is taken as the end shift value. The combination of the result is done by taking the average of all the values by default. Alternatively, the user can choose to keep the maximum of the amplitude of the peak by setting the “keep_max_amplitude” parameter to True. The user can also choose to weight the shift and linewidth by the amplitude of the peak by setting the “amplitude_weight” parameter to True. Note that in the latter case, the precise knowledge of the frequency axis is a must as averaging slightly uncentered peaks will lead to a wrong result.
- Parameters:
FSR (float, optional) – The Free Spectral Range of the spectrometer, by default 15Ghz
keep_max_amplitude (bool, optional) – If True, the maximum of the peak amplitude is stored in the amplitude array. If False, an average of all the amplitudes is stored. Default is False.
amplitude_weight (bool, optional) – If True, the amplitude of the spectra is used to weight the shift and linewidth. If set to false, a simple average is performed. Default is False.
shift_err_weight (bool, optional) – If True, the inverse of the standard deviation of the shift is used to weight the shift and linewidth. If set to false, a simple average is performed. Default is False.
position (list, optional) – The position of the spectrum to be updated in case we combine the sampled results. This is used to update the values of a spectrum that has been re-fitted.
- define_model(model: str = 'Lorentzian', elastic_correction: bool = False)[source]
Defines the model to be used to fit the data.
- Parameters:
model (str, optional) – The model to be used. The models should match the names of the attribute “models” of the class Models, by default “Lorentzian”
elastic_correction (bool, optional) – Whether to correct for the presence of an elastic peak by setting adding a linear function to the model, by default False
- estimate_width_inelastic_peaks(max_width_guess: float = 2)[source]
Estimates the full width at half maximum of the inelastic peaks stored in self.points. Note that the data is supposed to have a zero offset. The estimation is done by finding the samples of the data closes to half of the peak height.
- Parameters:
max_width_guess (float, optional) – The higher limit to the estimation of the full width. Default is 2 GHz.
- fit_all_inelastic_of_curve(default_width: float = 1, guess_offset: bool = False, update_point_position: bool = True, bound_shift: list = None, bound_linewidth: list = None)[source]
Fits a lineshape to each of the inelastic peaks using the points stored as Stokes or Anti-Stokes peaks in the points attribute. The linewidth can be estimated beforehand using the function estimate_width_inelastic_peaks. If not estimated, a fixed width is used (default_width). The offset can also be guessed or not (guess_offset). In the case the offset is guessed, the minimum of the data on the selected window is used as an initial guess. The position of the peak can also be updated based on the fitted shift if update_point_position is set to True. If set to False, the positions are not updated.
- Parameters:
default_width (float, optional) – If the width has not been estimated, the default width to use, by default 1 GHz
guess_offset (bool, optional) – If True, the offset is guessed based on the minimum of the data on the selected window. If false, the data is supposed to be normalized and the offset guess is set to 0, by default False
update_point_position (bool, optional) – If True, the position of the peak is updated based on the fitted shift. If False, the position of the peak is not updated, by default True
bound_shift (list, optional) – The lower and upper bounds of the shift, by default None means no restrictions are applied
bound_linewidth (list, optional) – The lower and upper bounds of the linewidth, by default None means no restrictions are applied
- mark_errors_BLT(min_BLT: float = 0, max_BLT: float = 10)[source]
Marks the points that present a value of BLT above or below given thresholds.
- Parameters:
min_shift (float, optional) – The threshold below which the shift is marked as an error , by default 0GHz
max_shift (float, optional) – The threshold above which the shift is marked as an error , by default 10GHz
- mark_errors_linewidth(min_linewidth: float = 0, max_linewidth: float = 10)[source]
Marks the points that present a value of linewidth above or below given thresholds.
- Parameters:
min_linewidth (float, optional) – The threshold below which the linewidth is marked as an error , by default 0GHz
max_linewidth (float, optional) – The threshold above which the linewidth is marked as an error , by default 10GHz
- mark_errors_shift(min_shift: float = 0, max_shift: float = 10)[source]
Marks the points that present a value of shift above or below given thresholds.
- Parameters:
min_shift (float, optional) – The threshold below which the shift is marked as an error , by default 0GHz
max_shift (float, optional) – The threshold above which the shift is marked as an error , by default 10GHz
- mark_errors_std_BLT(max_error_BLT_variance: float = 0.005)[source]
Marks the points that present a variance of the BLT greater than a certain threshold.
- Parameters:
max_error_shift_err (float, optional) – The threshold above which the shift is marked as an error , by default 5MHz
- mark_errors_std_linewidth(max_error_linewidth_variance: float = 0.005)[source]
Marks the points that present a variance of the linewidth greater than a certain threshold.
- Parameters:
max_error_linewidth_variance (float, optional) – The threshold above which the linewidth is marked as an error , by default 5MHz
- mark_errors_std_shift(max_error_shift_variance: float = 0.005)[source]
Marks the points that present a variance of the shift greater than a certain threshold.
- Parameters:
max_error_shift_err (float, optional) – The threshold above which the shift is marked as an error , by default 5MHz
- mark_point_error(position: list)[source]
Forces a point located at the position “position” to be considered as an error.
- Parameters:
position (list) – The position of the point error to be marked.
- Return type:
None
- multi_fit_all_inelastic(default_width: float = 1, guess_offset: bool = False, update_point_position: bool = True, bound_shift: list = None, bound_linewidth: list = None)[source]
Fits all inelastically scattered peak as a single curve. The linewidth of the individual peaks can be estimated beforehand using the function estimate_width_inelastic_peaks. If not estimated, a fixed width is used (default_width). The offset can also be guessed or not (guess_offset). In the case the offset is guessed, the minimum of the data on the window defined as the combination of all the peaks windoes is used as an initial guess. When applying the fit to data acquired successively, it might be interesting to update the initial position of the peak by selecting the last fitted position. This can be done by setting update_point_position to True.
- Parameters:
default_width (float, optional) – If the width has not been estimated, the default width to use, by default 1 GHz
guess_offset (bool, optional) – If True, the offset is guessed based on the minimum of the data on the selected window. If false, the data is supposed to be normalized and the offset guess is set to 0, by default False
update_point_position (bool, optional) – If True, the position of the peak is updated based on the fitted shift. If False, the position of the peak is not updated, by default True
bound_shift (list, optional) – The lower and upper bounds of the shift, by default None means no restrictions are applied
bound_linewidth (list, optional) – The lower and upper bounds of the linewidth, by default None means no restrictions are applied
- normalize_data(threshold_noise: float = 0.01)[source]
Normalizes the data by identifying the regions corresponding to noise, substracting the average of these regions from the data, and dividing by the average of the amplitude of all peaks that are not of type elastic.
- Parameters:
threshold_noise (float, optional) – The threshold for identifying noise regions. This value is the highest possible value for noise relative to the average intensity of the selected peaks, on the PSD when the minimal value of the PSD is brought to 0. Default is 1%
- Return type:
None
- single_fit_all_inelastic(default_width: float = 1, guess_offset: bool = False, update_point_position: bool = True, bound_shift: list = None, bound_linewidth: list = None)[source]
Fits each inelastically scattered peak individually. The linewidth can be estimated beforehand using the function estimate_width_inelastic_peaks. If not estimated, a fixed width is used (default_width). The offset can also be guessed or not (guess_offset). In the case the offset is guessed, the minimum of the data on the selected window is used as an initial guess. When applying the fit to data acquired successively, it might be interesting to update the initial position of the peak by selecting the last fitted position. This can be done by setting update_point_position to True.
- Parameters:
default_width (float, optional) – If the width has not been estimated, the default width to use, by default 1 GHz
guess_offset (bool, optional) – If True, the offset is guessed based on the minimum of the data on the selected window. If false, the data is supposed to be normalized and the offset guess is set to 0, by default False
update_point_position (bool, optional) – If True, the position of the peak is updated based on the fitted shift. If False, the position of the peak is not updated, by default True
bound_shift (list, optional) – The lower and upper bounds of the shift, by default None means no restrictions are applied
bound_linewidth (list, optional) – The lower and upper bounds of the linewidth, by default None means no restrictions are applied