From a77126e4df144110cb11bb62c3faca2efe9228ee Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Tue, 11 Jun 2024 13:05:06 -0400 Subject: [PATCH] initial draft commit to get more eyes on code --- jwst/outlier_detection/outlier_detection.py | 4 ++- .../tests/test_outlier_detection.py | 4 +++ jwst/regtest/test_nircam_align_to_gaia.py | 34 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/jwst/outlier_detection/outlier_detection.py b/jwst/outlier_detection/outlier_detection.py index a44a89433fa..e375776ac70 100644 --- a/jwst/outlier_detection/outlier_detection.py +++ b/jwst/outlier_detection/outlier_detection.py @@ -568,7 +568,9 @@ def gwcs_blot(median_model, blot_img, interp='poly5', sinscl=1.0): log.debug("Pixmap shape: {}".format(pixmap[:, :, 0].shape)) log.debug("Sci shape: {}".format(blot_img.data.shape)) - pix_ratio = 1 + pix_ratio = np.sqrt(blot_img.meta.photometry.pixelarea_arcsecsq / \ + median_model.meta.photometry.pixelarea_arcsecsq) + #log.warning(f"Pixel area ratio: {pix_ratio:.6f}") log.info('Blotting {} <-- {}'.format(blot_img.data.shape, median_model.data.shape)) outsci = np.zeros(blot_img.shape, dtype=np.float32) diff --git a/jwst/outlier_detection/tests/test_outlier_detection.py b/jwst/outlier_detection/tests/test_outlier_detection.py index 7757ce61dcc..40982cd4af6 100644 --- a/jwst/outlier_detection/tests/test_outlier_detection.py +++ b/jwst/outlier_detection/tests/test_outlier_detection.py @@ -141,6 +141,10 @@ def we_many_sci( sci1.var_rnoise = np.zeros(shape) + 1.0 sci1.meta.filename = "foo1_cal.fits" + # add pixel areas + sci1.meta.photometry.pixelarea_steradians = 1.0 + sci1.meta.photometry.pixelarea_arcsecsq = 1.0 + # Make copies with different noise all_sci = [sci1] for i in range(numsci - 1): diff --git a/jwst/regtest/test_nircam_align_to_gaia.py b/jwst/regtest/test_nircam_align_to_gaia.py index c91e6472071..99193ac7cca 100644 --- a/jwst/regtest/test_nircam_align_to_gaia.py +++ b/jwst/regtest/test_nircam_align_to_gaia.py @@ -13,6 +13,7 @@ def run_image3pipeline(rtdata_module): rtdata = rtdata_module rtdata.get_asn("nircam/image/level3_F277W_3img_asn.json") args = ["calwebb_image3", rtdata.input, + "--steps.outlier_detection.save_intermediate_results=True", "--steps.tweakreg.abs_refcat=GAIADR2", "--steps.tweakreg.save_results=True", "--steps.tweakreg.output_use_model=True", @@ -40,3 +41,36 @@ def test_tweakreg_with_gaia(run_image3pipeline, rtdata_module, root): assert_allclose(ra, ra_truth) assert_allclose(dec, dec_truth) + + + + +@pytest.mark.bigdata +def test_outlier_detection_flux_roundtrip(run_image3pipeline): + """ + Check flux scaling between input and output of OutlierDetectionStep. + Covers bugfix for JP-3635. Even after the change, the flux scaling + is not perfect, but at least this tolerance fails the test prior + to the fix and passes afterward(?) + """ + + import os + import numpy as np + ls = os.listdir(".") + for l in ls: + print(l) + + stem = "jw01069002004_01101_00013_nrca5" + + calfile = stem+"_cal.fits" + blotfile = stem+"_a3001_blot.fits" + + with datamodels.open(calfile) as cal, datamodels.open(blotfile) as blot: + + badcal = (np.isnan(cal.data)) * (np.isinf(cal.data)) + badblot = (np.isnan(blot.data)) * (np.isinf(blot.data)) + med_cal = np.nanmedian(cal.data[~badcal]) + med_blot = np.nanmedian(blot.data[~badblot]) + + print(med_cal, med_blot) + assert np.isclose(med_cal, med_blot, atol=3e-3)