Interactive spectral line fitting and Equivalent Width measurement tool
Project description
SpelacEW
Interactive spectral line fitting and Equivalent Width (EW) measurement tool for stellar spectroscopy.
SpelacEW is a Python-based interactive software designed for the analysis of stellar absorption lines through manual continuum placement and Gaussian profile fitting. The code allows the user to inspect spectral regions individually, perform single-line or multi-line (blended) fits, and export reproducible measurements in a structured format.
The project was developed for high-control spectroscopic analysis workflows where visual inspection and user-guided continuum selection are essential.
Features
- Interactive visualization of stellar spectra
- Support for:
- FITS spectra
- ASCII/TXT/CSV spectra
- Manual continuum placement
- Gaussian fitting of absorption lines
- Multi-Gaussian fitting for blended lines
- Automatic calculation of:
- Equivalent Width (EW)
- Full Width at Half Maximum (FWHM)
- Reduced chi-square (χ²)
- Reference continuum visualization from external datasets
- Interactive spectral exploration mode
- Automatic generation of:
- CSV results tables
- Multi-page PDF reports
- Session accumulation:
- Existing results are preserved between runs
- PDFs are automatically merged across sessions
Scientific Motivation
Precise measurement of spectral line parameters is a fundamental task in stellar spectroscopy and abundance analysis. While fully automated EW pipelines are efficient for large datasets, many scientific applications still require manual inspection due to:
- blended spectral features
- continuum uncertainties
- local noise structures
- line asymmetries
- crowded spectral regions
SpelacEW was designed as a semi-manual high-control alternative, prioritizing:
- reproducibility
- visual inspection
- interactive continuum definition
- robust treatment of blended lines
This makes the code particularly useful for:
- stellar abundance studies
- chemical tagging
- solar reference comparisons
- educational spectroscopy workflows
- spectroscopic quality control
Installation
Clone repository
git clone https://github.com/USERNAME/spelacew.git
cd spelacew
Install package
Recommended installation:
pip install -e .
This enables the command-line interface:
spelacew
Dependencies
Main dependencies:
- numpy
- scipy
- matplotlib
- pandas
- PyAstronomy
- pypdf
Python >= 3.9 is required.
Input Data
Spectrum
Supported formats:
.fits.fit.txt.dat.ascii.csv
ASCII files must contain:
wavelength flux
in two columns.
Line List
The line list must be provided as a CSV file.
Minimum required column:
wavelength
Optional columns:
- element
- species
- ep
- gf
Example:
wavelength,element,species,ep,gf
6562.79,H,1,10.2,-0.3
Usage
Interactive mode
Run:
spelacew
The program will ask interactively for:
- spectrum file
- line list
- optional reference file
- optional width
Command-line mode
spelacew spectrum.fits lines.csv
Optional arguments:
spelacew spectrum.fits lines.csv width
or
spelacew spectrum.fits lines.csv width reference.csv
Example:
spelacew HD10700.fits lines_fe.csv 1.5 solar_reference.csv
Interactive Interface
The interface displays:
- observed spectrum
- theoretical line center
- crosshair cursor
- local spectral window
- automatic zoom panel after fitting
- reference continuum visualization (optional)
The user interacts entirely through keyboard commands.
Controls
Navigation
| Key | Action |
|---|---|
n |
Next spectral line |
p |
Previous spectral line |
Normal Fitting Mode
| Key | Action |
|---|---|
k |
Select continuum points |
Procedure:
- Press
kon left continuum region - Press
kon right continuum region - Fit executes automatically
The continuum is estimated through a linear interpolation between the selected points.
Blending Mode
| Key | Action |
|---|---|
b |
Enable/disable blending mode |
d |
Define fitting region |
g |
Add Gaussian component center |
Enter |
Execute multi-Gaussian fit |
This mode is intended for partially or strongly blended spectral features.
Each Gaussian component is fitted simultaneously.
Exploration Mode
| Key | Action |
|---|---|
x |
Enable exploration mode |
c |
Manual zoom input |
w |
Change visualization width |
Exploration mode allows free navigation through the spectrum independently of the predefined line list.
Other Commands
| Key | Action |
|---|---|
r |
Full reset |
a |
Cancel input |
q |
Save and quit |
Outputs
For each session, the program generates a directory:
ajustes_<spectrum_name>_<date>/
Example:
ajustes_HD10700_2026-05-06/
CSV Results
File:
resultados.csv
Contains:
| Column | Description |
|---|---|
| wavelength | Central wavelength |
| wave_left | Left fitting boundary |
| wave_right | Right fitting boundary |
| left_continuum | Left continuum level |
| right_continuum | Right continuum level |
| element | Atomic species |
| species | Ionization state |
| ep | Excitation potential |
| gf | Oscillator strength |
| ew_ref | Reference EW |
| ew | Measured EW |
| FWHM | Full Width at Half Maximum |
| Chi2R | Reduced χ² |
| hpf | Reserved parameter |
Equivalent Width values are reported in milli-Angstroms (mÅ).
PDF Report
File:
resultados.pdf
Contains one page per fitted line including:
- observed spectrum
- continuum model
- Gaussian fit
- zoom visualization
- fit diagnostics
PDF sessions are automatically merged between runs.
Fitting Methodology
Continuum Normalization
The continuum is defined manually using two user-selected points.
A linear continuum model is constructed through:
F_c(\lambda) = a\lambda + b
The observed spectrum is normalized as:
F_{norm} = \frac{F}{F_c}
Gaussian Model
Single-line fits use:
F(\lambda) =
1 - A \exp
\left(
-\frac{(\lambda-\mu)^2}{2\sigma^2}
\right)
where:
- (A) = line depth
- (\mu) = line center
- (\sigma) = Gaussian width
Multi-Gaussian Blending
For blended lines:
F(\lambda)=
1-
\sum_i
A_i
\exp
\left(
-\frac{(\lambda-\mu_i)^2}{2\sigma_i^2}
\right)
Each component is fitted simultaneously.
Equivalent Width
Equivalent Width is computed numerically as:
EW =
\int
(1-F_{norm}) d\lambda
and reported in milli-Angstroms (mÅ).
Recommended Usage
For more stable fits:
- select continuum regions wider than the line core
- avoid noisy edge regions
- inspect blended features manually
- verify continuum placement visually
Broader continuum selections generally improve normalization stability and reduce sensitivity to local noise fluctuations.
Current Status
Current implemented features:
- Interactive continuum selection
- Single Gaussian fitting
- Multi-Gaussian blending
- EW/FWHM/χ² calculations
- PDF and CSV export
- Reference EW comparison
- Spectral exploration mode
- Session accumulation
Planned future developments:
- automatic continuum estimation
- Voigt profile support
- radial velocity correction tools
- abundance pipeline integration
- GUI improvements
- batch-processing utilities
Citation
If you use SpelacEW in scientific work, please cite the repository and acknowledge the software appropriately.
Author
Daniel Pérez
Universidad de Concepción
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spelacew-0.1.0.tar.gz.
File metadata
- Download URL: spelacew-0.1.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
046b1749cd6440fb2c8e0160b1505d72b0eda3f776a242f9613b69c477108923
|
|
| MD5 |
4188c43bafb95d3068189a6c1c23db5b
|
|
| BLAKE2b-256 |
5616f17e789cfdb850e3a4acda49fc2f4ea4a2a5b0e80aaaa04e02139fa5b1a7
|
File details
Details for the file spelacew-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spelacew-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a00b176d321e0f80b24249cb6da8d2c40486a44a66d39b0cfc641fa488a1696e
|
|
| MD5 |
c6e26dfb9d4c23974a3cba1f8cbf09bb
|
|
| BLAKE2b-256 |
b975f3481d8dc813be4810127e3a0ac075e96a2907f96688e918ef6d9e63d9d3
|