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

Apply basic code style changes to lastframe step #9147

Merged
merged 2 commits into from
Feb 10, 2025
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 @@ -61,7 +61,6 @@ repos:
jwst/imprint/.* |
jwst/ipc/.* |
jwst/jump/.* |
jwst/lastframe/.* |
jwst/lib/.* |
jwst/linearity/.* |
jwst/master_background/.* |
Expand Down
4 changes: 2 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exclude = [
"jwst/imprint/**.py",
"jwst/ipc/**.py",
"jwst/jump/**.py",
"jwst/lastframe/**.py",
# "jwst/lastframe/**.py",
"jwst/lib/**.py",
"jwst/linearity/**.py",
"jwst/master_background/**.py",
Expand Down Expand Up @@ -182,7 +182,7 @@ ignore-fully-untyped = true # Turn of annotation checking for fully untyped cod
"jwst/imprint/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/ipc/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/jump/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/lastframe/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
#"jwst/lastframe/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH"#, "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/lib/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/linearity/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
"jwst/master_background/**.py" = ["D", "N", "A", "ARG", "B", "C4", "ICN", "INP", "ISC", "LOG", "NPY", "PGH", "PTH", "S", "SLF", "SLOT", "T20", "TRY", "UP", "YTT", "E501"]
Expand Down
4 changes: 3 additions & 1 deletion jwst/lastframe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Set data quality flag of last group in MIRI data."""

from .lastframe_step import LastFrameStep

__all__ = ['LastFrameStep']
__all__ = ["LastFrameStep"]
32 changes: 22 additions & 10 deletions jwst/lastframe/lastframe_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,40 @@

class LastFrameStep(Step):
"""
LastFrameStep: This is a MIRI specific task. If the number of groups
is greater than 2, the GROUP data quality flags for the final group will
be set to DO_NOT_USE.
Set data quality flags for the last group in MIRI ramps.

A MIRI specific task. If the number of groups > 2, the GROUP
data quality flag for the final group will be set to DO_NOT_USE.
"""

class_alias = "lastframe"

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

def process(self, step_input):

"""
For MIRI data with more than 2 groups, set final group dq to DO_NOT_USE.

Parameters
----------
step_input : DataModel
Input datamodel to be corrected

Returns
-------
output_model : DataModel
Lastframe corrected datamodel
"""
# Open the input data model
with datamodels.RampModel(step_input) as input_model:

# check the data is MIRI data
detector = input_model.meta.instrument.detector

if detector[:3] != 'MIR':
self.log.warning('Last Frame Correction is only for MIRI data')
self.log.warning('Last frame step will be skipped')
input_model.meta.cal_step.lastframe = 'SKIPPED'
if detector[:3] != "MIR":
self.log.warning("Last Frame Correction is only for MIRI data")
self.log.warning("Last frame step will be skipped")
input_model.meta.cal_step.lastframe = "SKIPPED"
return input_model

# Work on a copy
Expand Down
30 changes: 15 additions & 15 deletions jwst/lastframe/lastframe_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@

def do_correction(output):
"""
Short Summary
-------------
The sole correction is to reset to DO_NOT_USE the GROUP data quality flags
for the final group, if the number of groups is greater than 2.
Set data quality flag of the final group in an integration to DO_NOT_USE.

This correction only works on MIRI data. If the number of groups
is greater than 2, then GROUP dq flag of final group is set to
DO_NOT_USE.

Parameters
----------
output: data model object
science data to be corrected
output : DataModel
Science data to be corrected

Returns
-------
output: data model object
lastframe-corrected science data

output : DataModel
Lastframe-corrected science data
"""

# Save some data params for easy use later
sci_ngroups = output.data.shape[1]

# Update the step status, and if ngroups > 2, set all of the GROUPDQ in
# the final group to 'DO_NOT_USE'
if sci_ngroups > 2:
output.groupdq[:, -1, :, :] = \
np.bitwise_or(output.groupdq[:, -1, :, :], dqflags.group['DO_NOT_USE'])
output.groupdq[:, -1, :, :] = np.bitwise_or(
output.groupdq[:, -1, :, :], dqflags.group["DO_NOT_USE"]
)
log.debug("LastFrame Sub: resetting GROUPDQ in last frame to DO_NOT_USE")
output.meta.cal_step.lastframe = 'COMPLETE'
else: # too few groups
output.meta.cal_step.lastframe = "COMPLETE"
else: # too few groups
log.warning("Too few groups to apply correction")
log.warning("Step will be skipped")
output.meta.cal_step.lastframe = 'SKIPPED'
output.meta.cal_step.lastframe = "SKIPPED"

return output