From 65e79cefcce926d6f470cd663d63e88938c2acb5 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Fri, 20 Dec 2024 11:38:25 -0500 Subject: [PATCH 1/2] Limit to last 32 bits --- python/lsst/drp/tasks/make_direct_warp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/lsst/drp/tasks/make_direct_warp.py b/python/lsst/drp/tasks/make_direct_warp.py index 71ec931..b7e0dcc 100644 --- a/python/lsst/drp/tasks/make_direct_warp.py +++ b/python/lsst/drp/tasks/make_direct_warp.py @@ -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) From 4a908b248b3dea9e01c609c70485fc6cb2bda9db Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Fri, 3 Jan 2025 13:48:58 -0500 Subject: [PATCH 2/2] Add a unit test to check success with long dataIDs --- tests/test_make_direct_warp.py | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_make_direct_warp.py b/tests/test_make_direct_warp.py index 6b4b841..a463cb7 100644 --- a/tests/test_make_direct_warp.py +++ b/tests/test_make_direct_warp.py @@ -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): @@ -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()