Skip to main content

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:

  1. Press k on left continuum region
  2. Press k on right continuum region
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spelacew-0.1.1.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spelacew-0.1.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file spelacew-0.1.1.tar.gz.

File metadata

  • Download URL: spelacew-0.1.1.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for spelacew-0.1.1.tar.gz
Algorithm Hash digest
SHA256 66b62865b43a16247e81f0fe9a781c5c467c396436522eed89b92b030fafbefd
MD5 4ceb04c42ecc84e615ea940a0d133477
BLAKE2b-256 f1080141a530b46eec3f4c000dd4143da5dbfefa3faa39701a225482f6036e2c

See more details on using hashes here.

File details

Details for the file spelacew-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: spelacew-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for spelacew-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3279fe8a62fa2e3a6d3716b324dd51f4fc189d9dfc2a600d61862ba54112194b
MD5 8411ad8b2caea30daaaf64be0f0e8cb0
BLAKE2b-256 1b11371a5fac7b680cc03c11bade6299e02cf80257c920b436975a828f85708a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page