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 [27]:
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

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

In [28]:
fname = fnames[-1]
reload(Telluric_Wavecal)
o2_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(690, ))
h2o_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(700., 715., 730.))

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, 139 of 94568 bins contained negative fluxes; they have been set to zero.
O2 Fit:
================
INFO:root:RV = -0.68 +/- 0.059


H2O Fit:
===============
INFO:root:RV = -0.36 +/- 0.070


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


(-0.67769752654349158, 0.058903622420281222)
(-0.3634620054844428, 0.070298832214354998)

In [30]:
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[30]:
[<matplotlib.lines.Line2D at 0x7fcfe23db7d0>]

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

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., 730.), 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_summary.csv', 'a') as f:
        f.write('{},{},{},{},{}\n'.format(fname, o2_rv, o2_rv_err, h2o_rv, h2o_rv_err))


File 1/120: ../20130106/HIP_28691.fits
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-4b61735b8596> in <module>()
      4 for i, fname in enumerate(fnames):
      5     print('File {}/{}: {}'.format(i+1, len(fnames), fname))
----> 6     o2_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(690.), telluric_model=full_model)
      7     h2o_fitter = Telluric_Wavecal.VelocityFitter(fname, tell_orders=(700., 715., 730.), telluric_model=full_model)
      8 

/home/kgullikson/School/Research/McDonaldData/TS23-Scripts/Telluric_Wavecal.pyc in __init__(self, filename, tell_orders, telluric_model)
     60             orders = HelperFunctions.ReadExtensionFits(fname)
     61             basename = os.path.basename(fname)
---> 62             for n in tell_orders:
     63                 if isinstance(n, int) and n < len(orders):
     64                     self.data[basename].append(orders[n])

TypeError: 'float' object is not iterable

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


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fb896851a90>

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


Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fb89662a390>

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 [26]:
orders = HelperFunctions.ReadExtensionFits('../20140110/KG13385-0.fits')
print(len(orders))
%matplotlib inline
fig = plt.figure(figsize=(15,7))
ordernums = HelperFunctions.FindOrderNums(orders, (690., 700., 715., 730.))

for order in orders:
    plt.plot(order.x, order.y/order.cont, 'k-', alpha=0.5)
    
    
for order in [orders[n] for n in ordernums]:
    plt.plot(order.x, order.y/order.cont, 'r-', alpha=0.5)
    print(order.x[0], order.x[-1])


55
(683.05213119143082, 694.06829395818613)
(696.99142286661333, 708.23179628605158)
(711.51142568514979, 722.98535037882675)
(726.64920786127971, 738.36661986523609)

In [ ]: