PyMolFit
PyMolFit is an independent pure-Python package for modelling and correcting telluric absorption in astronomical spectra. It is based on the concepts, workflow, and radiative-transfer approach of the original ESO Molecfit, with a Python API for both spectrum files and wavelength-flux arrays.
PyMolFit does not import or run Molecfit and is not affiliated with or endorsed by ESO.
Installation
python -m pip install pymolfit
Install plotting support for the tutorial notebooks:
python -m pip install "pymolfit[plot]" ipympl
PyMolFit supports Python 3.10 and newer.
Correct A Spectrum File
The main API is correct():
from pymolfit import correct
result = correct(
input_path="spectrum.fits",
wavelength_medium="air",
)
wavelength = result.corrected.wavelength
corrected_flux = result.corrected.flux
Use wavelength_medium="vacuum" for vacuum wavelengths. The argument may be
omitted only when the FITS metadata declares the wavelength medium
unambiguously.
Results remain in memory unless an output is requested:
from pymolfit import save_corrected_txt, save_fit_product_ecsv
save_corrected_txt(result, "corrected_spectrum.txt")
save_fit_product_ecsv(result, "fit_product.ecsv")
The text file contains a compact corrected spectrum. The ECSV product also contains the fitted transmission, model, masks, metadata, and provenance.
Correct Wavelength And Flux Arrays
Arrays do not have a FITS header, so observing metadata is supplied with an
Observation:
from pymolfit import Observation, correct
observation = Observation(
time="2025-09-28T07:44:51",
latitude_deg=-24.627,
longitude_deg=-70.404,
altitude_m=2635.0,
airmass=1.18,
resolving_power=140_000,
wavelength_frame="observatory",
instrument="ESPRESSO",
)
result = correct(
wavelength=wavelength,
flux=flux,
wavelength_unit="angstrom",
wavelength_medium="air",
observation=observation,
)
wavelength_medium states whether the numbers are air or vacuum wavelengths.
wavelength_frame separately states their velocity reference frame. Supported
frames are observatory, barycentric, and heliocentric.
Tutorials
The runnable notebooks in
tutorials/
cover:
- Correcting part of a spectrum
- Correcting a full spectrum
- Expert parameters
- Correcting wavelength-flux arrays
Start with Tutorial 1 for a short example or Tutorial 2 for a complete one-dimensional echelle spectrum.
Molecular And Atmospheric Data
The standard workflow automatically obtains the versioned AER molecular line
catalogue, verifies its checksum, and caches it under
~/.cache/pymolfit/aer. It is not bundled in the Python wheel, and the normal
workflow does not require a HITRAN API key.
Users may instead provide their own HITRAN .par files or other supported
line and continuum data.
Scientific Basis And References
PyMolFit builds on the methods and scientific data developed by several projects. Publications using PyMolFit should cite the relevant upstream resources:
- ESO Molecfit: Smette et al. 2015, A&A 576, A77 and Kausch et al. 2015, A&A 576, A78
- AER LBLRTM line-by-line radiative-transfer methods and data
- AER MT_CKD atmospheric continuum model
- HITRAN molecular spectroscopic data
- MIPAS atmospheric reference profiles
- NOAA GDAS meteorological profiles
PyMolFit uses NumPy, SciPy, and Astropy.
Development
git clone https://github.com/nikolasvalsamidis97/PyMolFit.git
cd PyMolFit
python -m pip install -e ".[dev,plot]"
python -m pytest
Report problems through the GitHub issue tracker.
Licensing And Third-Party Data
PyMolFit's original Python code is available under the
BSD 3-Clause License.
Scientific datasets and derived coefficient tables retain their upstream
terms and attribution requirements. See
THIRD_PARTY_NOTICES.md
for the included and automatically downloaded data.
Metadata
Release files for pymolfit 0.4.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 | |
|---|---|---|---|
| pymolfit-0.4.0.tar.gz | 491.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pymolfit-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 943.0 kB
Release files / pymolfit-0.4.0.tar.gz
| Download URL | pymolfit-0.4.0.tar.gz |
|---|---|
| Size | 491.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39b64f11989739152198b991d99ed21205d717447c9417f9a02b7ffc050112ee
|
|
BLAKE2b-256 checksum How to use checksums |
b223503e176ca03256c80e74df678ae53791390cb08ccd3d5e1dc0bf75ccfb57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / pymolfit-0.4.0-py3-none-any.whl
| Download URL | pymolfit-0.4.0-py3-none-any.whl |
|---|---|
| Size | 452.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27bc459da34ca8242bbd7ad3e1926d0edf027f6b7a2d37295ceea9585ba91df0
|
|
BLAKE2b-256 checksum How to use checksums |
abb791720bc311223ba417a5d25c139309acf5be0fb5d315af85b369d2ebbe99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|