Needed for consistently measuring RVs.

To consistently measure the RVs of my target stars, I need to align them with the telluric lines. That is because I took no effort to make sure they are consistent by e.g. observing an RV standard or something. I have a decent amount of code already written for the IGRINS pipeline, so lets just re-use that.

Status as of end of day Thusday, Sep 3:

  • Seems to work. Need to go through and apply to all of my stars I guess?
  • How stable is the rv fit?
  • Is it the same for all echi files that go into the final ones?
  • Need to keep track of the velocity changes to include in the companion velocities (or just re-run the ccf analysis on the new files)

In [1]:
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
import HelperFunctions
import telfit
from scipy.interpolate import InterpolatedUnivariateSpline as spline
import FittingUtilities
from scipy.optimize import minimize
from functools import partial
import Telluric_Wavecal
import logging

logger = logging.getLogger()
logger.setLevel(logging.INFO)
home = os.environ['HOME']
#sys.path.append('{}/School/Research/IGRINS_data/plp/recipes/'.format(home))
#import recipe_tell_wvsol

%matplotlib inline


/home/kgullikson/anaconda3/envs/python2/lib/python2.7/site-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
  "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)

In [2]:
with open('../starlist_20151016', 'r') as f:
    fnames = ['../{}'.format(fn).strip() for fn in f.readlines()]

In [6]:
fname = fnames[0]
o2_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(690,))
h2o_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(700., 715., 725., 735.))

print('O2 Fit:\n================')
o2_rv, o2_rv_err = o2_fitter.fit()
print('\n\nH2O Fit:\n===============')
h2o_rv, h2o_rv_err = h2o_fitter.fit()


Warning, 127 of 74515 bins contained negative fluxes; they have been set to zero.
O2 Fit:
================
INFO:root:RV = -0.20 +/- 0.005


H2O Fit:
===============
INFO:root:RV = 0.05 +/- 0.004


In [4]:
print(o2_rv, o2_rv_err)
print(h2o_rv, h2o_rv_err)


(-0.15427331607709174, 0.0045378657711410419)
(0.04757441906822106, 0.0035891945638753826)

In [3]:
import telfit
modeler = telfit.Modeler()
full_model = modeler.MakeModel(highfreq=1e7/680.0, lowfreq=1e7/780.0)
plt.plot(full_model.x, full_model.y)


Out[3]:
[<matplotlib.lines.Line2D at 0x7f9af14fb0d0>]

In [4]:
#with open('telluric_wavecal_summary2.csv', 'w') as f:
#    f.write('filename,o2_rv,o2_rv_err,h2o_rv,h2o_rv_err\n')

fnames = ['../20131216/HIP_59184.fits', 
          '../20140308/HIP_80112.fits',
          '../20140409/HIP_81266.fits', 
          '../20140417/HIP_81266.fits']
for i, fname in enumerate(fnames):
    print('File {}/{}: {}'.format(i+1, len(fnames), fname))
    o2_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(690, ), telluric_model=full_model)
    h2o_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(700., 715., 725., 735.), telluric_model=full_model)
    
    print('O2 Fit:\n================')
    o2_rv, o2_rv_err = o2_fitter.fit()
    print('\n\nH2O Fit:\n===============')
    h2o_rv, h2o_rv_err = h2o_fitter.fit()
    
    with open('telluric_wavecal_summary2.csv', 'a') as f:
        f.write('{},{},{},{},{}\n'.format(fname, o2_rv, o2_rv_err, h2o_rv, h2o_rv_err))


File 1/4: ../20131216/HIP_59184.fits
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
O2 Fit:
================
INFO:root:RV = -0.63 +/- 0.018


H2O Fit:
===============
INFO:root:RV = -0.11 +/- 0.027
File 2/4: ../20140308/HIP_80112.fits
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
O2 Fit:
================
INFO:root:RV = -0.20 +/- 0.005


H2O Fit:
===============
INFO:root:RV = 0.04 +/- 0.010
File 3/4: ../20140409/HIP_81266.fits
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
O2 Fit:
================
INFO:root:RV = -0.29 +/- 0.001


H2O Fit:
===============
INFO:root:RV = -0.04 +/- 0.010
File 4/4: ../20140417/HIP_81266.fits
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
Warning, 1337 of 684208 bins contained negative fluxes; they have been set to zero.
O2 Fit:
================
INFO:root:RV = -0.20 +/- 0.001


H2O Fit:
===============
INFO:root:RV = 0.07 +/- 0.004


In [8]:
import pandas as pd
df = pd.read_csv('../telluric_wavecal_summary.csv')
df.o2_rv.hist(bins=30)


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f9aeb634210>

In [9]:
df.h2o_rv.hist(bins=20)


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f9aeb634d50>

In [25]:
import scipy.stats
values = df.h2o_rv
loc, scale = scipy.stats.norm.fit(data=values[~np.isnan(values)])
df.h2o_rv.hist(bins=10, normed=True, alpha=0.4)
x = np.arange(-0.2, 0.3, 0.01)
y = scipy.stats.norm.pdf(x, loc=loc, scale=scale)
plt.plot(x, y, 'r-', lw=2)


Out[25]:
[<matplotlib.lines.Line2D at 0x7fb896294ad0>]

In [23]:
y


Out[23]:
array([ 0.00208537])