Skip to content

Commit a96345c

Browse files
authored
Merge pull request #484 from welucas2/u/welucas2/correct-photon-op-tests
Ensure self-consistent use of sky_pos and local_wcs in photon op tests.
2 parents a4c2d97 + 4b3f933 commit a96345c

File tree

1 file changed

+81
-28
lines changed

1 file changed

+81
-28
lines changed

tests/test_photon_ops.py

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ def create_test_photon_array(t=0.0, n_photons=10000):
6565
time=np.full(n_photons, t),
6666
)
6767

68+
def create_test_img_wcs(boresight, rottelpos=np.pi / 3 * galsim.radians):
69+
telescope = create_test_telescope(rottelpos)
70+
wcs_factory = BatoidWCSFactory(
71+
boresight,
72+
obstime=Time.strptime("2022-08-06 06:50:59.337600", "%Y-%m-%d %H:%M:%S.%f"),
73+
telescope=telescope,
74+
wavelength=622.3195217611445, # nm
75+
camera=get_camera(),
76+
temperature=280.0,
77+
pressure=72.7,
78+
H2O_pressure=1.0,
79+
)
80+
det_name = "R22_S11"
81+
camera = get_camera()[det_name]
82+
wcs = wcs_factory.getWCS(det=camera)
83+
return wcs
6884

6985
def create_test_rubin_optics(**kwargs):
7086
return photon_ops.RubinOptics(**create_test_rubin_optics_kwargs(**kwargs))
@@ -73,17 +89,17 @@ def create_test_rubin_optics(**kwargs):
7389
def create_test_rubin_optics_kwargs(
7490
boresight=galsim.CelestialCoord(0.543 * galsim.radians, -0.174 * galsim.radians),
7591
icrf_to_field=None,
76-
sky_pos=galsim.CelestialCoord(0.543 * galsim.radians, -0.174 * galsim.radians),
7792
image_pos=galsim.PositionD(809.6510740536025, 3432.6477953336625),
7893
rottelpos=np.pi / 3 * galsim.radians,
7994
):
8095
det_name = "R22_S11"
8196
if icrf_to_field is None:
8297
icrf_to_field = create_test_icrf_to_field(boresight, det_name=det_name)
98+
img_wcs = create_test_img_wcs(boresight, rottelpos)
8399
return dict(
84100
telescope=create_test_telescope(rottelpos),
85101
boresight=boresight,
86-
sky_pos=sky_pos,
102+
sky_pos=img_wcs.toWorld(image_pos),
87103
image_pos=image_pos,
88104
icrf_to_field=icrf_to_field,
89105
det_name=det_name,
@@ -140,7 +156,6 @@ def create_test_rubin_diffraction_optics(
140156
boresight,
141157
icrf_to_field,
142158
image_pos=image_pos,
143-
sky_pos=sky_pos,
144159
rottelpos=rottelpos,
145160
),
146161
rubin_diffraction=rubin_diffraction,
@@ -153,17 +168,19 @@ def create_test_rng():
153168

154169
def test_rubin_optics() -> None:
155170
"""Check that the image of a star is contained in a disc."""
156-
157-
rubin_optics = create_test_rubin_optics(rottelpos=0.0 * galsim.radians)
171+
boresight = galsim.CelestialCoord(0.543 * galsim.radians, -0.174 * galsim.radians)
172+
image_pos = galsim.PositionD(809.6510740536025, 3432.6477953336625)
173+
rottelpos = 0.0 * galsim.radians
174+
rubin_optics = create_test_rubin_optics(boresight=boresight, image_pos=image_pos, rottelpos=rottelpos)
158175
photon_array = create_test_photon_array()
159-
local_wcs = create_test_wcs()
176+
local_wcs = create_test_img_wcs(boresight, rottelpos).local(image_pos)
160177
u = photon_array.pupil_u.copy()
161178
v = photon_array.pupil_v.copy()
162179
rubin_optics.applyTo(photon_array, local_wcs=local_wcs, rng=create_test_rng())
163180
np.testing.assert_array_equal(photon_array.pupil_u, u)
164181
np.testing.assert_array_equal(photon_array.pupil_v, v)
165-
expected_x_pic_center = 564.5
166-
expected_y_pic_center = -1431.4
182+
expected_x_pic_center = -960.28
183+
expected_y_pic_center = -308.09
167184
expected_r_pic_center = 20.0
168185
np.testing.assert_array_less(
169186
np.hypot(
@@ -176,20 +193,28 @@ def test_rubin_optics() -> None:
176193

177194
def test_rubin_diffraction_produces_spikes() -> None:
178195
"""Checks that we have spike photons and that the spkies form a cross."""
196+
boresight = galsim.CelestialCoord(0.543 * galsim.radians, -0.174 * galsim.radians)
197+
image_pos = galsim.PositionD(809.6510740536025, 3432.6477953336625)
198+
rottelpos = 0.0 * galsim.radians
199+
img_wcs = create_test_img_wcs(boresight, rottelpos)
200+
sky_pos = img_wcs.toWorld(image_pos)
179201
rubin_diffraction_optics = create_test_rubin_diffraction_optics(
180-
rottelpos=0.0 * galsim.radians
202+
boresight=boresight,
203+
sky_pos=sky_pos,
204+
image_pos=image_pos,
205+
rottelpos=rottelpos
181206
)
182207
photon_array = create_test_photon_array(n_photons=1000000)
183-
local_wcs = create_test_wcs()
208+
local_wcs = img_wcs.local(image_pos)
184209
rubin_diffraction_optics.applyTo(
185210
photon_array, local_wcs=local_wcs, rng=create_test_rng()
186211
)
187212

188213
# The expected image is contained in a disc + spikes outside the disc:
189214
spike_angles = extract_spike_angles(
190215
photon_array,
191-
x_center=564.5,
192-
y_center=-1431.4,
216+
x_center=-960.28,
217+
y_center=-308.09,
193218
r=20.0,
194219
)
195220

@@ -231,13 +256,29 @@ def test_rubin_diffraction_optics_is_same_as_diffraction_and_optics() -> None:
231256
"""Checks that the result of applying RubinDiffraction and then RubinOptics
232257
is the same as applying the combined photon op RubinDiffractionOptics."""
233258
photon_array_combined = create_test_photon_array(n_photons=100000)
234-
local_wcs = create_test_wcs()
235-
rubin_diffraction_optics = create_test_rubin_diffraction_optics()
259+
boresight = galsim.CelestialCoord(0.543 * galsim.radians, -0.174 * galsim.radians)
260+
image_pos = galsim.PositionD(809.6510740536025, 3432.6477953336625)
261+
rottelpos = np.pi / 3 * galsim.radians
262+
img_wcs = create_test_img_wcs(boresight, rottelpos)
263+
local_wcs = img_wcs.local(image_pos)
264+
sky_pos = img_wcs.toWorld(image_pos)
265+
rubin_diffraction_optics = create_test_rubin_diffraction_optics(
266+
boresight=boresight,
267+
image_pos=image_pos,
268+
rottelpos=rottelpos,
269+
sky_pos=sky_pos
270+
)
236271
rubin_diffraction_optics.applyTo(
237272
photon_array_combined, local_wcs=local_wcs, rng=create_test_rng()
238273
)
239-
rubin_diffraction = create_test_rubin_diffraction()
240-
rubin_optics = create_test_rubin_optics()
274+
rubin_diffraction = create_test_rubin_diffraction(
275+
sky_pos=sky_pos
276+
)
277+
rubin_optics = create_test_rubin_optics(
278+
boresight=boresight,
279+
image_pos=image_pos,
280+
rottelpos=rottelpos
281+
)
241282
photon_array_modular = create_test_photon_array(n_photons=100000)
242283
rubin_diffraction.applyTo(
243284
photon_array_modular, local_wcs=local_wcs, rng=create_test_rng()
@@ -276,31 +317,43 @@ def test_rubin_diffraction_shows_field_rotation() -> None:
276317
latitude = -30.24463 * degrees
277318
azimuth = 45.0 * degrees
278319
altitude = 89.9 * degrees
320+
boresight = galsim.CelestialCoord(0.543 * galsim.radians, -0.174 * galsim.radians)
321+
image_pos = galsim.PositionD(809.6510740536025, 3432.6477953336625)
322+
rottelpos = 0.0 * galsim.radians
323+
img_wcs = create_test_img_wcs(boresight, rottelpos)
324+
sky_pos = img_wcs.toWorld(image_pos)
279325
rubin_diffraction_optics = create_test_rubin_diffraction_optics(
280-
latitude, azimuth, altitude, rottelpos=0.0 * galsim.radians
326+
latitude,
327+
azimuth,
328+
altitude,
329+
boresight=boresight,
330+
sky_pos=sky_pos,
331+
image_pos=image_pos,
332+
rottelpos=rottelpos
281333
)
282334
dt = 1.0
283335
photon_array_0 = create_test_photon_array(t=0.0, n_photons=1000000)
284336
photon_array_1 = create_test_photon_array(t=dt, n_photons=1000000)
285-
local_wcs = create_test_wcs()
337+
local_wcs = img_wcs.local(image_pos)
286338
rubin_diffraction_optics.applyTo(
287339
photon_array_0, local_wcs=local_wcs, rng=create_test_rng()
288340
)
289341
rubin_diffraction_optics.applyTo(
290342
photon_array_1, local_wcs=local_wcs, rng=create_test_rng()
291343
)
292344

345+
expected_center = np.array([-960.28, -308.09])
293346
# The expected image is contained in a disc + spikes outside the disc:
294347
spike_angles_0 = extract_spike_angles(
295348
photon_array_0,
296-
x_center=564.5,
297-
y_center=-1431.4,
349+
x_center=expected_center[0],
350+
y_center=expected_center[1],
298351
r=20.0,
299352
)
300353
spike_angles_1 = extract_spike_angles(
301354
photon_array_1,
302-
x_center=564.5,
303-
y_center=-1431.4,
355+
x_center=expected_center[0],
356+
y_center=expected_center[1],
304357
r=20.0,
305358
)
306359

@@ -579,6 +632,7 @@ def test_config_rubin_optics():
579632
"""Check the config interface to RubinOptics."""
580633

581634
image_pos = galsim.PositionD(3076.4462608524213, 1566.4896702703757)
635+
boresight = galsim.CelestialCoord(1.1047934165124105 * galsim.radians, -0.5261230452954583 * galsim.radians)
582636
config = {
583637
**deepcopy(TEST_BASE_CONFIG),
584638
"image_pos": image_pos, # This would get set appropriately during normal config processing.
@@ -588,20 +642,19 @@ def test_config_rubin_optics():
588642
"type": "RubinOptics",
589643
"camera": "LsstCam",
590644
"det_name": "R22_S11",
591-
"boresight": {
592-
"type": "RADec",
593-
"ra": "1.1047934165124105 radians",
594-
"dec": "-0.5261230452954583 radians",
595-
},
645+
"boresight": boresight,
596646
},
597647
]
598648
},
649+
"sky_pos": create_test_img_wcs(
650+
boresight=boresight,
651+
rottelpos=np.pi / 3 * galsim.radians
652+
).toWorld(image_pos),
599653
}
600654
galsim.config.ProcessInput(config)
601655
galsim.config.input.SetupInputsForImage(config, None)
602656
[photon_op] = galsim.config.BuildPhotonOps(config["stamp"], "photon_ops", config)
603657
reference_op = create_test_rubin_optics(
604-
sky_pos=TEST_BASE_CONFIG["sky_pos"],
605658
image_pos=image_pos,
606659
icrf_to_field=TEST_BASE_CONFIG["_icrf_to_field"],
607660
boresight=photon_op.boresight,

0 commit comments

Comments
 (0)