Helping to generate templates for the spectrographs

See core.wavecal.templates.py for polished versions


In [33]:
%matplotlib inline

In [28]:
# imports
from pkg_resources import resource_filename
from importlib import reload
from matplotlib import pyplot as plt
import os
import numpy as np
from scipy.io import readsav 

from astropy import units
from astropy.table import Table

from linetools import utils as ltu
from linetools.spectra import xspectrum1d as xspec

from pypeit import utils
from pypeit.core.wave import airtovac
from pypeit.core.wavecal import waveio
from pypeit.core.wavecal import autoid
from pypeit.core.wavecal import templates, qa
from pypeit.spectrographs import util

Keck/LRISb

400/3400

Load


In [30]:
xidl_file = '/home/xavier/local/idl/xidl/Spec/Longslit/calib/linelists/lris_blue_400_d560.sav'

In [31]:
xidl_dict = readsav(xidl_file)

In [32]:
nspec = xidl_dict['archive_arc'].shape[0]
npix = xidl_dict['archive_arc'].shape[1]
nspec, npix


Out[32]:
(21, 2048)

In [33]:
xidl_dict['calib']['FUNC']


Out[33]:
array([b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY',
       b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY',
       b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY', b'CHEBY',
       b'CHEBY', b'CHEBY', b'CHEBY'], dtype=object)

Find em


In [54]:
slit = 19 # blue;  ends at 5510
slit = 14 # very red
calib = xidl_dict['calib'][slit]
wv_air = templates.cheby_val(calib['FFIT'], np.arange(npix),
                       calib['NRM'], calib['NORD'])
wv_vac = airtovac(wv_air*units.AA)

In [55]:
plt.clf()
ax=plt.gca()
ax.plot(wv_vac, xidl_dict['archive_arc'][slit])
plt.show()


1200/3400

Load


In [110]:
xidl_file = '/home/xavier/local/idl/xidl/Spec/Longslit/calib/linelists/lris_blue_1200.sav'
xidl_dict = readsav(xidl_file)

In [111]:
nspec = xidl_dict['archive_arc'].shape[0]
npix = xidl_dict['archive_arc'].shape[1]
nspec, npix


Out[111]:
(46, 2048)

In [60]:
xidl_dict['calib']['FUNC'][0]


Out[60]:
b'CHEBY'

Find em


In [89]:
slit = 19 # blue
slit = 7 # red
slit = 40 # super blue
slit = 44 # reddest
calib = xidl_dict['calib'][slit]
wv_air = templates.cheby_val(calib['FFIT'], np.arange(npix),
                       calib['NRM'], calib['NORD'])
wv_vac = airtovac(wv_air*units.AA)

In [90]:
plt.clf()
ax=plt.gca()
ax.plot(wv_vac, xidl_dict['archive_arc'][slit])
plt.show()



Shane Kastb

MOVED TO Shane_kast_wavelengths Notebook


Keck/DEIMOS

600

Load


In [171]:
xidl_file = '/home/xavier/local/idl/xidl/Spec/Longslit/calib/linelists/deimos_600.sav'
xidl_dict = readsav(xidl_file)

In [172]:
nspec = xidl_dict['archive_arc'].shape[0]
npix = xidl_dict['archive_arc'].shape[1]
nspec, npix


Out[172]:
(2, 4096)

In [173]:
xidl_dict['calib']['FUNC']


Out[173]:
array([b'POLY', b'POLY'], dtype=object)

Check em


In [186]:
# Standard
slit = 0 # blue chip
#slit = 1 # red chip
calib = xidl_dict['calib'][slit]
wv_air = templates.poly_val(calib['FFIT'], np.arange(npix),
                           calib['NRM'])
wv_vac = airtovac(wv_air*units.AA)
wv_vac[0], wv_vac[-1]


Out[186]:
(<Quantity 4607.10556396 Angstrom>, <Quantity 7192.8248653 Angstrom>)

In [188]:
plt.clf()
ax=plt.gca()
ax.plot(wv_vac, xidl_dict['archive_arc'][slit])
plt.show()


Check 830G


In [192]:
outpath=resource_filename('pypeit', 'data/arc_lines/reid_arxiv')
outroot='keck_deimos_830G.fits'
outfile = os.path.join(outpath, outroot)

In [193]:
tbl = Table.read(outfile)

In [195]:
plt.clf()
ax = plt.gca()
ax.plot(tbl['wave'], tbl['flux'])
plt.show()


1200


In [5]:
mwv_file = os.path.join(os.getenv('PYPEIT_DEV'), 'dev_algorithms/wavelengths/template_files/Keck_DEIMOS/1200G', 
                        'MasterWaveCalib_A_1_07b.json')

In [6]:
wv_vac, spec = templates.pypeit_arcspec(mwv_file, 0)

In [7]:
plt.clf()
ax = plt.gca()
ax.plot(wv_vac, spec)
plt.show()



In [9]:
keck_deimos = util.load_spectrograph('keck_deimos')

In [10]:
par = keck_deimos.default_pypeit_par()

In [16]:
par['calibrations']['wavelengths']


Out[16]:
Parameter         Value               Default        Type                       Callable
----------------------------------------------------------------------------------------
reference         arc                 arc            str                        False   
method            holy-grail          holy-grail     str                        False   
echelle           False               False          bool                       False   
ech_fix_format    True                True           bool                       False   
ech_nspec_coeff   4                   4              int                        False   
ech_norder_coeff  4                   4              int                        False   
ech_sigrej        2.0                 2.0            int, float                 False   
lamps             ArI, NeI, KrI, XeI  None           list                       False   
nonlinear_counts  56360.1             10000000000.0  float                      False   
sigdetect         5.0                 5.0            int, float, list, ndarray  False   
fwhm              4.0                 4.0            int, float                 False   
reid_arxiv        None                None           str                        False   
nreid_min         1                   1              int                        False   
cc_thresh         0.7                 0.7            float, list, ndarray       False   
cc_local_thresh   0.7                 0.7            float                      False   
nlocal_cc         11                  11             int                        False   
rms_threshold     0.15                0.15           float, list, ndarray       False   
match_toler       2.5                 2.0            float                      False   
func              legendre            legendre       str                        False   
n_first           3                   2              int                        False   
n_final           4                   4              int, float, list, ndarray  False   
sigrej_first      2.0                 2.0            float                      False   
sigrej_final      3.0                 3.0            float                      False   
wv_cen            0.0                 0.0            float                      False   
disp              0.0                 0.0            float                      False   
numsearch         20                  20             int                        False   
nfitpix           5                   5              int                        False   
IDpixels          None                None           int, float, list           False   
IDwaves           None                None           int, float, list           False   
medium            vacuum              vacuum         str                        False   
frame             heliocentric        heliocentric   str                        False   
nsnippet          2                   2              int                        False   

Try running


In [21]:
ok_mask = np.array([0])
det = 7
binspec = 1
templ_dict = dict(wave=wv_vac, spec=spec, bin=1)

In [26]:
reload(autoid)
wv_calib = autoid.full_template(spec, par['calibrations']['wavelengths'], ok_mask, det, binspec,
                               template_dict=templ_dict)


[INFO]    :: autoid.py 680 full_template() - Processing slit 0
[INFO]    :: autoid.py 693 full_template() - Shift = -1.3642420526593924e-12; cc = 0.9999999999999776
[INFO]    :: autoid.py 483 reidentify() - Cross-correlating with arxiv slit # 0
[INFO]    :: autoid.py 483 reidentify() - Cross-correlating with arxiv slit # 0

In [27]:
wv_calib


Out[27]:
{'0': {'cen_disp': 0.3108942149410723,
  'cen_wave': 9400.409290344052,
  'fitc': array([ 9.39618192e+03,  6.35420822e+02, -8.09115674e+00, -7.26916863e-01,
          7.02659367e-02,  2.38440448e-02]),
  'fmax': 1.0,
  'fmin': 0.0,
  'function': 'legendre',
  'ions': array(['KrI', 'KrI', 'XeI', 'XeI', 'ArI', 'XeI', 'ArI', 'NeI', 'ArI',
         'ArI', 'ArI', 'NeI', 'ArI', 'KrI', 'ArI', 'XeI', 'XeI'],
        dtype='<U6'),
  'mask': array([ True,  True,  True,  True,  True,  True,  True, False,  True,
          True,  True,  True,  True,  True,  True,  True,  True]),
  'nrej': 3.0,
  'nspec': 4096,
  'pixel_fit': array([  80.42604643,  557.05087819,  631.18308594,  925.1334279 ,
         1170.4407947 , 1296.33770281, 1398.04054643, 1420.79381134,
         1493.07680483, 1707.08074939, 1907.91466792, 2488.4990218 ,
         2891.61825377, 3200.41915307, 3308.52758597, 3358.78719228,
         3769.66604113]),
  'rms': 0.026632510356509972,
  'shift': 0.0,
  'spec': array([43.82331828, 91.22659512, 71.67861412, ...,  9.95841035,
         11.91858442, 11.99683015]),
  'tcent': array([  22.4385431 ,   40.94668699,   64.58110232,   80.42604643,
           92.54715413,  102.35556425,  250.12238853,  322.03346056,
          348.55402814,  359.23805372,  494.26237889,  528.16562956,
          557.05087819,  631.18308594,  712.32023836,  721.86496022,
          743.25920673,  843.46952702,  852.42864459,  863.01423521,
          882.58255003,  925.1334279 , 1085.45965244, 1170.4407947 ,
         1251.98597922, 1296.33770281, 1311.72004273, 1398.04054643,
         1420.79381134, 1451.29966399, 1479.13795631, 1493.07680483,
         1656.02074288, 1707.08074939, 1737.02596223, 1755.43809655,
         1768.04799902, 1778.88515534, 1818.97989691, 1902.48069803,
         1907.91466792, 1933.16221208, 1973.72914616, 2093.51943376,
         2136.73437572, 2189.97133253, 2201.00362624, 2245.82941363,
         2334.69837114, 2368.29380173, 2421.1484049 , 2488.4990218 ,
         2510.34976064, 2531.62044997, 2564.17475649, 2574.05537159,
         2654.46807584, 2891.61825377, 2916.5723653 , 2981.85131848,
         3033.50207865, 3044.0013832 , 3089.73135677, 3172.18782832,
         3200.41915307, 3308.52758597, 3358.78719228, 3546.74044178,
         3769.66604113]),
  'wave_fit': array([8779.1607, 8931.1447, 8954.7086, 9047.9296, 9125.471 , 9165.1667,
         9197.161 , 9204.2841, 9227.03  , 9294.081 , 9356.787 , 9536.7793,
         9660.435 , 9754.4352, 9787.186 , 9802.384 , 9925.919 ]),
  'wave_soln': array([ 8753.44327556,  8753.76317041,  8754.08306222, ...,
         10022.28501578, 10022.58189871, 10022.8787746 ]),
  'weights': array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]),
  'xnorm': 4095.0,
  'xrej': array([1420.79381134]),
  'yrej': array([9204.2841])}}

In [34]:
qa.arc_fit_qa(wv_calib['0'])



In [35]:
jdict = ltu.jsonify(wv_calib)

In [38]:
outfile = os.path.join(os.getenv('PYPEIT_DEV'), 'dev_algorithms/wavelengths/template_files/Keck_DEIMOS/1200G', 
                        'MasterWaveCalib_A_1_07c.json')

In [39]:
ltu.savejson(outfile, jdict)

In [ ]: