Skip to main content

THz Deconvolution Library

PEP8 PyPI PyPI - Downloads

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.

Published in IEEE Transactions on Terahertz Science and Technology: DOI: 10.1109/TTHZ.2024.3456789

A. Demion, L. L. Stöckli, N. Thomas and S. Zahno, "Frequency-Dependent Deconvolution for Enhanced THz-TDS Scans: Accounting for Beam Width Variations in Time Traces," in IEEE Transactions on Terahertz Science and Technology, vol. 15, no. 3, pp. 505-513, May 2025, doi: 10.1109/TTHZ.2025.3546756.
keywords: {Frequency measurement;Time-frequency analysis;Imaging;Fourier transforms;Finite impulse response filters;Deconvolution;Time-domain analysis;Terahertz radiation;Antenna measurements;Spatial resolution;Deconvolution;knife edge technique;Richardson–Lucy (RL);Terahertz time-domain spectroscopy (THz-TDS);Wiener},

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:

pip install thz-deconvolution

Usage

A simple example is located in the examples directory.

Beam Width Fitting Example

To fit the beam widths from knife edge measurements, load in the measurements (.thz file) of the x and y axis:

from thz_deconvolution.deconvolution import Deconvolution
from pathlib import Path

DeconvolutionFilter = Deconvolution(
    knife_edge_x_path=Path("psf_data/example_beam_width/measurement_x/1750085285.8557956_data.thz"),
    knife_edge_y_path=Path("psf_data/example_beam_width/measurement_y/1750163177.929295_data.thz")
)

or load a psf file:

from thz_deconvolution.deconvolution import Deconvolution
from pathlib import Path

DeconvolutionFilter = Deconvolution(
    psf_path=Path("psf_data/example_beam_width/psf_file.thz")
)

Deconvolution Example

Then deconvole the scan ($n_x \times n_y \times n_t$ data):

deconvolved_traces = DeconvolutionFilter.apply_deconvolution(scan, x_min, x_max, nx, y_min, y_max, ny, max_iter=100)

or deconvole a single waveform:

deconvolved_trace = DeconvolutionFilter.apply_deconvolution_single_trace(trace, max_iter=100)

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, make sure to add them to the Changelog.

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.
  • Implement tests

License

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

Metadata

Release files for thz-deconvolution 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for thz-deconvolution 1.1.0
File Size Uploaded
thz_deconvolution-1.1.0.tar.gz 20.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for thz-deconvolution 1.1.0
File Interpreter ABI Platform
thz_deconvolution-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.8 kB

Release files / thz_deconvolution-1.1.0.tar.gz

Download URL thz_deconvolution-1.1.0.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a47dc4ca942dbcb68eab11ddd24defc604daf984da5c36c97f55d5f0d4ac0b6b
BLAKE2b-256 checksum
How to use checksums
0fe54b1d6ad81281cf710575b43af9290444cf5fbfbda463b56df4a18844ef2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / thz_deconvolution-1.1.0-py3-none-any.whl

Download URL thz_deconvolution-1.1.0-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e51b9e86a6598760aa482c297c26783d3ad58994ef88e8ed8ac388080c9eff83
BLAKE2b-256 checksum
How to use checksums
f5b73602d69d94306ad724e1725428ed1796092a62705bb07a70b918a212fa71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release history Release notifications | RSS feed

1.1.1

2 release files

This release

1.1.0 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page