Skip to main content

This Python Package is designed for advanced signal processing in THz time-domain spectroscopy.

Project description

THz Deconvolution Library

The THz Deconvolution Library is a Python package designed for advanced signal processing in THz time-domain spectroscopy (THz-TDS). This library provides tools to analyze and process THz signals, with a focus on beam profiling and deconvolution techniques to address frequency-dependent beam spreading effects.

Overview

THz time-domain spectroscopy is a powerful tool for studying materials and systems in the terahertz frequency range. However, the analysis of THz signals is often complicated by frequency-dependent beam spreading and other distortions. This library aims to simplify and enhance the processing of THz signals by providing robust algorithms and utilities for beam profiling, deconvolution, and signal restoration.

Key Features

1. Beam Width Fitting

  • Knife Edge Measurements: Fit beam widths using knife edge measurement data to accurately characterize the THz beam.
  • Frequency-Dependent Profiling: Profile the beam width per frequency to account for low-frequency spreading effects, ensuring precise analysis across the spectrum.
  • Gaussian Beam Fitting: Fit Gaussian profiles to beam data for accurate modeling and parameter extraction.

2. Deconvolution Algorithms

  • Classical Richardson-Lucy Deconvolution:
    • Supports clipped and unclipped variants
  • Frequency-dependent Richardson-Lucy Deconvolution:
    • Accounts for frequency-dependent distortions in the beam profile.
    • The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.
  • Frequency-dependent Wiener Deconvolution:
    • Noise-robust signal restoration using Wiener filtering.
    • The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.

3. Signal Processing Utilities

  • Windowing and Zero Padding: Tools for preparing signals for Fourier analysis, including Blackman and Kaiser windows.
  • Bandpass Filtering: Apply Kaiser window-based bandpass filters to isolate specific frequency ranges.
  • FFT Utilities: Efficient computation of FFTs and related operations, including zero-padded FFTs for enhanced resolution.
  • Custom Filters: Create and apply custom filters tailored to specific signal processing needs.

4. Data Handling

  • Knife Edge Data Loading: Load and preprocess knife edge measurement data for beam profiling.
  • Signal Windowing: Extract and process specific signal regions using custom window functions.

Installation

To install the library and its dependencies, clone the repository and use the following command:

pip install -r requirements.txt

Alternatively, you can install the dependencies manually using pip:

pip install numpy matplotlib scikit-image tqdm multiprocess
pip install git+https://github.com/dotTHzTAG/pydotthz.git@main#egg=pydotthz

Usage

Beam Width Fitting Example

from thz_deconvolution import load_knife_edge_meas, fit_beam_widths

# Frequency and filter parameters
low_cut = 0.1
high_cut = 10.0
start_freq = 0.25
end_freq = 4.0
win_width = 0.5
n_filters = 20
w_max = 30

# Load knife edge measurement data
x_axis, y_axis, psf_t_x, psf_t_y, times_psf  = load_knife_edge_meas("path_to_measurement_file_x", "path_to_measurement_file_y")

# Centering the data
x_axis -= np.mean(x_axis)
y_axis -= np.mean(y_axis)

print("Fitting the mean PSF")
x0, y0, popt_x, popt_y = fit_mean_beam(
    x_axis, y_axis, psf_t_x, psf_t_y)

# Create the PSF
x_start = np.abs(x_axis[0])
y_start = np.abs(y_axis[0])
dx = np.abs(x_axis[1] - x_axis[0])
dy = np.abs(y_axis[1] - y_axis[0])
xx = np.arange(-x_start, x_start + dx, dx)
yy = np.arange(-y_start, y_start + dy, dy)

gauss_x = gaussian(xx, 0.0, popt_x[1])
gauss_y = gaussian(yy, 0.0, popt_y[1])
gauss_x = gauss_x / np.max(gauss_x)
gauss_y = gauss_y / np.max(gauss_y)

_, _, psf_2d = create_psf_2d(gauss_x, gauss_y, xx, yy)

print("Creating the filters for the PSF")
filters, filt_freqs = create_filters(
    n_filters, times_psf, win_width, low_cut, high_cut, start_freq, end_freq)

print("Fitting the PSF beam widths by frequency")
_, _, popt_xs, popt_ys, _, _ = fit_beam_widths(
    x0, y0, x_psf, y_psf, np_psf_t_x, np_psf_t_y, filters, filt_freqs, w_max)

popt_xs and popt_ys contain all the parameters necessary to fit a gaussian beam at each frequency.

Deconvolution Example

from thz_deconvolution import richardson_lucy_freq

# Initialize the maximum number of iterations for Richardson-Lucy deconvolution
max_iter = 500

meas_type == 'reflectance' # or meas_type == 'transmission', to mirror the PSF
# Perform Richardson-Lucy deconvolution in the frequency domain
deconvolved_traces = richardson_lucy_freq(scan, xx, yy, popt_xs, popt_ys, filters, filt_freqs, max_iter, scan_type=meas_type)

deconvolved_traces and scan have the same shape and dimensions. scan is the original data, containing time traces for each (x,y) points in the scan.

Dependencies

This library relies on the following Python packages:

  • numpy: For numerical computations.
  • matplotlib: For data visualization.
  • scikit-image: For image and signal processing.
  • tqdm: For progress bars in iterative algorithms.
  • multiprocess: For parallel processing of computationally intensive tasks.
  • pydotthz: A custom library for THz signal processing (installed via GitHub).

Ensure all dependencies are installed by running the provided requirements.txt.

Contributing

Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, feel free to:

  1. Open an issue to discuss your ideas.
  2. Submit a pull request with your changes.

Please ensure your code adheres to the project's coding standards and includes appropriate tests.

Acknowledgments

This library was developed to support research in THz time-domain spectroscopy. Special thanks to the contributors and the open-source community for their invaluable tools and resources. This work is part of the MARVIS-Subice research program: https://subice.unibe.ch.

References

  1. Richardson-Lucy Deconvolution
  2. Wiener Filtering
  3. THz Time-Domain Spectroscopy

Future Work

  • Add support for additional deconvolution algorithms.
  • Expand the library to include more advanced beam profiling techniques.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

thz_deconvolution-1.0.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

thz_deconvolution-1.0.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file thz_deconvolution-1.0.1.tar.gz.

File metadata

  • Download URL: thz_deconvolution-1.0.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for thz_deconvolution-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6f9f036ac1503f37fd9d455bdd550085bd123dd841ed2a9d796d927960e64acd
MD5 5fef58156b7725a321a0e6def48ec443
BLAKE2b-256 3c8224d2f634f0fd2ad7798081f9cbb6d814e0d5055468f78b17fc152152e63b

See more details on using hashes here.

Provenance

The following attestation bundles were made for thz_deconvolution-1.0.1.tar.gz:

Publisher: publish.yml on Arnwald/thz_deconvolution

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thz_deconvolution-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for thz_deconvolution-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73b9b0e15ffe89c6248926526e18336f319490046616b3e2cbf8cec9cb1d7723
MD5 8f630cd451f8c59e07641f7effe5a2a4
BLAKE2b-256 cae04f3702e85dd9aea673136da9fab35fdd04472c34c279a5117fe0a8ed2531

See more details on using hashes here.

Provenance

The following attestation bundles were made for thz_deconvolution-1.0.1-py3-none-any.whl:

Publisher: publish.yml on Arnwald/thz_deconvolution

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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