Skip to content

thriveth/Pychelle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pychelle

Pychelle is a Python helper app for 1D and 2D echelle (and, to be honest, also most other kinds of) spectroscopy. It allows to load a 2D spectrum, select and extract a subset of the rows for modelling, building models by eye and calling a back-end fitter (for now, only LMfit) to perform the fitting. It allows to set the included and ignored fit ranges for each row or set of rows, and assigning identifying labels and color codes to individual components, allowing to treat them group-wise.

It manages transitions based on an easily extensible plain-text list. The resulting model is returned as a Pandas DataFrame.

The repository includes a sample data set of supernova 1987A, observed with the UVES spectrograph at the ESO Very Large Telescope in Paranal, Chile. The spectrum is public and the first analysis was presented in this paper (not using Pychelle).

Dependencies

Pychelle depends on the standard SciPy stack and, on top of that the Enthought Tool Suite, especially Traits & TraitsUI (GUI and interface libraries) and Chaco (plotting package).

Optional requirements are Astroquery and its dependency Astropy for finding redshifts online, and LMfit necessary for actual fitting.

Caveats & limitations

Pychelle is presented here as-is, mainly for the purpose of showcasing, although it should also be usable -- See this presentation for an example. However, it has several bugs and things that could be done better; I will fix these when I have time, but I am of course thankful for pull requests.

One known bug is that sometimes, reassigning identifier labels gets applied to the wrong components, and there is no way to revert this. It is probably not a very difficult bug to squash, but I have not had time to fix it yet This has now been fixed.

The modeling interface so far only supports a constant continuum and Gaussian emission peaks. Gaussian absorption is trivial to add, but other continuum and line profiles require a bit more work.

Data in units that give very small numerical values can give the viewer problems. A simple workaround is to multiply the data, errors and model amplitudes by the same number, and divide them again when saving.

Screenshots

Test data loaded into main window. Below is the colorscale editor dialog and the add-transition dialog. The latter supports adding a new transition based on the kinematics of an existing one and performing an immediate, quick fit of the new one allowing only the amplitudes to vary.

Pychelle main window

Wavelength range editor window:

Pychelle fitranges window

The 1D model editor and fitting window. The lower plot panel shows residuals in terms of error spectrum.

Line profile builder

Finally, the component editor. The three plot panels shows the three Gaussian parameters: Center, amplitude and width (given as σ). Colors reflect one-letter ID labels, which can be reassigned with the bottom dialog.

Component editor

Simple test session

First, load the data into a Spectrum2D object, and in turn load this into a Show2DSpec object:

import pychelle as pc

sn = pc.load_2d(
    './testdata/SN1987a-Halpha.fits',
    objname='SN1987a',  # Should be resolvable in NED if redshift query wanted.
    redshift=False,     # Calls NED through Astroquery, relevant for extragalactic objects
)
# Optional:
sn.load_model('./testdata/SN1987a-Halpha-model.csv')
# Vire the interface, returns the view.
SN = pc.view_2d(sn, Center=6564.)  # To view the H-Alpha region
# The view can be reopened:
SN.configure_traits(view='main')

When not working interactively, the model, data and other quantities can now be retrieved as properties of the Spectrum2D object, e.g.

fluxes = sn.flux  # Integrated flux for each model component
data = sn.data
error_spectrum = sn.errs
wave = sn.wavl
model = sn.model

TODO

  • 2D Spectrum object
  • Main overview window
  • Transition manager
  • Set wavelength ranges graphically
  • Set colorscale: Linear, log or square root. Select colorscheme.
  • Interactively build multi-component emission model by eye
  • Optionally call back-end fitting software, integrate results into model
  • Assign and edit ID labels for individual components
  • Save model as plain-text .csv file, read and import saved model
  • Save model as FITS file with metadata as header keywords
  • Support more different line shapes and absorption lines
  • Support velocity space besides wavelengths
  • Support more fitting backends (e.g. Sherpa, scipy.optimize, Astropy.modeling etc. )
  • Improve documentation.
  • Longer term: rewrite to be based on Astropy

About

Python-GUI for 1D and 2D spectroscopy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages