Wednesday, September 16, 2015

Convert vacuum wavelenths to air, using ascii.read() and ascii.write()

import ref_index   # python package ref_index does refractive index of air,
                   # for converting vacuum wavelengths to air wavelengths.
from astropy.io import ascii
import matplotlib.pyplot as plt
tbl = ascii.read("oh-lines-vac")
tbl.colnames    # should be vacwave and theo_intens
wave_vac_A =  tbl['vacwave'] # vacuum wavelength in angstroms
wave_air_A = ref_index.vac2air(wave_vac_A / 10.) * 10.  # ref_index assumes nanometers
plt.plot(wave_vac_A, (wave_vac_A / wave_air_A))
plt.show()
ascii.write([wave_vac_A, wave_air_A, tbl['theo_intens']], names=['wave_vac_A', 'wave_air_A', 'theor_intens'], output='Rousselot_OH_air_and_vac.out')


Update (June 2017) using Pandas, from air to vac:
import pandas
import ref_index
df = pandas.read_table("temp_Nicholls_He_linelist.txt", delim_whitespace=True, comment="#")
df['wave_nist_vac'] = ref_index.air2vac(df['wave_nist_air'] / 10.) * 10.
# That's it.  Easy-peasy

No comments:

Post a Comment