Splittag


This tutorial outlines the steps needed to split a single COS exposure into a number of smaller sub-exposures. To do this, we will use the Splittag python module to specify and split apart selected times, and then re-extract the data into x1d spectra.

This notebook is written in Python, as that is the language of the calibration pipeline (CalCOS) and the Splittag module. This task can also be run from PyRAF, and is located in the stsdas.hst_calib.hstcos package.

In [9]:
#-- Necessary library imports for the tutorial
import os
import glob
import numpy as np
from scipy.ndimage.filters import convolve
import matplotlib as mpl
import matplotlib.pyplot as plt
from astropy.io import fits

from calcos import calcos
from costools import splittag, x1dcorr
In [10]:
#-- iPython notebook 'magic' command to make plots appear within the 
#-- browser instead of opening a separate plotting window.
%matplotlib inline

#-- Increase the default fontsize for the plots
mpl.rcParams['font.size'] = 16

Transit spectroscopy

Splittage can be used in two primary ways; giving start, increment, and stop times or by supplying a complete time list:

splittag.splittag(infiles='rootname_corrtag_a.fits', 
                  outroot='rootname',
                  starttime=0., 
                  increment=3000,
                  endtime=1000.)

splittag.splittag(infiles='rootname_corrtag_a.fits', 
                  outroot='rootname',
                  time_list="0,500,1500,3000")

Since we know the times we would like to split apart, we will use the second method. New corrtag files will be created for each time increment with the rootname equal to the parameter outroot.

In [11]:
#-- Split the single dataset apart into three with the time intervals:
#-- 0 to 400, 400 to 900, and 900 - 1300 seconds.
splittag.splittag(infiles='data/lc1va0zgq_corrtag_a.fits', 
                  outroot='data/lc1va0zgq',
                  time_list="0,400,900,1300")
data/lc1va0zgq_1_corrtag_a.fits written
data/lc1va0zgq_2_corrtag_a.fits written
data/lc1va0zgq_3_corrtag_a.fits written

Re-extraction


After splitting the corrtag file into segments, all that is necessary is to re-extract the spectra. Running CalCOS or x1dcorr will accomplish this.

After extraction, we plot up the data to see the different spectra from each time segment.

In [12]:
#-- timefilter and CalCOS need reference files to function.
#-- this will set the lref environment variable if you don't have it set.
#--
#-- This is the correct location for users internal to STScI, you may have to change it.
if not 'lref' in os.environ:
    os.environ['lref'] = '/grp/hst/cdbs/lref/'
In [13]:
#-- Using the x1dcorr task, we can extract the split corrtag files back into x1d spectra.
dataset_list = glob.glob('data/*_?_corrtag_a.fits')

for item in dataset_list:
    x1dcorr.x1dcorr(item, outdir='data/')

Input     /Users/ely/AAS224/data/lc1va0zgq_1_corrtag_a.fits
OutFlt    data/lc1va0zgq_1_flt_a.fits
OutCounts data/lc1va0zgq_1_counts_a.fits
x1d       data/lc1va0zgq_1_x1d_a.fits

DQICORR   PERFORM (complete, but repeat)
BPIXTAB = lref$x1u1459hl_bpix.fits
GSAGTAB = lref$w9o1334ml_gsag.fits

Spectral Extraction -- 02-Jun-2014 08:37:00 EDT
Input     data/lc1va0zgq_1_flt_a.fits
Incounts  data/lc1va0zgq_1_counts_a.fits
Output    data/lc1va0zgq_1_x1d_a.fits

Info:  find-target option = no
X1DCORR   PERFORM
XTRACTAB= lref$x1v17418l_1dx.fits
DISPTAB = lref$x1v17415l_disp.fits
HELCORR   PERFORM
BACKCORR  PERFORM
STATFLAG  T
FLUXCORR  PERFORM
FLUXTAB = lref$x1v17416l_phot.fits
TDSCORR   PERFORM
TDSTAB  = lref$w7h1935dl_tds.fits
FUVA spectrum was found at y = 536.43 vs. nominal y = 540.31
    error estimate for y location = 5.16, FWHM = 5.51
Spectrum will be extracted at y = 540.31

Input     /Users/ely/AAS224/data/lc1va0zgq_2_corrtag_a.fits
OutFlt    data/lc1va0zgq_2_flt_a.fits
OutCounts data/lc1va0zgq_2_counts_a.fits
x1d       data/lc1va0zgq_2_x1d_a.fits

DQICORR   PERFORM (complete, but repeat)
BPIXTAB = lref$x1u1459hl_bpix.fits
GSAGTAB = lref$w9o1334ml_gsag.fits

Spectral Extraction -- 02-Jun-2014 08:40:36 EDT
Input     data/lc1va0zgq_2_flt_a.fits
Incounts  data/lc1va0zgq_2_counts_a.fits
Output    data/lc1va0zgq_2_x1d_a.fits

Info:  find-target option = no
X1DCORR   PERFORM
XTRACTAB= lref$x1v17418l_1dx.fits
DISPTAB = lref$x1v17415l_disp.fits
HELCORR   PERFORM
BACKCORR  PERFORM
STATFLAG  T
FLUXCORR  PERFORM
FLUXTAB = lref$x1v17416l_phot.fits
TDSCORR   PERFORM
TDSTAB  = lref$w7h1935dl_tds.fits
FUVA spectrum was found at y = 536.49 vs. nominal y = 540.31
    error estimate for y location = 13.70, FWHM = 5.36
Spectrum will be extracted at y = 540.31

Input     /Users/ely/AAS224/data/lc1va0zgq_3_corrtag_a.fits
OutFlt    data/lc1va0zgq_3_flt_a.fits
OutCounts data/lc1va0zgq_3_counts_a.fits
x1d       data/lc1va0zgq_3_x1d_a.fits

DQICORR   PERFORM (complete, but repeat)
BPIXTAB = lref$x1u1459hl_bpix.fits
GSAGTAB = lref$w9o1334ml_gsag.fits

Spectral Extraction -- 02-Jun-2014 08:42:15 EDT
Input     data/lc1va0zgq_3_flt_a.fits
Incounts  data/lc1va0zgq_3_counts_a.fits
Output    data/lc1va0zgq_3_x1d_a.fits

Info:  find-target option = no
X1DCORR   PERFORM
XTRACTAB= lref$x1v17418l_1dx.fits
DISPTAB = lref$x1v17415l_disp.fits
HELCORR   PERFORM
BACKCORR  PERFORM
STATFLAG  T
FLUXCORR  PERFORM
FLUXTAB = lref$x1v17416l_phot.fits
TDSCORR   PERFORM
TDSTAB  = lref$w7h1935dl_tds.fits
FUVA spectrum was found at y = 536.52 vs. nominal y = 540.31
    error estimate for y location = 7.53, FWHM = 5.26
Spectrum will be extracted at y = 540.31

In [15]:
fig, (ax1, ax2) = plt.subplots(2, figsize=(15,10), sharex=True)
boxsize = 15

hdu = fits.open('data/lc1va0zgq_x1d.fits')
ax1.plot(hdu[1].data['wavelength'].ravel(), convolve(hdu[1].data['flux'].ravel(), np.ones(boxsize)/boxsize), color='k', label='Archive Dataset')
ax1.set_ylim(0, 1e-14)
ax1.set_xlim(1100, 1650)
ax1.set_title('lc1va0zgq')
ax1.set_ylabel('Flux')

leg = ax1.legend(shadow=True, numpoints=1, markerscale=3)
# set the linewidth of each legend object
for legobj in leg.legendHandles:
    legobj.set_linewidth(3.0)


before = fits.open('data/lc1va0zgq_1_x1d.fits')
during = fits.open('data/lc1va0zgq_2_x1d.fits')
after = fits.open('data/lc1va0zgq_3_x1d.fits')

#-- Smooth and plot the data
ax2.plot(before[1].data['wavelength'].ravel(), convolve(before[1].data['flux'].ravel(), np.ones(boxsize)/boxsize), label='Before')
ax2.plot(during[1].data['wavelength'].ravel(), convolve(during[1].data['flux'].ravel(), np.ones(boxsize)/boxsize), label='During')
ax2.plot(after[1].data['wavelength'].ravel(), convolve(after[1].data['flux'].ravel(), np.ones(boxsize)/boxsize), label='After')

ax2.set_ylim(0, 1e-14)
ax2.set_xlim(1100, 1650)
ax2.set_xlabel('Wavelength $(\AA)$')
ax2.set_ylabel('Flux')

leg = ax2.legend(shadow=True, numpoints=1, markerscale=3)
# set the linewidth of each legend object to be a little bigger
for legobj in leg.legendHandles:
    legobj.set_linewidth(3.0)

fig.subplots_adjust(hspace=0)
fig.savefig('eclipse_split.pdf', bbox_inches='tight')
In []: