Infrared Time-series Photometry

Contents:

Time-series photometric reduction for ground-based IR photometry and spectroscopy.

Assumes a single filter and a regular dither pattern (or ‘staring’), and sky (& dark) removal via subtraction of temporally adjacent frames.

class ir.baseObject[source]

Empty object container.

ir.calibrate(obs, verbose=False, clobber=False)[source]

Take raw NIR frames and output sky-subtracted, flat-fielded frames ready for photometry extraction.

ir.ditherskysub(obs, sci_index, clobber=False, verbose=False, flatten=True, skyramp=False)[source]

Subtract sky (and dark) levels from a set of dithered exposures with equal exposure settings.

For now, compute a robust mean sky frame from each ndither set. Then subtract them, flat-field them, and output.

NOTE: unlike other reduction tasks, the input index here refers ONLY to science frames.

ir.hdradd(header, key, value)[source]

Add keyword to FITS header, without overwriting existing keys.

INPUTS:
header : FITS header object (from pyfits.getheader)

header to be updated

key : str

Keyword to use. If it exists, an integer will be appended to form a new, non-duplicate keyword.

value : (anything)

Value to assign to keyword in header.

ir.initobs(obsname='20091203k', verbose=False, cal='dome', home='/Users/ianc')[source]

Initialize variables for ground-based IR data analysis.

OPTIONAL INPUT:

obsname: (str) – e.g., 20091203k, 20091203h, ‘20120427_chip2’ cal : str

Valid options are ‘dome’ and ‘sky’, in case two sets of calibration files are available. If not, this option will have no effect.
OUTPUT:
‘obs’, an object containing many useful values in fields.
ir.linearity_correct(measurement, nread, ncoadd, dt, exptime, fmap, linfunc, npix=1048576, tol=1e-06, maxiter=10, verbose=False, linfuncargs=None, retall=False)[source]

Correct a set of IR array measurements for nonlinearity.

INPUTS:
measurement : 1D or 2D sequence or array

Values reported back by the infrared array detector (in ADU or DN, not photoelectrons)

nread : int

Number of reads used for measurement (for CDS, set nread = 1)

ncoadd : int

Number of coadds used for measurement

dt : scalar

Amount of time between successive reads of the detector

exptime : scalar

Integration time for measurement

fmap : sequence or array (same shape as ‘measurement’)

‘f’ values (cf. makefmap_moircs())

linfunc : function

Function which, when passed a measured value, returns the linearized value (the C_nl function of Vacca et al.; cf. linearity_moircs())

npix : int

Total number of pixels in each readout section of the detector.

tol : scalar

When all measurements have been linearized to within this tolerance, routine will exit.

maxiter : int

If ‘tol’ is not reached within this many iterations, linearization routine will exit anyway.

linfuncargs : dict

Dict of arguments, if any, to be passed to ‘linfunc’.

retall : bool

If True, also return the number of iterations.

OUTPUTS:

A Numpy array of the same shape as ‘measurement,’ but appropriately linearized following the algorithm of the reference below.

If retall is True, the linearized measurement is the first element of a 2-tuple.

NOTES:

Vacca et al. recommend that this algorithm be applied _after_ dark current has been subtracted and flat-fielding performed.

SEE_ALSO:

makefmap_moircs(), linearity_moircs()

REFERENCE:

Vacca et al. 2004, PASP.

EXAMPLE:
raw_mosfire_data = 2e4 * np.ones((2048, 2048), dtype=float)
coef_fn = '/Users/ianc/proj/transit/data/mosfire_linearity/linearity/mosfire_linearity_cnl_coefficients_bic-optimized_corners-fixed.fits'
fmap = ir.makefmap_mosfire()
corrected_data = ir.linearity_correct(dat, 1, 1, 100, 101, fmap, ir.linearity_mosfire, npix=2048*2048, verbose=True, linfuncargs=dict(polycoef=coef_fn))
ir.linearity_mosfire(measured_counts, polycoef=None, unityminimum=True, scale=10000.0)[source]

Linearity correction curve for Keck/MOSFIRE detectors.

INPUTS:
measured_counts : scalar or sequence

Measured digital counts (ADU or DN, _not_ photoelectrons)

polycoef : str, sequence, or None
sequence:

Sequence of polynomial coefficients [a_n, ... a_2, a_1, 1.], suitable for passing to numpy.polyval, to use in the implementation of Vacca et al.’s Eq. 20. If None, use my defaults (which are empirically calibrated only up to 30000 ADU)

str:

Filename of 3-D array c (of size [n+1]x2048x2048) of polynomial coefficients for each pixel, defined such that c[:,i,j] = [a_n, ... a_2, a_1, 1.] for pixel (i,j).

polycoef=’/Users/ianc/proj/transit/data/mosfire_linearity/linearity/mosfire_linearity_cnl_coefficients_bic-optimized.fits’

unityminimum : bool

If True, values less than unity (1.0) are never returned.

scale : scalar

Scale used to divide measured counts in polynomial evaluation. This helps to avoid extremely small coefficients.

NOTES:

This function should not be used to perform linearity corrections on MOSFIRE data; for that, you should use linearity_correct() (for which this function is only a helper).

SEE_ALSO:

makefmap_mosfire(), linearity_correct() linearity_moircs()

REFERENCE:

Vacca et al. 2004, PASP.

ir.makebadpixelmask_science(filenamelist, readnoise, gain=1, nsigma=5, frac=0.95, medfilt=[5, 1])[source]

Make bad pixel mask from science frames.

filenamelist : list of str

list of filenames, in ADU (i.e., DN).

These files should already have been flat-fielded!

readnoise : scalar
read noise, in electrons
gain : scalar
gain, in electrons / ADU
medfilt : odd int Width of 2D median filter (keep it low, or sky
lines start getting flagged!). A 2-vector (e.g., [5, 1]) can also be set, to to avoid marking sky lines.
ir.makeflat(flats, dark, badpix=None, samplemask=None, finalnorm=True)[source]

Helper function; input is list of FITS filenames and dark (to subtract).

ir.makefmap_moircs(tread=1.12e-05, treset=0.008, dt=11.8, npix=1048576)[source]

Make f-map for linearity correction of Subaru/MOIRCS data.

INPUTS:
tread : scalar

time between reads of individual pixels

treset : scalar

time required to reset an individual pixel

dt : scalar

time between successive reads of the detector array

npix : int

Total number of pixels in each readout section of the detector.

OUTPUTS:
fmap : 2D Numpy array

The variable ‘f’ defined in Equation 10 or 11 of the reference given below.

REFERENCES:

Vacca et al. 2004, PASP.

Private communications w/Dr. I. Tanaka, NAOJ/Subaru

ir.makefmap_mosfire(tread=1e-05, treset=0.008, dt=1.45, npix=131072)[source]

Make f-map for linearity correction of Keck/MOSFIRE data.

INPUTS:
tread : scalar

time between reads of individual pixels

treset : scalar

time required to reset an individual pixel

dt : scalar

time between successive reads of the detector array

npix : int

Total number of pixels in each readout section of the detector.

OUTPUTS:
fmap : 2D Numpy array

The variable ‘f’ defined in Equation 10 or 11 of the reference given below.

REFERENCES:

Vacca et al. 2004, PASP.

  1. Kulas, private communication, July 2012
ir.makemasterframe(list_or_array, nsigma=None)[source]

If an array is passed, return it. Otherwise, return a median stack of the input filename list.

ir.moircs_defringe(procfn, defringefns, subreg='SUBREG', clobber=False, plotonly=False, dx=None, dy=None, spatial_index='select', retall=False, pord=1, corners=None, defringe_options={})[source]

Defringe multiple subregions in MOIRCS multi-object spectroscopy frames.

subregions : str, or 2D numpy array
if str:
The primary header keyword from which the subregion boundaries will be read (e.g., ‘SUBREG0’, ‘SUBREG1’, etc; cf. moircs_speccal())

defringe_options – passed along to spec.defringe_sinusoid()

ir.moircs_photcal(skydark, skyflat, domedark, domeflat, objdark, rawframes, procframes, badpixelmask=None, clobber=False, retmaster=False, skysub=True, twoatatime=False, verbose=False, chip=None, linearize=True)[source]

Tanaka-san’s prescription for inital calibration of MOIRCS images.

INPUTS:
skydark : list of str, or 2D Numpy array

List of raw, long sky darks, or a 2D Numpy array Master Sky Dark

skyflat : list of str, or 2D Numpy array

List of raw, long sky flat frames, or a 2D Numpy array Master Sky Flat. Exposure time should be the same as for skydark.

domedark : list of str, or 2D Numpy array

List of raw, short dome darks, or a 2D Numpy array Master Dome Dark

domeflat : list of str, or 2D Numpy array

List of raw, short dome flats, or a 2D Numpy array Master Dome Flat. Exposure time per frame should be same as for skydark

objdark : list of str, or 2D Numpy array

List of raw, short darks, or a 2D Numpy array Master Dark. Per-frame exposure time should be the same as for rawframes

rawframes : list of str

List of raw, unprocessed science frames

procframes : list of str

List of processed science frames, to be written to disk

clobber : bool

Whether to overwrite existing FITS files

retmaster : bool

Whether to return master dark and (normalized) flat frames

skysub : bool

Whether to subtract the sky (not sure why you wouldn’t want to...)

twoatatime: bool

Whether to correct both chips simultaneously, in 2-frame pairs. If true, all the file inputs above must be len-2 lists of filename lists (or 2xN str arrays).

chip : 1 or 2

Which chip to use (to set gain and/or linearity correction)

linearize : bool

Whether or not to correct for detector nonlinearity.

EXAMPLE:
::

import ir obs2dome = ir.initobs(‘20111214_chip2’, cal=’dome’) obs2sky = ir.initobs(‘20111214_chip2’, cal=’sky’) obj2dark = [‘%sMCSA00187%i.fits’ % (obs2sky._raw, ii) for ii in range(804,833,2)] outfns2 = [fn2.replace(‘proc_M’, ‘proc_linear_M’) for fn2 in obs2sky.procsci] masterframes2 = ir.moircs_photcal(obs2sky.rawdark, obs2sky.rawflat, obs2dome.rawdark, obs2dome.rawflat, obj2dark, obs2sky.rawsci, outfns2, chip=2, clobber=False, retmaster=True, verbose=True)

obs1dome = ir.initobs(‘20111214_chip1’, cal=’dome’) obs1sky = ir.initobs(‘20111214_chip1’, cal=’sky’) obj1dark = [‘%sMCSA00187%i.fits’ % (obs1sky._raw, ii) for ii in range(803,833,2)] outfns1 = [fn1.replace(‘proc_M’, ‘proc_linear_M’) for fn1 in obs1sky.procsci] masterframes1 = ir.moircs_photcal(obs1sky.rawdark, obs1sky.rawflat, obs1dome.rawdark, obs1dome.rawflat, obj1dark, obs1sky.rawsci, outfns1, chip=1, clobber=False, retmaster=True, verbose=True)

::

import ir obs1dome = ir.initobs(‘20111214_chip1’, cal=’dome’) obs1sky = ir.initobs(‘20111214_chip1’, cal=’sky’) obs2dome = ir.initobs(‘20111214_chip2’, cal=’dome’) obs2sky = ir.initobs(‘20111214_chip2’, cal=’sky’) obj1dark = [‘%sMCSA00187%i.fits’ % (obs1sky._raw, ii) for ii in range(803,833,2)] obj2dark = [‘%sMCSA00187%i.fits’ % (obs2sky._raw, ii) for ii in range(804,833,2)]

outfns = [[fn1.replace(‘proc_M’, ‘proc_simul_M’) for fn1 in obs1sky.procsci],

[fn2.replace(‘proc_M’, ‘proc_simul_M’) for fn2 in obs2sky.procsci]]

ir.moircs_photcal([obs1sky.rawdark, obs2sky.rawdark], [obs1sky.rawflat, obs2sky.rawflat], [obs1dome.rawdark, obs2dome.rawdark], [obs1dome.rawflat, obs2dome.rawflat], [obj1dark, obj2dark], [obs1sky.rawsci, obs2sky.rawsci], outfns, clobber=False, retmaster=True, verbose=True, twoatatime=True)

NOTES:
  • Make master dark frames for flat and science observations.
  • Subtract master flat-dark frame from each raw flat frame
  • Make object masks for each raw data. [Not implemented yet!]
  • median-normalize each raw flat frame.
  • Median-combine these normalized raw sky data with object masks. This is master median flat (sky).
  • Make dome flat data.
  • Subtract 21-sec master dark from each WASP12 raw frame.
  • Flatfield them by Dome Flats.
  • Apply correction for inherent nonlinearity of IR detectors.
  • Measure each sky counts. Multiply the master normalized median sky frame by the sky counts (i.e. scale the sky for each data) then subtract that sky frame from the dome-flatfielded data. Apply the procedure to all frames.
  • Subtract the residual global pattern by the plane-fitting (imsurfit in IRAF, for example) if necessary.

As you may already know, making object mask is a critical part of the good median-sky data.

ir.moircs_speccal(skydark, sky, domedark, domeflat, rawframes, procframes, badpixelmask=None, samplemask=None, clobber=False, retmaster=False, skysub=True, verbose=False, writefiles=True, gain=3.3, readnoise=40, chip=None)[source]

Perform inital calibration of MOIRCS spectroscopic data.

INPUTS:
skydark : list of str, or 2D Numpy array

List of raw, long sky darks, or a 2D Numpy array Master Sky Dark. The “sky dark” frame is the dark frame taken with the same integration time as the main science frames (“rawframes”) and the sky frames (“skyflat”).

sky : list of str, or 2D Numpy array

List of raw sky frames, or a 2D Numpy array Master Sky frame. Exposure time should be the same as for “skydark” and “rawframes”.

domedark : list of str, or 2D Numpy array

List of raw, short dome darks, or a 2D Numpy array Master Dome Dark. In this (spectroscopic) case, the “domedark” files are the lamp-off spectroscopic files used to measure the thermal background underlying the main dome files (“domeflat”).

domeflat : list of str, or 2D Numpy array

List of raw flat frames (taken with the dome flat lamp ON), or a 2D Numpy array Master Dome Flat. Exposure time per frame should be same as for “domedark”.

rawframes : list of str

List of raw, unprocessed science frames. Integration times should be the same as “skydark” and “sky.”

procframes : list of str

List of processed science frames, to be written to disk.

badpixelmask : str, or 2D Numpy array

Bad pixel mask: equal to zero at good pixels, and to 1 at bad pixels.

samplemask : 2D Numpy array

Sampling mask tells the sky-scaling algorithms which parts of the image to use. Equal to 1 at points to be sampled, and zero elsewhere. If set to None (default), a crude algorithm will attempt to find these regions based on the “domedark” frames.

clobber : bool

Whether to overwrite existing FITS files

retmaster : bool

Whether to return master dark and (normalized) flat frames

skysub : bool

Whether to subtract the sky (e.g., you might not want to if sky conditions changed by a lot, and the subtraction is no longer valid).

writefiles : bool

Whether to write files (i.e., just to test things out)

chip : 1 or 2 ONLY

Which detector is being reduced (critical for linearity correction)

EXAMPLE:
::

import ir odome = ir.initobs(‘20120427_chip2’, cal=’dome’) osky = ir.initobs(‘20120427_chip2’, cal=’sky’)

masterframes = ir.moircs_speccal(osky.rawdark, osky.rawflat, odome.rawdark, odome.rawflat, odome.rawsci, odome.procsci, badpixelmask=odome.badpixelmask, clobber=False, retmaster=True, verbose=True, skysub=False, writefiles=False, chip=2)

DESCRIPTION:
  • Make master ‘science dark’ and bad pixel mask from individual “skydark” frames.
  • Make super-dome flat frames (two: lamp on, and lamp off)
  • Subtract LAMPOFF from LAMPON frame, creating master, unnormalized dome (MUD) flat.
  • Normalize each spectrum in the MUD flat along the dispersion direction (e.g., using a low-order polynomial), creating the master dome flat.
  • Make master sky frame by median-combining the raw sky frames and subtracting the master ‘science dark’ frame.
  • For each raw science frame: subtract ‘science dark’ frame; scale and subtract the master sky frame; divide by the master dome flat.
  • Apply linearity correction.
NOTES:

Unfortunately, MOIRCS reduction is best done as a two-step process. First, set up the observations in initobs() using some standard, generic bad pixel mask (perhaps produced by makebadpixelmask_darks()); reduce the data using this routine. From the reduced, flattened data, generate a second (higher-fidelity) bad pixel map (using makebadpixelmask_science()). Combine these two bad pixel masks (and perhaps, as well, the appropriate mask from the MOIRCS instrument website). Insert the proper reference to this in initobs(), and then re-reduce the data.

ir.moircs_spectra(fns, gain, readnoise, varfns=None, idlexec=None, dx=(200, -100), edgeboundary=25, specwidth=60, sep=100, findthresh=200, subregions='SUBREG', IDLoptions="adjoptions={center:1, centerfit:1, centerdeg:3}, bgdeg=3, adjfunc='adjgauss'", pyrafoptions=None, tempframefn='tempframe.fits', tempbpmfn='tempbpm.fits', tempspecfn='tempspec.fits', tempscriptfn='temp_specextract.pro', writefns=None, findlocs='pick', badpixelmask=None, mode='pyraf', superoptions=None, trace_options=None, multiordlocs=None, verbose=False)[source]

Extract spectra from a calibrated MOIRCS multi-object frame.

INPUTS:
fns : str, or list of strs

Filenames of MOIRCS files from which to extract spectra. No, this cannot be the MOIRCS frames as Numpy Arrays.

gain : scalar

Detector gain, in electrons / ADU

readnoise : scalar

Detector read noise, in electrons

idlexec : str

Path to the IDL executable. OPTSPECEXTR.PRO and its associated files must be in your IDL path. If set to None, then it will be set to: os.popen(‘which idl’).read().strip()

OPTIONS:
dx : 2-tuple

Extend the subregions as defined by dx[0] to the left, and by dx[0] to the right. Something of a fudge factor (sorry!).

edgeboundary : int

Trim both sides of each subregion by this many pixels in the spatial direction

varfns : str, or list of strs

Optional names of files with variances of data in ‘fns’.

specwidth : int

Approximate width of spectral profile, in pixels (for IDL mode).

sep : scalar

Minimum separation of spectral traces within a particular subregion. For finding multiple spectral traces within a given subregion.

findthresh : scalar

Ignore all values lower than this value (cf. tools.find_peaks())

subregions : str, or 2D numpy array
if str:

The primary header keyword from which the subregion boundaries will be read (e.g., ‘SUBREG0’, ‘SUBREG1’, etc; cf. moircs_speccal())

if array:

Each row of the array corresponds to the subregion boundaries.

In either case, the format of each subregion boundary B is such that the subregion is:

subreg = frame[B[2]:B[3], B[0]:B[1]]

IDLoptions : str

Options to pass to OPTSPECEXTR.PRO. For example: “adjfunc=’adjgauss’, adjoptions={center:1,centerfit:1,centerdeg:3}, bgdeg=3”

Note that this Python code will break if you _don’t_ trace the spectrum (adjoptions, etc.); this is an area for future work if I ever use a spectrograph with straight traces.

tempframefn : str

If input ‘frame’ is an array, it will be written to this filename in order to pass it to IDL.

tempbpmfn : str

Python will write the subregion bad pixel mask to this filename in order to pass it to IDL

tempspecfn : str

IDL will write the spectral data to this filename in order to pass it back to Python.

tempscriptfn : str

Filename in which a short IDL script will be written.

writefns : str or list of str

If None, write nothing.

returnspec : bool

If True, return outputs.

findlocs : str (‘auto’ or ‘pick’)

Find spectral traces automatically, or pick them manually.

badpixelmask : None or str

Filename of a 2D bad pixel mask, equal to 1 for bad pixels and 0 for good pixels.

superoptions : dict or None

options for mode ‘superextract’

trace_options : dict or None

options for spectral profile tracing (see spec.traceorders())

multiordlocs : None or 2D array (or list of lists)

My hackneyed way to automatically pass multiple ‘ordlocs’ calls to spec.traceorders() (if function is invoked via trace_options). Successively use each of the ordlocs values in multiordlocs.

mode : str

‘superextract’: see spec.superExtract()

‘idl’ : see optspecextr_idl()

‘pyraf’ : see optspecextr_pyraf()

OUTPUT:

For each frame, an object will be returned with various interesting and useful fields. The ‘specs’ field will contain a list (one per subregion), for which each element is the output of spec.optspecextr_idl().

TO_DO:

Allow the routine to write files to disk, and update FITS headers (writefns, returnspec).

Do better at finding the spectral trace.

REQUIREMENTS:

Plotting and analysis tools

SEE_ALSO:

moircs_speccal(), spec.optspecextr_idl()

EXAMPLE:
::

import ir obs = ir.initobs(‘20120429_wasp3_chip2’, cal=’dome’) filenames = [fn.replace(‘proc_‘, ‘proc_fft-defringe_‘) for fn in obs.procsci] out = ir.moircs_spectra(filenames[0], obs.gain, obs.readnoise, None, findlocs=’pick’, mode=’superextract’) all = ir.moircs_spectra(filenames[0:2], obs.gain, obs.readnoise, None, findlocs=out.locs, subregions=out.subregions[out.spec_subregions])

::

import ir obs = ir.initobs(‘20120429_wasp3_chip2’, cal=’dome’) filenames = [fn.replace(‘proc_‘, ‘proc_fft-defringe_‘) for fn in obs.procsci]

speclocs = ir.moircs_spectra(filenames[0], obs.gain, obs.readnoise, findlocs=’pick’, mode=’pickonly’) trace_options = dict(pord=3, fitwidth=60, dispaxis=0)

# Extract spectra once, just to trace spectra: superoptions = dict(bord=2, bkg_radii=[30, 70], extract_radius=18,

polyspacing=1., pord=1, verbose=True, qmode=’fast-linear’, dispaxis=0, csigma=5, retall=True)

trace_out = ir.moircs_spectra(filenames[0], obs.gain, obs.readnoise, None, mode=’superextract’, superoptions=superoptions, trace_options=trace_options, findlocs=speclocs.locs, subregions=speclocs.subregions[speclocs.spec_subregions])

# Extract spectra once, just to trace spectra: meanx = np.array(tools.flatten([range(ss.trace.size) for ss in trace_out.specs])).mean() meany = np.array(tools.flatten([ss.trace for ss in trace_out.specs])).mean() trace_options[‘ordlocs’] = [meanx, meany]

# Extract multiple spectra without any user interaction: superoptions.update(dict(pord=2, polyspacing=0.25)) out2 = ir.moircs_spectra(filenames[0:2], obs.gain, obs.readnoise, None, mode=’superextract’, superoptions=superoptions, trace_options=trace_options, findlocs=speclocs.locs, subregions=speclocs.subregions[speclocs.spec_subregions])

ir.mosfire_refpixvalues(fn, **kw)[source]

Compute and return MOSFIRE reference pixel values, from individual readouts.

INPUTS:
fn : str

Filename of science frame (e.g., ‘m121010_0487.fits’).

OPTIONS:
mode : str

e.g., ‘CDS’ [ONLY CDS MODE IS VALID, FOR NOW]

retframe : bool

If true, return the tuple (refpix_values, pyfits.getdata(fn))

OUTPUTS:

a length-32 Numpy array.

NOTES:

For a filename ‘frame.fits’, reads in the file as well as the individual CDS reads “frame_001.fits” and “frame_002.fits”. Computes the difference between (frame - (frame002-frame001)), and uses it to return the reference pixel bias levels.

ir.mosfire_speccal(sky, domedark, domeflat, rawframes, procframes, badpixelmask=None, samplemask=None, clobber=False, retmaster=False, skysub=False, verbose=False, writefiles=True, gain=2.15, readnoise=21, linearize=False, flatten=True, polycoef=None, slitjawflatcorrect=True, dodark=True)[source]

Perform inital calibration of MOSFIRE spectroscopic data.

INPUTS:
rawsky : list of str, or 2D Numpy array

List of raw sky frames, or a 2D Numpy array Master Sky frame. Exposure time should, ideally, be the same as for “rawframes”. [Deprecated – no longer necessary!]

domedark : list of str, or 2D Numpy array

List of raw, short dome darks, or a 2D Numpy array Master Dome Dark. In this (spectroscopic) case, the “domedark” files are the lamp-off spectroscopic files used to measure the thermal background underlying the main dome files (“domeflat”).

domeflat : list of str, or 2D Numpy array

List of raw flat frames (taken with the dome flat lamp ON), or a 2D Numpy array Master Dome Flat. Exposure time per frame should be same as for “domedark”.

rawframes : list of str

List of raw, unprocessed science frames. Integration times should be the same as “skydark” and “sky.”

procframes : list of str

List of processed science frames, to be written to disk.

badpixelmask : str, or 2D Numpy array

Bad pixel mask: equal to zero at good pixels, and to 1 at bad pixels. Note that bad pixels are not interpolated-over in this stage of the reduction; that doesn’t happen until spectra extraction.

samplemask : 2D Numpy array

Sampling mask tells the sky-scaling algorithms which parts of the image to use. Equal to 1 at points to be sampled, and zero elsewhere. If set to None (default), a crude algorithm will attempt to find these regions based on the “domedark” frames.

clobber : bool

Whether to overwrite existing FITS files

retmaster : bool

Whether to return master dark and (normalized) flat frames

skysub : bool

Whether to subtract the sky (e.g., you might not want to if sky conditions changed by a lot, and the subtraction is no longer valid).

writefiles : bool

Whether to write files (i.e., just to test things out)

linearize : bool

Whether to correct for detector nonlinearity.

flatten : bool

Whether to use flat-frames for correction

polycoef : str, None, or sequence

Polynomial coefficients for detector linearization: see ir.linearity_correct() and ir.linearity_mosfire().

slitjawflatcorrect : bool

Whether to try to correct the dome flats for the uneven slit width (from the slit jaw mechanisms).

dodark: bool

If True, apply correction for dark frames in ‘domedark.’ If False, don’t! (i.e., Y or J band observations)

EXAMPLE:
::

import ir obs = ir.initobs(‘20121010’)

masterframes = ir.mosfire_speccal(obs.rawsky[0:10], obs.rawdark[::2], obs.rawflat[::2], obs.rawsci, obs.procsci, badpixelmask=obs.badpixelmask, clobber=False, retmaster=True, verbose=True, skysub=False, linearize=True, polycoef=’/Users/ianc/proj/transit/data/mosfire_linearity/linearity/mosfire_linearity_cnl_coefficients_bic-optimized.fits’) mastersky, masterdomedark, masterdomeflat, mudflat, samplemask = masterframes

DESCRIPTION:
  • Make super-dome flat frames (two: lamp on, and lamp off)
  • Subtract LAMPOFF from LAMPON frame, creating master, unnormalized dome (MUD) flat.
  • Normalize each spectrum in the MUD flat along the dispersion direction (e.g., using a low-order polynomial), creating the master dome flat.
  • Make master sky frame by median-combining the raw sky frames
  • For each raw science frame: scale and subtract the master sky frame (if desired); divide by the master dome flat.
  • Apply linearity correction. (if desired)
NOTES:

Unfortunately, MOSFIRE reduction is best done as a two-step process. First, set up the observations in initobs() using some standard, generic bad pixel mask (perhaps produced by makebadpixelmask_darks()); reduce the data using this routine. From the reduced, flattened data, generate a second (higher-fidelity) bad pixel map (using makebadpixelmask_science()). Combine these two bad pixel masks (and perhaps, as well, the appropriate mask from the MOIRCS instrument website). Insert the proper reference to this in initobs(), and then re-reduce the data.

ir.optspecextr_pyraf(filename, specname, gain, readnoise, badpixelmask=None, options=None, verbose=False, cleanup=True)[source]

Python script to call Pyraf and extract spectra from a file.

INPUTS:
filename : str

filename of frame (measured in ADU) from which to extract spectrum.

specname : str

name of Pyraf-extracted spectrum.

gain : scalar

Gain of detector (electrons per ADU). If frame is already in units of electrons, set this to 1.0. If gain is a string, we will try to read the eponymous FITS header keyword.

readnoise : scalar

Read noise of detector, in electrons. If gain is a string, we will try to read the eponymous FITS header keyword.

badpixelmask : str

filename of bad pixel mask; equal to 1 at bad pixels, equal to 0 at good pixels.

options : dict

A dict of all the various options to be passed to iraf’s ‘apall’ command.

cleanup : bool

Whether to delete working files after processing

RETURNS:An object with spectral bands as defined in the IRAF output file.
ir.red_dark(obs, ind, num=nan, verbose=False, sigma=3, niter=1, clobber=False)[source]

Combine dark frames into a single dark frame:

ir.red_flat(obs, ind, num=nan, verbose=False, sigma=3, niter=1, clobber=False)[source]

Dark-correct flats, make normalized super-flat.

ir.red_masterflat(obs, nums=, []verbose=False, sigma=3, niter=1, clobber=False)[source]

Combine numbered super-flats into a single flat.

ir.red_sci(obs, ind, num=nan, verbose=False, sigma=3, niter=1)[source]

Dark-subtract science frames.

I don’t currently use this (Jan 2010)

ir.red_sub(ifiles, ofiles, subfile, num=nan, clobber=False)[source]

Subtract one file from a list of others, and save in a new location.

First two inputs are lists of strings, ‘subfile’ is a string.

ir.setairmassG(filename)[source]

Use PyRaf tasks to set airmass for Lick/GEMINI camera observations. Assumes PST times.

ir.spectral_subregion_mask(flatframedata, minsep=42, maxboundarywidth=15)[source]

Find boundaries of each slit’s spectrum, using a flat-field frame:

Helper function for mosfire_speccal() and moircs_speccal()

Previous topic

Planetary maps

Next topic

Aperture and simple PSF-fitting photometrymem

This Page