Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ repos:
jwst/cube_build/.* |
jwst/cube_skymatch/.* |
jwst/dark_current/.* |
jwst/dq_init/.* |
jwst/emicorr/.* |
jwst/engdblog/.* |
jwst/exp_to_source/.* |
Expand Down
4 changes: 2 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exclude = [
"jwst/cube_build/**.py",
"jwst/cube_skymatch/**.py",
"jwst/dark_current/**.py",
"jwst/dq_init/**.py",
# "jwst/datamodels/**.py",
"jwst/emicorr/**.py",
"jwst/engdblog/**.py",
"jwst/exp_to_source/**.py",
Expand Down Expand Up @@ -140,7 +140,7 @@ ignore-fully-untyped = true # Turn off annotation checking for fully untyped co
"jwst/cube_build/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/cube_skymatch/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/dark_current/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/dq_init/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
# "jwst/datamodels/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/emicorr/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/engdblog/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/exp_to_source/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
Expand Down
2 changes: 2 additions & 0 deletions jwst/dq_init/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Initialize the data with data quality information."""

from .dq_init_step import DQInitStep

__all__ = ["DQInitStep"]
30 changes: 15 additions & 15 deletions jwst/dq_init/dq_init_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


class DQInitStep(Step):
"""Initialize the Data Quality extension from the
mask reference file.
"""
Initialize the Data Quality extension from the mask reference file.

The dq_init step initializes the pixeldq attribute of the
input datamodel using the MASK reference file. For some
Expand All @@ -22,23 +22,23 @@
class_alias = "dq_init"

spec = """
""" # noqa: E501
reference_file_types = ['mask']
""" # noqa: E501
reference_file_types = ["mask"]

def process(self, step_input):
"""Perform the dq_init calibration step
"""
Perform the dq_init calibration step.

Parameters
----------
input : JWST datamodel
input jwst datamodel
step_input : JWST datamodel
Input jwst datamodel.

Returns
-------
output_model : JWST datamodel
result JWST datamodel
Result JWST datamodel.
"""

# Try to open the input as a regular RampModel
try:
input_model = datamodels.RampModel(step_input)
Expand All @@ -62,14 +62,14 @@
raise

# Retrieve the mask reference file name
self.mask_filename = self.get_reference_file(input_model, 'mask')
self.log.info('Using MASK reference file %s', self.mask_filename)
self.mask_filename = self.get_reference_file(input_model, "mask")
self.log.info("Using MASK reference file %s", self.mask_filename)

# Check for a valid reference file
if self.mask_filename == 'N/A':
self.log.warning('No MASK reference file found')
self.log.warning('DQ initialization step will be skipped')
input_model.meta.cal_step.dq_init = 'SKIPPED'
if self.mask_filename == "N/A":
self.log.warning("No MASK reference file found")
self.log.warning("DQ initialization step will be skipped")
input_model.meta.cal_step.dq_init = "SKIPPED"

Check warning on line 72 in jwst/dq_init/dq_init_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/dq_init/dq_init_step.py#L70-L72

Added lines #L70 - L72 were not covered by tests
return input_model

# Work on a copy
Expand Down
56 changes: 23 additions & 33 deletions jwst/dq_init/dq_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@


# FGS guide star mode exposure types
guider_list = ['FGS_ID-IMAGE', 'FGS_ID-STACK', 'FGS_ACQ1', 'FGS_ACQ2',
'FGS_TRACK', 'FGS_FINEGUIDE']
guider_list = ["FGS_ID-IMAGE", "FGS_ID-STACK", "FGS_ACQ1", "FGS_ACQ2", "FGS_TRACK", "FGS_FINEGUIDE"]


def correct_model(input_model, mask_model):
"""Perform the dq_init step on a JWST datamodel
"""
Perform the dq_init step on a JWST datamodel.

Parameters
----------
input_model : input JWST datamodel
The jwst datamodel to be corrected

mask_model : mask datamodel
The mask model to use in the correction

Expand All @@ -32,20 +31,19 @@
output_model : JWST datamodel
The corrected JWST datamodel
"""

output_model = do_dqinit(input_model, mask_model)

return output_model


def do_dqinit(output_model, mask_model):
"""Perform the dq_init step on a JWST datamodel
"""
Perform the dq_init step on a JWST datamodel.

Parameters
----------
output_model : input JWST datamodel
The jwst datamodel to be corrected

mask_model : mask datamodel
The mask model to use in the correction

Expand All @@ -54,17 +52,15 @@
output_model : JWST datamodel
The corrected JWST datamodel
"""

# Inflate empty DQ array, if necessary
check_dimensions(output_model)

# Extract subarray from reference data, if necessary
if reffile_utils.ref_matches_sci(output_model, mask_model):
mask_array = mask_model.dq
else:
log.info('Extracting mask subarray to match science data')
mask_sub_model = reffile_utils.get_subarray_model(output_model,
mask_model)
log.info("Extracting mask subarray to match science data")
mask_sub_model = reffile_utils.get_subarray_model(output_model, mask_model)
mask_array = mask_sub_model.dq.copy()
mask_sub_model.close()

Expand All @@ -77,15 +73,20 @@
output_model.pixeldq = dq
# Additionally, propagate mask DO_NOT_USE flags to groupdq to
# ensure no ramps are fit to bad pixels.
output_model.groupdq = np.bitwise_or(output_model.groupdq, mask_array & dqflags.group['DO_NOT_USE'])
output_model.groupdq = np.bitwise_or(
output_model.groupdq, mask_array & dqflags.group["DO_NOT_USE"]
)

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

return output_model


def check_dimensions(input_model):
"""Check that the input model pixeldq attribute has the same dimensions as
"""
Check the input model pixeldq dimensions.

The pixeldq attribute should have the same dimensions as
the image plane of the input model science data
If it has dimensions (0,0), create an array of zeros with the same shape
as the image plane of the input model. For the FGS modes, the
Expand All @@ -94,45 +95,34 @@
Parameters
----------
input_model : JWST datamodel
input datamodel

Returns
-------
None
Input datamodel.
"""

input_shape = input_model.data.shape

if isinstance(input_model, datamodels.GuiderRawModel):
if input_model.dq.shape != input_shape[-2:]:

# If the shape is different, then the mask model should have
# a shape of (0,0).
# If that's the case, create the array
if input_model.dq.shape == (0, 0):
input_model.dq = np.zeros((input_shape[-2:])).astype('uint32')
input_model.dq = np.zeros(input_shape[-2:]).astype("uint32")

Check warning on line 108 in jwst/dq_init/dq_initialization.py

View check run for this annotation

Codecov / codecov/patch

jwst/dq_init/dq_initialization.py#L108

Added line #L108 was not covered by tests
else:
log.error("DQ array has the wrong shape: (%d, %d)" %
input_model.dq.shape)
log.error(f"DQ array has the wrong shape: {input_model.dq.shape}")

Check warning on line 110 in jwst/dq_init/dq_initialization.py

View check run for this annotation

Codecov / codecov/patch

jwst/dq_init/dq_initialization.py#L110

Added line #L110 was not covered by tests

else: # RampModel
else: # RampModel
if input_model.pixeldq.shape != input_shape[-2:]:

# If the shape is different, then the mask model should have
# a shape of (0,0).
# If that's the case, create the array
if input_model.pixeldq.shape == (0, 0):
input_model.pixeldq = \
np.zeros((input_shape[-2:])).astype('uint32')
input_model.pixeldq = np.zeros(input_shape[-2:]).astype("uint32")

Check warning on line 118 in jwst/dq_init/dq_initialization.py

View check run for this annotation

Codecov / codecov/patch

jwst/dq_init/dq_initialization.py#L118

Added line #L118 was not covered by tests
else:
log.error("Pixeldq array has the wrong shape: (%d, %d)" %
input_model.pixeldq.shape)
log.error(f"Pixeldq array has the wrong shape: {input_model.pixeldq.shape}")

Check warning on line 120 in jwst/dq_init/dq_initialization.py

View check run for this annotation

Codecov / codecov/patch

jwst/dq_init/dq_initialization.py#L120

Added line #L120 was not covered by tests

# Perform the same check for the input model groupdq array
if input_model.groupdq.shape != input_shape:
if input_model.groupdq.shape == (0, 0, 0, 0):
input_model.groupdq = np.zeros((input_shape)).astype('uint8')
input_model.groupdq = np.zeros(input_shape).astype("uint8")

Check warning on line 125 in jwst/dq_init/dq_initialization.py

View check run for this annotation

Codecov / codecov/patch

jwst/dq_init/dq_initialization.py#L125

Added line #L125 was not covered by tests
else:
log.error("Groupdq array has wrong shape: (%d, %d, %d, %d)" %
input_model.groupdq.shape)
log.error(f"Groupdq array has wrong shape: {input_model.groupdq.shape}")

Check warning on line 127 in jwst/dq_init/dq_initialization.py

View check run for this annotation

Codecov / codecov/patch

jwst/dq_init/dq_initialization.py#L127

Added line #L127 was not covered by tests
return