From 29d8f58d31ea15bd9f2fad83b9d35218832fb642 Mon Sep 17 00:00:00 2001 From: William Lucas Date: Fri, 17 Jan 2025 17:03:53 +0000 Subject: [PATCH] Create imview at start of photon pooling and reuse. --- imsim/photon_pooling.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/imsim/photon_pooling.py b/imsim/photon_pooling.py index 2c7ab4be..4d406ee6 100644 --- a/imsim/photon_pooling.py +++ b/imsim/photon_pooling.py @@ -128,6 +128,12 @@ def buildImage(self, config, base, image_num, _obj_num, logger): photon_ops = galsim.config.BuildPhotonOps(photon_ops_cfg, 'photon_ops', base, logger) local_wcs = base['wcs'].local(full_image.true_center) resume = False # Initial call to accumulate will need to do some setup for SiliconSensors. + if sensor is None: + sensor = Sensor() + # Create the image view here and reuse as we accumulate. + imview = full_image._view() + imview._shift(-full_image.center) # equiv. to setCenter(), but faster + imview.wcs = PixelScale(1.0) for batch_num, batch in enumerate(phot_batches, start=current_photon_batch_num): if not batch: continue @@ -145,7 +151,7 @@ def buildImage(self, config, base, image_num, _obj_num, logger): # is no longer any way to distinguish which belong to which object. photons.x -= full_image.center.x photons.y -= full_image.center.y - self.accumulate_photons(photons, full_image, sensor, full_image.center, resume=resume) + self.accumulate_photons(photons, imview, sensor, resume=resume) # Later iterations can skip any setup in sensor accumulation. resume = True @@ -182,21 +188,15 @@ def merge_photon_arrays(stamps): return merged @staticmethod - def accumulate_photons(photons, image, sensor, center, resume=False): + def accumulate_photons(photons, imview, sensor, resume=False): """Accumulate a photon array onto a sensor. Parameters: photons: A PhotonArray containing the photons to be accumulated. - image: The image to which we draw the accumulated photons. + imview: The image view to which we draw the accumulated photons. sensor: Sensor to use for accumulation. If None, a temporary sensor is created here. - center: Center of the image as galsim.PositionI. resume: Resume accumulating following an earlier call for some extra performance. Default False. """ - if sensor is None: - sensor = Sensor() - imview = image._view() - imview._shift(-center) # equiv. to setCenter(), but faster - imview.wcs = PixelScale(1.0) if imview.dtype in (np.float32, np.float64): sensor.accumulate(photons, imview, imview.center, resume=resume) else: