corgidrp.detector#
Attributes#
Functions#
|
For a given bias subtracted frame of dn counts, return a same sized |
|
Slice 2d section out of frame |
|
Embed subframe data into a full frame with a specified value per pixel everywhere else. |
|
Safely check format of geom sub-dictionary and return values. |
|
Return geometry of imaging area (including shielded pixels) |
|
Select only the real counts from full frame and exclude virtual. |
|
Identify and remove saturated cosmic ray hits and tails. |
|
Find the beginning index of each cosmic plateau in a row. |
|
Calculates the lowest full well capacity saturation threshold for each frame. |
|
Replaces each DQ-flagged pixel (>= the given threshold) in the dataset with np.nan. |
|
Assigns a DQ flag to each nan pixel in the dataset. |
|
Returns the extra-noise function (ENF). |
Module Contents#
- corgidrp.detector.get_relgains(frame, em_gain, non_lin_correction)[source]#
For a given bias subtracted frame of dn counts, return a same sized array of relative gain values.
This algorithm contains two interpolations:
A 2d interpolation to find the relative gain curve for a given EM gain
A 1d interpolation to find a relative gain value for each given dn count value.
Both of these interpolations are linear, and both use their edge values as constant extrapolations for out of bounds values.
- Parameters:
frame (array_like) – Array of dn count values.
em_gain (float) – Detector EM gain.
non_lin_correction (corgi.drp.NonLinearityCorrection) – A NonLinearityCorrection calibration file.
- Returns:
Array of relative gain values.
- Return type:
array_like
- corgidrp.detector.slice_section(frame, arrtype, key, detector_regions=None)[source]#
Slice 2d section out of frame
Ported from II&T read_metadata.py
- Parameters:
frame (np.ndarray) – Full frame consistent with size given in frame_rows, frame_cols
arrtype (str) – Keyword referencing the observation type (e.g. ‘ENG’ or ‘SCI’)
key (str) – Keyword referencing section to be sliced; must exist in detector_areas
detector_regions (dict) – a dictionary of detector geometry properties. Keys should be as found in detector_areas in detector.py. Defaults to that dictionary.
- Returns:
a 2D array of the specified detector area
- Return type:
np.ndarray
- corgidrp.detector.embed(data, arrtype, key, pad_val=0, detector_regions=None)[source]#
Embed subframe data into a full frame with a specified value per pixel everywhere else.
- Parameters:
data (np.ndarray) – Subframe data to embed
arrtype (str) – Keyword referencing the observation type (e.g. ‘ENG’ or ‘SCI’)
key (str) – Keyword referencing section to be sliced; must exist in detector_areas
pad_val (float) – Value to fill in each pixel outside the subframe region
detector_regions (dict) – a dictionary of detector geometry properties. Keys should be as found in detector_areas in detector.py. Defaults to that dictionary.
- Returns:
a 2D array of the full detector area with embedded subframe
- Return type:
np.ndarray
- corgidrp.detector.unpack_geom(arrtype, key, detector_regions=None)[source]#
Safely check format of geom sub-dictionary and return values.
- Parameters:
arrtype – str
type (Keyword referencing the observation)
key – str
section (Desired)
detector_regions – dict
dictionary. (a dictionary of detector geometry properties. Keys should be as found in detector_areas in detector.py. Defaults to that)
- Returns:
int Number of rows of frame cols : int Number of columns of frame r0c0: tuple Tuple of (row position, column position) of corner closest to (0,0)
- Return type:
rows
- corgidrp.detector.imaging_area_geom(arrtype, detector_regions=None)[source]#
Return geometry of imaging area (including shielded pixels) in reference to full frame. Different from normal image area.
- Parameters:
arrtype – str
type (Keyword referencing the observation)
detector_regions – dict
dictionary. (a dictionary of detector geometry properties. Keys should be as found in detector_areas in detector.py. Defaults to that)
- Returns:
int Number of rows of imaging area cols : int Number of columns of imaging area r0c0: tuple Tuple of (row position, column position) of corner closest to (0,0)
- Return type:
rows
- corgidrp.detector.imaging_slice(arrtype, frame, detector_regions=None)[source]#
Select only the real counts from full frame and exclude virtual. Includes shielded pixels.
Use this to transform mask and embed from acting on the full frame to acting on only the image frame.
- Parameters:
arrtype – str
type (Keyword referencing the observation)
frame (Input) – array_like
frame
detector_regions – dict
dictionary. (a dictionary of detector geometry properties. Keys should be as found in detector_areas in detector.py. Defaults to that)
- Returns:
array_like Imaging slice
- Return type:
sl
- corgidrp.detector.flag_cosmics(cube, fwc, sat_thresh, plat_thresh, cosm_filter, cosm_box, cosm_tail, mode='image', detector_regions=None, arrtype='SCI')[source]#
Identify and remove saturated cosmic ray hits and tails.
Use sat_thresh (interval 0 to 1) to set the threshold above which cosmics will be detected. For example, sat_thresh=0.99 will detect cosmics above 0.99*fwc.
Use plat_thresh (interval 0 to 1) to set the threshold under which cosmic plateaus will end. For example, if plat_thresh=0.85, once a cosmic is detected the beginning and end of its plateau will be determined where the pixel values drop below 0.85*fwc.
Use cosm_filter to determine the smallest plateaus (in pixels) that will be identified. A reasonable value is 2.
- Parameters:
cube (array_like, float) – 3D cube of image data (bias of zero).
fwc (float) – Full well capacity of detector in DNs. Note that this may require a conversion as FWCs are usually specified in electrons, but the image is in DNs at this point.
sat_thresh (float) – Multiplication factor for fwc that determines saturated cosmic pixels.
plat_thresh (float) – Multiplication factor for fwc that determines edges of cosmic plateu.
cosm_filter (int) – Minimum length in pixels of cosmic plateus to be identified.
cosm_box (int) – Number of pixels out from an identified cosmic head (i.e., beginning of the plateau) to mask out. For example, if cosm_box is 3, a 7x7 box is masked, with the cosmic head as the center pixel of the box.
cosm_tail (int) – Number of pixels in the row downstream of the end of a cosmic plateau to mask. If cosm_tail is greater than the number of columns left to the end of the row from the cosmic plateau, the cosmic masking ends at the end of the row.
mode (string) – If ‘image’, an image-area input is assumed, and if the input tail length is longer than the length to the end of the image-area row, the mask is truncated at the end of the row. If ‘full’, a full-frame input is assumed, and if the input tail length is longer than the length to the end of the full-frame row, the masking continues onto the next row. Defaults to ‘image’.
detector_regions – (dict): A dictionary of detector geometry properties. Keys should be as found in detector_areas in detector.py. Defaults to detector_areas in detector.py.
arrtype (string) – ‘ARRTYPE’ from the header associated with the input data cube. Defaults to ‘SCI’.
- Returns:
Mask for pixels that have been set to zero.
- Return type:
array_like, int
Notes
This algorithm uses a row by row method for cosmic removal. It first finds streak rows, which are rows that potentially contain cosmics. It then filters each of these rows in order to differentiate cosmic hits (plateaus) from any outlier saturated pixels. For each cosmic hit it finds the leading ledge of the plateau and kills the plateau (specified by cosm_filter) and the tail (specified by cosm_tail).
- |<-------- streak row is the whole row ----------------------->|
……|<-plateau->|<——————tail———->|………
B Nemati and S Miller - UAH - 02-Oct-2018 Kevin Ludwick - UAH - 2024
- corgidrp.detector.find_plateaus(streak_row, fwc, sat_thresh, plat_thresh, cosm_filter)[source]#
Find the beginning index of each cosmic plateau in a row.
- Parameters:
streak_row (array_like, float) – Row with possible cosmics.
fwc (float) – Full well capacity of detector in DNs. Note that this may require a conversion as FWCs are usually specified in electrons, but the image is in DNs at this point.
sat_thresh (float) – Multiplication factor for fwc that determines saturated cosmic pixels.
plat_thresh (float) – Multiplication factor for fwc that determines edges of cosmic plateau.
cosm_filter (float) – Minimum length in pixels of cosmic plateaus to be identified.
- Returns:
Index of plateau beginnings, or None if there is no plateau.
- Return type:
array_like, int
- corgidrp.detector.calc_sat_fwc(emgain_arr, fwcpp_arr, fwcem_arr, sat_thresh)[source]#
Calculates the lowest full well capacity saturation threshold for each frame.
Args: emgain_arr (np.array): 1D array of the EM gain value for each frame. fwcpp_arr (np.array): 1D array of the full-well capacity in the image
frame (before em gain readout) value for each frame.
- fwcem_arr (np.array): 1D array of the full-well capacity in the EM gain
register for each frame.
- sat_thresh (float): Multiplier for the full-well capacity to determine
what qualifies as saturation. A reasonable value is 0.99
- Returns:
lowest full well capacity saturation threshold for frames
- Return type:
np.array
- corgidrp.detector.nan_flags(dataset, threshold=1)[source]#
Replaces each DQ-flagged pixel (>= the given threshold) in the dataset with np.nan.
- Parameters:
dataset (corgidrp.data.Dataset) – input dataset.
threshold (int, optional) – DQ threshold to replace with nans. Defaults to 1.
- Returns:
dataset with flagged pixels replaced.
- Return type:
- corgidrp.detector.flag_nans(dataset, flag_val=1)[source]#
Assigns a DQ flag to each nan pixel in the dataset.
- Parameters:
dataset (corgidrp.data.Dataset) – input dataset.
flag_val (int, optional) – DQ value to assign. Defaults to 1.
- Returns:
dataset with nan values flagged.
- Return type: