corgidrp.l1_to_l2a#
Functions#
|
Measure and subtract the median bias in each row of the pre-scan detector region. |
|
Detects cosmic rays in a given dataset. Updates the DQ to reflect the pixels that are affected. |
|
Perform non-linearity correction of a dataset using the corresponding non-linearity correction. We check for non-linear pixel and flag them in the DQ. |
|
Discards images from the dataset that have more than a frac_frame_sat_limit fraction of values |
|
Updates the data level to L2a. Only works on L1 data. |
|
Discard frames that are setup/engineering frames based on header keywords. |
Module Contents#
- corgidrp.l1_to_l2a.prescan_biassub(input_dataset, noise_maps=None, return_full_frame=False, detector_regions=None, use_imaging_area=False, dataset_copy=True)[source]#
Measure and subtract the median bias in each row of the pre-scan detector region. This step also crops the images to just the science area, or optionally returns the full detector frames.
- Parameters:
input_dataset (corgidrp.data.Dataset) – a dataset of Images (L1a-level)
noise_maps (corgidrp.data.DetectorNoiseMaps) – the bias offset (an offset value to be subtracted from the bias) is extracted from this calibration class instance.
None (If)
error. (a default value of 0 is used for the bias offset and its)
return_full_frame (bool) – flag indicating whether to return the full frame or only the bias-subtracted image area. Defaults to False.
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.
use_imaging_area (bool) – flag indicating whether to use the imaging area (like in the trap pump code) or use the defualt (equivalent to EMCCDFrame)
dataset_copy (bool) – flag indicating whether the input dataset will be preserved after this function is executed or not. If False, the output dataset will be the input dataset modified, and the input and output datasets will be identical. This is useful when handling a large dataset and when the input dataset is not needed afterwards. Defaults to True.
- Returns:
a pre-scan bias subtracted version of the input dataset
- Return type:
- corgidrp.l1_to_l2a.detect_cosmic_rays(input_dataset, detector_params, k_gain=None, sat_thresh=0.7, plat_thresh=0.7, cosm_filter=1, cosm_box=3, cosm_tail=10, mode='image', detector_regions=None, pct_oversat_lim=20, dataset_copy=True)[source]#
Detects cosmic rays in a given dataset. Updates the DQ to reflect the pixels that are affected. TODO: (Eventually) Decide if we want to invest time in improving CR rejection (modeling and subtracting the hit and tail rather than just flagging the whole row.) TODO: Decode incoming DQ mask to avoid double counting saturation/CR flags in case a similar custom step has been run beforehand.
- Parameters:
input_dataset (corgidrp.data.Dataset) – a dataset of Images that need cosmic ray identification (L1-level)
detector_params (corgidrp.data.DetectorParams) – a calibration file storing detector calibration values
k_gain (corgidrp.data.KGain) – KGain calibration file
sat_thresh (float) – Multiplication factor for the pixel full-well capacity (fwc) that determines saturated cosmic pixels. Interval 0 to 1, defaults to 0.7. Lower numbers are more aggressive in flagging saturation.
plat_thresh (float) – Multiplication factor for pixel full-well capacity (fwc) that determines edges of cosmic plateau. Interval 0 to 1, defaults to 0.7. Lower numbers are more aggressive in flagging cosmic ray hits.
cosm_filter (int) – Minimum length in pixels of cosmic plateaus to be identified. Defaults to 1.
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. Defaults to 3.
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. Defaults to 10.
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.
pct_oversat_lim – (float): Percent of total frame over sat_fwc over which we determine the frame is oversaturated and will be discarded. Frame saturations equal to this argument are not discarded.
dataset_copy (bool) – flag indicating whether the input dataset will be preserved after this function is executed or not. If False, the output dataset will be the input dataset modified, and the input and output datasets will be identical. This is useful when handling a large dataset and when the input dataset is not needed afterwards. Defaults to True.
- Returns:
A version of the input dataset of the input dataset where the cosmic rays have been identified.
- Return type:
- corgidrp.l1_to_l2a.correct_nonlinearity(input_dataset, non_lin_correction, threshold=np.inf)[source]#
Perform non-linearity correction of a dataset using the corresponding non-linearity correction. We check for non-linear pixel and flag them in the DQ.
- Parameters:
input_dataset (corgidrp.data.Dataset) – a dataset of Images that need non-linearity correction (L2a-level).
non_lin_correction (corgidrp.data.NonLinearityCorrection) – a NonLinearityCorrection calibration file to model the non-linearity.
threshold (float) – threshold for flagging pixels in the DQ array, value above this threshold will be flagged in the DQ map as too nonlinear. By default it is set to infinity, user can change it to a different value.
- Returns:
A non-linearity corrected version of the input dataset
- Return type:
- corgidrp.l1_to_l2a.remove_sat_images(input_dataset, sat_fwcs, pct_oversat_lim=20, dataset_copy=True)[source]#
Discards images from the dataset that have more than a frac_frame_sat_limit fraction of values over the sat_thresh limit. Also removes corresponding fwc elements from sat_fwc array. Intended to be called by detect_cosmic_rays to remove problematic images before processing.
- Parameters:
input_dataset (corgidrp.data.Dataset) – a dataset of Images (L1-level)
sat_fwcs (list) – List of calculated SAT_DN values per frame. Already multiplied with sat_thresh and ready to compare with pixel values.
pct_oversat_lim – (float): Percent of total frame over sat_fwc over which we determine the frame is oversaturated and will be discarded, Frame saturations equal to this argument are not discarded.
dataset_copy (bool) – flag indicating whether the input dataset will be preserved after this function is executed or not. If False, the output dataset will be the input dataset modified, and the input and output datasets will be identical. This is useful when handling a large dataset and when the input dataset is not needed afterwards. Defaults to True.
- Returns:
a version of the input dataset with only the frames we want to use pruned_sat_fwcs (list): input sat_fwcs with corresponding saturated frame fwcs removed
- Return type:
- corgidrp.l1_to_l2a.update_to_l2a(input_dataset)[source]#
Updates the data level to L2a. Only works on L1 data.
Applies merge_headers to each frame (removes deleted keywords, applies other header rules), then sets DATALVL to L2a and updates filenames.
- Parameters:
input_dataset (corgidrp.data.Dataset) – a dataset of Images (L1-level)
- Returns:
same dataset now at L2a level
- Return type:
- corgidrp.l1_to_l2a.discard_setup_frames(input_dataset, keywords_to_check=None)[source]#
Discard frames that are setup/engineering frames based on header keywords.
Checks each frame’s extension header for the specified keywords. If any keyword has a value of 1, the frame is considered a setup frame and is discarded. This is used to filter out acquisition frames (ISACQ), speckle balance frames (SPBAL), and HOWFSC frames (ISHOWFSC).
- Parameters:
input_dataset (corgidrp.data.Dataset) – a dataset of Images
keywords_to_check (list of str) – FITS header keywords to check. Frames where any of these keywords equals 1 will be discarded. If None or empty, no frames are discarded.
- Returns:
dataset with setup frames removed
- Return type: