Wavelength conversion (air and vacuum)¶
PyA provides tools to convert wavelengths from air into vacuum conditions and vice versa:
- These functions allow to use the conversions specified by:
Edlen 1953, J. Opt. Soc. Am 43 no. 5
Peck and Reeder 1972, J. Opt. Soc. 62 no. 8
Ciddor 1996, Applied Optics 35 no. 9
Warning
The function airtovac and vactoair are based on the formula by Edlen 1953. It seems that air wavelengths (or wavenumbers) are used, where vacuum wavenumbers should be used.
Moreover, you can use:
to convert from vacuum into air conditions or vice versa, but retain the input wavelength axis.
Usage examples for airtovac2 and vactoair2¶
Example: From air to vacuum and back¶
from __future__ import print_function, division
from PyAstronomy import pyasl
import numpy as np
# Define wavelength array
wvl = np.arange(10) + 5000.0
print("Input wavelengths: ", wvl)
# Convert wavelength in air to wavelength
# in vacuum. By default, the conversion
# specified by Ciddor 1996 are used.
wvlVac = pyasl.airtovac2(wvl)
print("Wavelength in vacuum: ", wvlVac)
# Convert wavelength from vacuum to air
wvlAir = pyasl.vactoair2(wvlVac)
print("Wavelength in air: ", wvlAir)
Example: Compare Edlen and Ciddor conversions¶
from PyAstronomy import pyasl
import numpy
import matplotlib.pylab as plt
# Compare the Edlen and Ciddor conversions
wvl = numpy.arange(3000, 10000, 1.0)
wvlVacCiddor = pyasl.airtovac2(wvl, mode="ciddor")
wvlVacEdlen = pyasl.airtovac2(wvl, mode="edlen53")
plt.subplot(2, 1, 1)
plt.title("Difference in air wavelength (Ciddor-Edlen)")
plt.ylabel("dWvl [A]")
plt.xlabel("Vacuum wvl [A]")
plt.plot(wvl, wvlVacCiddor-wvlVacEdlen, 'b.-')
plt.subplot(2, 1, 2)
plt.title("Difference in air wavelength (Ciddor-Edlen, in RV)")
plt.ylabel("dRV [m/s]")
plt.xlabel("Vacuum wvl [A]")
plt.plot(wvl, (wvlVacCiddor-wvlVacEdlen)/wvlVacCiddor*299792458., 'b.-')
plt.show()
API documentation: airtovac2 and vactoair2¶
- PyAstronomy.pyasl.airtovac2(wvl, mode='ciddor', **kwargs)¶
Converts wavelength in air into wavelength in vacuum.
This function is a wrapper around the RefractiveIndexAV class.
- Parameters
- wvl :float or array
Wavelength in vacuum [A].
- modestring, {edlen53, peckReeder, ciddor}, optional
The source for the wavelength conversion. The default is “ciddor”.
- kwargsdict
Additional parameters handed to the airtovac method of RefractiveIndexAV.
- Returns
- wvlfloat or array
Wavelength in vacuum [A].
- PyAstronomy.pyasl.vactoair2(wvl, mode='ciddor', **kwargs)¶
Converts wavelength in vacuum into wavelength in air.
This function is a wrapper around the RefractiveIndexAV class.
- Parameters
- wvl :float or array
Wavelength in vacuum [A].
- modestring, {edlen53, peckReeder, ciddor}, optional
The source for the wavelength conversion. The default is “ciddor”.
- kwargsdict
Additional parameters handed to the vactoair method of RefractiveIndexAV.
- Returns
- wvlfloat or array
Wavelength in air [A].
Obtaining the refractive index¶
Although the conversion of wavelength between air and vacuum conditions is the primary application targeted here, what is really needed to carry out the conversion is the refractive index.
- class PyAstronomy.pyasl.RefractiveIndexAV(mode='ciddor')¶
Refractive index for conversion between air- and vacuum wavelengths.
- The conversion is based on the formulae provided either by:
Edlen 1953, J. Opt. Soc. Am 43 no. 5
Peck and Reeder 1972, J. Opt. Soc. 62 no. 8
Ciddor 1996, Applied Optics 35 no. 9
This class provides the routine refractiveIndex, vactoair, and airtovac to convert between wavelengths in air and vacuum.
The method refractiveIndex points to either of _edlen53, _ciddor, or _peckReeder depending on the mode chosen.
To conversion from vacuum to air wavelengths is given by the respective formulae provided by the authors of the above papers, who all specify the refractive index of “standard air” as a function of vacuum wave number. The reverse conversion from air into vacuum is done by applying an iterative scheme. Standard air is at 15 degrees Celsius, dry, and at a pressure of 750 mmHg = 101325 Pa. Ciddor assumes a CO2 concentration of 450 ppm, while Edlen, and Peck and Reeder have assumed 300 ppm.
- Parameters
- modestring, {edlen53, peckReeder, ciddor}, optional
The source for the wavelength conversion. The default is “ciddor”.
Methods
airtovac
(wvl[, precision, maxiter])Convert air wavelength into wavelength in vacuum.
vactoair
(wvl, **kwargs)Convert vacuum wavelength into wavelength in air.
- _ciddor(wvl, xc=None)¶
Refractive index given by Ciddor 1996.
- Parameters
- wvlfloat or array
Vacuum wavelength [A]
- xcfloat, optional
Concentration of CO2 [ppm]
- Returns
- nfloat or array
Refractive index
- _edlen53(wvl)¶
Refractive index according to Edlen 1953.
- Parameters
- wvlfloat or array
Vacuum wavelength [A]
- Returns
- nfloat or array
The refractive index.
- _peckReeder(wvl)¶
Refractive index from Peck and Reeder 1972.
- Parameters
- wvlfloat or array
Vacuum wavelength [A]
- Returns
- nfloat or array
The refractive index.
- airtovac(wvl, precision=1e-12, maxiter=30, **kwargs)¶
Convert air wavelength into wavelength in vacuum.
An iterative scheme is applied to invert the formula.
- Parameters
- wvlfloat or array
Wavelength in vacuum [A].
- precisionfloat, optional
The target precision beyond which iteration should be stopped; default is 1e-12.
- maxiterint, optional
Maximum number of iterations used to invert the conversion; default is 30.
- kwargsdict
Additional keywords eventually needed in the call to the refractiveIndex function (depends on the specified ‘mode’).
- Returns
- wvlfloat or array
Wavelength in air.
- vactoair(wvl, **kwargs)¶
Convert vacuum wavelength into wavelength in air.
- Parameters
- wvlfloat or array
Wavelength in vacuum [A].
- kwargsdict
Additional keywords eventually needed in the call to the refractiveIndex function (depends on the specified ‘mode’).
- Returns
- wvlfloat or array
Wavelength in air.
Example: Obtain refractive index of standard air¶
from __future__ import print_function, division
from PyAstronomy import pyasl
import numpy as np
# Define wavelength array
wvl = np.arange(10) + 5000.0
# Obtain refractive index according to Ciddor 1996
ri = pyasl.RefractiveIndexAV(mode="ciddor")
n = ri.refractiveIndex(wvl)
print("Wavelength and 1.0 - Refractive index of 'standard air':")
for w, nc in zip(wvl, n):
print("{0:5.1f} {1:10.8e}".format(w, nc-1.0))
Transform spectrum, but retain wavelength axis¶
- PyAstronomy.pyasl.specAirVacConvert(wvl, flux, direction, dontUse2=False)¶
Transform spectrum between air and vacuum wavelengths.
In contrast to
airtovac()
andvactoair()
, which only transform the wavelength axis, this function converts the wavelength axis and interpolates the shifted spectrum to retain the input wavelength axis.Due to the shift, a fraction of the spectrum is lost on one side, while there is no valid information on the other. Therefore, the function returns both a new flux array obtained by linear interpolation and an array of valid indices, i.e., those indices in the new spectrum, which are not NaN.
Warning
Linear interpolation of the spectrum can affect its noise properties. This function does nothing to prevent or correct for that effect.
- Parameters
- wvlarray
Input wavelength axis.
- fluxarray
Input flux array.
- directionstring, {“airtovac”,”vactoair”}
If the direction is “vactoair”, the input spectrum is assumed to be obtained in vacuum conditions. The opposite is true otherwise.
- dontUse2boolean, optional
If True, the now deprecated function airtovac and vactoair will be used. Otherwise (default), airtovac2 and vactoair2 will be used with default settings.
- Returns
- New fluxarray
The shifted flux array, defined on the input wavelength axis.
- Valid indicesarray
The array of valid, i.e., not NaN, indices.
Example: Convert spectrum from vacuum into air conditions¶
from PyAstronomy import pyasl
from PyAstronomy import funcFit as fuf
import numpy as np
import matplotlib.pylab as plt
g = fuf.GaussFit1d()
g["A"] = -0.1
g["sig"] = 0.03
g["mu"] = 5004.4752
g["off"] = 1.0
# Create a "spectrum" ...
wvl = np.linspace(5000., 5010., 1000)
flux = g.evaluate(wvl)
# ... and add some noise
flux += np.random.normal(0., 0.02, len(wvl))
# Assume that this spectrum is one observed
# or modeled in vacuum conditions. We want
# to convert it into a spectrum in air, but
# retain the old wavelength axis.
airflux, vind = pyasl.specAirVacConvert(wvl, flux,
direction="vactoair")
# Plot the result
plt.plot(wvl, flux, "b.-")
plt.plot(wvl, airflux, "r.-")
plt.show()
API documentation: airtovac and vactoair¶
Note
These function are now considered deprecated.
Both functions have been ported from IDL’s astrolib.
- PyAstronomy.pyasl.airtovac(wave, depWarn=True)¶
Convert air wavelengths to vacuum wavelengths
Warning
The conversion implemented here is based on the older formulae given by Edlen 1953. Furthermore, it seems that wave numbers in air are used, where vacuum wave numbers should be used, which, however, produces only a second-order deviation. Consider using
airtovac2()
instead.- Parameters
- wavefloat, array
The wavelength in air [Angstrom]
- depWarnboolean, optional
If True (default), a deprecation warning will be given.
- Returns
- Wavelengtharray
Wavelength in vacuum [Angstrom]
Notes
Note
This function was ported from the IDL Astronomy User’s Library.
- IDL - Documentation
- NAME:
AIRTOVAC
- PURPOSE:
Convert air wavelengths to vacuum wavelengths
- EXPLANATION:
Wavelengths are corrected for the index of refraction of air under standard conditions. Wavelength values below 2000 A will not be altered. Uses the IAU standard for conversion given in Morton (1991 Ap.J. Suppl. 77, 119)
- CALLING SEQUENCE:
AIRTOVAC, WAVE
- INPUT/OUTPUT:
- WAVE - Wavelength in Angstroms, scalar or vector
WAVE should be input as air wavelength(s), it will be returned as vacuum wavelength(s). WAVE is always converted to double precision upon return.
- EXAMPLE:
If the air wavelength is W = 6056.125 (a Krypton line), then AIRTOVAC, W yields an vacuum wavelength of W = 6057.8019
- METHOD:
See Morton (Ap. J. Suppl. 77, 119) for the formula used
- REVISION HISTORY
Written W. Landsman November 1991 Converted to IDL V5.0 W. Landsman September 1997
- PyAstronomy.pyasl.vactoair(wave, depWarn=True)¶
Convert vacuum wavelengths to air wavelengths
Warning
The conversion implemented here is based on the older formulae given by Edlen 1953. Furthermore, it seems that wave numbers in air are used, where vacuum wave numbers should be used, which, however, produces only a second-order deviation. Consider using
vactoair2()
instead.- Parameters
- wavefloat, array
The wavelength in vacuum [Angstrom]
- Returns
- Wavelengtharray,
Wavelength in air [Angstrom]
- depWarnboolean, optional
If True (default), a deprecation warning will be given.
Notes
Note
This function was ported from the IDL Astronomy User’s Library.
- IDL - Documentation
- NAME:
VACTOAIR
- PURPOSE:
Convert vacuum wavelengths to air wavelengths
- EXPLANATION:
Corrects for the index of refraction of air under standard conditions. Wavelength values below 2000 A will not be altered. Accurate to about 0.005 A
- CALLING SEQUENCE:
VACTOAIR, WAVE
- INPUT/OUTPUT:
- WAVE - Wavelength in Angstroms, scalar or vector
WAVE should be input as vacuum wavelength(s), it will be returned as air wavelength(s). WAVE is always converted to double precision
- EXAMPLE:
If the vacuum wavelength is W = 2000, then
IDL> VACTOAIR, W
yields an air wavelength of W = 1999.353 Angstroms
- METHOD:
An approximation to the 4th power of inverse wavenumber is used See IUE Image Processing Manual Page 6-15.
- REVISION HISTORY
Written, D. Lindler 1982 Documentation W. Landsman Feb. 1989 Converted to IDL V5.0 W. Landsman September 1997