extractcube module

extractcube.getcube(filename, read_idx=[1, None], calibdir='calibrations/20160408/', bgsub=True, mask=True, gain=2, noisefac=0, saveramp=False, R=30, method='lstsq', refine=True, suppressrn=True, fitshift=True, flatfield=True, smoothandmask=True, minpct=70, fitbkgnd=True, saveresid=False, maxcpus=8)[source]

Provisional routine getcube. Construct and return a data cube from a set of reads.

Inputs: 1. filename: name of the file containing the up-the-ramp reads.

Should include the full path/to/file.

Optional inputs: 1. read_idx: list of two numbers, the first and last reads to use in

the up-the-ramp combination. Default [2, None], i.e., discard the first read and use all of the rest.
  1. calibdir: name of the directory containing the calibration files.
    Default calibrations/20160408/
  2. bgsub: Subtract the file background.fits in calibdir? Default
    True.
  3. mask: Apply the bad pixel mask mask.fits in the directory
    calibdir? Strongly recommended. Default True.
  4. gain: Detector gain, used to compute shot noise. Default 2.
  5. noisefac: Extra factor of noise to account for imperfect lenslet
    models: variance = readnoise + shotnoise + noisefac*countrate Default zero, values of around 0.05 should give reduced chi squared values of around 1 in the fit.
  6. R: integer, approximate resolution lam/delta(lam) of the
    extracted data cube. Resolutions higher than ~25 or 30 are comparable to or finer than the pixel sampling and are not recommended–there is very strong covariance. Default 30.
  7. method: string, method used to extract data cube. Should be
    either ‘lstsq’ for a least-squares extraction or ‘optext’ for a quasi-optimal extraction. Default ‘lstsq’
  8. refine: Fit the data cube twice to account for nearest neighbor
    crosstalk? Approximately doubles runtime. This option also enables read noise suppression (below). Default True
  9. suppress_rn: Remove correlated read noise between channels using
    the residuals of the 50% least illuminated pixels? Default True.
  10. fitshift: Fit a subpixel shift in the psflet locations across
    the detector? Recommended except for quicklook. Cost is modest compared to cube extraction

Returns: 1. datacube: an instance of the Image class containing the data cube.

Steps performed:

1. Up-the-ramp combination. As of yet no special read noise suppression (just a channel-by-channel correction of the reference voltages). Do a full nonlinear fit for high count pixels, and remove an exponential decay of the reference voltage in the first read. 2. Subtraction of thermal background from file in calibration directory. 3. Application of hot pixel mask (as zero inverse variances). 4. Load calibration files from calibration directory for the data cube extraction, optionally fit for subpixel shifts across the detector. 5. Extract the data cube.

Notes for now: the quasi-optimal extraction isn’t really an optimal extraction. Every lenslet’s spectrum natively samples a different set of wavelengths, so right now they are all simply interpolated onto the same wavelength array. This is certainly not optimal, but I don’t see any particularly good alternatives (other than maybe convolving to a lower, but uniform, resolution). The lstsq extraction can include all errors and covariances. Errors are included (the diagonal of the covariance matrix), but the full covariance matrix is currently discarded.