Skip to content

Commit

Permalink
JP-3613: Update error arrays to match NaN in data (#8463)
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieclarke committed May 8, 2024
1 parent 4e91a1c commit 241c5c0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ flat_field
- Update the flatfield code for NIRSpec IFU data to ensure that SCI=ERR=NaN and
DQ has the DO_NOT_USE flag set outside the footprint of the IFU slices [#8385]

- Update NIRSpec flatfield code for all modes to ensure SCI=ERR=NaN wherever the
DO_NOT_USE flag is set in the DQ array. [#8463]

general
-------

Expand Down
21 changes: 18 additions & 3 deletions jwst/flatfield/flat_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,12 @@ def nirspec_fs_msa(output_model, f_flat_model, s_flat_model, d_flat_model, dispa

# Make sure all DO_NOT_USE pixels are set to NaN,
# including those flagged by this step
slit.data[np.where(slit.dq & dqflags.pixel['DO_NOT_USE'])] = np.nan
dnu = np.where(slit.dq & dqflags.pixel['DO_NOT_USE'])
slit.data[dnu] = np.nan
slit.err[dnu] = np.nan
slit.var_poisson[dnu] = np.nan
slit.var_rnoise[dnu] = np.nan
slit.var_flat[dnu] = np.nan

any_updated = True

Expand Down Expand Up @@ -521,7 +526,12 @@ def nirspec_brightobj(output_model, f_flat_model, s_flat_model, d_flat_model, di

# Make sure all DO_NOT_USE pixels are set to NaN,
# including those flagged by this step
output_model.data[np.where(output_model.dq & dqflags.pixel['DO_NOT_USE'])] = np.nan
dnu = np.where(output_model.dq & dqflags.pixel['DO_NOT_USE'])
output_model.data[dnu] = np.nan
output_model.err[dnu] = np.nan
output_model.var_poisson[dnu] = np.nan
output_model.var_rnoise[dnu] = np.nan
output_model.var_flat[dnu] = np.nan

output_model.meta.cal_step.flat_field = 'COMPLETE'

Expand Down Expand Up @@ -591,7 +601,12 @@ def nirspec_ifu(output_model, f_flat_model, s_flat_model, d_flat_model, dispaxis

# Make sure all DO_NOT_USE pixels are set to NaN,
# including those flagged by this step
output_model.data[np.where(output_model.dq & dqflags.pixel['DO_NOT_USE'])] = np.nan
dnu = np.where(output_model.dq & dqflags.pixel['DO_NOT_USE'])
output_model.data[dnu] = np.nan
output_model.err[dnu] = np.nan
output_model.var_poisson[dnu] = np.nan
output_model.var_rnoise[dnu] = np.nan
output_model.var_flat[dnu] = np.nan

output_model.meta.cal_step.flat_field = 'COMPLETE'

Expand Down
7 changes: 7 additions & 0 deletions jwst/regtest/test_nirspec_steps_spec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def test_ff_inv(rtdata, fitsdiff_default_kwargs):
# make sure NaNs are only at do_not_use pixels
assert np.all(unflatted.dq[is_nan] & dm.dqflags.pixel['DO_NOT_USE'])

# make sure NaNs at science pixels are also NaN in error and var arrays
assert np.all(np.isnan(unflatted.err[is_nan]))
assert np.all(np.isnan(unflatted.var_poisson[is_nan]))
assert np.all(np.isnan(unflatted.var_rnoise[is_nan]))
assert np.all(np.isnan(unflatted.var_flat[is_nan]))


@pytest.mark.slow
@pytest.mark.bigdata
def test_pathloss_corrpars(rtdata):
Expand Down

0 comments on commit 241c5c0

Please sign in to comment.