From 3f83f7d264f6e53258376a073d90c5cb52aad2bd Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 13 May 2026 05:36:42 -0500 Subject: [PATCH 1/6] test: skip tests of deprecated stuff --- tests/test_deprecated.py | 215 ++++++++++----------------------------- 1 file changed, 54 insertions(+), 161 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 9ed754a034..581c1dce3e 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -35,12 +35,10 @@ def check_dep(f, *args, **kwargs): @timer def test_gsparams(): - if is_jax_galsim(): - pass - else: - check_dep(galsim.GSParams, allowed_flux_variation=0.90) - check_dep(galsim.GSParams, range_division_for_extrema=50) - check_dep(galsim.GSParams, small_fraction_of_flux=1.e-6) + if is_jax_galsim(): return + check_dep(galsim.GSParams, allowed_flux_variation=0.90) + check_dep(galsim.GSParams, range_division_for_extrema=50) + check_dep(galsim.GSParams, small_fraction_of_flux=1.e-6) @timer @@ -498,6 +496,8 @@ def test_hsm_depr(): @timer def test_photon_array_depr(): + if is_jax_galsim(): return + nphotons = 1000 # First create from scratch @@ -544,182 +544,75 @@ def test_photon_array_depr(): # Using the getter is allowed, but deprecated. photon_array = galsim.PhotonArray(nphotons) - if is_jax_galsim(): - # jax-galsim always sets these additional properties - # dxdz = check_dep(getattr, photon_array, 'dxdz') - # however jax-galsim sets them to NaN so they are not allocated - assert not photon_array.hasAllocatedAngles() - assert len(photon_array.dxdz) == nphotons - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.dxdz = 0.17 - # non-nan means allocated for jax-galsim - assert photon_array.hasAllocatedAngles() - else: - dxdz = check_dep(getattr, photon_array, 'dxdz') - assert photon_array.hasAllocatedAngles() - assert photon_array.hasAllocatedAngles() - assert len(photon_array.dxdz) == nphotons - assert len(photon_array.dydz) == nphotons - dxdz[:] = 0.17 + dxdz = check_dep(getattr, photon_array, 'dxdz') + assert photon_array.hasAllocatedAngles() + assert photon_array.hasAllocatedAngles() + assert len(photon_array.dxdz) == nphotons + assert len(photon_array.dydz) == nphotons + dxdz[:] = 0.17 np.testing.assert_array_equal(photon_array.dxdz, 0.17) np.testing.assert_array_equal(photon_array.dydz, 0.) - if is_jax_galsim(): - assert hasattr(photon_array, "dydz") - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.dydz = 0.59 - else: - dydz = photon_array.dydz # Allowed now. - dydz[:] = 0.59 + dydz = photon_array.dydz # Allowed now. + dydz[:] = 0.59 np.testing.assert_array_equal(photon_array.dydz, 0.59) - if is_jax_galsim(): - # jax-galsim always sets these additional properties - # wave = check_dep(getattr, photon_array, 'wavelength') - # however jax-galsim sets them to NaN so they are not allocated - assert not photon_array.hasAllocatedWavelengths() - else: - wave = check_dep(getattr, photon_array, 'wavelength') - assert photon_array.hasAllocatedWavelengths() + wave = check_dep(getattr, photon_array, 'wavelength') + assert photon_array.hasAllocatedWavelengths() assert len(photon_array.wavelength) == nphotons - if is_jax_galsim(): - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.wavelength = 500.0 - # jax-galsim is allocated now - assert photon_array.hasAllocatedWavelengths() - else: - wave[:] = 500. + wave[:] = 500. np.testing.assert_array_equal(photon_array.wavelength, 500) - if is_jax_galsim(): - # jax-galsim always sets these additional properties - # u = check_dep(getattr, photon_array, "pupil_u") - # however jax-galsim sets them to NaN so they are not allocated - assert not photon_array.hasAllocatedPupil() - else: - u = check_dep(getattr, photon_array, 'pupil_u') - assert photon_array.hasAllocatedPupil() - assert len(photon_array.pupil_u) == nphotons + u = check_dep(getattr, photon_array, 'pupil_u') + assert photon_array.hasAllocatedPupil() + assert len(photon_array.pupil_u) == nphotons assert len(photon_array.pupil_v) == nphotons - if is_jax_galsim(): - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.pupil_u = 6.0 - # jax-galsim is allocated now - assert photon_array.hasAllocatedPupil() - else: - u[:] = 6.0 + u[:] = 6.0 np.testing.assert_array_equal(photon_array.pupil_u, 6.0) np.testing.assert_array_equal(photon_array.pupil_v, 0.0) - if is_jax_galsim(): - assert hasattr(photon_array, "pupil_v") - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.pupil_v = 10.0 - else: - v = photon_array.pupil_v - v[:] = 10.0 + v = photon_array.pupil_v + v[:] = 10.0 np.testing.assert_array_equal(photon_array.pupil_v, 10.0) - if is_jax_galsim(): - # jax-galsim always sets these additional properties - # t = check_dep(getattr, photon_array, "time") - # however jax-galsim sets them to NaN so they are not allocated - assert not photon_array.hasAllocatedTimes() - # jax-galsim needs to set 0 - photon_array.time = 0.0 - # jax-galsim is allocated now - assert photon_array.hasAllocatedTimes() - else: - t = check_dep(getattr, photon_array, 'time') + t = check_dep(getattr, photon_array, 'time') assert photon_array.hasAllocatedTimes() assert len(photon_array.time) == nphotons np.testing.assert_array_equal(photon_array.time, 0.0) - if is_jax_galsim(): - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.time = 10 - else: - t[:] = 10 + t[:] = 10 np.testing.assert_array_equal(photon_array.time, 10.0) # For coverage, also need to test the two pair ones in other order. photon_array = galsim.PhotonArray(nphotons) - if is_jax_galsim(): - # jax-galsim always sets these additional properties - # dydz = check_dep(getattr, photon_array, "dydz") - # however jax-galsim sets them to NaN so they are not allocated - assert not photon_array.hasAllocatedAngles() - else: - dydz = check_dep(getattr, photon_array, 'dydz') - assert photon_array.hasAllocatedAngles() - assert photon_array.hasAllocatedAngles() + dydz = check_dep(getattr, photon_array, 'dydz') + assert photon_array.hasAllocatedAngles() + assert photon_array.hasAllocatedAngles() assert len(photon_array.dxdz) == nphotons assert len(photon_array.dydz) == nphotons - if is_jax_galsim(): - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.dydz = 0.59 - # non-nan means allocated for jax-galsim - assert photon_array.hasAllocatedAngles() - else: - dydz[:] = 0.59 + dydz[:] = 0.59 np.testing.assert_array_equal(photon_array.dxdz, 0.) np.testing.assert_array_equal(photon_array.dydz, 0.59) - if is_jax_galsim(): - assert hasattr(photon_array, "dxdz") - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.dxdz = 0.17 - else: - dxdz = photon_array.dxdz # Allowed now. - dxdz[:] = 0.17 + dxdz = photon_array.dxdz # Allowed now. + dxdz[:] = 0.17 np.testing.assert_array_equal(photon_array.dxdz, 0.17) - if is_jax_galsim(): - # jax-galsim always sets these additional properties - # v = check_dep(getattr, photon_array, "pupil_v") - # however jax-galsim sets them to NaN so they are not allocated - assert not photon_array.hasAllocatedPupil() - else: - v = check_dep(getattr, photon_array, 'pupil_v') - assert photon_array.hasAllocatedPupil() - assert len(photon_array.pupil_u) == nphotons + v = check_dep(getattr, photon_array, 'pupil_v') + assert photon_array.hasAllocatedPupil() + assert len(photon_array.pupil_u) == nphotons assert len(photon_array.pupil_v) == nphotons - if is_jax_galsim(): - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.pupil_v = 10.0 - # jax-galsim is allocated now - assert photon_array.hasAllocatedPupil() - else: - v[:] = 10.0 + v[:] = 10.0 np.testing.assert_array_equal(photon_array.pupil_u, 0.0) np.testing.assert_array_equal(photon_array.pupil_v, 10.0) - if is_jax_galsim(): - assert hasattr(photon_array, "pupil_u") - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.pupil_u = 6.0 - else: - u = photon_array.pupil_u - u[:] = 6.0 + u = photon_array.pupil_u + u[:] = 6.0 np.testing.assert_array_equal(photon_array.pupil_u, 6.0) # Check assignAt pa1 = galsim.PhotonArray(50) pa1.x = photon_array.x[:50] - if is_jax_galsim(): - pa1.y = photon_array.y[:50] - pa1.flux.at[0:50].set(photon_array.flux[:50]) - else: - for i in range(50): - pa1.y[i] = photon_array.y[i] - pa1.flux[0:50] = photon_array.flux[:50] + for i in range(50): + pa1.y[i] = photon_array.y[i] + pa1.flux[0:50] = photon_array.flux[:50] pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] pa1.pupil_u = photon_array.pupil_u[:50] @@ -727,20 +620,20 @@ def test_photon_array_depr(): pa2 = galsim.PhotonArray(100) check_dep(pa2.assignAt, 0, pa1) check_dep(pa2.assignAt, 50, pa1) - np.testing.assert_array_almost_equal(pa2.x[:50], pa1.x) - np.testing.assert_array_almost_equal(pa2.y[:50], pa1.y) - np.testing.assert_array_almost_equal(pa2.flux[:50], pa1.flux) - np.testing.assert_array_almost_equal(pa2.dxdz[:50], pa1.dxdz) - np.testing.assert_array_almost_equal(pa2.dydz[:50], pa1.dydz) - np.testing.assert_array_almost_equal(pa2.pupil_u[:50], pa1.pupil_u) - np.testing.assert_array_almost_equal(pa2.pupil_v[:50], pa1.pupil_v) - np.testing.assert_array_almost_equal(pa2.x[50:], pa1.x) - np.testing.assert_array_almost_equal(pa2.y[50:], pa1.y) - np.testing.assert_array_almost_equal(pa2.flux[50:], pa1.flux) - np.testing.assert_array_almost_equal(pa2.dxdz[50:], pa1.dxdz) - np.testing.assert_array_almost_equal(pa2.dydz[50:], pa1.dydz) - np.testing.assert_array_almost_equal(pa2.pupil_u[50:], pa1.pupil_u) - np.testing.assert_array_almost_equal(pa2.pupil_v[50:], pa1.pupil_v) + np.testing.assert_almost_equal(pa2.x[:50], pa1.x) + np.testing.assert_almost_equal(pa2.y[:50], pa1.y) + np.testing.assert_almost_equal(pa2.flux[:50], pa1.flux) + np.testing.assert_almost_equal(pa2.dxdz[:50], pa1.dxdz) + np.testing.assert_almost_equal(pa2.dydz[:50], pa1.dydz) + np.testing.assert_almost_equal(pa2.pupil_u[:50], pa1.pupil_u) + np.testing.assert_almost_equal(pa2.pupil_v[:50], pa1.pupil_v) + np.testing.assert_almost_equal(pa2.x[50:], pa1.x) + np.testing.assert_almost_equal(pa2.y[50:], pa1.y) + np.testing.assert_almost_equal(pa2.flux[50:], pa1.flux) + np.testing.assert_almost_equal(pa2.dxdz[50:], pa1.dxdz) + np.testing.assert_almost_equal(pa2.dydz[50:], pa1.dydz) + np.testing.assert_almost_equal(pa2.pupil_u[50:], pa1.pupil_u) + np.testing.assert_almost_equal(pa2.pupil_v[50:], pa1.pupil_v) # Error if it doesn't fit. with assert_raises(ValueError): From 7da01dae45f98cf3c03a23375a3fb8eaa394052b Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 13 May 2026 05:46:21 -0500 Subject: [PATCH 2/6] fix: dry it up --- tests/test_draw.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 8d337a65ee..846e0bcc76 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1259,12 +1259,7 @@ def test_fft(): [4,6,8,4], [2,4,6,6] ], xmin=-2, ymin=-2, dtype=dt, scale=0.1) - if is_jax_galsim(): - if dt not in [np.complex128, complex]: - kim = xim.calculate_fft() - xim2 = kim.calculate_inverse_fft() - np.testing.assert_array_almost_equal(xim.array, xim2.array) - else: + if (not is_jax_galsim()) or (is_jax_galsim() and (not np.iscomplexobj(dt(1)))): kim = xim.calculate_fft() xim2 = kim.calculate_inverse_fft() np.testing.assert_array_almost_equal(xim.array, xim2.array) @@ -1299,12 +1294,7 @@ def test_fft(): xim2 = galsim.Image([ [2,4,6], [4,6,8] ], xmin=-2, ymin=-1, dtype=dt, scale=0.1) - if is_jax_galsim(): - if dt not in [np.complex128, complex]: - kim = xim.calculate_fft() - kim2 = xim2.calculate_fft() - np.testing.assert_array_almost_equal(kim.array, kim2.array) - else: + if (not is_jax_galsim()) or (is_jax_galsim() and (not np.iscomplexobj(dt(1)))): kim = xim.calculate_fft() kim2 = xim2.calculate_fft() np.testing.assert_array_almost_equal(kim.array, kim2.array) From 7061ca2e8bb707295f7a1eed1d2ce3bd1f7dc3b1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 13 May 2026 05:49:07 -0500 Subject: [PATCH 3/6] fix: smaller diff --- tests/test_interpolatedimage.py | 57 ++++++++++++++++----------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 6d3b2bc520..e838a55b52 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1892,38 +1892,37 @@ def test_drawreal_seg_fault(): """Test to reproduce bug report in Issue #1164 that was causing seg faults """ # this test only runs with real galsim - if is_jax_galsim(): - pass - else: - import pickle + if is_jax_galsim(): return - prof_file = os.path.join( - os.path.dirname(__file__), - 'input/test_interpolatedimage_seg_fault_prof.pkl' - ) - with open(prof_file, 'rb') as f: - prof = pickle.load(f) - print(repr(prof)) - - image = galsim.Image( - galsim.BoundsI( - xmin=-12, - xmax=12, - ymin=-12, - ymax=12 - ), - dtype=float, - scale=1 - ) + import pickle + + prof_file = os.path.join( + os.path.dirname(__file__), + 'input/test_interpolatedimage_seg_fault_prof.pkl' + ) + with open(prof_file, 'rb') as f: + prof = pickle.load(f) + print(repr(prof)) + + image = galsim.Image( + galsim.BoundsI( + xmin=-12, + xmax=12, + ymin=-12, + ymax=12 + ), + dtype=float, + scale=1 + ) - image.fill(3) - prof.drawReal(image) + image.fill(3) + prof.drawReal(image) - # The problem was that the object is shifted fully off the target image and that was leading - # to an attempt to create a stack of length -1, which caused the seg fault. - # So mostly this test just confirms that this runs without seg faulting. - # But we can check that the image is now correctly all zeros. - np.testing.assert_array_equal(image.array, 0) + # The problem was that the object is shifted fully off the target image and that was leading + # to an attempt to create a stack of length -1, which caused the seg fault. + # So mostly this test just confirms that this runs without seg faulting. + # But we can check that the image is now correctly all zeros. + np.testing.assert_array_equal(image.array, 0) @timer From 16c8a8bed3cd3bd311094091fce8e02eaeff7430 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 13 May 2026 05:51:41 -0500 Subject: [PATCH 4/6] fix: combine if statements --- tests/test_photon_array.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 2f55f6e175..6053e7f3af 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -194,12 +194,10 @@ def test_photon_array(): pa1.x = photon_array.x[:50] if is_jax_galsim(): pa1.y = photon_array.y[:50] + pa1.flux = photon_array.flux[:50] else: for i in range(50): pa1.y[i] = photon_array.y[i] - if is_jax_galsim(): - pa1.flux = photon_array.flux[:50] - else: pa1.flux[0:50] = photon_array.flux[:50] pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] From 0b8b4738c4dc720e78a8f9aca1a4efcb36b748a9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 13 May 2026 05:55:55 -0500 Subject: [PATCH 5/6] fix: put back almost equal --- tests/test_moffat.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index b0ef58eb2e..de1a96aea5 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -153,29 +153,29 @@ def test_moffat_properties(): cen = galsim.PositionD(0, 0) np.testing.assert_equal(psf.centroid, cen) # Check Fourier properties - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) - np.testing.assert_array_almost_equal(psf.stepk, 0.62831853071795873) - np.testing.assert_array_almost_equal(psf.kValue(cen), test_flux+0j) - np.testing.assert_array_almost_equal(psf.half_light_radius, 1.0) - np.testing.assert_array_almost_equal(psf.fwhm, fwhm_backwards_compatible) - np.testing.assert_array_almost_equal(psf.xValue(cen), 0.50654651638242509) - np.testing.assert_array_almost_equal(psf.kValue(cen), (1+0j) * test_flux) - np.testing.assert_array_almost_equal(psf.flux, test_flux) - np.testing.assert_array_almost_equal(psf.xValue(cen), psf.max_sb) + np.testing.assert_almost_equal(psf.maxk, 11.634597424960159) + np.testing.assert_almost_equal(psf.stepk, 0.62831853071795873) + np.testing.assert_almost_equal(psf.kValue(cen), test_flux+0j) + np.testing.assert_almost_equal(psf.half_light_radius, 1.0) + np.testing.assert_almost_equal(psf.fwhm, fwhm_backwards_compatible) + np.testing.assert_almost_equal(psf.xValue(cen), 0.50654651638242509) + np.testing.assert_almost_equal(psf.kValue(cen), (1+0j) * test_flux) + np.testing.assert_almost_equal(psf.flux, test_flux) + np.testing.assert_almost_equal(psf.xValue(cen), psf.max_sb) # Now create the same profile using the half_light_radius: psf = galsim.Moffat(beta=2.0, half_light_radius=1., trunc=2*fwhm_backwards_compatible, flux=test_flux) np.testing.assert_equal(psf.centroid, cen) - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) - np.testing.assert_array_almost_equal(psf.stepk, 0.62831853071795862) - np.testing.assert_array_almost_equal(psf.kValue(cen), test_flux+0j) - np.testing.assert_array_almost_equal(psf.half_light_radius, 1.0) - np.testing.assert_array_almost_equal(psf.fwhm, fwhm_backwards_compatible) - np.testing.assert_array_almost_equal(psf.xValue(cen), 0.50654651638242509) - np.testing.assert_array_almost_equal(psf.kValue(cen), (1+0j) * test_flux) - np.testing.assert_array_almost_equal(psf.flux, test_flux) - np.testing.assert_array_almost_equal(psf.xValue(cen), psf.max_sb) + np.testing.assert_almost_equal(psf.maxk, 11.634597424960159) + np.testing.assert_almost_equal(psf.stepk, 0.62831853071795862) + np.testing.assert_almost_equal(psf.kValue(cen), test_flux+0j) + np.testing.assert_almost_equal(psf.half_light_radius, 1.0) + np.testing.assert_almost_equal(psf.fwhm, fwhm_backwards_compatible) + np.testing.assert_almost_equal(psf.xValue(cen), 0.50654651638242509) + np.testing.assert_almost_equal(psf.kValue(cen), (1+0j) * test_flux) + np.testing.assert_almost_equal(psf.flux, test_flux) + np.testing.assert_almost_equal(psf.xValue(cen), psf.max_sb) # Check input flux vs output flux for inFlux in np.logspace(-2, 2, 10): From 1534a05f049bd05d8bdc87b811cbdcda9e9a6780 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 13 May 2026 06:00:00 -0500 Subject: [PATCH 6/6] fix: use withOrigin for local wcs --- tests/test_wcs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index b4fe853253..a45fc68284 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -504,7 +504,7 @@ def do_local_wcs(wcs, ufunc, vfunc, name): wcs2 = wcs.local() assert wcs == wcs2, name+' local() is not == the original' new_origin = galsim.PositionI(123,321) - wcs3 = wcs.shiftOrigin(new_origin) + wcs3 = wcs.withOrigin(new_origin) assert wcs != wcs3, name+' is not != wcs.withOrigin(pos)' assert wcs3 != wcs, name+' is not != wcs.withOrigin(pos) (reverse)' wcs2 = wcs3.local() @@ -518,7 +518,7 @@ def do_local_wcs(wcs, ufunc, vfunc, name): world_pos2.y, world_pos1.y, digits, 'withOrigin(new_origin) returned wrong world position') new_world_origin = galsim.PositionD(5352.7, 9234.3) - wcs4 = wcs.shiftOrigin(new_origin, new_world_origin) + wcs4 = wcs.withOrigin(new_origin, new_world_origin) world_pos3 = wcs4.toWorld(new_origin) np.testing.assert_almost_equal( world_pos3.x, new_world_origin.x, digits, @@ -526,7 +526,7 @@ def do_local_wcs(wcs, ufunc, vfunc, name): np.testing.assert_almost_equal( world_pos3.y, new_world_origin.y, digits, 'withOrigin(new_origin, new_world_origin) returned wrong position') - wcs5 = wcs.shiftOrigin(new_origin, new_world_origin) + wcs5 = wcs.withOrigin(new_origin, new_world_origin) assert wcs4 == wcs5 # For LocalWCS, shiftOrigin is equivalent to withOrigin # Check inverse: