Skip to content

Commit 2491b40

Browse files
JP-3855: Style Updates for DQ init (#9161)
2 parents 068aaf0 + 0e0ecf3 commit 2491b40

File tree

5 files changed

+42
-51
lines changed

5 files changed

+42
-51
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ repos:
4545
jwst/cube_build/.* |
4646
jwst/cube_skymatch/.* |
4747
jwst/dark_current/.* |
48-
jwst/dq_init/.* |
4948
jwst/emicorr/.* |
5049
jwst/engdblog/.* |
5150
jwst/exp_to_source/.* |

.ruff.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exclude = [
3030
"jwst/cube_build/**.py",
3131
"jwst/cube_skymatch/**.py",
3232
"jwst/dark_current/**.py",
33-
"jwst/dq_init/**.py",
33+
# "jwst/datamodels/**.py",
3434
"jwst/emicorr/**.py",
3535
"jwst/engdblog/**.py",
3636
"jwst/exp_to_source/**.py",
@@ -140,7 +140,7 @@ ignore-fully-untyped = true # Turn off annotation checking for fully untyped co
140140
"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"]
141141
"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"]
142142
"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"]
143-
"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"]
143+
# "jwst/datamodels/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
144144
"jwst/emicorr/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
145145
"jwst/engdblog/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
146146
"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"]

jwst/dq_init/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Initialize the data with data quality information."""
2+
13
from .dq_init_step import DQInitStep
24

35
__all__ = ["DQInitStep"]

jwst/dq_init/dq_init_step.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010

1111
class DQInitStep(Step):
12-
"""Initialize the Data Quality extension from the
13-
mask reference file.
12+
"""
13+
Initialize the Data Quality extension from the mask reference file.
1414
1515
The dq_init step initializes the pixeldq attribute of the
1616
input datamodel using the MASK reference file. For some
@@ -22,23 +22,23 @@ class DQInitStep(Step):
2222
class_alias = "dq_init"
2323

2424
spec = """
25-
""" # noqa: E501
26-
reference_file_types = ['mask']
25+
""" # noqa: E501
26+
reference_file_types = ["mask"]
2727

2828
def process(self, step_input):
29-
"""Perform the dq_init calibration step
29+
"""
30+
Perform the dq_init calibration step.
3031
3132
Parameters
3233
----------
33-
input : JWST datamodel
34-
input jwst datamodel
34+
step_input : JWST datamodel
35+
Input jwst datamodel.
3536
3637
Returns
3738
-------
3839
output_model : JWST datamodel
39-
result JWST datamodel
40+
Result JWST datamodel.
4041
"""
41-
4242
# Try to open the input as a regular RampModel
4343
try:
4444
input_model = datamodels.RampModel(step_input)
@@ -62,14 +62,14 @@ def process(self, step_input):
6262
raise
6363

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

6868
# Check for a valid reference file
69-
if self.mask_filename == 'N/A':
70-
self.log.warning('No MASK reference file found')
71-
self.log.warning('DQ initialization step will be skipped')
72-
input_model.meta.cal_step.dq_init = 'SKIPPED'
69+
if self.mask_filename == "N/A":
70+
self.log.warning("No MASK reference file found")
71+
self.log.warning("DQ initialization step will be skipped")
72+
input_model.meta.cal_step.dq_init = "SKIPPED"
7373
return input_model
7474

7575
# Work on a copy

jwst/dq_init/dq_initialization.py

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212

1313

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

1817

1918
def correct_model(input_model, mask_model):
20-
"""Perform the dq_init step on a JWST datamodel
19+
"""
20+
Perform the dq_init step on a JWST datamodel.
2121
2222
Parameters
2323
----------
2424
input_model : input JWST datamodel
2525
The jwst datamodel to be corrected
26-
2726
mask_model : mask datamodel
2827
The mask model to use in the correction
2928
@@ -32,20 +31,19 @@ def correct_model(input_model, mask_model):
3231
output_model : JWST datamodel
3332
The corrected JWST datamodel
3433
"""
35-
3634
output_model = do_dqinit(input_model, mask_model)
3735

3836
return output_model
3937

4038

4139
def do_dqinit(output_model, mask_model):
42-
"""Perform the dq_init step on a JWST datamodel
40+
"""
41+
Perform the dq_init step on a JWST datamodel.
4342
4443
Parameters
4544
----------
4645
output_model : input JWST datamodel
4746
The jwst datamodel to be corrected
48-
4947
mask_model : mask datamodel
5048
The mask model to use in the correction
5149
@@ -54,17 +52,15 @@ def do_dqinit(output_model, mask_model):
5452
output_model : JWST datamodel
5553
The corrected JWST datamodel
5654
"""
57-
5855
# Inflate empty DQ array, if necessary
5956
check_dimensions(output_model)
6057

6158
# Extract subarray from reference data, if necessary
6259
if reffile_utils.ref_matches_sci(output_model, mask_model):
6360
mask_array = mask_model.dq
6461
else:
65-
log.info('Extracting mask subarray to match science data')
66-
mask_sub_model = reffile_utils.get_subarray_model(output_model,
67-
mask_model)
62+
log.info("Extracting mask subarray to match science data")
63+
mask_sub_model = reffile_utils.get_subarray_model(output_model, mask_model)
6864
mask_array = mask_sub_model.dq.copy()
6965
mask_sub_model.close()
7066

@@ -77,15 +73,20 @@ def do_dqinit(output_model, mask_model):
7773
output_model.pixeldq = dq
7874
# Additionally, propagate mask DO_NOT_USE flags to groupdq to
7975
# ensure no ramps are fit to bad pixels.
80-
output_model.groupdq = np.bitwise_or(output_model.groupdq, mask_array & dqflags.group['DO_NOT_USE'])
76+
output_model.groupdq = np.bitwise_or(
77+
output_model.groupdq, mask_array & dqflags.group["DO_NOT_USE"]
78+
)
8179

82-
output_model.meta.cal_step.dq_init = 'COMPLETE'
80+
output_model.meta.cal_step.dq_init = "COMPLETE"
8381

8482
return output_model
8583

8684

8785
def check_dimensions(input_model):
88-
"""Check that the input model pixeldq attribute has the same dimensions as
86+
"""
87+
Check the input model pixeldq dimensions.
88+
89+
The pixeldq attribute should have the same dimensions as
8990
the image plane of the input model science data
9091
If it has dimensions (0,0), create an array of zeros with the same shape
9192
as the image plane of the input model. For the FGS modes, the
@@ -94,45 +95,34 @@ def check_dimensions(input_model):
9495
Parameters
9596
----------
9697
input_model : JWST datamodel
97-
input datamodel
98-
99-
Returns
100-
-------
101-
None
98+
Input datamodel.
10299
"""
103-
104100
input_shape = input_model.data.shape
105101

106102
if isinstance(input_model, datamodels.GuiderRawModel):
107103
if input_model.dq.shape != input_shape[-2:]:
108-
109104
# If the shape is different, then the mask model should have
110105
# a shape of (0,0).
111106
# If that's the case, create the array
112107
if input_model.dq.shape == (0, 0):
113-
input_model.dq = np.zeros((input_shape[-2:])).astype('uint32')
108+
input_model.dq = np.zeros(input_shape[-2:]).astype("uint32")
114109
else:
115-
log.error("DQ array has the wrong shape: (%d, %d)" %
116-
input_model.dq.shape)
110+
log.error(f"DQ array has the wrong shape: {input_model.dq.shape}")
117111

118-
else: # RampModel
112+
else: # RampModel
119113
if input_model.pixeldq.shape != input_shape[-2:]:
120-
121114
# If the shape is different, then the mask model should have
122115
# a shape of (0,0).
123116
# If that's the case, create the array
124117
if input_model.pixeldq.shape == (0, 0):
125-
input_model.pixeldq = \
126-
np.zeros((input_shape[-2:])).astype('uint32')
118+
input_model.pixeldq = np.zeros(input_shape[-2:]).astype("uint32")
127119
else:
128-
log.error("Pixeldq array has the wrong shape: (%d, %d)" %
129-
input_model.pixeldq.shape)
120+
log.error(f"Pixeldq array has the wrong shape: {input_model.pixeldq.shape}")
130121

131122
# Perform the same check for the input model groupdq array
132123
if input_model.groupdq.shape != input_shape:
133124
if input_model.groupdq.shape == (0, 0, 0, 0):
134-
input_model.groupdq = np.zeros((input_shape)).astype('uint8')
125+
input_model.groupdq = np.zeros(input_shape).astype("uint8")
135126
else:
136-
log.error("Groupdq array has wrong shape: (%d, %d, %d, %d)" %
137-
input_model.groupdq.shape)
127+
log.error(f"Groupdq array has wrong shape: {input_model.groupdq.shape}")
138128
return

0 commit comments

Comments
 (0)