SLiPy

A Spectroscopy and astrophysics Library for Python 3

This Python package is an expanding code base for doing computational astronomy, particularly spectroscopy. It contains both a Spectrum class for handling spectra as objects (with +, -, *, /, etc... operations defined) and a growing suite of analysis tools.

Dependencies: Python 3.x, astropy, matplotlib, numpy, scipy

astropy GitHub license

Quick note: the subpackage astrolibpy was not developed by me. It was coded by Sergey Koposov (@segasai) at Cambridge (then at least). I found it useful for performing velocity corrections on my spectroscopic data. I've modified several modules such that it can be imported and used in Python 3.x. See his README file.

Contents

SLiPy is split into several components. The principle component is the subpackage SLiPy itself, which contains all the relevant functionality. Further, Data is a package I'm working on that will provide an API for searching astronomical data archives in a simple way. The other two subpackages Framework and astrolibpy are of utility to the project but not necessarily intended for export. As stated previously, astrolibpy was not developed by me, only modified. I'm not going to document it's usage here. Its name is unfortunate for me as it is a bit over done with the convention I was already using, but for consistency I will keep it as it was from the author.

The following modules are elevated to the package level and are available to import:

SLiPy/ Functions/Classes
Spectrum WaveVector, Spectrum,
Fits Find, RFind, GetData, Header, Search, PositionSort,
Simbad Position, Distance, Sptype, IDList,
Correlate XCorr,
Telluric Correct,
Velocity HelioCorrect, BaryCorrect, IrafInput,
Observatory ...,
Plot SPlot, Iterate,
Profile Select, Fit, Extract,
Montage SolveGrid, Mosaic, SubField, Field,


SLiPy/Data Functions/Classes
Elodie Archive, Script, Download,
Atomic Ion, IonManager,

Installation

To install SLiPy, there is no setup procedure. Simply download the package, either by clicking on the download link for a tar or zip archive or by cloning it.

Extract it's contents to wherever you like in a directory (ostensibly named slipy, but actually you can call this library whatever you want as well because all the imports are relative). Then add the parent directory to your PYTHONPATH if it isn't already. For example:

$ cd
$ git clone http://github.com/glentner/slipy
$ echo "export PYTHONPATH=$PYTHONPATH:~" >> ~/.bashrc

And your ready to go!

Exceptions

SLiPy attempts to catch all foreseeable exceptions and re-throw them under a common handle with a human readable message. There is a unique exception class for every module, all derived from a common SlipyError. The naming convention is for a module's exception to be named after the module with the addition of the word Error. So the Fits module will throw a FitsError. These are meant to handle erros internally. The user need not worry about these in an interactive session; however, inside of scipts you might catch SlipyError. For finer control, catch the individual exceptions (e.g., Fits.FitsError).

Contribute

If you use SLiPy or have your own code related to spectroscopy or computing for astronomy and think it would be a useful addition (or you find a bug/mistake) I'm more than open to suggested contributions/additions.

Author(s)

Geoffrey Lentner, B.S.
Graduate Research Assistant
Department of Physics & Astronomy
University of Louisville

Significant intellectual contributions have been made by my thesis advisor, specifically in terms of the science behind much of this package.

James Lauroesch, Ph.D.
Associate Professor
Department of Physics & Astronomy
University of Louisville

Acknowledge SLiPy

If you have made use of SLiPy in your project/research, you can acknowledge your use in the following ways:

Publications
This research has made use of SLiPy, an open source spectroscopy and astrophysics library for Python 3 (G. Lentner, 2015).

Projects
If your code either makes use of or borrows from SLiPy, a good way to reference this is with a shield in your README file.

SLiPy

The above badge is generated using the following snippet

[![SLiPy](http://img.shields.io/badge/running-SLiPy-green.svg?style=flat)](http://glentner.github.io/SLiPy)

Documentation


Spectrum

Objects for representing astronomical data. Currently, this includes the Spectrum class and it's helper function WaveVector.


Fits

Manipulate FITS files. Import data into Spectrum objects. Filter results by right ascension and declination. Grab header elements. Search for attributes of the data such as distance, spectral type, etc.


Simbad

This module allows the user to query the SIMBAD astronomical database from inside Python or shell commands/scripts. It's four current major functions Position, Distance, Sptype, and IDList return real variables with appropriate types ready for use.

As a shell script:

$ Simbad.py

 usage: Simbad.py @Attribute <identifier> [**kwargs]

 The 'Attribute' points to a function within this module and indicates
 what is to be run. Execute 'Simbad.py @Attribute help' for usage details of
 a specific function. Currently available attributes are: `Position`,
 `Distance`, `Sptype` and `IDList`.

 The identifier names can be anything recognized by SIMBAD (e.g., Regulus,
 "alpha leo", "HD 121475", "del cyg", etc ...) if the name is two parts make
 sure to use quotation to enclose it.

 The **kwargs is the conventional reference to Python keyword arguments.
 These should be specific to the 'Attribute' being pointed to.


Correlate

Correlation functions for astronomical data.


Telluric

Removal of atmospheric absorption lines in spectra.


Velocity

Radial velocity corrections for 1D spectra.


Observatory

Define observatory parameter similar to the IRAF task. All observatories should follow the following pattern. The user can add as many as they like to this module. I welcome suggestions.

class OHP(Observatory):
    """
    The Observatoire de Haute-Provence, France.
    """
    def __init__(self):
        self.name       = 'Observatoire de Haute-Provence'
        self.longitude  = 356.28667  * u.degree # West
        self.latitude   = 43.9308334 * u.degree # North
        self.altitude   = 650        * u.meter
        self.timezone   = 1          * u.hourangle
        self.resolution = 42000

There are currently 69 defined observatories:

Class ID Observatory Name
OHP The Observatoire de Haute-Provence, France.
KPNO Kitt Peak National Observatory
WIYN WIYN Observatory
CTIO Cerro Tololo Interamerican Observatory
LASILLA European Southern Observatory: La Silla.
PARANAL European Southern Observatory: Paranal
LICK Lick Observatory
MMTO MMT Observatory
CFHT Canada-France-Hawaii Telescope
LAPALMA Roque de los Muchachos, La Palma.
MSO Mt. Stromlo Observatory
SSO Siding Spring Observatory
AAO Anglo-Australian Observatory
MCDONALD McDonald Observatory
LCO Las Campanas Observatory
MTBIGELOW Catalina Observatory: 61 inch telescope
DAO Dominion Astrophysical Observatory
SPM Observatorio Astronomico Nacional, San Pedro Martir.
TONA Observatorio Astronomico Nacional, Tonantzintla.
PALOMAR The Hale Telescope
MDM Michigan-Dartmouth-MIT Observatory
NOV National Observatory of Venezuela
BMO Black Moshannon Observatory
BAO Beijing XingLong Observatory
KECK W. M. Keck Observatory
EKAR Mt. Ekar 182 cm. Telescope
APO Apache Point Observatory
LOWELL Lowell Observatory
VBO Vainu Bappu Observatory
IAO Indian Astronomical Observatory, Hanle
FLWO Whipple Observatory
FLWO1 Whipple Observatory
ORO Oak Ridge Observatory
LNA Laboratorio Nacional de Astrofisica - Brazil
SAAO South African Astronomical Observatory
CASLEO Complejo Astronomico El Leoncito, San Juan.
BOSQUE Estacion Astrofisica Bosque Alegre, Cordoba.
ROZHEN National Astronomical Observatory Rozhen - Bulgaria.
IRTF NASA Infrared Telescope Facility
BGSUO Bowling Green State Univ Observatory.
DSAZ Deutsch-Spanisches Observatorium Calar Alto - Spain.
CA Calar Alto Observatory
HOLI Observatorium Hoher List (Universitaet Bonn) - Germany.
LMO Leander McCormick Observatory
FMO Fan Mountain Observatory
WHITIN Whitin Observatory,Wellesley College
OSN Observatorio de Sierra Nevada
GEMINI NORTH Gemini North Observatory
GEMINI SOUTH Gemini South Observatory
LASILLA European Southern Observatory: La Silla.
PARANAL European Southern Observatory: Paranal.
ESONTT European Southern Observatory, NTT, La Silla.
ESO36M European Southern Observatory, 3.6m Telescope, La Silla.
ESOVLT European Southern Observatory, VLT, Paranal.
SLN SLN - Catania Astrophysical Observatory.
EUO Ege University Observatory
TNO Turkiye National Observatory
TUG TUBITAK National Observatory, Turkey.
MGO Mount Graham Observatory
ARIES Aryabhatta Research Institute of Observational Sciences.
OALP Observatorio Astronomico de La Plata
OLIN Connecticut College - Olin Observatory
BOYDEN Boyden Observatory
LULIN Lulin Observatory
SOAR Southern Astrophysical Research Telescope.
BAKER Baker Observatory
HET McDonald Observatory - Hobby-Eberly Telescope.
JCDO Jack C. Davis Observatory, Western Nevada College
LNO Langkawi National Observatory


Plot

Convenient wrappers to matplotlib for plotting spectra. A SPlot simply creates a handle to remember figure attributes, to quickly go from looking at one spectra to another. One can also overlay spectra.


Profile

Profile fitting tasks for spectra.


Montage

Montage is a very powerful suite of C code for creating image mosaics. This module is a wrapper to automate not only the process for small projects, but to segment large fields into a grid and mosaic each site before combining them into a master mosaic.

At the outset of the development of this module, the author was unaware of the currently available montage_wrapper. This module will no longer be developed. Nevertheless, it remains a high level manager for creating mosaics.

See the example in Figure 5.


Elodie

Methods for data retrieval from the Elodie Archive.


Atomic

Convenient access to a large set of published atomic data for absorption lines:

``Atomic data for resonance absorption lines. III. Wavelengths longward of the Lyman limit for the elements Hydrogen to Gallium''
Author: Donald C. Morton (2003)
Online: http://iopscience.iop.org/0067-0049/149/1/205/fulltext/

The IonManager can be imported via the member instance IonSearch.

Examples:

Import the data set:

from slipy.Data.Atomic import IonSearch
# equivalent to `from slipy.Data.Atomic import IonManager; IonSearch = IonManager()`

The member .data contains the entire table from Morton 2003. We can access information of interest directly however by calling the Ions object.

IonSearch('C III')
[(<Quantity 977.0201 Angstrom>, 0.7570010842747638),
 (<Quantity 1908.734 Angstrom>, 1.6875419997146983e-07)]

The second item in each of those pairs was the oscillator strength, or fvalue, for the lines. The wavelength given was in vacuum. We can request the same lines in air:

IonSearch('C III', wavelength='air')
[(None, 0.7570010842747638), (None, 1.6875419997146983e-07)]

The result is None because those values don't exist in the data set. But they are indeed the same lines.

We can ask for a wavelength range, and change what we are looking up:

IonSearch( (5885, 5900), wavelength='air', lookup='ion')
[(<Quantity 5889.951 Angstrom>, 'Na I'),
 (<Quantity 5894.092 Angstrom>, 'Ti I'),
 (<Quantity 5895.924 Angstrom>, 'Na I')]

Units work as well:

from astropy import units as u
IonSearch( (588.5 * u.nm, 590.0 * u.nm), wavelength='air', lookup='ion')
[(<Quantity 5889.951 Angstrom>, 'Na I'),
 (<Quantity 5894.092 Angstrom>, 'Ti I'),
 (<Quantity 5895.924 Angstrom>, 'Na I')]


Example:

from slipy.Data import Atomic
D2 = Atomic.Ion('Na I', 589.1 * u.nm, A = 6.16e7 / u.s)
D2
Ion:        Na I
Wavelength: 589.1583300000001 nm
fvalue:     0.6408671009122726
A:          61600000.0 1 / s