-
Notifications
You must be signed in to change notification settings - Fork 169
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-3777: Select first and last groups in ramp fitting #9095
base: main
Are you sure you want to change the base?
Changes from 5 commits
1504c2b
f608a8e
dbeed17
1444b88
b2bdf9b
762ca26
522da63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Add code to enable users to select firstgroup and lastgroup parameters when performing | ||
ramp fitting. It works by setting the DO_NOT_USE bit in the GROUPDQ extension for groups | ||
outside the selected range. Added a unit test and updated the docs. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import pytest | ||
import logging | ||
import numpy as np | ||
|
||
from stdatamodels.jwst.datamodels import dqflags, RampModel, GainModel, ReadnoiseModel | ||
|
||
from jwst.ramp_fitting.ramp_fit_step import RampFitStep | ||
from jwst.ramp_fitting.ramp_fit_step import RampFitStep, set_groupdq | ||
from jwst.tests.helpers import LogWatcher | ||
|
||
@pytest.fixture | ||
def log_watcher(monkeypatch): | ||
# Set a log watcher to check for a log message at any level | ||
# in RampFitStep | ||
watcher = LogWatcher('') | ||
logger = logging.getLogger('stpipe') | ||
stscirij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for level in ['debug', 'info', 'warning', 'error']: | ||
monkeypatch.setattr(logger, level, watcher) | ||
return watcher | ||
|
||
DELIM = "-" * 80 | ||
|
||
|
@@ -258,6 +270,35 @@ def test_int_times2(generate_miri_reffiles, setup_inputs): | |
|
||
assert len(cube_model.int_times) == nints | ||
|
||
def test_set_groups(generate_miri_reffiles, setup_inputs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve test coverage, by creating the function above, a new test could be parametrize There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a new parametrized test that tested that the appropriate warnings are emitted |
||
# Test results when using the firstgroup and lastgroup options | ||
ngroups = 20 | ||
rampmodel, gdq, rnmodel, pixdq, err, gain = setup_inputs(ngroups=ngroups) | ||
# Set up data array as group# squared | ||
# This has the property that the slope=(firstgroup+lastgroup) | ||
squares = np.array([k*k for k in range(ngroups)],dtype=np.float32) | ||
rampmodel.data[0,:] = squares[:, np.newaxis, np.newaxis] | ||
firstgroup = 3 | ||
lastgroup = 11 | ||
slopes, cubemodel = RampFitStep.call(rampmodel, override_gain=gain, override_readnoise=rnmodel, | ||
firstgroup=firstgroup, lastgroup=lastgroup) | ||
np.testing.assert_allclose(slopes.data, firstgroup+lastgroup, rtol=1e-7) | ||
|
||
def test_warnings(log_watcher): | ||
# Test user warnings | ||
ngroups = 20 | ||
groupdqflags = dqflags.group | ||
groupdq = np.zeros((1, ngroups, 1024, 1024), dtype=np.uint16) | ||
firstgroup = -10 | ||
lastgroup = None | ||
log_watcher.message = "first group < 0, reset to 0" | ||
set_groupdq(firstgroup, lastgroup, ngroups, groupdq, groupdqflags) | ||
log_watcher.assert_seen() | ||
firstgroup = 3 | ||
lastgroup = ngroups | ||
log_watcher.message = f"Last group number >= #groups ({ngroups}), reset to {ngroups-1}" | ||
set_groupdq(firstgroup, lastgroup, ngroups, groupdq, groupdqflags) | ||
log_watcher.assert_seen() | ||
|
||
def one_group_suppressed(nints, suppress, setup_inputs): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend moving this section of code to a function and calling that function conditioned on
if firstgroup is not None or lastgroup is not None:
.