Skip to content

Commit

Permalink
Merge pull request #83 from lsst/tickets/DM-48123
Browse files Browse the repository at this point in the history
DM-48123: Make seed generation possible with long exposure/visit IDs
  • Loading branch information
arunkannawadi authored Jan 6, 2025
2 parents ede91d6 + 4a908b2 commit 982c578
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/lsst/drp/tasks/make_direct_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,10 @@ def run(self, inputs: Mapping[int, WarpDetectorInputs], sky_info, visit_summary)
input_exposure = detector_inputs.exposure
# Generate noise image(s) in-situ.
seed = self.get_seed_from_data_id(detector_inputs.data_id)
rng = np.random.RandomState(seed + self.config.seedOffset)
# Limit to last 32 bits to avoid overflow in numpy.
np_seed = (seed + self.config.seedOffset) & 0xFFFFFFFF
self.log.debug("Setting numpy random seed to %d for noise realization", np_seed)
rng = np.random.RandomState(np_seed)

# Generate noise images in-situ.
noise_calexps = self.make_noise_exposures(input_exposure, rng)
Expand Down
35 changes: 35 additions & 0 deletions tests/test_make_direct_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,38 @@ def test_background_errors(self):
with self.assertRaises(RuntimeError, msg="No background to revert"):
makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

def test_long_data_ids(self):
"""Test MakeDirectWarpTask fails gracefully with no good pixels.
It should return an empty exposure, with no PSF.
"""
warp_detector_inputs = {
self.dataRef.dataId.detector.id: WarpDetectorInputs(
exposure_or_handle=self.dataRef, data_id=self.dataRef.dataId
)
}

self.config.border = 0 # Repeated calls will expand it otherwise.
makeWarp_original = MakeDirectWarpTask(config=self.config)
makeWarp_short = MakeDirectWarpTask(config=self.config)
makeWarp_short.get_seed_from_data_id = (
lambda data_id: 2**32 - 1 + makeWarp_original.get_seed_from_data_id(data_id)
)
makeWarp_long = MakeDirectWarpTask(config=self.config)
makeWarp_long.get_seed_from_data_id = lambda data_id: 2**32 + makeWarp_original.get_seed_from_data_id(
data_id
)

result_long = makeWarp_long.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)
result_short = makeWarp_short.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)
result_original = makeWarp_original.run(
warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None
)

self.assertMaskedImagesAlmostEqual(result_long.noise_warp0, result_original.noise_warp0, atol=6e-8)
with self.assertRaises(AssertionError):
self.assertMaskedImagesEqual(result_short.noise_warp0, result_original.noise_warp0)


class MakeWarpNoGoodPixelsTestCase(MakeWarpTestCase):
def setUp(self):
Expand Down Expand Up @@ -393,6 +425,9 @@ def test_makeWarp(self):
def test_compare_warps(self):
"""This test is not applicable when there are no good pixels."""

def test_long_data_ids(self):
"""This test is not applicable when there are no good pixels."""


def setup_module(module):
lsst.utils.tests.init()
Expand Down

0 comments on commit 982c578

Please sign in to comment.