Skip to content

Instantly share code, notes, and snippets.

@wkerzendorf
Created September 16, 2015 11:55
Show Gist options
  • Save wkerzendorf/93240687eebbe6a8b5e8 to your computer and use it in GitHub Desktop.
Save wkerzendorf/93240687eebbe6a8b5e8 to your computer and use it in GitHub Desktop.
from astropy.table import Table
from astropy.io import fits
import pandas as pd
import numpy as np
class XShooterEchelle(object):
coef_types = ['cen', 'edgup', 'edglo']
def __init__(self, order_table_fname):
self.order_table = Table.read(order_table_fname).to_pandas()
self.coefs = self._get_coefs()
def _get_coefs(self):
coefs = {}
poly_deg = int(self.order_table.loc[0, 'DEGY'])
for coef_type in self.coef_types:
coef = self.order_table.loc[:,
['{0}coef{1}'.format(coef_type, i).upper()
for i in xrange(poly_deg + 1)]].values
coefs[coef_type] = coef
return coefs
def get_y_array(self, order_id):
return np.arange(self.order_table.loc[order_id, 'STARTY'],
self.order_table.loc[order_id, 'ENDY'], )
def calculate_order_trace(self, order_id, coef_type='cen'):
coef_type = coef_type.upper()
poly_deg = int(self.order_table.loc[order_id, 'DEGY'])
coefs = self.order_table.loc[order_id,
['{0}{1}'.format(coef_type, i) for i in xrange(poly_deg + 1)]]
y_array = self.get_y_array(order_id)
return y_array, np.polyval(coefs[::-1], y_array)
if __name__ == '__main__':
data = fits.getdata('../test_data/XSHOO.2011-07-22T23:34:46.953.fits')
xshe = XShooterEchelle('ORDER_TAB_AFC_SLIT_VIS.fits')
clf()
imshow(data, vmin=1000, vmax=1500, cmap=cm.gray)
yrange = np.arange(data.shape[0]) * 2
x = np.polynomial.polynomial.polyval(yrange, xshe.coefs['edglo'].T)
for order_id in xrange(15):
plot(x[order_id]/2. + 2, yrange/2. + 2, color='red')
x = np.polynomial.polynomial.polyval(yrange, xshe.coefs['edgup'].T)
for order_id in xrange(15):
plot(x[order_id]/2. + 2, yrange/2. + 2, color='blue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment