From 889ffc622b6cac3fd7b66f8fba4997c6a96e30fc Mon Sep 17 00:00:00 2001 From: Patrick Sheehan Date: Mon, 13 Jul 2026 22:40:26 -0400 Subject: [PATCH] Reintroduce normalization by nrays for source intensity when raytracing sources, and add a test to catch differences in the max pixel value in the image created. --- pinballrt/sources.py | 2 +- pinballrt/tests/test_E2E.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pinballrt/sources.py b/pinballrt/sources.py index 2ca51d3..88380cf 100644 --- a/pinballrt/sources.py +++ b/pinballrt/sources.py @@ -155,7 +155,7 @@ def emit_rays(self, nu, distance_unit, ez, nrays, physical_pixel_size, device="c direction = torch.unsqueeze(torch.tensor(ez, dtype=torch.float32, device=device), 0).repeat(nrays, 1) - intensity = (self.intensity(nu.data)*np.pi).to(u.Jy / u.steradian).value * \ + intensity = (self.intensity(nu.data)*np.pi / nrays).to(u.Jy / u.steradian).value * \ ((self.radius / physical_pixel_size).decompose()**2).value intensity = torch.unsqueeze(torch.tensor(intensity, dtype=torch.float32, device=device), 0).repeat(nrays, 1) tau_intensity = torch.zeros((nrays, nu.size), dtype=torch.float32, device=device) diff --git a/pinballrt/tests/test_E2E.py b/pinballrt/tests/test_E2E.py index 1915b9c..17f5aea 100644 --- a/pinballrt/tests/test_E2E.py +++ b/pinballrt/tests/test_E2E.py @@ -102,6 +102,7 @@ def test_E2E(grid_class, grid_kwargs, dust, percentile, device, return_vals=Fals base_image = xr.open_dataset(os.path.join(os.path.dirname(__file__), f"data/{grid_class.__name__}_E2E_image.nc")) Q = calculate_Qvalue(image.intensity.data.value, base_image.intensity, percentile=99.0, clip=0.1) assert Q < 1.025, f"Image difference exceeds tolerance: {Q}" + assert np.abs(image.intensity.data.value.max() - base_image.intensity.max()) < 0.01 * base_image.intensity.max(), f"Image max difference exceeds tolerance: {(image.intensity.max() - base_image.intensity.max()) / base_image.intensity.max()}" base_mom0 = xr.open_dataset(os.path.join(os.path.dirname(__file__), f"data/{grid_class.__name__}_E2E_mom0.nc")) Q = calculate_Qvalue(mom0.intensity.data.value, base_mom0.intensity, percentile=99.0, clip=0.1)