Skip to content

Commit

Permalink
vactoair
Browse files Browse the repository at this point in the history
  • Loading branch information
profxj committed Jul 14, 2016
1 parent 5dd2bff commit 15c7457
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion linetools/spectra/tests/test_xspectrum_utils.py
Expand Up @@ -26,13 +26,16 @@ def data_path(filename):
data_dir = os.path.join(os.path.dirname(__file__), 'files')
return os.path.join(data_dir, filename)

def test_airtovac(spec):
def test_airtovac_andback(spec):
npix = 1000
spec = XSpectrum1D.from_tuple((np.linspace(5000.,6000,npix), np.ones(npix)))
# Airtovac
spec.airtovac()
# Test
np.testing.assert_allclose(spec.wavelength[0].value, 5001.394869990007, rtol=1e-5)
# Vactoair
spec.vactoair()
np.testing.assert_allclose(spec.wavelength[0].value, 5000., rtol=1e-5)


def test_write(spec,specm):
Expand Down
21 changes: 21 additions & 0 deletions linetools/spectra/xspectrum1d.py
Expand Up @@ -539,6 +539,27 @@ def airtovac(self):
# Finish
self.wavelength = new_wave

def vactoair(self):
"""Convert to air-based wavelengths from vacuum
Returns:
----------
Resultant wavelength array is in AA no matter the input units
"""
# Convert to AA
wavelength = self.wavelength.to(u.AA).value

# Standard conversion format
sigma_sq = (1.e4/wavelength)**2. #wavenumber squared
factor = 1 + (5.792105e-2/(238.0185-sigma_sq)) + (1.67918e-3/(57.362-sigma_sq))
factor = factor*(wavelength>=2000.) + 1.*(wavelength<2000.) #only modify above 2000A

# Convert
wavelength = wavelength/factor
# Units
new_wave = wavelength*u.AA
# Finish
self.wavelength = new_wave

def constant_sig(self, sigv=0.):
"""Set the uncertainty array to a constant value.
Expand Down

0 comments on commit 15c7457

Please sign in to comment.