Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JP-3858-superbias #9232

Merged
merged 10 commits into from
Mar 7, 2025
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ repos:
jwst/spectral_leak/.* |
jwst/srctype/.* |
jwst/straylight/.* |
jwst/superbias/.* |
jwst/tests/.* |
jwst/tso_photometry/.* |
jwst/wfs_combine/.* |
Expand Down
2 changes: 0 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ exclude = [
"jwst/spectral_leak/**.py",
"jwst/srctype/**.py",
"jwst/straylight/**.py",
"jwst/superbias/**.py",
"jwst/tso_photometry/**.py",
"jwst/wfs_combine/**.py",
"jwst/white_light/**.py",
Expand Down Expand Up @@ -147,7 +146,6 @@ ignore-fully-untyped = true # Turn off annotation checking for fully untyped co
"jwst/spectral_leak/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/srctype/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/straylight/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/superbias/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/tso_photometry/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/wfs_combine/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/white_light/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
4 changes: 3 additions & 1 deletion jwst/superbias/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Subtract super-bias reference data from the input science data model."""

from .superbias_step import SuperBiasStep

__all__ = ['SuperBiasStep']
__all__ = ["SuperBiasStep"]
50 changes: 20 additions & 30 deletions jwst/superbias/bias_sub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#
# Module for subtracting a super-bias image from science data sets
#
"""Module for subtracting a super-bias image from science data sets."""

import numpy as np
import logging
Expand All @@ -12,25 +10,20 @@

def do_correction(input_model, bias_model):
"""
Short Summary
-------------
Execute all tasks for Super-Bias Subtraction
Execute all tasks for Super-Bias Subtraction.

Parameters
----------
input_model: data model object
science data to be corrected

bias_model: super-bias model object
bias data
input_model : RampModel
Science data to be corrected
bias_model : SuperBiasModel
Bias data

Returns
-------
output_model: data model object
bias-subtracted science data

output_model : stdatamodels.jwst.datamodels.ramp.RampModel
Bias-subtracted science data
"""

# Check for subarray mode and extract subarray from the
# bias reference data if necessary
if not reffile_utils.ref_matches_sci(input_model, bias_model):
Expand All @@ -42,33 +35,30 @@ def do_correction(input_model, bias_model):
# Subtract the bias ref image from the science data
output_model = subtract_bias(input_model, bias_model)

output_model.meta.cal_step.superbias = 'COMPLETE'
output_model.meta.cal_step.superbias = "COMPLETE"

return output_model


def subtract_bias(output, bias):
"""
Subtracts a superbias image from a science data set, subtracting the
superbias from each group of each integration in the science data.
Subtract the superbias image from each group of each integration in the science data.

The DQ flags in the bias reference image are propagated into the science
data pixeldq array. The error array is unchanged.
data pixel DQ array. The error array is unchanged.

Parameters
----------
output: data model object
the input science data

bias: superbias model object
the superbias image data
output : stdatamodels.jwst.datamodels.ramp.RampModel
Input science data
bias : stdatamodels.jwst.datamodels.superbias.SuperBiasModel
Superbias image data

Returns
-------
output: data model object
bias-subtracted science data

output : stdatamodels.jwst.datamodels.ramp.RampModel
Bias-subtracted science data
"""

# combine the science and superbias DQ arrays
output.pixeldq = np.bitwise_or(output.pixeldq, bias.dq)

Expand All @@ -81,8 +71,8 @@ def subtract_bias(output, bias):
# If ZEROFRAME is present, subtract the super bias. Zero values
# indicate bad data, so should be kept zero.
if output.meta.exposure.zero_frame:
wh_zero = np.where(output.zeroframe == 0.)
wh_zero = np.where(output.zeroframe == 0.0)
output.zeroframe -= bias.data
output.zeroframe[wh_zero] = 0. # Zero values indicate unusable data
output.zeroframe[wh_zero] = 0.0 # Zero values indicate unusable data

return output
38 changes: 23 additions & 15 deletions jwst/superbias/superbias_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,40 @@


class SuperBiasStep(Step):
"""
SuperBiasStep: Performs super-bias subtraction by subtracting
super-bias reference data from the input science data model.
"""
"""Subtract super-bias reference data from the input science data model."""

class_alias = "superbias"

spec = """
""" # noqa: E501
""" # noqa: E501

reference_file_types = ['superbias']
reference_file_types = ["superbias"]

def process(self, step_input):

"""
Apply the superbias correction.

Parameters
----------
step_input : str or stdatamodels.jwst.datamodels.ramp.RampModel
Either the path to the file or the science data model to be corrected.

Returns
-------
stdatamodels.jwst.datamodels.ramp.RampModel
Superbias-corrected science data model.
"""
# Open the input data model
with datamodels.open(step_input) as input_model:

# Get the name of the superbias reference file to use
self.bias_name = self.get_reference_file(input_model, 'superbias')
self.log.info('Using SUPERBIAS reference file %s', self.bias_name)
self.bias_name = self.get_reference_file(input_model, "superbias")
self.log.info("Using SUPERBIAS reference file %s", self.bias_name)

# Check for a valid reference file
if self.bias_name == 'N/A':
self.log.warning('No SUPERBIAS reference file found')
self.log.warning('Superbias step will be skipped')
input_model.meta.cal_step.superbias = 'SKIPPED'
if self.bias_name == "N/A":
self.log.warning("No SUPERBIAS reference file found")
self.log.warning("Superbias step will be skipped")
input_model.meta.cal_step.superbias = "SKIPPED"
return input_model

# Open the superbias ref file data model
Expand All @@ -43,7 +51,7 @@ def process(self, step_input):

# Do the bias subtraction
result = bias_sub.do_correction(result, bias_model)
result.meta.cal_step.superbias = 'COMPLETE'
result.meta.cal_step.superbias = "COMPLETE"

# Cleanup
del bias_model
Expand Down