Skip to main content

A package to treat BLS power spectra densities and extract relevant infomration.

Project description

The HDF5_BLS_treat package

This package is a part of the HDF5_BLS project. It's purpose is to unify the extraction of relevant information from power spectra data.

Installation

To install the package, you can use pip:

pip install HDF5_BLS_treat

To install the package from source for local development, please refer to the documentation.

Documentation

You can access the documentation of the project at this link or on the dedicated ReadTheDocs page at this link.

Example of usage

from HDF5_BLS_treat import Treat, Models
import numpy as np
import sys

def progress(current, total):
    """
    Function to display the progress of the treatment.
    """
    percent = (current / total) * 100
    sys.stdout.write(f"\rProgress: sample {current} of {total} - {percent:.2f}% treated")
    sys.stdout.flush()

# We first recover the model we are going to use to simulate the data
models = Models()
models = models.models
lorentzian = models["DHO"]

# We then create a frequency axis and a PSD based on the model
frequency = np.linspace(-10,10,512)
psd = lorentzian(frequency, 0, 1, -5, 1) + lorentzian(frequency, 0, 1, 5, 1) + 0.1 * np.random.normal(size = frequency.shape)

# We set the list parameters for the analysis
points = [-5, 5] # An initial guess for the center of the peak
windows_find = [3, 3] # The size of the windows around the peaks given to refine their position
windows_fit = [[3, 1.5], [1.5, 3]] # The windows around the peaks to fit them
point_type = ["Anti-Stokes", "Stokes"] # The nature of the peaks to fit
max_width_guess = 2 # The maximal estimation allowed for the linewidth before the fitting
bound_shift = [[-7, -3], [3, 7]] # The bounds for the fitting of the shift
bound_linewidth = [[0, 5], [0, 5]] # The bounds for the fitting of the linewidth

# Initialising the Treat object on the a doublet of frequency and PSD
treat = Treat(frequency = frequency, PSD = psd)

# Setting the progress callback (optional, this allows us to display the progress of the treatment on large datasets)
treat._progress_callback = progress

# Adding the points to normalize the data
for point, window in zip(points, windows_find):
    treat.add_point(position_center_window = point, type_pnt = "Other", window_width = window)
treat.normalize_data(threshold_noise = 0.05)

# Adding the peaks to fit
for point, window, tpe in zip(points, windows_fit, point_type):
    treat.add_point(position_center_window = point, type_pnt = tpe, window_width = window)

# Defining the model for fitting the peaks - you can choose between the models defined in the Models class
treat.define_model(model = "Lorentzian", elastic_correction = True)

# Estimating the linewidth from selected peaks
treat.estimate_width_inelastic_peaks(max_width_guess = max_width_guess)

# Fitting all the selected inelastic peaks with multiple peaks fitting
treat.single_fit_all_inelastic(guess_offset = True, 
                                update_point_position = True, 
                                bound_shift = bound_shift, 
                                bound_linewidth = bound_linewidth)

# Applying the algorithm to all the spectra (in the case where PSD is a 2D array)
treat.apply_algorithm_on_all()

# Combining the two fitted peaks together here weighing the result on the standard deviation of the shift
treat.combine_results_FSR(FSR = 60, keep_max_amplitude = False, amplitude_weight = False, shift_err_weight= True)

# Printing the results
print("\nFinal results:")
print(f"Shfit: {treat.shift}")
print(f"Linewidth: {treat.linewidth}")
print(f"Amplitude: {treat.amplitude}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hdf5_bls_treat-1.1.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hdf5_bls_treat-1.1.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file hdf5_bls_treat-1.1.0.tar.gz.

File metadata

  • Download URL: hdf5_bls_treat-1.1.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for hdf5_bls_treat-1.1.0.tar.gz
Algorithm Hash digest
SHA256 bf90e79a6d667cf42a47efc15b2232ccd9fdada0fee1dbb10dc0fa150413e5eb
MD5 b1b465f31754f1e3d558962ad926a77b
BLAKE2b-256 199f3b47041bb494ada39699115e49e6d76f9a3503adb001cf59c749b8f5fe04

See more details on using hashes here.

File details

Details for the file hdf5_bls_treat-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: hdf5_bls_treat-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for hdf5_bls_treat-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8284652f712ecf851e867182e760b09f827e4a2638653082d6bde7c361ad86ff
MD5 54429e150cdf79b424815024cdfac3e2
BLAKE2b-256 7e735a13375d6e586d73e893329183644e2cf00f770e8f5552be50853be007b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page