Skip to content

Commit

Permalink
Merge pull request #1 from emolter/AL-852
Browse files Browse the repository at this point in the history
fixed outlier test failures
  • Loading branch information
nden authored Dec 16, 2024
2 parents 6a05b4a + eb20239 commit e0f2987
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
48 changes: 30 additions & 18 deletions jwst/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,17 @@ def test_flag_cr(sci_blot_image_pair):
assert sci.dq[10, 10] == datamodels.dqflags.pixel["GOOD"]


# not a fixture - now has options
def we_many_sci(
numsci=3, sigma=0.02, background=1.5, signal=7, exptype="MIR_IMAGE", tsovisit=False
):
"""Provide numsci science images with different noise but identical source
and same background level"""
shape = (21, 20)
def make_sci1(shape):
"""Needs to be a fixture because we want to change exposure.type
in the subsequent tests without rerunning AssignWCS"""

sci1 = datamodels.ImageModel(shape)

# Populate keywords
sci1.meta.instrument.name = "MIRI"
sci1.meta.instrument.detector = "MIRIMAGE"
sci1.meta.exposure.type = exptype
sci1.meta.visit.tsovisit = tsovisit
sci1.meta.exposure.type = "MIR_IMAGE"
sci1.meta.visit.tsovisit = False
sci1.meta.observation.date = "2020-01-01"
sci1.meta.observation.time = "00:00:00"
sci1.meta.telescope = "JWST"
Expand All @@ -135,6 +131,8 @@ def we_many_sci(
sci1.meta.wcsinfo.roll_ref = 0
sci1.meta.wcsinfo.ra_ref = 1.5e-5
sci1.meta.wcsinfo.dec_ref = 1.5e-5
sci1.meta.wcsinfo.v2_ref = 0
sci1.meta.wcsinfo.v3_ref = 0
sci1.meta.wcsinfo.v3yangle = 0
sci1.meta.wcsinfo.vparity = -1
sci1.meta.wcsinfo.pc1_1 = 1
Expand All @@ -148,23 +146,37 @@ def we_many_sci(
sci1.meta.wcsinfo.cunit1 = "deg"
sci1.meta.wcsinfo.cunit2 = "deg"
sci1.meta.background.subtracted = False
sci1.meta.background.level = background
sci1.meta.background.level = 1.5

sci1 = AssignWcsStep.call(sci1)

sci1.meta.filename = "foo1_cal.fits"

# add pixel areas
sci1.meta.photometry.pixelarea_steradians = 1.0
sci1.meta.photometry.pixelarea_arcsecsq = 1.0
return sci1


# not a fixture - now has options
def we_many_sci(
numsci=3, sigma=0.02, background=1.5, signal=7, exptype="MIR_IMAGE", tsovisit=False
):
"""Provide numsci science images with different noise but identical source
and same background level"""
shape = (21,20)
sci1 = make_sci1(shape)
sci1.meta.exposure.type = exptype
sci1.meta.visit.tsovisit = tsovisit

# Replace the FITS-type WCS with an Identity WCS
sci1.meta.wcs = create_fitswcs(sci1)
sci1.meta.wcsinfo.s_region = compute_s_region_imaging(sci1.meta.wcs, shape=shape, center=False)
rng = np.random.default_rng(720)
sci1.data = rng.normal(loc=background, size=shape, scale=sigma)
sci1.err = np.zeros(shape) + sigma
sci1.data[7, 7] += signal
# update the noise for this source to include the photon/measurement noise
sci1.err[7, 7] = np.sqrt(sigma ** 2 + signal)
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]
Expand Down Expand Up @@ -650,7 +662,7 @@ def test_drizzle_and_median_with_resample(three_sci_as_asn, tmp_cwd):
0.7)

assert isinstance(wcs, WCS)
assert median.shape == (21,20)
assert median.shape == (34,34)

resamp.single = False
with pytest.raises(ValueError):
Expand Down
2 changes: 0 additions & 2 deletions jwst/resample/resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import numpy as np
from astropy import units as u
from astropy import wcs as fitswcs
from astropy.modeling import Model
import gwcs

from stdatamodels.dqflags import interpret_bit_flags
Expand Down

0 comments on commit e0f2987

Please sign in to comment.