flamingo
flamingo stands for Flexible Library for Amplitude and Motion Inaccuracies Neatly Gone Out 🦩
and is a THz data analysis tool which corrects subtle time distortion errors in Terahertz time-domain spectroscopy (THz-TDS) measurements.
Origin and Motivation
This project is a fork of Correct-TDS from the group of Romain Peretti. While the original implementation provided valuable algorithms, flamingo reimplements these with several key improvements:
- Lightweight design - Built using minimal dependencies (numpy, scipy, matplotlib) for easier installation and maintenance
- Memory efficiency - Processing one trace at a time, allowing even large datasets (10,000+ traces) to be analyzed on modest hardware
- Modern GUI - Using CustomTkinter instead of PyQT for a lighter-weight graphical user interface
- Cross-platform compatibility - Designed to work seamlessly across operating systems with minimal setup
The scientific foundation remains the excellent work described in:
E. Denakpo, T. Hannotte, N. Osseiran, F. Orieux and R. Peretti,
"Signal Estimation and Uncertainties Extraction in Terahertz Time-Domain Spectroscopy,"
in IEEE Transactions on Instrumentation and Measurement, vol. 74, pp. 1-13, 2025, Art no. 6005413,
What does flamingo do?
flamingo analyzes THz-TDS data and corrects systematic errors that affect measurement precision. It specifically targets data from commercial THz-TDS systems like Menlo and Toptica, providing tools to reduce the standard deviation across multiple measurements.
The software features:
- Small footprint - Minimal dependencies and optimized code for simpler installation and deployment
- Efficient processing - Single-trace processing approach that preserves memory even with very large datasets
- Multiple interfaces - Python API, command-line tool, and graphical user interface to suit different workflows
- Standalone executable - Available for Windows, macOS (Apple Silicon) and Linux for users without Python programming experience
Overview
flamingo is a comprehensive toolset for analyzing and correcting THz time-domain spectroscopy (THz-TDS) data. It features:
- Efficient processing of raw THz data from HDF-5 (.h5) files
- Memory-optimized algorithms that read one trace at a time, enabling processing of large datasets even on low-spec hardware
- Flexible correction methods for systematic errors in THz-TDS measurements:
- Delay correction
- Dilatation correction
- Periodic error correction ("Ghost" spectrum suppression)
- Interactive visualization tools for both time-domain and frequency-domain data
- Multiple interfaces: Python API, command-line, and graphical user interface
Installation
Executable Version
For users without a Python background, a standalone executable version is available. It runs without installing Python or any dependencies.
- Latest Release - View release notes and all available files
- Windows - unpack the
.zipand double-clickflamingo.exe - macOS, Apple Silicon - unpack the
.zipand openflamingo.app - Linux, x86-64 - unpack with
tar -xzfand run./flamingo
The executables are not signed. On macOS the first start is blocked ("cannot be opened"): open
System Settings → Privacy & Security and click Open Anyway, or run xattr -dr com.apple.quarantine flamingo.app.
On Windows, SmartScreen may ask for confirmation (More info → Run anyway).
Note: Please scroll down to Usage/Example data to see how you can make your first steps with flamingo.
Using pip
# Install from PyPI
pip install flamingo-thz
From source
# Clone the repository
git clone https://github.com/TimVog/flamingo.git
cd flamingo
# Install in development mode
pip install -e .
Project Structure
flamingo/
├── README.md
├── flamingo.spec # PyInstaller specification for executable
├── pyproject.toml # Package configuration
└── src/ # Source code
└── flamingo/ # Main package
├── __init__.py
├── cli.py # Command-line interface
├── main.py # Main API entry points
├── algorithms/ # Error correction algorithms
│ ├── __init__.py
│ ├── correction_methods.py
│ └── error_fit_functions.py
├── core/ # Core processing functionality
│ ├── __init__.py
│ ├── optimization_parameter.py
│ └── processing_pipeline.py
├── gui/ # Graphical user interface
│ ├── __init__.py
│ ├── app.py # Main window and entry point
│ └── components.py
├── utils/ # Utility functions
│ ├── __init__.py
│ ├── config.py
│ ├── helper_functions.py
│ ├── log_capture.py
│ └── progress.py
└── visualization/ # Plotting tools
├── __init__.py
└── plot_data.py
Usage
Flamingo provides three different interfaces for flexibility:
Graphical User Interface
# Launch the GUI
flamingo-gui
The GUI provides an intuitive interface with:
- File selection
- Processing parameter configuration
- Interactive visualizations
- Optimization parameter adjustment
- Export functionality for corrected data
Python API
from flamingo import process_data
# Process data with custom parameters
data, correction_params, trace_time, freq = process_data(
filepath='path/to/your/data.h5',
trace_start=0,
trace_end=1000,
lowcut=0.2e12, # Low cut frequency in Hz
config_options={
"enable_dilatation": True,
"enable_periodic": True
}
)
# For more advanced usage with full access to the processing pipeline:
from flamingo import ProcessingPipeline
from flamingo.core.optimization_parameter import CorrectionConfig
# Create configuration with custom settings
config = CorrectionConfig()
config.enabled_corrections["dilatation"] = True
config.enabled_corrections["periodic"] = True
# Create processing pipeline
pipeline = ProcessingPipeline(config)
# Process file
result = pipeline.process_file(
filepath='path/to/your/data.h5',
trace_start=0,
trace_end=1000,
lowcut=0.2e12
)
# Export corrected data to a new file
pipeline.export_corrected_data(
'path/to/your/data.h5',
'path/to/output/corrected_data.h5',
trace_start=0,
trace_end=1000
)
Command-Line Interface
# Basic usage (without --end all traces are processed)
flamingo --input data.h5 --start 0 --end 1000 --lowcut 0.2e12
# Disable specific corrections
flamingo --input data.h5 --no-dilatation --no-periodic
# Export corrected data
flamingo --input data.h5 --export corrected_data.h5
Reproducibility
The delay/dilatation initialisation and the periodic sampling fit use differential evolution, a stochastic
optimizer. flamingo seeds it explicitly (default 847290), so identical input gives bit-identical results with
the API, the CLI and the GUI. Use process_data(..., seed=...), flamingo --seed ... or
CorrectionConfig().optimization_settings["seed"] to choose another seed; seed=None gives a different
result on every run.
Data Format
Flamingo expects H5 files containing THz time-domain spectroscopy data with the following structure:
- Time trace axis stored as
timeaxis - Multiple amplitude time traces stored as numeric keys ("0", "1", "2", ...)
- All traces must have the same number of samples and be based on the same time axis
Example Data
If you'd like to try flamingo but don't have suitable THz-TDS data available, you can download an example file:
- Get the file
04-12-2023_0mb_50k_100ps.h5from this research data repository - This file is already in the correct format for flamingo
Note: This example file contains 50 000 traces, which is a large dataset. For an initial exploration of the software's capabilities, try setting the "End trace" parameter to 1 000 in the GUI or via the command line. This is typically sufficient to get a good feel for the software while keeping processing times reasonable.
Correction Methods
Flamingo implements several correction methods to improve the quality of THz-TDS data:
- Delay Correction: Compensates for time shifts between traces
- Dilatation Correction: Corrects for stretching/compression effects in the time domain
- Residual Noise Correction: Reduces amplitude variations
- Periodic Error Correction: Suppresses "Ghost" spectra caused by periodic sampling errors
The periodic error is fitted by minimizing the spectrum of the mean trace above a frequency limit. By default
(auto) this limit is where the mean spectrum reaches its noise floor, so a ghost copy anywhere outside the
signal band is penalized and data without a periodic error give an amplitude of about zero. A fixed limit can be
set in the GUI, with flamingo --frequency-limit 7.5e12 or config_options={"frequency_limit": 7.5e12}; the
limit used is logged and stored in results["periodic_frequency_limit"].
Visualization
The package includes comprehensive visualization tools:
- Time-domain signal plots
- Frequency-domain spectrum plots
- Correction parameter visualization
- Before/after comparison plots
from flamingo.visualization import plot_data
# Generate plots of processed data
plot_data.visualize_processing_steps(data, trace_time, freq)
plot_data.plot_comparison(data, trace_time, freq)
plot_data.plot_correction_parameter(correction_params)
How does this software compare to the other THz-TDS packages like parrot and phoeniks?
- parrot 🦜 is a fully-fledged solution for continuously recorded THz data with two raw streams (position and THz signal). It takes care of cutting, correcting the phase shift between these two streams, interpolation and so on. The presented algorithms are also going into parrot to keep it as a complete package.
- phoeniks 🐦 is at the end of the processing chain, if one is interested in the complex refractive index. It uses already averaged data as an input and needs a sample and reference trace.
- flamingo 🦩 is more specialized, using already interpolated traces like they can be recorded with commercial THz-TDS. By correcting subtle errors, which can be detected having an ensemble of traces, the standard deviation of the dataset can be reduced, improving phase accuracy, which is a pre-requisite for accurate extraction of the complex refractive index.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Credits
- Original Correct-TDS implementation by Romain Peretti's group
- Algorithms based on the paper by E. Denakpo et al. (2025)
- Package development by Tim Vogel
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for flamingo-thz 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flamingo_thz-0.2.0.tar.gz | 41.4 kB | With provenance | Details for flamingo_thz-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flamingo_thz-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for flamingo_thz-0.2.0-py3-none-any.whl |
Total release size: 84.6 kB
Release files / flamingo_thz-0.2.0.tar.gz
| Download URL | flamingo_thz-0.2.0.tar.gz |
|---|---|
| Size | 41.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c28d20c34029df3678914e0733a51cbfa9548dcd436c927b7ab8956384bcc59
|
|
BLAKE2b-256 checksum How to use checksums |
d29d5fef9ea9c16db9524dcb510c4427779f089343f4e11835c42fcae300ec7a
|
| 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 Oct 19, 2026.
Transparency logRelease files / flamingo_thz-0.2.0-py3-none-any.whl
| Download URL | flamingo_thz-0.2.0-py3-none-any.whl |
|---|---|
| Size | 43.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a6acdf471efddf9b8191d9e10a457d466f90372a0c595e6fb7a2b9d031a7bb50
|
|
BLAKE2b-256 checksum How to use checksums |
eccaff7d95a2e76f369db898d4e2d70038d0fe18bebe1d4df47b8689997784d9
|
| 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 Oct 19, 2026.
Transparency logSecurity for flamingo-thz 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for flamingo_thz-0.2.0.tar.gz
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 Oct 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.