thz-deconvolution 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- thz_deconvolution-1.0.1/LICENSE +21 -0
- thz_deconvolution-1.0.1/PKG-INFO +183 -0
- thz_deconvolution-1.0.1/README.md +162 -0
- thz_deconvolution-1.0.1/pyproject.toml +23 -0
- thz_deconvolution-1.0.1/setup.cfg +4 -0
- thz_deconvolution-1.0.1/src/__init__.py +1 -0
- thz_deconvolution-1.0.1/src/thz_deconvolution.egg-info/PKG-INFO +183 -0
- thz_deconvolution-1.0.1/src/thz_deconvolution.egg-info/SOURCES.txt +10 -0
- thz_deconvolution-1.0.1/src/thz_deconvolution.egg-info/dependency_links.txt +1 -0
- thz_deconvolution-1.0.1/src/thz_deconvolution.egg-info/requires.txt +6 -0
- thz_deconvolution-1.0.1/src/thz_deconvolution.egg-info/top_level.txt +2 -0
- thz_deconvolution-1.0.1/src/utils.py +1234 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Arnwald
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: thz_deconvolution
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: This Python Package is designed for advanced signal processing in THz time-domain spectroscopy.
|
|
5
|
+
Author-email: Arnaud Demion <arnaud.demion@hevs.ch>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Arnwald/thz_deconvolution
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/Arnwald/thz_deconvolution/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: scipy
|
|
16
|
+
Requires-Dist: matplotlib
|
|
17
|
+
Requires-Dist: zmq
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Requires-Dist: pydotthz
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# THz Deconvolution Library
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
## Overview
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
## Key Features
|
|
31
|
+
|
|
32
|
+
### 1. Beam Width Fitting
|
|
33
|
+
|
|
34
|
+
- **Knife Edge Measurements**: Fit beam widths using knife edge measurement data to accurately characterize the THz beam.
|
|
35
|
+
- **Frequency-Dependent Profiling**: Profile the beam width per frequency to account for low-frequency spreading effects, ensuring precise analysis across the spectrum.
|
|
36
|
+
- **Gaussian Beam Fitting**: Fit Gaussian profiles to beam data for accurate modeling and parameter extraction.
|
|
37
|
+
|
|
38
|
+
### 2. Deconvolution Algorithms
|
|
39
|
+
|
|
40
|
+
- **Classical Richardson-Lucy Deconvolution**:
|
|
41
|
+
- Supports clipped and unclipped variants
|
|
42
|
+
- **Frequency-dependent Richardson-Lucy Deconvolution**:
|
|
43
|
+
- Accounts for frequency-dependent distortions in the beam profile.
|
|
44
|
+
- The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.
|
|
45
|
+
- **Frequency-dependent Wiener Deconvolution**:
|
|
46
|
+
- Noise-robust signal restoration using Wiener filtering.
|
|
47
|
+
- The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.
|
|
48
|
+
|
|
49
|
+
### 3. Signal Processing Utilities
|
|
50
|
+
|
|
51
|
+
- **Windowing and Zero Padding**: Tools for preparing signals for Fourier analysis, including Blackman and Kaiser windows.
|
|
52
|
+
- **Bandpass Filtering**: Apply Kaiser window-based bandpass filters to isolate specific frequency ranges.
|
|
53
|
+
- **FFT Utilities**: Efficient computation of FFTs and related operations, including zero-padded FFTs for enhanced resolution.
|
|
54
|
+
- **Custom Filters**: Create and apply custom filters tailored to specific signal processing needs.
|
|
55
|
+
|
|
56
|
+
### 4. Data Handling
|
|
57
|
+
|
|
58
|
+
- **Knife Edge Data Loading**: Load and preprocess knife edge measurement data for beam profiling.
|
|
59
|
+
- **Signal Windowing**: Extract and process specific signal regions using custom window functions.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
To install the library and its dependencies, clone the repository and use the following command:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install -r requirements.txt
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Alternatively, you can install the dependencies manually using `pip`:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install numpy matplotlib scikit-image tqdm multiprocess
|
|
73
|
+
pip install git+https://github.com/dotTHzTAG/pydotthz.git@main#egg=pydotthz
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
### Beam Width Fitting Example
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from thz_deconvolution import load_knife_edge_meas, fit_beam_widths
|
|
82
|
+
|
|
83
|
+
# Frequency and filter parameters
|
|
84
|
+
low_cut = 0.1
|
|
85
|
+
high_cut = 10.0
|
|
86
|
+
start_freq = 0.25
|
|
87
|
+
end_freq = 4.0
|
|
88
|
+
win_width = 0.5
|
|
89
|
+
n_filters = 20
|
|
90
|
+
w_max = 30
|
|
91
|
+
|
|
92
|
+
# Load knife edge measurement data
|
|
93
|
+
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")
|
|
94
|
+
|
|
95
|
+
# Centering the data
|
|
96
|
+
x_axis -= np.mean(x_axis)
|
|
97
|
+
y_axis -= np.mean(y_axis)
|
|
98
|
+
|
|
99
|
+
print("Fitting the mean PSF")
|
|
100
|
+
x0, y0, popt_x, popt_y = fit_mean_beam(
|
|
101
|
+
x_axis, y_axis, psf_t_x, psf_t_y)
|
|
102
|
+
|
|
103
|
+
# Create the PSF
|
|
104
|
+
x_start = np.abs(x_axis[0])
|
|
105
|
+
y_start = np.abs(y_axis[0])
|
|
106
|
+
dx = np.abs(x_axis[1] - x_axis[0])
|
|
107
|
+
dy = np.abs(y_axis[1] - y_axis[0])
|
|
108
|
+
xx = np.arange(-x_start, x_start + dx, dx)
|
|
109
|
+
yy = np.arange(-y_start, y_start + dy, dy)
|
|
110
|
+
|
|
111
|
+
gauss_x = gaussian(xx, 0.0, popt_x[1])
|
|
112
|
+
gauss_y = gaussian(yy, 0.0, popt_y[1])
|
|
113
|
+
gauss_x = gauss_x / np.max(gauss_x)
|
|
114
|
+
gauss_y = gauss_y / np.max(gauss_y)
|
|
115
|
+
|
|
116
|
+
_, _, psf_2d = create_psf_2d(gauss_x, gauss_y, xx, yy)
|
|
117
|
+
|
|
118
|
+
print("Creating the filters for the PSF")
|
|
119
|
+
filters, filt_freqs = create_filters(
|
|
120
|
+
n_filters, times_psf, win_width, low_cut, high_cut, start_freq, end_freq)
|
|
121
|
+
|
|
122
|
+
print("Fitting the PSF beam widths by frequency")
|
|
123
|
+
_, _, popt_xs, popt_ys, _, _ = fit_beam_widths(
|
|
124
|
+
x0, y0, x_psf, y_psf, np_psf_t_x, np_psf_t_y, filters, filt_freqs, w_max)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`popt_xs` and `popt_ys` contain all the parameters necessary to fit a gaussian beam at each frequency.
|
|
128
|
+
|
|
129
|
+
### Deconvolution Example
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from thz_deconvolution import richardson_lucy_freq
|
|
133
|
+
|
|
134
|
+
# Initialize the maximum number of iterations for Richardson-Lucy deconvolution
|
|
135
|
+
max_iter = 500
|
|
136
|
+
|
|
137
|
+
meas_type == 'reflectance' # or meas_type == 'transmission', to mirror the PSF
|
|
138
|
+
# Perform Richardson-Lucy deconvolution in the frequency domain
|
|
139
|
+
deconvolved_traces = richardson_lucy_freq(scan, xx, yy, popt_xs, popt_ys, filters, filt_freqs, max_iter, scan_type=meas_type)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`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.
|
|
143
|
+
|
|
144
|
+
## Dependencies
|
|
145
|
+
|
|
146
|
+
This library relies on the following Python packages:
|
|
147
|
+
|
|
148
|
+
- `numpy`: For numerical computations.
|
|
149
|
+
- `matplotlib`: For data visualization.
|
|
150
|
+
- `scikit-image`: For image and signal processing.
|
|
151
|
+
- `tqdm`: For progress bars in iterative algorithms.
|
|
152
|
+
- `multiprocess`: For parallel processing of computationally intensive tasks.
|
|
153
|
+
- `pydotthz`: A custom library for THz signal processing (installed via GitHub).
|
|
154
|
+
|
|
155
|
+
Ensure all dependencies are installed by running the provided `requirements.txt`.
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, feel free to:
|
|
160
|
+
|
|
161
|
+
1. Open an issue to discuss your ideas.
|
|
162
|
+
2. Submit a pull request with your changes.
|
|
163
|
+
|
|
164
|
+
Please ensure your code adheres to the project's coding standards and includes appropriate tests.
|
|
165
|
+
|
|
166
|
+
## Acknowledgments
|
|
167
|
+
|
|
168
|
+
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](https://subice.unibe.ch).
|
|
169
|
+
|
|
170
|
+
## References
|
|
171
|
+
|
|
172
|
+
1. [Richardson-Lucy Deconvolution](https://en.wikipedia.org/wiki/Richardson%E2%80%93Lucy_deconvolution)
|
|
173
|
+
2. [Wiener Filtering](https://en.wikipedia.org/wiki/Wiener_filter)
|
|
174
|
+
3. [THz Time-Domain Spectroscopy](https://en.wikipedia.org/wiki/Terahertz_time-domain_spectroscopy)
|
|
175
|
+
|
|
176
|
+
## Future Work
|
|
177
|
+
|
|
178
|
+
- Add support for additional deconvolution algorithms.
|
|
179
|
+
- Expand the library to include more advanced beam profiling techniques.
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# THz Deconvolution Library
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
### 1. Beam Width Fitting
|
|
12
|
+
|
|
13
|
+
- **Knife Edge Measurements**: Fit beam widths using knife edge measurement data to accurately characterize the THz beam.
|
|
14
|
+
- **Frequency-Dependent Profiling**: Profile the beam width per frequency to account for low-frequency spreading effects, ensuring precise analysis across the spectrum.
|
|
15
|
+
- **Gaussian Beam Fitting**: Fit Gaussian profiles to beam data for accurate modeling and parameter extraction.
|
|
16
|
+
|
|
17
|
+
### 2. Deconvolution Algorithms
|
|
18
|
+
|
|
19
|
+
- **Classical Richardson-Lucy Deconvolution**:
|
|
20
|
+
- Supports clipped and unclipped variants
|
|
21
|
+
- **Frequency-dependent Richardson-Lucy Deconvolution**:
|
|
22
|
+
- Accounts for frequency-dependent distortions in the beam profile.
|
|
23
|
+
- The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.
|
|
24
|
+
- **Frequency-dependent Wiener Deconvolution**:
|
|
25
|
+
- Noise-robust signal restoration using Wiener filtering.
|
|
26
|
+
- The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.
|
|
27
|
+
|
|
28
|
+
### 3. Signal Processing Utilities
|
|
29
|
+
|
|
30
|
+
- **Windowing and Zero Padding**: Tools for preparing signals for Fourier analysis, including Blackman and Kaiser windows.
|
|
31
|
+
- **Bandpass Filtering**: Apply Kaiser window-based bandpass filters to isolate specific frequency ranges.
|
|
32
|
+
- **FFT Utilities**: Efficient computation of FFTs and related operations, including zero-padded FFTs for enhanced resolution.
|
|
33
|
+
- **Custom Filters**: Create and apply custom filters tailored to specific signal processing needs.
|
|
34
|
+
|
|
35
|
+
### 4. Data Handling
|
|
36
|
+
|
|
37
|
+
- **Knife Edge Data Loading**: Load and preprocess knife edge measurement data for beam profiling.
|
|
38
|
+
- **Signal Windowing**: Extract and process specific signal regions using custom window functions.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
To install the library and its dependencies, clone the repository and use the following command:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install -r requirements.txt
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Alternatively, you can install the dependencies manually using `pip`:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install numpy matplotlib scikit-image tqdm multiprocess
|
|
52
|
+
pip install git+https://github.com/dotTHzTAG/pydotthz.git@main#egg=pydotthz
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### Beam Width Fitting Example
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from thz_deconvolution import load_knife_edge_meas, fit_beam_widths
|
|
61
|
+
|
|
62
|
+
# Frequency and filter parameters
|
|
63
|
+
low_cut = 0.1
|
|
64
|
+
high_cut = 10.0
|
|
65
|
+
start_freq = 0.25
|
|
66
|
+
end_freq = 4.0
|
|
67
|
+
win_width = 0.5
|
|
68
|
+
n_filters = 20
|
|
69
|
+
w_max = 30
|
|
70
|
+
|
|
71
|
+
# Load knife edge measurement data
|
|
72
|
+
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")
|
|
73
|
+
|
|
74
|
+
# Centering the data
|
|
75
|
+
x_axis -= np.mean(x_axis)
|
|
76
|
+
y_axis -= np.mean(y_axis)
|
|
77
|
+
|
|
78
|
+
print("Fitting the mean PSF")
|
|
79
|
+
x0, y0, popt_x, popt_y = fit_mean_beam(
|
|
80
|
+
x_axis, y_axis, psf_t_x, psf_t_y)
|
|
81
|
+
|
|
82
|
+
# Create the PSF
|
|
83
|
+
x_start = np.abs(x_axis[0])
|
|
84
|
+
y_start = np.abs(y_axis[0])
|
|
85
|
+
dx = np.abs(x_axis[1] - x_axis[0])
|
|
86
|
+
dy = np.abs(y_axis[1] - y_axis[0])
|
|
87
|
+
xx = np.arange(-x_start, x_start + dx, dx)
|
|
88
|
+
yy = np.arange(-y_start, y_start + dy, dy)
|
|
89
|
+
|
|
90
|
+
gauss_x = gaussian(xx, 0.0, popt_x[1])
|
|
91
|
+
gauss_y = gaussian(yy, 0.0, popt_y[1])
|
|
92
|
+
gauss_x = gauss_x / np.max(gauss_x)
|
|
93
|
+
gauss_y = gauss_y / np.max(gauss_y)
|
|
94
|
+
|
|
95
|
+
_, _, psf_2d = create_psf_2d(gauss_x, gauss_y, xx, yy)
|
|
96
|
+
|
|
97
|
+
print("Creating the filters for the PSF")
|
|
98
|
+
filters, filt_freqs = create_filters(
|
|
99
|
+
n_filters, times_psf, win_width, low_cut, high_cut, start_freq, end_freq)
|
|
100
|
+
|
|
101
|
+
print("Fitting the PSF beam widths by frequency")
|
|
102
|
+
_, _, popt_xs, popt_ys, _, _ = fit_beam_widths(
|
|
103
|
+
x0, y0, x_psf, y_psf, np_psf_t_x, np_psf_t_y, filters, filt_freqs, w_max)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`popt_xs` and `popt_ys` contain all the parameters necessary to fit a gaussian beam at each frequency.
|
|
107
|
+
|
|
108
|
+
### Deconvolution Example
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from thz_deconvolution import richardson_lucy_freq
|
|
112
|
+
|
|
113
|
+
# Initialize the maximum number of iterations for Richardson-Lucy deconvolution
|
|
114
|
+
max_iter = 500
|
|
115
|
+
|
|
116
|
+
meas_type == 'reflectance' # or meas_type == 'transmission', to mirror the PSF
|
|
117
|
+
# Perform Richardson-Lucy deconvolution in the frequency domain
|
|
118
|
+
deconvolved_traces = richardson_lucy_freq(scan, xx, yy, popt_xs, popt_ys, filters, filt_freqs, max_iter, scan_type=meas_type)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`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.
|
|
122
|
+
|
|
123
|
+
## Dependencies
|
|
124
|
+
|
|
125
|
+
This library relies on the following Python packages:
|
|
126
|
+
|
|
127
|
+
- `numpy`: For numerical computations.
|
|
128
|
+
- `matplotlib`: For data visualization.
|
|
129
|
+
- `scikit-image`: For image and signal processing.
|
|
130
|
+
- `tqdm`: For progress bars in iterative algorithms.
|
|
131
|
+
- `multiprocess`: For parallel processing of computationally intensive tasks.
|
|
132
|
+
- `pydotthz`: A custom library for THz signal processing (installed via GitHub).
|
|
133
|
+
|
|
134
|
+
Ensure all dependencies are installed by running the provided `requirements.txt`.
|
|
135
|
+
|
|
136
|
+
## Contributing
|
|
137
|
+
|
|
138
|
+
Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, feel free to:
|
|
139
|
+
|
|
140
|
+
1. Open an issue to discuss your ideas.
|
|
141
|
+
2. Submit a pull request with your changes.
|
|
142
|
+
|
|
143
|
+
Please ensure your code adheres to the project's coding standards and includes appropriate tests.
|
|
144
|
+
|
|
145
|
+
## Acknowledgments
|
|
146
|
+
|
|
147
|
+
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](https://subice.unibe.ch).
|
|
148
|
+
|
|
149
|
+
## References
|
|
150
|
+
|
|
151
|
+
1. [Richardson-Lucy Deconvolution](https://en.wikipedia.org/wiki/Richardson%E2%80%93Lucy_deconvolution)
|
|
152
|
+
2. [Wiener Filtering](https://en.wikipedia.org/wiki/Wiener_filter)
|
|
153
|
+
3. [THz Time-Domain Spectroscopy](https://en.wikipedia.org/wiki/Terahertz_time-domain_spectroscopy)
|
|
154
|
+
|
|
155
|
+
## Future Work
|
|
156
|
+
|
|
157
|
+
- Add support for additional deconvolution algorithms.
|
|
158
|
+
- Expand the library to include more advanced beam profiling techniques.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tools.setuptools]
|
|
6
|
+
packages = ["thz_deconvolution"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "thz_deconvolution"
|
|
10
|
+
version = "1.0.1"
|
|
11
|
+
authors = [{ name = "Arnaud Demion", email = "arnaud.demion@hevs.ch" }]
|
|
12
|
+
description = "This Python Package is designed for advanced signal processing in THz time-domain spectroscopy."
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.7"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
dependencies = ["numpy", "scipy", "matplotlib", "zmq", "tqdm", "pydotthz"]
|
|
21
|
+
[project.urls]
|
|
22
|
+
"Homepage" = "https://github.com/Arnwald/thz_deconvolution"
|
|
23
|
+
"Bug Tracker" = "https://github.com/Arnwald/thz_deconvolution/issues"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .utils import *
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: thz_deconvolution
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: This Python Package is designed for advanced signal processing in THz time-domain spectroscopy.
|
|
5
|
+
Author-email: Arnaud Demion <arnaud.demion@hevs.ch>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Arnwald/thz_deconvolution
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/Arnwald/thz_deconvolution/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: scipy
|
|
16
|
+
Requires-Dist: matplotlib
|
|
17
|
+
Requires-Dist: zmq
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Requires-Dist: pydotthz
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# THz Deconvolution Library
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
## Overview
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
## Key Features
|
|
31
|
+
|
|
32
|
+
### 1. Beam Width Fitting
|
|
33
|
+
|
|
34
|
+
- **Knife Edge Measurements**: Fit beam widths using knife edge measurement data to accurately characterize the THz beam.
|
|
35
|
+
- **Frequency-Dependent Profiling**: Profile the beam width per frequency to account for low-frequency spreading effects, ensuring precise analysis across the spectrum.
|
|
36
|
+
- **Gaussian Beam Fitting**: Fit Gaussian profiles to beam data for accurate modeling and parameter extraction.
|
|
37
|
+
|
|
38
|
+
### 2. Deconvolution Algorithms
|
|
39
|
+
|
|
40
|
+
- **Classical Richardson-Lucy Deconvolution**:
|
|
41
|
+
- Supports clipped and unclipped variants
|
|
42
|
+
- **Frequency-dependent Richardson-Lucy Deconvolution**:
|
|
43
|
+
- Accounts for frequency-dependent distortions in the beam profile.
|
|
44
|
+
- The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.
|
|
45
|
+
- **Frequency-dependent Wiener Deconvolution**:
|
|
46
|
+
- Noise-robust signal restoration using Wiener filtering.
|
|
47
|
+
- The time traces of the scans are modified to account for frequency-dependent distortions, thus preserving the depth information.
|
|
48
|
+
|
|
49
|
+
### 3. Signal Processing Utilities
|
|
50
|
+
|
|
51
|
+
- **Windowing and Zero Padding**: Tools for preparing signals for Fourier analysis, including Blackman and Kaiser windows.
|
|
52
|
+
- **Bandpass Filtering**: Apply Kaiser window-based bandpass filters to isolate specific frequency ranges.
|
|
53
|
+
- **FFT Utilities**: Efficient computation of FFTs and related operations, including zero-padded FFTs for enhanced resolution.
|
|
54
|
+
- **Custom Filters**: Create and apply custom filters tailored to specific signal processing needs.
|
|
55
|
+
|
|
56
|
+
### 4. Data Handling
|
|
57
|
+
|
|
58
|
+
- **Knife Edge Data Loading**: Load and preprocess knife edge measurement data for beam profiling.
|
|
59
|
+
- **Signal Windowing**: Extract and process specific signal regions using custom window functions.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
To install the library and its dependencies, clone the repository and use the following command:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install -r requirements.txt
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Alternatively, you can install the dependencies manually using `pip`:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install numpy matplotlib scikit-image tqdm multiprocess
|
|
73
|
+
pip install git+https://github.com/dotTHzTAG/pydotthz.git@main#egg=pydotthz
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
### Beam Width Fitting Example
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from thz_deconvolution import load_knife_edge_meas, fit_beam_widths
|
|
82
|
+
|
|
83
|
+
# Frequency and filter parameters
|
|
84
|
+
low_cut = 0.1
|
|
85
|
+
high_cut = 10.0
|
|
86
|
+
start_freq = 0.25
|
|
87
|
+
end_freq = 4.0
|
|
88
|
+
win_width = 0.5
|
|
89
|
+
n_filters = 20
|
|
90
|
+
w_max = 30
|
|
91
|
+
|
|
92
|
+
# Load knife edge measurement data
|
|
93
|
+
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")
|
|
94
|
+
|
|
95
|
+
# Centering the data
|
|
96
|
+
x_axis -= np.mean(x_axis)
|
|
97
|
+
y_axis -= np.mean(y_axis)
|
|
98
|
+
|
|
99
|
+
print("Fitting the mean PSF")
|
|
100
|
+
x0, y0, popt_x, popt_y = fit_mean_beam(
|
|
101
|
+
x_axis, y_axis, psf_t_x, psf_t_y)
|
|
102
|
+
|
|
103
|
+
# Create the PSF
|
|
104
|
+
x_start = np.abs(x_axis[0])
|
|
105
|
+
y_start = np.abs(y_axis[0])
|
|
106
|
+
dx = np.abs(x_axis[1] - x_axis[0])
|
|
107
|
+
dy = np.abs(y_axis[1] - y_axis[0])
|
|
108
|
+
xx = np.arange(-x_start, x_start + dx, dx)
|
|
109
|
+
yy = np.arange(-y_start, y_start + dy, dy)
|
|
110
|
+
|
|
111
|
+
gauss_x = gaussian(xx, 0.0, popt_x[1])
|
|
112
|
+
gauss_y = gaussian(yy, 0.0, popt_y[1])
|
|
113
|
+
gauss_x = gauss_x / np.max(gauss_x)
|
|
114
|
+
gauss_y = gauss_y / np.max(gauss_y)
|
|
115
|
+
|
|
116
|
+
_, _, psf_2d = create_psf_2d(gauss_x, gauss_y, xx, yy)
|
|
117
|
+
|
|
118
|
+
print("Creating the filters for the PSF")
|
|
119
|
+
filters, filt_freqs = create_filters(
|
|
120
|
+
n_filters, times_psf, win_width, low_cut, high_cut, start_freq, end_freq)
|
|
121
|
+
|
|
122
|
+
print("Fitting the PSF beam widths by frequency")
|
|
123
|
+
_, _, popt_xs, popt_ys, _, _ = fit_beam_widths(
|
|
124
|
+
x0, y0, x_psf, y_psf, np_psf_t_x, np_psf_t_y, filters, filt_freqs, w_max)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`popt_xs` and `popt_ys` contain all the parameters necessary to fit a gaussian beam at each frequency.
|
|
128
|
+
|
|
129
|
+
### Deconvolution Example
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from thz_deconvolution import richardson_lucy_freq
|
|
133
|
+
|
|
134
|
+
# Initialize the maximum number of iterations for Richardson-Lucy deconvolution
|
|
135
|
+
max_iter = 500
|
|
136
|
+
|
|
137
|
+
meas_type == 'reflectance' # or meas_type == 'transmission', to mirror the PSF
|
|
138
|
+
# Perform Richardson-Lucy deconvolution in the frequency domain
|
|
139
|
+
deconvolved_traces = richardson_lucy_freq(scan, xx, yy, popt_xs, popt_ys, filters, filt_freqs, max_iter, scan_type=meas_type)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`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.
|
|
143
|
+
|
|
144
|
+
## Dependencies
|
|
145
|
+
|
|
146
|
+
This library relies on the following Python packages:
|
|
147
|
+
|
|
148
|
+
- `numpy`: For numerical computations.
|
|
149
|
+
- `matplotlib`: For data visualization.
|
|
150
|
+
- `scikit-image`: For image and signal processing.
|
|
151
|
+
- `tqdm`: For progress bars in iterative algorithms.
|
|
152
|
+
- `multiprocess`: For parallel processing of computationally intensive tasks.
|
|
153
|
+
- `pydotthz`: A custom library for THz signal processing (installed via GitHub).
|
|
154
|
+
|
|
155
|
+
Ensure all dependencies are installed by running the provided `requirements.txt`.
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, feel free to:
|
|
160
|
+
|
|
161
|
+
1. Open an issue to discuss your ideas.
|
|
162
|
+
2. Submit a pull request with your changes.
|
|
163
|
+
|
|
164
|
+
Please ensure your code adheres to the project's coding standards and includes appropriate tests.
|
|
165
|
+
|
|
166
|
+
## Acknowledgments
|
|
167
|
+
|
|
168
|
+
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](https://subice.unibe.ch).
|
|
169
|
+
|
|
170
|
+
## References
|
|
171
|
+
|
|
172
|
+
1. [Richardson-Lucy Deconvolution](https://en.wikipedia.org/wiki/Richardson%E2%80%93Lucy_deconvolution)
|
|
173
|
+
2. [Wiener Filtering](https://en.wikipedia.org/wiki/Wiener_filter)
|
|
174
|
+
3. [THz Time-Domain Spectroscopy](https://en.wikipedia.org/wiki/Terahertz_time-domain_spectroscopy)
|
|
175
|
+
|
|
176
|
+
## Future Work
|
|
177
|
+
|
|
178
|
+
- Add support for additional deconvolution algorithms.
|
|
179
|
+
- Expand the library to include more advanced beam profiling techniques.
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/__init__.py
|
|
5
|
+
src/utils.py
|
|
6
|
+
src/thz_deconvolution.egg-info/PKG-INFO
|
|
7
|
+
src/thz_deconvolution.egg-info/SOURCES.txt
|
|
8
|
+
src/thz_deconvolution.egg-info/dependency_links.txt
|
|
9
|
+
src/thz_deconvolution.egg-info/requires.txt
|
|
10
|
+
src/thz_deconvolution.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|