Welcome to Tihi documentation!
Contents:
Indices and tables
tihi package
tihi module
app module
- class tihi.app.Window
Bases:
QMainWindowMain window of the application
- finish_wizard()
- normalize()
- plot_approx()
- plot_decompositions()
- plot_input_data()
Plot the input data called by the self.read_file function
- read_file()
- Reads a signal file data in the following format:
first column : independent variable data
second column : dependent variable data
- run_wizard()
- save_parameters()
- set_max_value()
sets the max x-value of the input signal
- set_min_value()
sets the min x-value of the input signal
- set_title()
Set the title of the plot
- set_xlabel()
Set the x-axis label of the plot
- set_ylabel()
Set the y-axis label of the plot
- tihi.app.main()
wizard module
- class tihi.wizard.MagicWizard(x_vals, y_vals, x_label='x-axis', y_label='y-axis', title='title')
Bases:
QWizardWizard for peak profiling using PyQt5 and custom pages.
- out_profiles
List to store output profiles.
- Type:
list
- out_params
List to store output parameters.
- Type:
list
- out_model
Placeholder for output model.
- page_num
Current page number.
- Type:
int
- interpolate
Interpolation page instance.
- Type:
ipp
- baseline
Baseline fitting page instance.
- Type:
blp
- peak_detect
Peak detection page instance.
- Type:
pdp
- distribution
Distribution fitting page instance.
- Type:
dfp
- back_button()
Placeholder method for handling the back button.
- Returns:
None
- finish_line()
Placeholder method for finishing the wizard.
- Returns:
None
- handlePageChange()
Handle changes in wizard pages.
Disables the “go back” button on the first page.
- initializePage(pageId)
Initialize wizard pages and manage the “go back” button’s visibility.
- Parameters:
pageId – ID of the wizard page being initialized.
- Returns:
None
- next_button()
Move to the next wizard page based on the current page number.
- Returns:
None
tihi_utils package
tihi_utils module
tihi_utils.baseline_corrector module
- tihi.tihi_utils.baseline_corrector.airPLS(y, lamb=100, niter=15)
Perform AirPLS baseline correction algorithm on spectral data.
:param y (ndarray) : Input signal (spectral data). :param lamb (float, optional (default=100)) : Parameter controlling the smoothness of the baseline. :param niter (int, optional (default=15)) : Maximum number of iterations. :return (ndarray) : airPLS baseline.
- tihi.tihi_utils.baseline_corrector.arPLS(y, ratio=1e-06, lam=100, niter=100, full_output=False)
Perform arPLS baseline correction algorithm on spectral data.
:param y (ndarray) : Input signal (spectral data). :param ratio (float, optional (default=1e-6)) : Convergence threshold. :param lam (float, optional (default=100)) : Parameter controlling the smoothness of the baseline. :param niter (int, optional (default=100)) : Maximum number of iterations. :param full_output (bool, optional (default=False)) : If True, return additional information about the iteration. :return (ndarray) : arPLS baseline. :return (dict, if full_output=True) : Dictionary containing information about the iteration (num_iter, stop_criterion).
- tihi.tihi_utils.baseline_corrector.linear_baseline_correction(x_val, y_val, window_length=31, percentile=5)
Perform linear baseline correction using a percentile threshold on smoothed data.
:param x_val (ndarray) : x values of the data points. :param y_val (ndarray) : y values of the data points. :param window_length (int, optional (default=31)) : Length of the window for median filtering. :param percentile (int, optional (default=5)) : Percentile threshold for selecting baseline points. :return (ndarray) : Linear baseline y values.
tihi_utils.distributions module
- class tihi.tihi_utils.distributions.GaussianFitter(InterpolatedData, peaks, max_iter=100)
Bases:
object- approximator(max_iter)
Perform Gaussian fitting using least squares optimization.
:param max_iter (int) : Maximum number of iterations for fitting. :return error (float) : Mean absolute error of the fitting. :Notes : Uses soft L1 loss and bounds parameters to constrain optimization.
- gaussian(x, center, amplitude, sigma)
Calculate a Gaussian function.
:param x (ndarray) : X values. :param center (float) : Center of the Gaussian function. :param amplitude (float) : Amplitude of the Gaussian function. :param sigma (float) : Standard deviation of the Gaussian function. :return (ndarray) : Calculated Gaussian function values.
- gaussian_sum(x, params)
Calculate the sum of Gaussian functions.
:param x (ndarray) : X values. :param params (ndarray) : Array of parameters for Gaussian functions. :return (ndarray) : Sum of Gaussian functions.
- residual(params, x_vals, y_vals)
Calculate residual between data and Gaussian fit.
:param params (ndarray) : Array of parameters for Gaussian functions. :param x_vals (ndarray) : X values of the data. :param y_vals (ndarray) : Y values of the data. :return (ndarray) : Residual values.
- class tihi.tihi_utils.distributions.LorentzianFitter(InterpolatedData, peaks, max_iter=100)
Bases:
objectLorentzian peak fitting class.
:param InterpolatedData (object) : Interpolated data object containing x_val and y_val. :param peaks (array_like) : Indices of peaks in the data. :param max_iter (int, optional (default=100)) : Maximum number of iterations for fitting. :attribute x_vals (ndarray) : X values from InterpolatedData. :attribute y_vals (ndarray) : Y values from InterpolatedData. :attribute centers (ndarray) : Initial centers of Lorentzian peaks. :attribute amplitudes (ndarray) : Initial amplitudes of Lorentzian peaks. :attribute gammas (list) : Initial full width at half maximum (FWHM) of Lorentzian peaks. :attribute params (ndarray) : Array of initial parameters for least squares fitting. :attribute start_params (list) : Flattened list of initial parameters. :attribute decompositions (list) : List to store individual Lorentzian functions.
- approximator(max_iter)
Perform Lorentzian fitting using least squares optimization.
:param max_iter (int) : Maximum number of iterations for fitting. :return error (float) : Mean absolute error of the fitting. :Notes : Uses soft L1 loss and bounds parameters to constrain optimization.
- lorentzian(x, center, amplitude, gamma)
Calculate a Lorentzian function.
:param x (ndarray) : X values. :param center (float) : Center of the Lorentzian function. :param amplitude (float) : Amplitude of the Lorentzian function. :param gamma (float) : Full width at half maximum (FWHM) of the Lorentzian function. :return (ndarray) : Calculated Lorentzian function values.
- lorentzian_sum(x, params)
Calculate the sum of Lorentzian functions.
:param x (ndarray) : X values. :param params (ndarray) : Array of parameters for Lorentzian functions. :return (ndarray) : Sum of Lorentzian functions.
- residual(params, x_vals, y_vals)
Calculate residual between data and Lorentzian fit.
:param params (ndarray) : Array of parameters for Lorentzian functions. :param x_vals (ndarray) : X values of the data. :param y_vals (ndarray) : Y values of the data. :return (ndarray) : Residual values.
- class tihi.tihi_utils.distributions.VoigtFitter(InterpolatedData, peaks, max_iter=50)
Bases:
object- approximator(max_iter)
Perform Voigt fitting using least squares optimization.
:param max_iter (int) : Maximum number of iterations for fitting. :return error (float) : Mean absolute error of the fitting. :Notes : Uses soft L1 loss and bounds parameters to constrain optimization.
- residual(params, x_vals, y_vals)
Calculate residual between data and Voigt fit.
:param params (ndarray) : Array of parameters for Voigt profiles. :param x_vals (ndarray) : X values of the data. :param y_vals (ndarray) : Y values of the data. :return (ndarray) : Residual values.
- voigt(x, center, amplitude, gauss_width, lorentz_width)
Calculate a Voigt profile using Faddeeva function approximation.
:param x (ndarray) : X values. :param center (float) : Center of the Voigt profile. :param amplitude (float) : Amplitude of the Voigt profile. :param gauss_width (float) : Gaussian component width of the Voigt profile. :param lorentz_width (float) : Lorentzian component width of the Voigt profile. :return (ndarray) : Calculated Voigt profile values.
- voigt_sum(x, params)
Calculate the sum of Voigt profiles.
:param x (ndarray) : X values. :param params (ndarray) : Array of parameters for Voigt profiles. :return (ndarray) : Sum of Voigt profiles.
tihi_utils.interpolate module
- class tihi.tihi_utils.interpolate.Interpolate(input_x, input_y, degree_spline=3, gratings=1000, denoising_window_size=10, denoising_order=3)
Bases:
object- denoise_signal()
Apply Savitzky-Golay filter for signal denoising.
- interpolate(x_in, y_in)
Perform spline interpolation.
- Parameters:
x_in (1D np array) – input x values
y_in (1D np array) – input y values
tihi_utils.peak_detection module
- tihi.tihi_utils.peak_detection.find_peaks(class_interpolate, window_size=10, threshold=0.01, min_amp=0.0)
Find peaks in the interpolated signal based on the second derivative.
- Parameters:
class_interpolate (Interpolate) – Instance of Interpolate containing interpolated data.
window_size (int, optional) – Size of the window for peak detection. Defaults to 10.
threshold (float, optional) – Threshold for peak detection. Defaults to 0.01.
min_amp (float, optional) – Minimum amplitude of peaks. Defaults to 0.0.
- Returns:
List of indices where peaks are detected.
- Return type:
peaks (list)
- tihi.tihi_utils.peak_detection.second_derivative(class_interpolate)
Compute the second derivative of the interpolated signal.
- Parameters:
class_interpolate (Interpolate) – Instance of Interpolate containing interpolated data.
- Returns:
Array of second derivative values.
- Return type:
second_deriv (np.array)
tihi_wizardPages package
tihi_wizardPages module
tihi_wizardPages.baselinePage module
- class tihi.tihi_wizardPages.baselinePage.BaselinePage(x_vals, y_vals, x_label='x-axis', y_label='y-axis', title='title')
Bases:
QWizardPageWizard page for baseline correction using various methods.
x_vals : x-axis values of the data y_vals : y-axis values of the data x_label : label for the x-axis y_label : label for the y-axis title : title for the plot
- clear()
Clears the plot and resets the x and y values to the original data.
- lambda_changes()
Updates the lambda parameter for PLS methods based on user input.
- method_changes()
Updates the baseline correction method based on user selection.
- plot_input_data()
Plots the input data along with the baseline if it exists.
- ratio_changes()
Updates the ratio parameter for arPLS based on user input.
- run()
Executes the baseline correction based on the selected method.
- class tihi.tihi_wizardPages.baselinePage.QIComboBox(parent=None)
Bases:
QComboBoxCustom ComboBox class inheriting from QComboBox.
tihi_wizardPages.distributionPage module
- class tihi.tihi_wizardPages.distributionPage.DistributionFittingPage(interpolation_class, x_label='x-axis', y_label='y-axis', title='title')
Bases:
QWizardPageWizard page for fitting distributions to data.
interpolation_class : Instance of a class containing x_val and y_val attributes for data. x_label : Label for the x-axis. y_label : Label for the y-axis. title : Title for the plot.
- clear()
Clears the plot and re-plots the original data.
- distribution_type_changes()
Updates the selected distribution type based on user input.
- max_iter_changes()
Updates the maximum iteration value based on user input.
- method_changes()
Updates the optimizer loss type based on user input.
- plot_all()
Plots all decompositions.
- plot_input_data(plot_approximation=False, plot_all_distributions=False)
Plots the input data along with the approximation or all decompositions if specified.
plot_approximation : If True, plot the approximation. (the sum of distributions) plot_all_distributions: If True, plot all decompositions.
- run()
Executes the decomposition based on the selected distribution type.
- class tihi.tihi_wizardPages.distributionPage.QIComboBox(parent=None)
Bases:
QComboBoxCustom ComboBox class inheriting from QComboBox.
tihi_wizardPages.interpolatePage module
- class tihi.tihi_wizardPages.interpolatePage.InterpolationPage(x_vals, y_vals, x_label='x-axis', y_label='y-axis', title='title')
Bases:
QWizardPageWizard page for interpolating and denoising data.
x_vals : Input x-axis values. y_vals : Input y-axis values. x_label : Label for the x-axis. y_label : Label for the y-axis. title : Title for the plot.
- change_denoise_window_size()
Updates the denoise window size based on user input.
- change_numpoints()
Updates the number of points to use for interpolation based on user input.
- clear()
Clears the plot and re-plots the original data.
- denoise()
Denoises the interpolated data and updates the plot.
- interpolate_data()
Interpolates the original data and updates the plot.
- plot_input_data(denoise=False)
Plots the input data.
denoise: If True, plot with denoising (green line).
tihi_wizardPages.peak_detectionPage module
- class tihi.tihi_wizardPages.peak_detectionPage.PeakDetectionPage(interpolation_class, x_label='x-axis', y_label='y-axis', title='title')
Bases:
QWizardPageWizard page for peak detection on interpolated data.
interpolation_class : Interpolation class containing x_val and y_val attributes from the Interpolation Page. x_label : Label for the x-axis. y_label : Label for the y-axis. title : Title for the plot.
- clear()
Clears the plot area.
- min_amp_changes()
Updates the minimum amplitude for peak detection based on user input.
- plot_input_data(peak=False)
Plot the input data called by the self.read_file function
- run()
Executes peak detection using specified parameters and updates the plot.
- threshold_changes()
Updates the second-derivative difference threshold for peak detection based on user input.
- window_size_changes()
Updates the window size for peak detection based on user input.