Skip to content

Instantly share code, notes, and snippets.

@autocorr
Created August 10, 2016 06:02
Show Gist options
  • Select an option

  • Save autocorr/6e4f868d9010879ea03037a70c786f25 to your computer and use it in GitHub Desktop.

Select an option

Save autocorr/6e4f868d9010879ea03037a70c786f25 to your computer and use it in GitHub Desktop.
from __future__ import print_function
import glob
from os import path
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from astropy import units as u
from astropy import constants as c
def read_spectra(filen):
df = pd.read_csv(filen, names=['wavel', 'intens'], sep=' ', skiprows=1)
return df
def plot_spectra(filen):
cen_wavel = 6569.53 # Angstroms
del_wavel = 0.5
ref = read_spectra('ReferenceSpectrum.txt')
obs = read_spectra(filen)
ref['velo'] = (ref['wavel'] - cen_wavel) / cen_wavel * c.c.to('km/s').value
obs['velo'] = (obs['wavel'] - cen_wavel) / cen_wavel * c.c.to('km/s').value
fig, ax = plt.subplots()
ax.step(ref.velo, ref.intens, where='mid', color='red', label='Ref')
ax.step(obs.velo, obs.intens, where='mid', color='black', label='Obs')
ax.set_xlim([-10, +10])
ax.set_xlabel('Velocity [km / s]')
ax.set_ylabel('Intensity')
ax.legend()
ax.grid()
plt.savefig(path.splitext(filen)[0] + '.pdf')
plt.close()
def plot_all():
for filen in glob.glob('Group*.txt'):
plot_spectra(filen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment