Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-48123: Make seed generation possible with long exposure/visit IDs #83

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading