Skip to content

Commit

Permalink
initial draft commit to get more eyes on code
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Jun 11, 2024
1 parent d6435f1 commit a77126e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion jwst/outlier_detection/outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions jwst/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 34 additions & 0 deletions jwst/regtest/test_nircam_align_to_gaia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

0 comments on commit a77126e

Please sign in to comment.