Calibration Utilities

General utilities for ACS calibration adapted from HSTCAL.

acstools.utils_calib.extract_dark(prihdr, scihdu)

Extract superdark data from DARKFILE or DRKCFILE.

Parameters:
  • prihdr (obj) – FITS primary header HDU.
  • scihdu (obj) – Extension HDU of the science image. This is only used to extract subarray data.
Returns:

dark – Superdark, if any. Subtract this to apply DARKCORR.

Return type:

ndarray or None

acstools.utils_calib.extract_flash(prihdr, scihdu)

Extract postflash data from FLSHFILE.

Parameters:
  • prihdr (obj) – FITS primary header HDU.
  • scihdu (obj) – Extension HDU of the science image. This is only used to extract subarray data.
Returns:

flash – Postflash, if any. Subtract this to apply FLSHCORR.

Return type:

ndarray or None

acstools.utils_calib.extract_flatfield(prihdr, scihdu)

Extract flatfield data from PFLTFILE.

Parameters:
  • prihdr (obj) – FITS primary header HDU.
  • scihdu (obj) – Extension HDU of the science image. This is only used to extract subarray data.
Returns:

invflat – Inverse flatfield, if any. Multiply this to apply FLATCORR.

Return type:

ndarray or None

acstools.utils_calib.from_irafpath(irafpath)

Resolve IRAF path like jref$ into actual file path.

Parameters:irafpath (str) – Path containing IRAF syntax.
Returns:realpath – Actual file path. If input does not follow path$filename format, then this is the same as input.
Return type:str
Raises:ValueError – The required environment variable is undefined.
acstools.utils_calib.extract_ref(scihdu, refhdu)

Extract section of the reference image that corresponds to the given science image.

This only returns a view, not a copy of the reference image’s array.

Parameters:

refhdu (scihdu,) – Extension HDU’s of the science and reference image, respectively.

Returns:

refdata – Section of the relevant reference image.

Return type:

array-like

Raises:
  • NotImplementedError – Either science or reference data are binned.
  • ValueError – Extracted section size mismatch.
acstools.utils_calib.find_line(scihdu, refhdu)

Obtain bin factors and corner location to extract and bin the appropriate subset of a reference image to match a science image.

If the science image has zero offset and is the same size and binning as the reference image, same_size will be set to True. Otherwise, the values of rx, ry, x0, and y0 will be assigned.

Normally the science image will be binned the same or more than the reference image. In that case, rx and ry will be the bin size of the science image divided by the bin size of the reference image.

If the binning of the reference image is greater than the binning of the science image, the ratios (rx and ry) of the bin sizes will be the reference image size divided by the science image bin size. This is not necessarily an error.

Note

Translated from calacs/lib/findbin.c.

Parameters:refhdu (scihdu,) – Extension HDU’s of the science and reference image, respectively.
Returns:
  • same_size (bool) – True if zero offset and same size and binning.
  • rx, ry (int) – Ratio of bin sizes.
  • x0, y0 (int) – Location of start of subimage in reference image.
Raises:ValueError – Science and reference data size mismatch.
acstools.utils_calib.get_corner(hdr, rsize=1)

Obtain bin and corner information for a subarray.

LTV1, LTV2, LTM1_1, and LTM2_2 keywords are extracted from the given extension header and converted to bin and corner values (0-indexed).

LTV1 for the CCD uses the beginning of the illuminated portion as the origin, not the beginning of the overscan region. Thus, the computed X-corner has the same origin as LTV1, which is what we want, but it differs from the CENTERA1 header keyword, which has the beginning of the overscan region as origin.

Note

Translated from calacs/lib/getcorner.c.

Parameters:
  • hdr (obj) – Extension header.
  • rsize (int, optional) – Size of reference pixel in units of high-res pixels.
Returns:

  • bin (tuple of int) – Pixel size in X and Y.
  • corner (tuple of int) – Corner of subarray in X and Y.

acstools.utils_calib.get_lt(hdr)

Obtain the LTV and LTM keyword values.

Note that this returns the values just as read from the header, which means in particular that the LTV values are for one-indexed pixel coordinates.

LTM keywords are the diagonal elements of MWCS linear transformation matrix, while LTV’s are MWCS linear transformation vector (1-indexed).

Note

Translated from calacs/lib/getlt.c.

Parameters:hdr (obj) – Extension header.
Returns:ltm, ltv(LTM1_1, LTM2_2) and (LTV1, LTV2). Values are (1, 1) and (0, 0) if not found, to accomodate reference files with missing info.
Return type:tuple of float
Raises:ValueError – Invalid LTM* values.
acstools.utils_calib.from_lt(rsize, ltm, ltv)

Compute the corner location and pixel size in units of unbinned pixels.

Note

Translated from calacs/lib/fromlt.c.

Parameters:
  • rsize (int) – Reference pixel size. Usually 1.
  • ltv (ltm,) – See get_lt().
Returns:

  • bin (tuple of int) – Pixel size in X and Y.
  • corner (tuple of int) – Corner of subarray in X and Y.

acstools.utils_calib.hdr_vals_for_overscan(root)

Retrieve header keyword values from RAW and SPT FITS files to pass on to check_oscntab() and check_overscan().

Parameters:root (str) – Rootname of the observation. Can be relative path to the file excluding the type of FITS file and extension, e.g., ‘/my/path/jxxxxxxxq’.
Returns:
  • ccdamp (str) – Amplifiers used to read out the CCDs.
  • xstart (int) – Starting column of the readout in detector coordinates.
  • ystart (int) – Starting row of the readout in detector coordinates.
  • xsize (int) – Number of columns in the readout.
  • ysize (int) – Number of rows in the readout.
acstools.utils_calib.check_oscntab(oscntab, ccdamp, xsize, ysize, leading, trailing)

Check if the supplied parameters are in the OSCNTAB reference file.

Note

Even if an entry does not exist in OSCNTAB, as long as the subarray does not have any overscan, it should not be a problem for CALACS.

Note

This function does not check the virtual bias rows.

Parameters:
  • oscntab (str) – Path to the OSCNTAB reference file being checked against.
  • ccdamp (str) – Amplifier(s) used to read out the CCDs.
  • xsize (int) – Number of columns in the readout.
  • ysize (int) – Number of rows in the readout.
  • leading (int) – Number of columns in the bias section (“TRIMX1” to be trimmed off by BLEVCORR) on the A/C amplifiers side of the CCDs.
  • trailing (int) – Number of columns in the bias section (“TRIMX2” to be trimmed off by BLEVCORR) on the B/D amplifiers side of the CCDs.
Returns:

supported – Result of test if input parameters are in OSCNTAB.

Return type:

bool

acstools.utils_calib.check_overscan(xstart, xsize, total_prescan_pixels=24, total_science_pixels=4096)

Check image for bias columns.

Parameters:
  • xstart (int) – Starting column of the readout in detector coordinates.
  • xsize (int) – Number of columns in the readout.
  • total_prescan_pixels (int) – Total prescan pixels for a single amplifier on a detector. Default is 24 for WFC.
  • total_science_pixels (int) – Total science pixels across a detector. Default is 4096 for WFC (across two amplifiers).
Returns:

  • hasoverscan (bool) – Indication if there are bias columns in the image.
  • leading (int) – Number of bias columns on the A/C amplifiers side of the CCDs (“TRIMX1” in OSCNTAB).
  • trailing (int) – Number of bias columns on the B/D amplifiers side of the CCDs (“TRIMX2” in OSCNTAB).