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.
#-- 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
#-- 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
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.
#-- 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")
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.
#-- 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/'
#-- 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/')
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')