romanimpreprocess.utils.fitting

Utility functions for ramp fitting.

Functions

construct_weights

Makes a numpy array of weights for slope fitting.

jump_detect

Searches for a jump.

ramp_fit

Ramp fitting.

Functions

construct_weights(u, meta[, exclude_first])

Makes a numpy array of weights for slope fitting.

jump_detect(data, rdq, pdq, meta, caldir, mylog[, ...])

Searches for a jump.

ramp_fit(data, rdq, pdq, meta, caldir, mylog[, ...])

Ramp fitting.

Module Contents

construct_weights(u, meta, exclude_first=True)[source]

Makes a numpy array of weights for slope fitting.

Parameters:
  • u (float) – Poisson to read noise ratio, unit: 1/(e*s).

  • meta (dict) – Metadata for setting the weights.

  • exclude_first (bool, optional) – Whether to exclude the first read (this is because the reset-read frame is sometimes hard to calibrate).

Returns:

K – The weight vector; length is the number of groups (meta['ngrp']).

Return type:

np.array of float

Notes

These are optimized for a ratio of u = flux / (gain * read_noise_variance). The units are: [DN/s] / ([e/DN] * [DN^2]) = 1/(e*s).

The meta dictionary should contain: * 'ngrp' : int

Number of groups

  • 'N' : np.array of int Number of frames in each group

  • 'tbar' : np.array of float Mean time since reset of each group

  • 'tau' : np.array of float Variance-weighted time since reset of each group

This follows the notation and optimization of Casertano et al. (2022), except that we don’t use the adaptive aspect of the algorithm.

The returned array K is intended to be used in computing a slope, sum_i K_i R_i (in DN/s). The weights should sum to 0 so that we aren’t sensitive to the reset level.

jump_detect(data, rdq, pdq, meta, caldir, mylog, exclude_first=True, truncate_ramp=None)[source]

Searches for a jump.

Note that affected pixels are only flagged by this function: they are not corrected!

Parameters:
  • data (np.array) – The input data in DN, shape = (ngrp,ny,nx).

  • rdq (np.array) – 3D array, flags (ramp data quality)

  • pdq (np.array) – 2D array, flags (pixel data quality)

  • meta (dict) – Other metadata (right now: frame_time and read_pattern)

  • caldir (dict) – Locations of calibration files.

  • mylog (romanimpreprocess.utils.processlog.ProcessLog) – Processing log.

  • exclude_first (bool, optional) – Exclude the first sample?

  • truncate_ramp (int or None, optional) – If given, truncates the ramp at this sample (useful for saturated pixels).

Returns:

  • slope (np.array) – Slope image (2D, DN/s).

  • slope_err_read (np.array) – Slope error image from read noise (2D, DN/s).

  • slope_err_poisson (np.array) – Slope error image from Poisson noise (2D, DN/s).

  • smap (np.array) – 3D jump significance cube, dimensionless (axes: difference, y, x).

Notes

Data operated on is in the cube data (ngrp,ny,nx); and the uint32 flags are in rdq (ngrp,ny,nx) and pdq (ny,nx).

The meta dictionary contains at least:

  • 'ngrp' : int Number of groups

  • 'N' : np.array of int Number of frames in each group

  • 'tbar' : np.array of float Mean time since reset of each group

  • 'tau' : np.array of float Variance-weighted time since reset of each group

  • 'K' : np.array 1D weight vector, ususally comes from construct_weights.

If meta contains “jump_detect_pars”, then this can override the default settings in the algorithm.

The gain is read from caldir, and is in e/DN.

The current version implements the Sharma & Casertano (2024) flagging algorithm except for fitting the weights.

See: Sanjib Sharma and Stefano Casertano 2024 PASP 136 054504 DOI 10.1088/1538-3873/ad4b9e

ramp_fit(data, rdq, pdq, meta, caldir, mylog, exclude_first=True)[source]

Ramp fitting.

Note that the slope image still fits objects that saturate during the exposure, since the same bright stars will keep saturating and we don’t want to keep masking them. But for CR hits on unsaturated objects we want to reject that exposure, since the ePSF may be different due to jitter.

Parameters:
  • data (np.array) – The input data in DN, shape = (ngrp,ny,nx).

  • rdq (np.array) – 3D array, flags (ramp data quality)

  • pdq (np.array) – 2D array, flags (pixel data quality)

  • meta (dict) – Other metadata (right now: frame_time and read_pattern)

  • caldir (dict) – Locations of calibration files.

  • mylog (romanimpreprocess.utils.processlog.ProcessLog) – Processing log.

  • exclude_first (bool, optional) – Exclude the first sample?

Returns:

  • slope (np.array) – Slope image (2D, DN/s).

  • slope_err_read (np.array) – Slope error image from read noise (2D, DN/s).

  • slope_err_poisson (np.array) – Slope error image from Poisson noise (2D, DN/s).

Notes

The meta dictionary contains at least:

  • 'ngrp' : int Number of groups

  • 'N' : np.array of int Number of frames in each group

  • 'tbar' : np.array of float Mean time since reset of each group

  • 'tau' : np.array of float Variance-weighted time since reset of each group

  • 'K' : np.array 1D weight vector, ususally comes from construct_weights.