# Creating Master Reference Files¶

Master calibration reference (MasterCal) files are derived from calibration or science observations, and are used to remove the various components of the instrument signature from the data. Calibration exposures may combined or characterized to create a calibration, so that it may be applied when science data are processed. Some other instrument calibrations (e.g., slit mask definition files) have already been created for you by Gemini scientists, and are distributed with the gemini.gmos package software.

Caution

The code examples in this chapter for creating MasterCals are for IRAF users. Code examples for PyRAF users are integrated into the various PyRAF tutorials (see in addition SQL-Based File Selection). However, the conceptual descriptions in this chapter are relevant for all users.

Note

In the code blocks below the commands are intended to be executed within the IRAF command language (cl), unless otherwise noted. The traditional prompt (e.g., “cl> ”) has been omitted to make it easier to cut-and-paste commands into your own IRAF session. Terse comments are prepended with a pound sign (“#”, or hashtag).

This chapter summarizes how to create the reference files that will be needed for your data reduction.

## Create File Lists¶

The first step is to create lists of input files for MasterCal creation.

Caution

The PHDU must be explicitly inherited to access keyword values (this is because Gemini sets INHERIT = 'F' in the raw extension HDUs). Thus, an extra step must be performed, using gemextn, to generate the file list. See the IRAF FITS Kernel User’s Guide for details.

# Bias exposures must match the RoI and CCD binning:
cd /path/to/science_files/raw
string biasSelect = "obstype=='BIAS' && obsclass=='dayCal' && detrO1ys>1024 && ccdsum=='2 2'"
string omit = "exten,index,kernel"

# Select using information from both PHDU and HDU-1
hselect ("*.fits[1,inherit=yes]", "$I", biasSelect, > "bias_tmp.txt") # Now remove the IRAF index and kernel parameters from the file names gemextn ("@bias_tmp.txt", omit=omit, outfile="biasfiles.txt") rename ("biasfiles.txt", "../")  Similar steps apply for imaging flat-fields, one per filter: # Identify flat exposures: # Note: IRAF refers to the OBJECT keyword with the special name: "i_title" string flatS1 = "i_title=='Twilight' && obsclass=='dayCal' " # Flat-fields must match the RoI, CCD binning, grating, and aperture. s2 = "&& detro1ys>1024 && ccdsum=='2 2' && grating='MIRROR' && maskname='None' " s1 = flatS1 // s2 # Generate lists of filenames using above criteria and the filters of interest. # For the r' filter; hselect ("*.fits[1,inherit=yes]", "$I", (s1 // "&& filter2=='r_G0326'"), > "flt_tmp.txt")
gemextn ("@flt_tmp.txt", omit=omit, outfile="flt_r.txt")
rename ("flt_r.txt", "../")


The selection criteria for the arcs is similar to the bias exposures, except for MOS and IFU modes where the slitlets or fibers are split into separate spectra.

# Identify Arc exposures:
string arcS1 = "obstype=='ARC' && obsclass=='dayCal' && detro1ys>1024 && ccdsum=='2 2' "
#s1 = arcS1

# For MOS and IFU modes:
# Arcs for MOS or IFU must match the grating, central wavelength, and aperture.
s2 = "masktyp==1 && grating=='R831+_G5302' && centwave==853. "
s1 = arcS1 // s2

# Generate lists of filenames using above criteria.

### IFU Flats¶

IFU flat-fields are summed over the spatial extent of each fiber and are used to remove few-pixel variations in sensitivity in the dispersion direction. They are also used to define the trace parameters for contemporaneous on-sky exposures, as instrument flexure can displace the spectra on the FPA; for this reason they are rarely combined with other flat-field exposures. Finally, flat-field exposures are used to locate the order gaps on the FPA in order to model the scattered light on science and calibration exposures.

Note

Processing IFU spectroscopic flat-field exposures is somewhat more involved than for IFU:

1. Perform Overscan and Bias Residual corrections on each exposure.
2. Determine the location of the fiber bundle gaps in the spectrogram.
3. Characterize and remove the scattered light background from the spectrogram as derived from the gap regions.
3a. (Optional) remove cosmic rays from the flat-field exposure if necessary.
1. Perform the QE correction for affected CCDs.
2. Re-extract the fiber flats from the background-subtracted spectrograms.
3. Characterize the shape in the dispersion direction (i.e., the color term) by fitting a curve of relatively high order to each fiber spectrum, and divide the spectrum by the polynomial.
4. Normalize the color-corrected flat-field spectra.

#### Basic Processing¶

Use gfreduce to bias-correct and trim the images. You will need to add (or append) the static BPM MasterCal to these images.

cd /path/to/science_files/

# Use primarily the default task parameters.
unlearn gemextn
unlearn gfreduce
gfreduce.logfile = "gfreduceLog.txt"
gfreduce.rawpath = "./raw/"

# Process the raw flat-fields for grating B600/625, including VAR & DQ arrays.
gfreduce ("@flatGcal_B6-625.txt", outimages="@trace_B6-625.txt", \
bias="MCbiasS", fl_inter-, fl_vardq+, fl_extract+, fl_gscrrej-,
fl_gsappwave-, fl_wavtran-, fl_skysub-, fl_fluxcal-)


Use gffindblocks and gfsubscat to characterize and remove the scattered light background.

# Loop over individual flats to correct for scattered light.
unlearn gfscatsub
sections ("rg//@flatGcal_B6-625.txt", option="root", >"procFlats_B6-625.txt")

list = "procFlats_B6-625.txt"
while (fscan (list, s1) != EOF) {
# Find the gaps of unilluminated regions
gffindblocks (s1, "ex"//s1//"_tr", s1//"_gaps.txt")

# Use the gaps to model & remove the scattered light from the flats
gfscatsub (s1, "ex"//s1//"_tr.fits", xorder="5,9,5", yorder="5,7,5", \
cross+)
}


Now re-extract the fiber spectra, and normalize.

gfreduce.rawpath="./"
gfreduce ("b@procFlats_B6-625.txt", fl_addmdf-, fl_over-, fl_trim-, fl_bias-, \
fl_bias-, fl_inter-, fl_vardq+, fl_extract+, fl_gscrrej-, fl_gsappwave+, \
fl_wavtran-, fl_skysub-, fl_fluxcal-)

# Normalize flats to create the response functions.
unlearn gfresponse
gfresponse.logfile="gfresponseLog.txt"

sections ("ebrg//@flatGcal_B6-625.txt", option="root", >"bFlats_B6-625.txt")
list = "bFlats_B6-625.txt"
while (fscan (list, s1) != EOF) {
gfresponse (s1, s1//'_flat', skyimage='', function='spline3',
order=47, sample="1:1,30:2855,2879:2879", fl_inter+)
}


## Wavelength Calibration¶

Overscan-corrected exposures of the Cu-Ar lamp are used to determine the dispersion solution for a given disperser and slit position. An atlas of such a comparison arc is shown below.

Additional line identifications may be found on the Gemini/GMOS CuAr Spectra page.

Note

You can use the high-dispersion line list (download: cuarHiRes.txt) to determine the dispersion solution for the highest resolution configurations (B1200 and R831 with a slitwidth <1.0arcsec), provided the Arc exposure is sufficiently deep. In these cases it should be possible to include more than 100 lines in the dispersion solution (with an RMS less than a few tenths of a pixel), except in the near IR. The fit will require a polynomial of order 6 or 7 to yield an acceptable solution.

### Basic Processing¶

Arc lamp exposures need only be processed through Overscan and Bias corrections, and initializing the dispersion solution. However, MOS and IFU modes require that the arcs be split: one for each slitlet or fiber.

# Use primarily the default task parameters.
unlearn gsreduce
gsreduce.logfile="gsreduceLog.txt"
gsreduce.rawpath="./raw"

# Perform basic reductions on the list of arc exposures.
gsreduce ("@arcFull_B600.txt", bias="MCbiasFull", \
fl_flat-, fl_fixpix-, fl_oversize-)


Now perform determine the dispersion solution with gswavelength, using a line list and linewidth appropriate to the slit width and CCD binning in use. The dispersion solution will be stored in a subdirectory of the working directory called ./database. The fit to the dispersion solution should be done interactively (which is the default) to ensure the quality of the solution.

# Use primarily the default task parameters.
# In this case, the default medium-resolution line list will work well.
unlearn gswavelength
gswavelength.logfile="gswaveLog.txt"

## Spectrophotometric Calibration¶

The flux calibration for spectra is derived from exposures of one or more spectrophotometric standard stars. These exposures should be processed through flat-fielding, wavelength calibration, sky subtraction and 1-D extraction (sky subtraction may be performed during extraction). Be sure to use the improved atmospheric extinction curve for Mauna Kea (download: mk_extinct.txt), or the curve for CTIO in the IRAF directory onedstds$ctioextinct.dat, as appropriate. Note that the name of the observed standard must match the IRAF name: see the table in Standards List. # Derive the sensitivity function. unlearn gsstandard gsstandard.logfile="gsstdLog.txt" # Use the calibration directory appropriate for your standard star. gsstandard.caldir="onedstds$ctionewcal/"
gsstandard.extinction="./mk_extinct.txt"

gsstandard ("estLTT9239.fits", sfile="std", sfunction="sens", order=7, \
starname="l9239", fl_inter-)


The fit to the sensitivity function is shown below.