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-3242: Proper Handling of Timing for Final Slope Computation for only 0th Good Group Ramps #7612

Merged
merged 8 commits into from
Jun 24, 2023
10 changes: 9 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
1.11.1 (unreleased)
===================

-
ramp_fitting
------------

- Updated the CI tests due to change in STCAL, which fixed bug for using the
correct timing for slope computation. Since there are now special cases that
use ZEROFRAME data, as well as ramps that have only good data in the 0th
group, the timing for these ramps is not group time. These adjusted times
are now used. [#7612, spacetelescope/stcal#173]


1.11.0 (2023-06-21)
===================
Expand Down
18 changes: 9 additions & 9 deletions jwst/ramp_fitting/tests/test_ramp_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,10 @@ def test_twenty_groups_two_segments():
np.testing.assert_allclose(oslope[wh_data], 10. / deltatime, rtol=1E-4)
np.testing.assert_allclose(oyint[0, 0, 0, :], model1.data[0, 0, 0, :], rtol=1E-5)

np.testing.assert_allclose(
opedestal[0, 0, :],
model1.data[0, 0, 0, :] - 10.,
rtol=1E-5)
check = model1.data[0, 0, 0, :] - oslope
tol = 1E-5
# Pixel 1 has zero slope, so ignore it.
np.testing.assert_allclose(opedestal[0, 0, 1:], check[0, 0, 0, 1:], tol)


def test_miri_all_sat():
Expand Down Expand Up @@ -897,7 +897,7 @@ def test_zeroframe_usage():
# Check slopes information
sdata, sdq, svp, svr, serr = slopes

check = np.array([[20.709406, 0.46572033, 4.6866207]])
check = np.array([[41.003822, 0.46572033, 21.655062]])
np.testing.assert_allclose(sdata, check, tol, tol)

# Since the second integration is GOOD the final DQ is GOOD.
Expand All @@ -916,8 +916,8 @@ def test_zeroframe_usage():
# Check slopes information
cdata, cdq, cvp, cvr, cerr = cube

check = np.array([[[186.28912, np.nan, 93.14456]],
[[0.46572027, 0.46572033, 0.46572033]]])
check = np.array([[[3.7257825e+02, np.nan, 4.6572281e+02]],
[[4.6572030e-01, 4.6572030e-01, 4.6572030e-01]]])
np.testing.assert_allclose(cdata, check, tol, tol)

# Column 2 in the first integration is marked GOOD because there
Expand Down Expand Up @@ -1041,8 +1041,8 @@ def setup_small_cube(ngroups=10, nints=1, nrows=2, ncols=2, deltatime=10.,


# Need test for multi-ints near zero with positive and negative slopes
def setup_inputs(ngroups=10, readnoise=10, nints=1,
nrows=103, ncols=102, nframes=1, grouptime=1.0, gain=1, deltatime=1):
def setup_inputs(ngroups=10, readnoise=10, nints=1, nrows=103, ncols=102,
nframes=1, grouptime=1.0, gain=1, deltatime=1):

data = np.zeros(shape=(nints, ngroups, nrows, ncols), dtype=np.float32)
err = np.ones(shape=(nints, ngroups, nrows, ncols), dtype=np.float32)
Expand Down
35 changes: 18 additions & 17 deletions jwst/ramp_fitting/tests/test_ramp_fit_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from stdatamodels.jwst.datamodels import RampModel, GainModel, ReadnoiseModel, dqflags


#
# The first 12 tests are for a single ramp in a single integration. The ramps
# have a variety of GROUPDQ vectors, with 1 or more segments in each ramp. The
Expand Down Expand Up @@ -54,7 +55,7 @@ def test_pix_0():
# Set truth values for OPTIONAL results:
# [slope, sigslope, var_poisson, var_rnoise, yint, sigyint, ped, weights]
o_true = [1.0117551, 4.874572, 0.0020202, 0.00647973,
15.911023, 27.789335, 4.882449, 13841.038]
15.911023, 27.789335, 13.988245, 13841.038]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -92,7 +93,7 @@ def test_pix_1():

# Set truth values for OPTIONAL results:
o_true = [1.9, 56.870003, 0.03454545, 1.0691562, -3., 56.870003,
-3.999998, 0.82091206]
13.1, 0.82091206]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -129,7 +130,7 @@ def test_pix_2():
[0.26728904, 1.0691562, 1.0691562], # var_rnoise
[14.999998, 51., 15.], # yint
[36.709427, 56.870003, 56.870003], # sigyint
[6.5166273], # pedestal
[14.151663], # pedestal
[13.091425, 0.84580624, 0.84580624], # weights
]

Expand Down Expand Up @@ -169,7 +170,7 @@ def test_pix_3():
[0.01272805, 1.0691562],
[14.504965, 15.],
[27.842508, 56.870003],
[4.253134],
[13.925313],
[4.2576841e+03, 8.458062e-01],
]

Expand Down Expand Up @@ -202,7 +203,7 @@ def test_pix_4():
p_true = [1.5, GOOD, 1.047105, 0.02727273, 1.0691562]

# Set truth values for OPTIONAL results:
o_true = [1.5, 0., 0.02727273, 1.0691562, 0., 0., 0., 0.8318386]
o_true = [1.5, 0., 0.02727273, 1.0691562, 0., 0., 13.5, 0.8318386]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -241,7 +242,7 @@ def test_pix_5():
[0.10691562, 0.03054732],
[13.537246, 2015.0737],
[35.301933, 67.10882],
[4.2391253],
[13.923912],
[78.34764, 855.78046]
]

Expand Down Expand Up @@ -282,7 +283,7 @@ def test_pix_6():
[1.0691562, 0.01909207],
[15., -143.2391],
[56.870003, 58.76999],
[-45.92052],
[8.907948],
[8.4580624e-01, 2.0433204e+03]
]

Expand Down Expand Up @@ -315,7 +316,7 @@ def test_pix_7():

# Set truth values for OPTIONAL results:
o_true = [1.0757396, 6.450687, 0.0025974, 0.01272805, 14.504951,
27.842508, 4.2426033, 4257.684]
27.842508, 13.92426, 4257.684]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -347,7 +348,7 @@ def test_pix_8():

# Set truth values for OPTIONAL results:
o_true = [0.98561335, 9.920554, 0.00363636, 0.03054732, 16.508228,
39.383667, 5.1438665, 855.78046]
39.383667, 14.014386, 855.78046]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -385,7 +386,7 @@ def test_pix_9():
[1.0691562, 0.05345781, 1.0691562],
[15., 20.119896, 15.],
[56.870003, 68.618195, 56.870003],
[5.000005],
[14.],
[0.84580624, 297.23172, 0.84580624]
]

Expand Down Expand Up @@ -425,7 +426,7 @@ def test_pix_10():
[1.0691562, 0.26728904, 0.05345781],
[15., 17.999956, 15.000029],
[56.870003, 88.40799, 93.73906],
[5.],
[14.],
[0.84580624, 13.091425, 297.23172]
]

Expand Down Expand Up @@ -457,7 +458,7 @@ def test_pix_11():
p_true = [1., GOOD, 1.042755, 0.01818182, 1.0691562]

# Set truth values for OPTIONAL results:
o_true = [1., 56.870003, 0.01818182, 1.0691562, 15., 56.870003, 5.,
o_true = [1., 56.870003, 0.01818182, 1.0691562, 15., 56.870003, 14.,
0.84580624]

assert_pri(p_true, new_mod, 0)
Expand Down Expand Up @@ -498,7 +499,7 @@ def test_pix_12():
# slope, sig_slope, var_p, var_r, yint, sig_yint, pedestal, weights
# slope = group1 / deltatime = 15 / 10 = 1.5
# sig_slope, yint, sig_yint, and pedestal are all zero, because only 1 good group
o_true = [1.5, 0., 0.027273, 1.069156, 0., 0., 0., 0.831839]
o_true = [1.5, 0., 0.027273, 1.069156, 0., 0., 13.5, 0.831839]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -544,7 +545,7 @@ def test_miri_0():

# Set truth values for OPTIONAL results:
o_true = [1.025854, 6.450687, 0.0025974, 0.01272805, 26.439266, 27.842508,
14.74146, 4257.684]
23.974146, 4257.684]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -576,7 +577,7 @@ def test_miri_1():

# Set truth values for OPTIONAL results:
o_true = [1.1996487, 6.450687, 0.0025974, 0.01272805, 126.110214,
27.842508, 113.00351, 4257.684]
27.842508, 123.800354, 4257.684]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -608,7 +609,7 @@ def test_miri_2():

# Set truth values for OPTIONAL results:
o_true = [1.025854, 6.450687, 0.0025974, 0.01272805, 26.439266, 27.842508,
14.74146, 4257.684]
23.974146, 4257.684]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down Expand Up @@ -640,7 +641,7 @@ def test_miri_3():

# Set truth values for OPTIONAL results:
o_true = [1.025854, 6.450687, 0.0025974, 0.01272805, 26.439266,
27.842508, 14.74146, 4257.684]
27.842508, 23.974146, 4257.684]

assert_pri(p_true, new_mod, 0)
assert_opt(o_true, opt_mod, 0)
Expand Down
20 changes: 10 additions & 10 deletions jwst/ramp_fitting/tests/test_ramp_fit_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def test_one_group_not_suppressed_one_integration(setup_inputs):
tol = 1e-5

# Check slopes information
check = np.array([[np.nan, 1., 1.0000002]])
check = np.array([[np.nan, .2, 0.2]])
np.testing.assert_allclose(slopes.data, check, tol)

check = np.array([[DNU | SAT, GOOD, GOOD]])
Expand All @@ -346,7 +346,7 @@ def test_one_group_not_suppressed_one_integration(setup_inputs):
np.testing.assert_allclose(slopes.err, check, tol)

# Check slopes information
check = np.array([[[np.nan, 1., 1.0000001]]])
check = np.array([[[np.nan, .2, .2]]])
np.testing.assert_allclose(cube.data, check, tol)

check = np.array([[[DNU | SAT, GOOD, GOOD]]])
Expand Down Expand Up @@ -377,7 +377,7 @@ def test_one_group_suppressed_one_integration(setup_inputs):
tol = 1e-5

# Check slopes information
check = np.array([[np.nan, np.nan, 1.0000002]])
check = np.array([[np.nan, np.nan, .2]])
np.testing.assert_allclose(slopes.data, check, tol)

check = np.array([[DNU | SAT, DNU, GOOD]])
Expand All @@ -393,7 +393,7 @@ def test_one_group_suppressed_one_integration(setup_inputs):
np.testing.assert_allclose(slopes.err, check, tol)

# Check slopes information
check = np.array([[[np.nan, np.nan, 1.0000001]]])
check = np.array([[[np.nan, np.nan, .2]]])
np.testing.assert_allclose(cube.data, check, tol)

check = np.array([[[DNU | SAT, DNU, 0]]])
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_one_group_not_suppressed_two_integrations(setup_inputs):
tol = 1e-5

# Check slopes information
check = np.array([[1.0000001, 1.0000002, 1.0000002]])
check = np.array([[.2, .2, .2]])
np.testing.assert_allclose(slopes.data, check, tol)

check = np.array([[GOOD, GOOD, GOOD]])
Expand All @@ -442,8 +442,8 @@ def test_one_group_not_suppressed_two_integrations(setup_inputs):
np.testing.assert_allclose(slopes.err, check, tol)

# Check slopes information
check = np.array([[[np.nan, 1., 1.0000001]],
[[1.0000001, 1.0000001, 1.0000001]]])
check = np.array([[[np.nan, .2, .2]],
[[.2, .2, .2]]])
np.testing.assert_allclose(cube.data, check, tol)

check = np.array([[[SAT | DNU, GOOD, GOOD]],
Expand Down Expand Up @@ -480,7 +480,7 @@ def test_one_group_suppressed_two_integrations(setup_inputs):
tol = 1e-5

# Check slopes information
check = np.array([[1.0000001, 1.0000001, 1.0000002]])
check = np.array([[.2, .2, .2]])
np.testing.assert_allclose(slopes.data, check, tol)

check = np.array([[GOOD, GOOD, GOOD]])
Expand All @@ -496,8 +496,8 @@ def test_one_group_suppressed_two_integrations(setup_inputs):
np.testing.assert_allclose(slopes.err, check, tol)

# Check slopes information
check = np.array([[[np.nan, np.nan, 1.0000001]],
[[1.0000001, 1.0000001, 1.0000001]]])
check = np.array([[[np.nan, np.nan, .2]],
[[.2, .2, .2]]])
np.testing.assert_allclose(cube.data, check, tol)

check = np.array([[[DNU | SAT, DNU, GOOD]],
Expand Down