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.