From ff42160838407217e010bd85325ded960dafbfa5 Mon Sep 17 00:00:00 2001 From: Francois Lanusse Date: Sat, 22 Jul 2023 23:05:07 -0700 Subject: [PATCH 001/351] fix assert for arrays --- tests/test_transforms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index bc8c3a985b..753e4f6035 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -948,9 +948,9 @@ def test_compound(): gal5.drawImage(image=im5_f, method='sb', scale=0.2) np.testing.assert_almost_equal(im3_f[1,1], gal3.xValue(-0.7,-0.7), decimal=4) np.testing.assert_almost_equal(im5_f[1,1], gal3.xValue(-0.7,-0.7), decimal=4) - np.testing.assert_almost_equal(im3_f.array, im5_f.array, decimal=4) - np.testing.assert_almost_equal(im3_f.array, im3_d.array, decimal=4) - np.testing.assert_almost_equal(im5_f.array, im5_d.array, decimal=4) + np.testing.assert_array_almost_equal(im3_f.array, im5_f.array, decimal=4) + np.testing.assert_array_almost_equal(im3_f.array, im3_d.array, decimal=4) + np.testing.assert_array_almost_equal(im5_f.array, im5_d.array, decimal=4) gal3.drawKImage(image=im3_cd, scale=0.5) gal5.drawKImage(image=im5_cd, scale=0.5) From 2e69064252332e999634d064dfa601f8ace888d0 Mon Sep 17 00:00:00 2001 From: Francois Lanusse Date: Sun, 23 Jul 2023 15:41:14 -0700 Subject: [PATCH 002/351] added fix to test_sum.py --- tests/test_sum.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_sum.py b/tests/test_sum.py index f5e0aa0985..c52fffb738 100644 --- a/tests/test_sum.py +++ b/tests/test_sum.py @@ -260,12 +260,12 @@ def test_sum_transform(): rgal2_im = rgal2.drawImage(nx=64, ny=64, scale=0.2) # Check that the objects are equivalent, even if they may be written differently. - np.testing.assert_almost_equal(gal1_im.array, sgal1_im.array, decimal=8) - np.testing.assert_almost_equal(gal1_im.array, rgal1_im.array, decimal=8) + np.testing.assert_array_almost_equal(gal1_im.array, sgal1_im.array, decimal=8) + np.testing.assert_array_almost_equal(gal1_im.array, rgal1_im.array, decimal=8) # These two used to fail. - np.testing.assert_almost_equal(gal2_im.array, sgal2_im.array, decimal=8) - np.testing.assert_almost_equal(gal2_im.array, rgal2_im.array, decimal=8) + np.testing.assert_array_almost_equal(gal2_im.array, sgal2_im.array, decimal=8) + np.testing.assert_array_almost_equal(gal2_im.array, rgal2_im.array, decimal=8) check_pickle(gal0) check_pickle(gal1) From 46f34e31d4df5f3b192a3be7f6e64d3d074c7f6f Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 17 Sep 2023 15:30:12 -0500 Subject: [PATCH 003/351] REF use file to find path --- tests/test_convolve.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_convolve.py b/tests/test_convolve.py index 37862aa390..99ca3b8fdf 100644 --- a/tests/test_convolve.py +++ b/tests/test_convolve.py @@ -23,8 +23,8 @@ import galsim from galsim_test_helpers import * -imgdir = os.path.join(".", "SBProfile_comparison_images") # Directory containing the reference - # images. +# Directory containing the reference images. +imgdir = os.path.join(os.path.dirname(__file__), "SBProfile_comparison_images") @timer def test_convolve(): From 6889567d3d2e7ddfcf2714c560208f5f8ca987f2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 17 Sep 2023 16:33:13 -0500 Subject: [PATCH 004/351] fix more array comps --- tests/galsim_test_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 90b3009be7..01a9a4b643 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -199,7 +199,7 @@ def check_basic_k(prof, name): # Check negative flux: neg_image = prof.withFlux(-prof.flux).drawKImage(kimage.copy()) - np.testing.assert_almost_equal(neg_image.array/prof.flux, -kimage.array/prof.flux, 7, + np.testing.assert_array_almost_equal(neg_image.array/prof.flux, -kimage.array/prof.flux, 7, '%s negative flux drawK is not negative of +flux image'%name) # If supposed to be axisymmetric, make sure it is in the kValues. From 0b4414a8938594773ba23ee19c611fb694d4585b Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 05:35:10 -0500 Subject: [PATCH 005/351] allow float-like vlaues --- tests/galsim_test_helpers.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 01a9a4b643..ae5a938fb5 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -211,6 +211,17 @@ def check_basic_k(prof, name): np.testing.assert_allclose(test_values, ref_value, rtol=1.e-5, err_msg="%s profile not axisymmetric in kValues"%name) +def assert_floatlike(val): + assert ( + isinstance(val, float) + or ( + hasattr(val, "shape") + and val.shape == () + and hasattr(val, "dtype") + and val.dtype.name in ["float", "float32", "float64"] + ) + ), "Value is not float-like: type(%r) = %r" % (val, type(val)) + def check_basic(prof, name, approx_maxsb=False, scale=None, do_x=True, do_k=True): """Do some basic sanity checks that should work for all profiles. """ @@ -225,12 +236,12 @@ def check_basic(prof, name, approx_maxsb=False, scale=None, do_x=True, do_k=True prof.positive_flux - prof.negative_flux, prof.flux, err_msg="%s profile flux not equal to posflux + negflux"%name) assert isinstance(prof.centroid, galsim.PositionD) - assert isinstance(prof.flux, float) - assert isinstance(prof.positive_flux, float) - assert isinstance(prof.negative_flux, float) - assert isinstance(prof.max_sb, float) - assert isinstance(prof.stepk, float) - assert isinstance(prof.maxk, float) + assert_floatlike(prof.flux) + assert_floatlike(prof.positive_flux) + assert_floatlike(prof.negative_flux) + assert_floatlike(prof.max_sb) + assert_floatlike(prof.stepk) + assert_floatlike(prof.maxk) assert isinstance(prof.has_hard_edges, bool) assert isinstance(prof.is_axisymmetric, bool) assert isinstance(prof.is_analytic_x, bool) From 40c80dd2227dadd9203e1cae75475737f24a2d1a Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 05:43:25 -0500 Subject: [PATCH 006/351] fix more array asserts --- tests/galsim_test_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index ae5a938fb5..08719d9d2f 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -143,8 +143,8 @@ def check_basic_x(prof, name, approx_maxsb=False, scale=None): # Check negative flux: neg_image = prof.withFlux(-prof.flux).drawImage(method='sb', scale=scale, use_true_center=False) - np.testing.assert_almost_equal(neg_image.array/prof.flux, -image.array/prof.flux, 7, - '%s negative flux drawReal is not negative of +flux image'%name) + np.testing.assert_array_almost_equal(neg_image.array/prof.flux, -image.array/prof.flux, 7, + '%s negative flux drawReal is not negative of +flux image'%name) # Direct call to drawReal should also work and be equivalent to the above with scale = 1. prof.drawImage(image, method='sb', scale=1., use_true_center=False) From 9713ddc6339428530c795e931763f4d854dd242f Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 05:43:58 -0500 Subject: [PATCH 007/351] fix more array asserts --- tests/galsim_test_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 08719d9d2f..f243f232a2 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -150,8 +150,8 @@ def check_basic_x(prof, name, approx_maxsb=False, scale=None): prof.drawImage(image, method='sb', scale=1., use_true_center=False) image2 = image.copy() prof.drawReal(image2) - np.testing.assert_equal(image2.array, image.array, - err_msg="%s drawReal not equivalent to drawImage"%name) + np.testing.assert_array_equal(image2.array, image.array, + err_msg="%s drawReal not equivalent to drawImage"%name) # If supposed to be axisymmetric, make sure it is. if prof.is_axisymmetric: From 850ca16104d2fc149138ca9da9bcd0f48186831f Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 05:47:47 -0500 Subject: [PATCH 008/351] fix directory path --- tests/test_fitsheader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_fitsheader.py b/tests/test_fitsheader.py index ab05e6071e..afaebf63da 100644 --- a/tests/test_fitsheader.py +++ b/tests/test_fitsheader.py @@ -51,7 +51,7 @@ def check_tpv(header): assert 54384.18627436 in header.itervalues() file_name = 'tpv.fits' - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') # First option: give a file_name header = galsim.FitsHeader(file_name=os.path.join(dir,file_name)) check_tpv(header) From 00f453745b45cd43dc2e62fc0d94d5bb28e32a70 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 05:48:40 -0500 Subject: [PATCH 009/351] fix directory path --- tests/test_fitsheader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_fitsheader.py b/tests/test_fitsheader.py index afaebf63da..e61cd82578 100644 --- a/tests/test_fitsheader.py +++ b/tests/test_fitsheader.py @@ -191,7 +191,7 @@ def check_tpv(header): def test_scamp(): """Test that we can read in a SCamp .head file correctly """ - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') file_name = 'scamp.head' header = galsim.FitsHeader(file_name=file_name, dir=dir, text_file=True) From 3d77514edf5f2285b4b2f245438c857b76db082a Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 05:51:58 -0500 Subject: [PATCH 010/351] fix directory path --- tests/test_sum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_sum.py b/tests/test_sum.py index c52fffb738..d441482006 100644 --- a/tests/test_sum.py +++ b/tests/test_sum.py @@ -23,8 +23,8 @@ import galsim from galsim_test_helpers import * -imgdir = os.path.join(".", "SBProfile_comparison_images") # Directory containing the reference - # images. +# Directory containing the reference images. +imgdir = os.path.join(os.path.dirname(__file__), "SBProfile_comparison_images") @timer def test_add(): From 34e9778eae8d1da03d967a37efb4fd525aeca48f Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:00:26 -0500 Subject: [PATCH 011/351] fix comp of pos --- tests/test_sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_sum.py b/tests/test_sum.py index d441482006..f7bc307f2b 100644 --- a/tests/test_sum.py +++ b/tests/test_sum.py @@ -45,7 +45,7 @@ def test_add(): err_msg="Using GSObject Add(gauss1,gauss2) disagrees with expected result") cen = galsim.PositionD(0,0) - np.testing.assert_equal(sum_gauss.centroid, cen) + assert sum_gauss.centroid == cen, "Centers not equal: %r != %r" % (sum_gauss.centroid, cen) np.testing.assert_almost_equal(sum_gauss.flux, gauss1.flux + gauss2.flux) np.testing.assert_almost_equal(sum_gauss.xValue(cen), sum_gauss.max_sb) From b8212695cc8d7672339acb61a35cdd6bdcc754e7 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:05:06 -0500 Subject: [PATCH 012/351] revert this --- tests/test_sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_sum.py b/tests/test_sum.py index f7bc307f2b..d441482006 100644 --- a/tests/test_sum.py +++ b/tests/test_sum.py @@ -45,7 +45,7 @@ def test_add(): err_msg="Using GSObject Add(gauss1,gauss2) disagrees with expected result") cen = galsim.PositionD(0,0) - assert sum_gauss.centroid == cen, "Centers not equal: %r != %r" % (sum_gauss.centroid, cen) + np.testing.assert_equal(sum_gauss.centroid, cen) np.testing.assert_almost_equal(sum_gauss.flux, gauss1.flux + gauss2.flux) np.testing.assert_almost_equal(sum_gauss.xValue(cen), sum_gauss.max_sb) From 486b9722e7810b1da95cdda965dfc1e2d53d1101 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:09:35 -0500 Subject: [PATCH 013/351] provide some namespace control here --- tests/galsim_test_helpers.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index f243f232a2..7199544243 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -30,6 +30,29 @@ from numpy.testing import assert_raises from numpy.testing import assert_warns +__all__ = [ + "default_params", + "gsobject_compare", + "printval", + "convertToShear", + "check_basic_x", + "check_basic_k", + "assert_floatlike", + "check_basic", + "do_shoot", + "do_kvalue", + "radial_integrate", + "drawNoise", + "do_pickle", + "all_obj_diff", + "funcname", + "timer", + "CaptureLog", + "assert_raises", + "assert_warns", + "profile", +] + # This file has some helper functions that are used by tests from multiple files to help # avoid code duplication. From 41a1f3093e0fe246d766fffc483deefc92162da2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:16:53 -0500 Subject: [PATCH 014/351] fix more directory paths --- tests/test_transforms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 753e4f6035..06d8a336c5 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -23,8 +23,8 @@ import galsim from galsim_test_helpers import * -imgdir = os.path.join(".", "SBProfile_comparison_images") # Directory containing the reference - # images. +# Directory containing the reference images. +imgdir = os.path.join(os.path.dirname(__file__), "SBProfile_comparison_images") # for flux normalization tests test_flux = 1.8 From 0da5a609d48da13d971a96359baf02cce0fac14a Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:20:26 -0500 Subject: [PATCH 015/351] test galsim internals only if they are there --- tests/test_utilities.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 9b5ab18a05..dd55105e2d 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -37,7 +37,8 @@ def test_pos(): assert pi1.y == 23 assert isinstance(pi1.x, int) assert isinstance(pi1.y, int) - assert isinstance(pi1._p, galsim._galsim.PositionI) + if hasattr(galsim, '_galsim'): + assert isinstance(pi1._p, galsim._galsim.PositionI) pi2 = galsim.PositionI((11,23)) pi3 = galsim.PositionI(x=11.0, y=23.0) @@ -63,7 +64,8 @@ def test_pos(): assert pd1.y == 23. assert isinstance(pd1.x, float) assert isinstance(pd1.y, float) - assert isinstance(pd1._p, galsim._galsim.PositionD) + if hasattr(galsim, '_galsim'): + assert isinstance(pd1._p, galsim._galsim.PositionD) pd2 = galsim.PositionD((11,23)) pd3 = galsim.PositionD(x=11.0, y=23.0) From 8a862ce715f0e0c1a14405d36fb7b866ba2bc79a Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:25:34 -0500 Subject: [PATCH 016/351] test galsim internals only if they are there --- tests/test_utilities.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index dd55105e2d..639cb5f269 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -46,7 +46,10 @@ def test_pos(): pi5 = galsim.PositionI(galsim.PositionD(11.0,23.0)) pi6 = galsim.PositionD(11.3,23.4).round() pi7 = pi2.round() - pi8 = galsim._PositionI(11,23) + if hasattr(galsim, '_galsim'): + pi8 = galsim._PositionI(11,23) + else: + pi8 = galsim.PositionI(11,23) assert pi2 == pi1 assert pi3 == pi1 assert pi4 == pi1 @@ -72,7 +75,10 @@ def test_pos(): pd4 = galsim.PositionD(pd1) pd5 = galsim.PositionD(pi1) pd6 = galsim.PositionD(galsim.PositionD(11.3,23.4).round()) - pd7 = galsim._PositionD(11.0,23.0) + if hasattr(galsim, '_galsim'): + pd7 = galsim._PositionD(11.0,23.0) + else: + pd7 = galsim.PositionD(11.0,23.0) assert pd2 == pd1 assert pd3 == pd1 assert pd4 == pd1 From 45e74bbe8a09207f819154e835797912c54df735 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:52:21 -0500 Subject: [PATCH 017/351] test galsim internals only if they are there --- tests/test_utilities.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 639cb5f269..e6402a335f 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -180,7 +180,8 @@ def test_bounds(): assert isinstance(bi1.xmax, int) assert isinstance(bi1.ymin, int) assert isinstance(bi1.ymax, int) - assert isinstance(bi1._b, galsim._galsim.BoundsI) + if hasattr(galsim, '_galsim'): + assert isinstance(bi1._b, galsim._galsim.BoundsI) bi2 = galsim.BoundsI(galsim.PositionI(11,17), galsim.PositionI(23,50)) bi3 = galsim.BoundsI(galsim.PositionD(11.,50.), galsim.PositionD(23.,17.)) @@ -217,7 +218,8 @@ def test_bounds(): assert isinstance(bd1.xmax, float) assert isinstance(bd1.ymin, float) assert isinstance(bd1.ymax, float) - assert isinstance(bd1._b, galsim._galsim.BoundsD) + if hasattr(galsim, '_galsim'): + assert isinstance(bd1._b, galsim._galsim.BoundsD) bd2 = galsim.BoundsD(galsim.PositionI(11,17), galsim.PositionI(23,50)) bd3 = galsim.BoundsD(galsim.PositionD(11.,50.), galsim.PositionD(23.,17.)) From 9c8652eb110404c04dc2e378b6788eabffeaad5c Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 06:54:32 -0500 Subject: [PATCH 018/351] test galsim internals only if they are there --- tests/test_utilities.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index e6402a335f..5af8e4a062 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -194,7 +194,10 @@ def test_bounds(): bi10 = galsim.BoundsI() + galsim.PositionI(11,17) + galsim.PositionI(23,50) bi11 = galsim.BoundsI(galsim.BoundsD(11.,23.,17.,50.)) bi12 = galsim.BoundsI(xmin=11,ymin=17,xmax=23,ymax=50) - bi13 = galsim._BoundsI(11,23,17,50) + if hasattr(galsim, '_galsim'): + bi13 = galsim._BoundsI(11,23,17,50) + else: + bi13 = galsim.BoundsI(11,23,17,50) bi14 = galsim.BoundsI() bi14 += galsim.PositionI(11,17) bi14 += galsim.PositionI(23,50) @@ -232,7 +235,10 @@ def test_bounds(): bd10 = galsim.BoundsD() + galsim.PositionD(11,17) + galsim.PositionD(23,50) bd11 = galsim.BoundsD(galsim.BoundsI(11,23,17,50)) bd12 = galsim.BoundsD(xmin=11.0,ymin=17.0,xmax=23.0,ymax=50.0) - bd13 = galsim._BoundsD(11,23,17,50) + if hasattr(galsim, '_galsim'): + bd13 = galsim._BoundsD(11,23,17,50) + else: + bd13 = galsim.BoundsD(11,23,17,50) bd14 = galsim.BoundsD() bd14 += galsim.PositionD(11.,17.) bd14 += galsim.PositionD(23,50) From 4ce3d702e3550885f6b9a544ad5797f8d63e8cf8 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 08:32:40 -0500 Subject: [PATCH 019/351] int-like tests fixed --- tests/galsim_test_helpers.py | 16 +++++++++++++++- tests/test_utilities.py | 24 ++++++++++++------------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 7199544243..8c2bdf9fcf 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -38,6 +38,7 @@ "check_basic_x", "check_basic_k", "assert_floatlike", + "assert_intlike", "check_basic", "do_shoot", "do_kvalue", @@ -238,13 +239,26 @@ def assert_floatlike(val): assert ( isinstance(val, float) or ( - hasattr(val, "shape") + (not hasattr(galsim, "_galsim")) + and hasattr(val, "shape") and val.shape == () and hasattr(val, "dtype") and val.dtype.name in ["float", "float32", "float64"] ) ), "Value is not float-like: type(%r) = %r" % (val, type(val)) +def assert_intlike(val): + assert ( + isinstance(val, int) + or ( + (not hasattr(galsim, "_galsim")) + and hasattr(val, "shape") + and val.shape == () + and hasattr(val, "dtype") + and val.dtype.name in ["int", "int32", "int64"] + ) + ), "Value is not int-like: type(%r) = %r" % (val, type(val)) + def check_basic(prof, name, approx_maxsb=False, scale=None, do_x=True, do_k=True): """Do some basic sanity checks that should work for all profiles. """ diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 5af8e4a062..db854145c9 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -204,10 +204,10 @@ def test_bounds(): for b in [bi1, bi2, bi3, bi4, bi5, bi6, bi7, bi8, bi9, bi10, bi11, bi12, bi13, bi14]: assert b.isDefined() assert b == bi1 - assert isinstance(b.xmin, int) - assert isinstance(b.xmax, int) - assert isinstance(b.ymin, int) - assert isinstance(b.ymax, int) + assert_intlike(b.xmin) + assert_intlike(b.xmax) + assert_intlike(b.ymin) + assert_intlike(b.ymax) assert b.origin == galsim.PositionI(11, 17) assert b.center == galsim.PositionI(17, 34) assert b.true_center == galsim.PositionD(17, 33.5) @@ -217,10 +217,10 @@ def test_bounds(): assert bd1.xmax == bd1.getXMax() == 23. assert bd1.ymin == bd1.getYMin() == 17. assert bd1.ymax == bd1.getYMax() == 50. - assert isinstance(bd1.xmin, float) - assert isinstance(bd1.xmax, float) - assert isinstance(bd1.ymin, float) - assert isinstance(bd1.ymax, float) + assert_floatlike(bd1.xmin) + assert_floatlike(bd1.xmax) + assert_floatlike(bd1.ymin) + assert_floatlike(bd1.ymax) if hasattr(galsim, '_galsim'): assert isinstance(bd1._b, galsim._galsim.BoundsD) @@ -245,10 +245,10 @@ def test_bounds(): for b in [bd1, bd2, bd3, bd4, bd5, bd6, bd7, bd8, bd9, bd10, bd11, bd12, bd13, bd14]: assert b.isDefined() assert b == bd1 - assert isinstance(b.xmin, float) - assert isinstance(b.xmax, float) - assert isinstance(b.ymin, float) - assert isinstance(b.ymax, float) + assert_floatlike(b.xmin) + assert_floatlike(b.xmax) + assert_floatlike(b.ymin) + assert_floatlike(b.ymax) assert b.origin == galsim.PositionD(11, 17) assert b.center == galsim.PositionD(17, 33.5) assert b.true_center == galsim.PositionD(17, 33.5) From a32eef423a3e0c669ef7b6edbdc653c20293cce5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 08:47:02 -0500 Subject: [PATCH 020/351] fix import to only be top level in tests --- tests/test_utilities.py | 103 +++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index db854145c9..bfce4d289d 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -519,15 +519,14 @@ def test_check_all_contiguous(): @timer def test_deInterleaveImage(): - from galsim.utilities import deInterleaveImage, interleaveImages np.random.seed(84) # for generating the same random instances # 1) Check compatability with interleaveImages img = galsim.Image(np.random.randn(64,64),scale=0.25) img.setOrigin(galsim.PositionI(5,7)) ## for non-trivial bounds - im_list, offsets = deInterleaveImage(img,8) - img1 = interleaveImages(im_list,8,offsets) + im_list, offsets = galsim.utilities.deInterleaveImage(img,8) + img1 = galsim.utilities.interleaveImages(im_list,8,offsets) np.testing.assert_array_equal(img1.array,img.array, err_msg = "interleaveImages cannot reproduce the input to deInterleaveImage for square " "images") @@ -537,8 +536,8 @@ def test_deInterleaveImage(): img = galsim.Image(abs(np.random.randn(16*5,16*2)),scale=0.5) img.setCenter(0,0) ## for non-trivial bounds - im_list, offsets = deInterleaveImage(img,(2,5)) - img1 = interleaveImages(im_list,(2,5),offsets) + im_list, offsets = galsim.utilities.deInterleaveImage(img,(2,5)) + img1 = galsim.utilities.interleaveImages(im_list,(2,5),offsets) np.testing.assert_array_equal(img1.array,img.array, err_msg = "interleaveImages cannot reproduce the input to deInterleaveImage for " "rectangular images") @@ -548,7 +547,7 @@ def test_deInterleaveImage(): # 2) Checking for offsets img = galsim.Image(np.random.randn(32,32),scale=2.0) - im_list, offsets = deInterleaveImage(img,(4,2)) + im_list, offsets = galsim.utilities.deInterleaveImage(img,(4,2)) ## Checking if offsets are centered around zero assert np.sum([offset.x for offset in offsets]) == 0. @@ -565,7 +564,7 @@ def test_deInterleaveImage(): img0 = galsim.Image(32,32) g0.drawImage(image=img0,method='no_pixel',scale=0.25) - im_list0, offsets0 = deInterleaveImage(img0,2,conserve_flux=True) + im_list0, offsets0 = galsim.utilities.deInterleaveImage(img0,2,conserve_flux=True) for n in range(len(im_list0)): im = galsim.Image(16,16) @@ -588,8 +587,8 @@ def test_deInterleaveImage(): g1.drawImage(image=img1,scale=0.5/n1,method='no_pixel') g2.drawImage(image=img2,scale=0.5/n2,method='no_pixel') - im_list1, offsets1 = deInterleaveImage(img1,(n1**2,1),conserve_flux=True) - im_list2, offsets2 = deInterleaveImage(img2,[1,n2**2],conserve_flux=False) + im_list1, offsets1 = galsim.utilities.deInterleaveImage(img1,(n1**2,1),conserve_flux=True) + im_list2, offsets2 = galsim.utilities.deInterleaveImage(img2,[1,n2**2],conserve_flux=False) for n in range(n1**2): im, offset = im_list1[n], offsets1[n] @@ -606,26 +605,24 @@ def test_deInterleaveImage(): "horizontal direction") # im is scaled to account for flux not being conserved - assert_raises(TypeError, deInterleaveImage, image=img0.array, N=2) - assert_raises(TypeError, deInterleaveImage, image=img0, N=2.0) - assert_raises(TypeError, deInterleaveImage, image=img0, N=(2.0, 2.0)) - assert_raises(TypeError, deInterleaveImage, image=img0, N=(2,2,3)) - assert_raises(ValueError, deInterleaveImage, image=img0, N=7) - assert_raises(ValueError, deInterleaveImage, image=img0, N=(2,7)) - assert_raises(ValueError, deInterleaveImage, image=img0, N=(7,2)) + assert_raises(TypeError, galsim.utilities.deInterleaveImage, image=img0.array, N=2) + assert_raises(TypeError, galsim.utilities.deInterleaveImage, image=img0, N=2.0) + assert_raises(TypeError, galsim.utilities.deInterleaveImage, image=img0, N=(2.0, 2.0)) + assert_raises(TypeError, galsim.utilities.deInterleaveImage, image=img0, N=(2,2,3)) + assert_raises(ValueError, galsim.utilities.deInterleaveImage, image=img0, N=7) + assert_raises(ValueError, galsim.utilities.deInterleaveImage, image=img0, N=(2,7)) + assert_raises(ValueError, galsim.utilities.deInterleaveImage, image=img0, N=(7,2)) # It is legal to have the input image with wcs=None, but it emits a warning img0.wcs = None with assert_warns(galsim.GalSimWarning): - deInterleaveImage(img0, N=2) + galsim.utilities.deInterleaveImage(img0, N=2) # Unless suppress_warnings is True - deInterleaveImage(img0, N=2, suppress_warnings=True) + galsim.utilities.deInterleaveImage(img0, N=2, suppress_warnings=True) @timer def test_interleaveImages(): - from galsim.utilities import interleaveImages, deInterleaveImage - # 1a) With galsim Gaussian g = galsim.Gaussian(sigma=3.7,flux=1000.) gal = galsim.Convolve([g,galsim.Pixel(1.0)]) @@ -643,7 +640,7 @@ def test_interleaveImages(): scale = im.scale # Input to N as an int - img = interleaveImages(im_list,n,offsets=offset_list) + img = galsim.utilities.interleaveImages(im_list,n,offsets=offset_list) im = galsim.Image(16*n*n,16*n*n) g = galsim.Gaussian(sigma=3.7,flux=1000.*n*n) gal = galsim.Convolve([g,galsim.Pixel(1.0)]) @@ -669,7 +666,7 @@ def test_interleaveImages(): im_list_randperm = [im_list[idx] for idx in rand_idx] offset_list_randperm = [offset_list[idx] for idx in rand_idx] # Input to N as a tuple - img_randperm = interleaveImages(im_list_randperm,(n,n),offsets=offset_list_randperm) + img_randperm = galsim.utilities.interleaveImages(im_list_randperm,(n,n),offsets=offset_list_randperm) np.testing.assert_array_equal(img_randperm.array,img.array, err_msg="Interleaved images do not match when 'offsets' is supplied") @@ -692,9 +689,9 @@ def test_interleaveImages(): N = (n,n) with assert_raises(ValueError): - interleaveImages(im_list,N,offset_list) + galsim.utilities.interleaveImages(im_list,N,offset_list) # Can turn off the checks and just use these as they are with catch_offset_errors=False - interleaveImages(im_list,N,offset_list, catch_offset_errors=False) + galsim.utilities.interleaveImages(im_list,N,offset_list, catch_offset_errors=False) offset_list = [] im_list = [] @@ -711,8 +708,8 @@ def test_interleaveImages(): N = (n,n) with assert_raises(ValueError): - interleaveImages(im_list, N, offset_list) - interleaveImages(im_list, N, offset_list, catch_offset_errors=False) + galsim.utilities.interleaveImages(im_list, N, offset_list) + galsim.utilities.interleaveImages(im_list, N, offset_list, catch_offset_errors=False) # 2a) Increase resolution along one direction - square to rectangular images n = 2 @@ -731,8 +728,8 @@ def test_interleaveImages(): gal1.drawImage(im,offset=offset,method='no_pixel',scale=2.0) im_list.append(im) - img = interleaveImages(im_list, N=[1,n**2], offsets=offset_list, - add_flux=False, suppress_warnings=True) + img = galsim.utilities.interleaveImages(im_list, N=[1,n**2], offsets=offset_list, + add_flux=False, suppress_warnings=True) im = galsim.Image(16,16*n*n) # The interleaved image has the total flux averaged out since `add_flux = False' gal = galsim.Gaussian(sigma=3.7*n,flux=100.) @@ -759,7 +756,7 @@ def test_interleaveImages(): gal2.drawImage(im,offset=offset,method='no_pixel',scale=3.0) im_list.append(im) - img = interleaveImages(im_list, N=np.array([n**2,1]), offsets=offset_list, + img = galsim.utilities.interleaveImages(im_list, N=np.array([n**2,1]), offsets=offset_list, suppress_warnings=True) im = galsim.Image(16*n*n,16*n*n) gal = galsim.Gaussian(sigma=3.7,flux=100.*n*n) @@ -788,8 +785,8 @@ def test_interleaveImages(): im.setOrigin(3,3) # for non-trivial bounds im_list.append(im) - img = interleaveImages(im_list,N=n,offsets=offset_list) - im_list_1, offset_list_1 = deInterleaveImage(img, N=n) + img = galsim.utilities.interleaveImages(im_list,N=n,offsets=offset_list) + im_list_1, offset_list_1 = galsim.utilities.deInterleaveImage(img, N=n) for k in range(n**2): assert offset_list_1[k] == offset_list[k] @@ -800,50 +797,50 @@ def test_interleaveImages(): assert im_list[k].bounds == im_list_1[k].bounds # Checking for non-default flux option - img = interleaveImages(im_list,N=n,offsets=offset_list,add_flux=False) - im_list_2, offset_list_2 = deInterleaveImage(img,N=n,conserve_flux=True) + img = galsim.utilities.interleaveImages(im_list,N=n,offsets=offset_list,add_flux=False) + im_list_2, offset_list_2 = galsim.utilities.deInterleaveImage(img,N=n,conserve_flux=True) for k in range(n**2): assert offset_list_2[k] == offset_list[k] np.testing.assert_array_equal(im_list_2[k].array, im_list[k].array) assert im_list_2[k].wcs == im_list[k].wcs - assert_raises(TypeError, interleaveImages, im_list=img, N=n, offsets=offset_list) - assert_raises(ValueError, interleaveImages, [img], N=1, offsets=offset_list) - assert_raises(ValueError, interleaveImages, im_list, n, offset_list[:-1]) - assert_raises(TypeError, interleaveImages, [im.array for im in im_list], n, offset_list) - assert_raises(TypeError, interleaveImages, + assert_raises(TypeError, galsim.utilities.interleaveImages, im_list=img, N=n, offsets=offset_list) + assert_raises(ValueError, galsim.utilities.interleaveImages, [img], N=1, offsets=offset_list) + assert_raises(ValueError, galsim.utilities.interleaveImages, im_list, n, offset_list[:-1]) + assert_raises(TypeError, galsim.utilities.interleaveImages, [im.array for im in im_list], n, offset_list) + assert_raises(TypeError, galsim.utilities.interleaveImages, [im_list[0]] + [im.array for im in im_list[1:]], n, offset_list) - assert_raises(TypeError, interleaveImages, + assert_raises(TypeError, galsim.utilities.interleaveImages, [galsim.Image(16+i,16+j,scale=1) for i in range(n) for j in range(n)], n, offset_list) - assert_raises(TypeError, interleaveImages, + assert_raises(TypeError, galsim.utilities.interleaveImages, [galsim.Image(16,16,scale=i) for i in range(n) for j in range(n)], n, offset_list) - assert_raises(TypeError, interleaveImages, im_list, N=3.0, offsets=offset_list) - assert_raises(TypeError, interleaveImages, im_list, N=(3.0, 3.0), offsets=offset_list) - assert_raises(TypeError, interleaveImages, im_list, N=(3,3,3), offsets=offset_list) - assert_raises(ValueError, interleaveImages, im_list, N=7, offsets=offset_list) - assert_raises(ValueError, interleaveImages, im_list, N=(2,7), offsets=offset_list) - assert_raises(ValueError, interleaveImages, im_list, N=(7,2), offsets=offset_list) - assert_raises(TypeError, interleaveImages, im_list, N=n) - assert_raises(TypeError, interleaveImages, im_list, N=n, offsets=offset_list[0]) - assert_raises(TypeError, interleaveImages, im_list, N=n, offsets=range(n*n)) + assert_raises(TypeError, galsim.utilities.interleaveImages, im_list, N=3.0, offsets=offset_list) + assert_raises(TypeError, galsim.utilities.interleaveImages, im_list, N=(3.0, 3.0), offsets=offset_list) + assert_raises(TypeError, galsim.utilities.interleaveImages, im_list, N=(3,3,3), offsets=offset_list) + assert_raises(ValueError, galsim.utilities.interleaveImages, im_list, N=7, offsets=offset_list) + assert_raises(ValueError, galsim.utilities.interleaveImages, im_list, N=(2,7), offsets=offset_list) + assert_raises(ValueError, galsim.utilities.interleaveImages, im_list, N=(7,2), offsets=offset_list) + assert_raises(TypeError, galsim.utilities.interleaveImages, im_list, N=n) + assert_raises(TypeError, galsim.utilities.interleaveImages, im_list, N=n, offsets=offset_list[0]) + assert_raises(TypeError, galsim.utilities.interleaveImages, im_list, N=n, offsets=range(n*n)) # It is legal to have the input images with wcs=None, but it emits a warning for im in im_list: im.wcs = None with assert_warns(galsim.GalSimWarning): - interleaveImages(im_list, N=n, offsets=offset_list) + galsim.utilities.interleaveImages(im_list, N=n, offsets=offset_list) # Unless suppress_warnings is True - interleaveImages(im_list, N=n, offsets=offset_list, suppress_warnings=True) + galsim.utilities.interleaveImages(im_list, N=n, offsets=offset_list, suppress_warnings=True) # Also legal to have different origins im_list[0].setCenter(0,0) with assert_warns(galsim.GalSimWarning): - interleaveImages(im_list, N=n, offsets=offset_list) - interleaveImages(im_list, N=n, offsets=offset_list, suppress_warnings=True) + galsim.utilities.interleaveImages(im_list, N=n, offsets=offset_list) + galsim.utilities.interleaveImages(im_list, N=n, offsets=offset_list, suppress_warnings=True) @timer From 4a28f59893aa074e428ca2b30cdc0576960ebda7 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 09:13:19 -0500 Subject: [PATCH 021/351] jax does not do checking --- tests/test_utilities.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index bfce4d289d..0f5fee79cc 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -96,7 +96,8 @@ def test_pos(): assert_raises(TypeError, galsim.PositionI, x=11) assert_raises(TypeError, galsim.PositionD, x=11, y=23, z=17) assert_raises(TypeError, galsim.PositionI, 11, 23, x=13, z=21) - assert_raises(TypeError, galsim.PositionI, 11, 23.5) + if hasattr(galsim, '_galsim'): + assert_raises(TypeError, galsim.PositionI, 11, 23.5) assert_raises(TypeError, galsim.PositionD, 11) assert_raises(TypeError, galsim.PositionD, 11, 23, 9) From 48594bc4e3541584c2237532b8456da6cb0273f0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 09:25:22 -0500 Subject: [PATCH 022/351] jax does not do checking --- tests/test_utilities.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 0f5fee79cc..e1bb3a8ef1 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -260,7 +260,8 @@ def test_bounds(): assert_raises(TypeError, galsim.BoundsI, 11, 23, 9, 12, 59) assert_raises(TypeError, galsim.BoundsI, xmin=11, xmax=23, ymin=17, ymax=50, z=23) assert_raises(TypeError, galsim.BoundsI, xmin=11, xmax=50) - assert_raises(TypeError, galsim.BoundsI, 11, 23.5, 17, 50.9) + if hasattr(galsim, '_galsim'): + assert_raises(TypeError, galsim.BoundsI, 11, 23.5, 17, 50.9) assert_raises(TypeError, galsim.BoundsI, 11, 23, 9, 12, xmin=19, xmax=2) with assert_raises(TypeError): bi1 += (11,23) From 8065c6e03d7907139178083aafc6fe7b6fd5cd6d Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 10:14:38 -0500 Subject: [PATCH 023/351] no range checking for jax --- tests/test_utilities.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index e1bb3a8ef1..c31ac9e92b 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -393,10 +393,11 @@ def test_bounds(): assert galsim.BoundsD() == galsim.BoundsD() + galsim.BoundsD() assert galsim.BoundsD().area() == 0 - assert galsim.BoundsI(23, 11, 17, 50) == galsim.BoundsI() - assert galsim.BoundsI(11, 23, 50, 17) == galsim.BoundsI() - assert galsim.BoundsD(23, 11, 17, 50) == galsim.BoundsD() - assert galsim.BoundsD(11, 23, 50, 17) == galsim.BoundsD() + if hasattr(galsim, "_galsim"): + assert galsim.BoundsI(23, 11, 17, 50) == galsim.BoundsI() + assert galsim.BoundsI(11, 23, 50, 17) == galsim.BoundsI() + assert galsim.BoundsD(23, 11, 17, 50) == galsim.BoundsD() + assert galsim.BoundsD(11, 23, 50, 17) == galsim.BoundsD() assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsI(), 'center') assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsD(), 'center') From 82b60a8688d4ee9bfac26c25ce5bec227d14dc2c Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 13:49:07 -0500 Subject: [PATCH 024/351] compare as array --- tests/test_shear.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_shear.py b/tests/test_shear.py index fbbd650ea3..cbe7293d65 100644 --- a/tests/test_shear.py +++ b/tests/test_shear.py @@ -118,7 +118,7 @@ def test_shear_initialization(): vec_ideal = np.zeros(len(vec)) np.testing.assert_array_almost_equal(vec, vec_ideal, decimal = decimal, err_msg = "Incorrectly initialized empty shear") - np.testing.assert_equal(s.q, 1.) + np.testing.assert_array_equal(s.q, 1.) # now loop over shear values and ways of initializing for ind in range(n_shear): # initialize with reduced shear components From 8b24db67f4b9e5de7edb1c9ad472286eff4e02a3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 18 Sep 2023 13:51:22 -0500 Subject: [PATCH 025/351] compare using numpy --- tests/test_shear_position.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_shear_position.py b/tests/test_shear_position.py index c06a8c4162..888d96c312 100644 --- a/tests/test_shear_position.py +++ b/tests/test_shear_position.py @@ -88,7 +88,7 @@ def test_shear_position_image_integration_pixelwcs(): ) print("err:", np.max(np.abs(im1.array - im2.array))) - assert np.allclose(im1.array, im2.array, rtol=0, atol=5e-8) + np.testing.assert_allclose(im1.array, im2.array, rtol=0, atol=5e-8) @timer @@ -119,9 +119,7 @@ def test_shear_position_image_integration_offsetwcs(): ) print("err:", np.max(np.abs(im1.array - im2.array))) - assert np.allclose(im1.array, im2.array, rtol=0, atol=2e-7), ( - np.max(np.abs(im1.array - im2.array)) - ) + np.testing.assert_allclose(im1.array, im2.array, rtol=0, atol=2e-7) if __name__ == "__main__": From 864b9dd284ad19b8cda64009195b7d01554d0d5e Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 23 Sep 2023 06:11:05 -0500 Subject: [PATCH 026/351] interp test fixes --- tests/test_interpolatedimage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 365c1cfdc7..dd2c8f4946 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -453,8 +453,8 @@ def test_fluxnorm(): # First, make some Image with some total flux value (sum of pixel values) and scale im = galsim.ImageF(im_lin_scale, im_lin_scale, scale=im_scale, init_value=im_fill_value) total_flux = im_fill_value*(im_lin_scale**2) - np.testing.assert_equal(total_flux, im.array.sum(), - err_msg='Created array with wrong total flux') + np.testing.assert_array_equal(total_flux, im.array.sum(), + err_msg='Created array with wrong total flux') # Check that if we make an InterpolatedImage with flux normalization, it keeps that flux interp = galsim.InterpolatedImage(im) # note, flux normalization is the default From f427efa4f5299ea2f3d4d9944507311ffd23ad7b Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 23 Sep 2023 06:14:48 -0500 Subject: [PATCH 027/351] interp test fixes --- tests/test_interpolatedimage.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index dd2c8f4946..d1bf471e77 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -744,8 +744,11 @@ def test_operations(): test_decimal = 3 # Make some nontrivial image - im = galsim.fits.read('./real_comparison_images/test_images.fits') # read in first real galaxy - # in test catalog + im_path = os.path.join( + os.path.dirname(__file__), "real_comparison_images/test_images.fits" + ) + im = galsim.fits.read(im_path) # read in first real galaxy + # in test catalog int_im = galsim.InterpolatedImage(im) orig_mom = im.FindAdaptiveMom() From 8b10124f39f97f21ca5115102fb5b61d4449b153 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 23 Sep 2023 06:17:14 -0500 Subject: [PATCH 028/351] interp test fixes --- tests/test_interpolatedimage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index d1bf471e77..a9b766094a 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1850,7 +1850,10 @@ def test_drawreal_seg_fault(): import pickle - prof_file = 'input/test_interpolatedimage_seg_fault_prof.pkl' + 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)) From 6a34cfed512901b977eb7d6334ed3d55e49c799a Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 23 Sep 2023 06:19:11 -0500 Subject: [PATCH 029/351] interp test fixes --- tests/test_interpolatedimage.py | 61 +++++++++++++++++---------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index a9b766094a..0b7e14caad 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1847,36 +1847,37 @@ def test_depixelize(): def test_drawreal_seg_fault(): """Test to reproduce bug report in Issue #1164 that was causing seg faults """ - - 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) - - # 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) + # this test only runs with real galsim + if hasattr(galsim, '_galsim'): + 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) + + # 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) From 62fad1cd61dfa839fe28b308f665bd034533dd84 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 23 Sep 2023 06:20:23 -0500 Subject: [PATCH 030/351] interp test fixes --- tests/test_interpolatedimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 0b7e14caad..3e4570c643 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1700,7 +1700,7 @@ def test_quintic_glagn(): """This is code that was giving a seg fault. cf. Issue 1079. """ - fname = os.path.join('fits_files','GLAGN_host_427_0_disk.fits') + fname = os.path.join(os.path.dirname(__file__), 'fits_files','GLAGN_host_427_0_disk.fits') for interpolant in 'linear cubic quintic'.split(): print(interpolant) fits_image = galsim.InterpolatedImage(fname, scale=0.04, x_interpolant=interpolant) From 1a593942068048160af74b314ebfc949ea2cda90 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 23 Sep 2023 06:21:28 -0500 Subject: [PATCH 031/351] interp test fixes --- tests/test_interpolatedimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 3e4570c643..cc668713e3 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -957,7 +957,7 @@ def test_corr_padding(): # Set up some defaults for tests. decimal_precise=4 decimal_coarse=2 - imgfile = 'fits_files/blankimg.fits' + imgfile = os.path.join(os.path.dirname(__file__), 'fits_files/blankimg.fits') orig_nx = 187 orig_ny = 164 big_nx = 319 From b49945f4836413cf94dce000b05aec6b8acde647 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 30 Sep 2023 10:03:05 -0500 Subject: [PATCH 032/351] fix doc test --- tests/galsim_test_helpers.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 8c2bdf9fcf..2867cbe593 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -162,8 +162,16 @@ def check_basic_x(prof, name, approx_maxsb=False, scale=None): np.testing.assert_allclose( image(i,j), prof._xValue(galsim.PositionD(x,y)), rtol=1.e-5, err_msg="%s profile sb image does not match _xValue at %d,%d"%(name,i,j)) - assert prof.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ - assert prof.__class__.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ + if hasattr(galsim, "_galsim"): + assert prof.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ + assert prof.__class__.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ + else: + for line in galsim.GSObject.withFlux.__doc__.splitlines(): + if line.strip(): + assert line.strip() in prof.withFlux.__doc__ + for line in galsim.GSObject.withFlux.__doc__.splitlines(): + if line.strip(): + assert line.strip() in prof.__class__.withFlux.__doc__ # Check negative flux: neg_image = prof.withFlux(-prof.flux).drawImage(method='sb', scale=scale, use_true_center=False) From 010868162828f704c70a2c4936f1b6f0af6a5be6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 30 Sep 2023 10:06:01 -0500 Subject: [PATCH 033/351] fix doc test --- tests/galsim_test_helpers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 2867cbe593..6383f1969f 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -168,10 +168,14 @@ def check_basic_x(prof, name, approx_maxsb=False, scale=None): else: for line in galsim.GSObject.withFlux.__doc__.splitlines(): if line.strip(): - assert line.strip() in prof.withFlux.__doc__ + assert line.strip() in prof.withFlux.__doc__, ( + prof.withFlux.__doc__, galsim.GSObject.withFlux.__doc__, + ) for line in galsim.GSObject.withFlux.__doc__.splitlines(): if line.strip(): - assert line.strip() in prof.__class__.withFlux.__doc__ + assert line.strip() in prof.__class__.withFlux.__doc__, ( + prof.__class__.withFlux.__doc__, galsim.GSObject.withFlux.__doc__, + ) # Check negative flux: neg_image = prof.withFlux(-prof.flux).drawImage(method='sb', scale=scale, use_true_center=False) From dd7bf6eee075f9421dc64ae95beb228511399db1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 30 Sep 2023 10:07:43 -0500 Subject: [PATCH 034/351] fix doc test --- tests/galsim_test_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 6383f1969f..26e249cbcc 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -167,12 +167,12 @@ def check_basic_x(prof, name, approx_maxsb=False, scale=None): assert prof.__class__.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ else: for line in galsim.GSObject.withFlux.__doc__.splitlines(): - if line.strip(): + if line.strip() and "LAX" not in line: assert line.strip() in prof.withFlux.__doc__, ( prof.withFlux.__doc__, galsim.GSObject.withFlux.__doc__, ) for line in galsim.GSObject.withFlux.__doc__.splitlines(): - if line.strip(): + if line.strip() and "LAX" not in line: assert line.strip() in prof.__class__.withFlux.__doc__, ( prof.__class__.withFlux.__doc__, galsim.GSObject.withFlux.__doc__, ) From 8caaacfea8f481ea4b3c85b68cf5374acfaee6c1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 4 Oct 2023 14:22:30 -0500 Subject: [PATCH 035/351] TST fix tests for jax --- tests/test_wcs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index bd5e4d3690..4c9f2c13cb 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -1180,7 +1180,8 @@ def test_pixelscale(): assert wcs.world_origin == galsim.PositionD(0,0) assert_raises(TypeError, galsim.PixelScale) - assert_raises(TypeError, galsim.PixelScale, scale=galsim.PixelScale(scale)) + if hasattr(galsim, "_galsim"): + assert_raises(TypeError, galsim.PixelScale, scale=galsim.PixelScale(scale)) assert_raises(TypeError, galsim.PixelScale, scale=scale, origin=galsim.PositionD(0,0)) assert_raises(TypeError, galsim.PixelScale, scale=scale, world_origin=galsim.PositionD(0,0)) From a31673d69779b7a01e554187cb09bd16409a9d26 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 4 Oct 2023 16:13:32 -0500 Subject: [PATCH 036/351] TST more test fixes for jax --- tests/test_convolve.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_convolve.py b/tests/test_convolve.py index 99ca3b8fdf..1a9baf61e7 100644 --- a/tests/test_convolve.py +++ b/tests/test_convolve.py @@ -497,9 +497,9 @@ def test_deconvolve(): cen = galsim.PositionD(0,0) np.testing.assert_equal(inv_psf.centroid, cen) - np.testing.assert_almost_equal(inv_psf.flux, 1./psf.flux) + np.testing.assert_array_almost_equal(inv_psf.flux, 1./psf.flux) # This doesn't really have any meaning, but this is what we've assigned to a deconvolve max_sb. - np.testing.assert_almost_equal(inv_psf.max_sb, -psf.max_sb / psf.flux**2) + np.testing.assert_array_almost_equal(inv_psf.max_sb, -psf.max_sb / psf.flux**2) check_basic(inv_psf, "Deconvolve(Moffat)", do_x=False) From 3e648096c6d3f32766f5e52e11b7eeaea326758b Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 8 Oct 2023 07:55:12 -0400 Subject: [PATCH 037/351] TST fix tests for jax --- tests/test_shear.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_shear.py b/tests/test_shear.py index cbe7293d65..abf0368320 100644 --- a/tests/test_shear.py +++ b/tests/test_shear.py @@ -178,11 +178,12 @@ def test_shear_initialization(): assert_raises(TypeError,galsim.Shear,g1=0.3,e2=0.2) assert_raises(TypeError,galsim.Shear,eta1=0.3,beta=0.*galsim.degrees) assert_raises(TypeError,galsim.Shear,q=0.3) - assert_raises(galsim.GalSimRangeError,galsim.Shear,q=1.3,beta=0.*galsim.degrees) - assert_raises(galsim.GalSimRangeError,galsim.Shear,g1=0.9,g2=0.6) - assert_raises(galsim.GalSimRangeError,galsim.Shear,e=-1.3,beta=0.*galsim.radians) - assert_raises(galsim.GalSimRangeError,galsim.Shear,e=1.3,beta=0.*galsim.radians) - assert_raises(galsim.GalSimRangeError,galsim.Shear,e1=0.7,e2=0.9) + if hasattr(galsim, "_galsim"): + assert_raises(galsim.GalSimRangeError,galsim.Shear,q=1.3,beta=0.*galsim.degrees) + assert_raises(galsim.GalSimRangeError,galsim.Shear,g1=0.9,g2=0.6) + assert_raises(galsim.GalSimRangeError,galsim.Shear,e=-1.3,beta=0.*galsim.radians) + assert_raises(galsim.GalSimRangeError,galsim.Shear,e=1.3,beta=0.*galsim.radians) + assert_raises(galsim.GalSimRangeError,galsim.Shear,e1=0.7,e2=0.9) assert_raises(TypeError,galsim.Shear,g=0.5) assert_raises(TypeError,galsim.Shear,e=0.5) assert_raises(TypeError,galsim.Shear,eta=0.5) From f1beb3a8ce1ca0323e55b1855ffa7f343059aad1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 8 Oct 2023 07:56:11 -0400 Subject: [PATCH 038/351] TST fix tests for jax --- tests/test_shear.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_shear.py b/tests/test_shear.py index abf0368320..fb71440726 100644 --- a/tests/test_shear.py +++ b/tests/test_shear.py @@ -187,9 +187,10 @@ def test_shear_initialization(): assert_raises(TypeError,galsim.Shear,g=0.5) assert_raises(TypeError,galsim.Shear,e=0.5) assert_raises(TypeError,galsim.Shear,eta=0.5) - assert_raises(galsim.GalSimRangeError,galsim.Shear,eta=-0.5,beta=0.*galsim.radians) - assert_raises(galsim.GalSimRangeError,galsim.Shear,g=1.3,beta=0.*galsim.radians) - assert_raises(galsim.GalSimRangeError,galsim.Shear,g=-0.3,beta=0.*galsim.radians) + if hasattr(galsim, "_galsim"): + assert_raises(galsim.GalSimRangeError,galsim.Shear,eta=-0.5,beta=0.*galsim.radians) + assert_raises(galsim.GalSimRangeError,galsim.Shear,g=1.3,beta=0.*galsim.radians) + assert_raises(galsim.GalSimRangeError,galsim.Shear,g=-0.3,beta=0.*galsim.radians) assert_raises(TypeError,galsim.Shear,e=0.3,beta=0.) assert_raises(TypeError,galsim.Shear,eta=0.3,beta=0.) assert_raises(TypeError,galsim.Shear,randomkwarg=0.1) From d63cbdef5e81528ebdca2a18ae100530c8aa23ea Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 8 Oct 2023 11:08:41 -0400 Subject: [PATCH 039/351] TST fix tests for jax --- tests/test_wcs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 4c9f2c13cb..8b89a51cf6 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2580,7 +2580,7 @@ def test_fitswcs(): except: pass - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') for tag in test_tags: file_name, ref_list = references[tag] @@ -2688,7 +2688,7 @@ def test_fittedsipwcs(): 'ZTF': (0.1, 0.1), } - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') if __name__ == "__main__": test_tags = all_tags @@ -2917,7 +2917,7 @@ def test_fittedsipwcs(): def test_scamp(): """Test that we can read in a SCamp .head file correctly """ - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') file_name = 'scamp.head' wcs = galsim.FitsWCS(file_name, dir=dir, text_file=True) @@ -3138,7 +3138,7 @@ def test_int_args(): test_tags = all_tags - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') for tag in test_tags: file_name, ref_list = references[tag] @@ -3211,7 +3211,7 @@ def test_razero(): import astropy.wcs import scipy # AstropyWCS constructor will do this, so check now. - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') # This file is based in sipsample.fits, but with the CRVAL1 changed to 0.002322805429 file_name = 'razero.fits' wcs = galsim.AstropyWCS(file_name, dir=dir) From 66f60843113462364f026e5407f219b5bca23336 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 16 Oct 2023 02:20:25 -0500 Subject: [PATCH 040/351] Update galsim_test_helpers.py --- tests/galsim_test_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 26e249cbcc..4a752edf33 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -44,8 +44,8 @@ "do_kvalue", "radial_integrate", "drawNoise", - "do_pickle", - "all_obj_diff", + "check_pickle", + "check_all_diff", "funcname", "timer", "CaptureLog", From fc557d16e6820e426e5e12fa43ea8fc686d85562 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 16 Oct 2023 06:19:43 -0500 Subject: [PATCH 041/351] Update tests/galsim_test_helpers.py --- tests/galsim_test_helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 4a752edf33..748fb48fa1 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -46,7 +46,6 @@ "drawNoise", "check_pickle", "check_all_diff", - "funcname", "timer", "CaptureLog", "assert_raises", From 57dc77f99f3d2ce221d57b25716f1b5953b50590 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 16 Oct 2023 06:28:17 -0500 Subject: [PATCH 042/351] Update tests/galsim_test_helpers.py --- tests/galsim_test_helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 748fb48fa1..aba9998174 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -50,7 +50,6 @@ "CaptureLog", "assert_raises", "assert_warns", - "profile", ] # This file has some helper functions that are used by tests from multiple files to help From 153587d830650efaaf0bcdb630c8e9b266317bef Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 07:01:33 -0500 Subject: [PATCH 043/351] readd Profile --- tests/galsim_test_helpers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index aba9998174..9197a84ccd 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -50,6 +50,7 @@ "CaptureLog", "assert_raises", "assert_warns", + "Profile", ] # This file has some helper functions that are used by tests from multiple files to help From 5140919da7b5a71ff5461149117b083d788924d0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 07:07:30 -0500 Subject: [PATCH 044/351] fix more tests --- tests/test_celestial.py | 1 + tests/test_chromatic.py | 1 + tests/test_config_gsobject.py | 1 + tests/test_correlatednoise.py | 1 + tests/test_download.py | 1 + tests/test_errors.py | 1 + tests/test_main.py | 1 + tests/test_roman.py | 2 ++ 8 files changed, 9 insertions(+) diff --git a/tests/test_celestial.py b/tests/test_celestial.py index 71bc251c98..4839d9b46c 100644 --- a/tests/test_celestial.py +++ b/tests/test_celestial.py @@ -17,6 +17,7 @@ # import numpy +import numpy as np import os import sys import math diff --git a/tests/test_chromatic.py b/tests/test_chromatic.py index 303fdeadc3..6b69260f63 100644 --- a/tests/test_chromatic.py +++ b/tests/test_chromatic.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import copy import os import numpy as np diff --git a/tests/test_config_gsobject.py b/tests/test_config_gsobject.py index 04776354e3..a6cfc82381 100644 --- a/tests/test_config_gsobject.py +++ b/tests/test_config_gsobject.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import logging import numpy as np import os import sys diff --git a/tests/test_correlatednoise.py b/tests/test_correlatednoise.py index be6994f885..caed1976f7 100644 --- a/tests/test_correlatednoise.py +++ b/tests/test_correlatednoise.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import os import time import numpy as np diff --git a/tests/test_download.py b/tests/test_download.py index 04070f8a1f..92e6414bf2 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import os import sys import logging import builtins diff --git a/tests/test_errors.py b/tests/test_errors.py index fcd70314a6..ba0e016682 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import numpy as np import galsim from galsim_test_helpers import * diff --git a/tests/test_main.py b/tests/test_main.py index d1e1114427..c35041e4e3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import os import sys import logging from unittest import mock diff --git a/tests/test_roman.py b/tests/test_roman.py index 4a041fc90a..de2b0127c1 100644 --- a/tests/test_roman.py +++ b/tests/test_roman.py @@ -16,6 +16,8 @@ # and/or other materials provided with the distribution. # +import logging +import os import numpy as np import datetime from unittest import mock From 11731e12e4c0094e8f4dc98bab5a71c2099857f3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 09:50:20 -0500 Subject: [PATCH 045/351] fix more tests and make import patchable --- galsim/utilities.py | 6 ++++-- tests/test_roman.py | 1 + tests/test_table.py | 2 +- tests/test_wcs.py | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/galsim/utilities.py b/galsim/utilities.py index 88ccfd7f17..0803bf83a2 100644 --- a/galsim/utilities.py +++ b/galsim/utilities.py @@ -36,6 +36,10 @@ import copy from distutils.version import LooseVersion +# import these here so JAX-GalSim can patch them +import galsim +import coord + from . import _galsim from .errors import GalSimError, GalSimValueError, GalSimIncompatibleValuesError, GalSimRangeError from .errors import galsim_warn @@ -1576,8 +1580,6 @@ def check_pickle(obj, func = lambda x : x, irreprable=False, random=None): it has an rng attribute or it is a galsim.BaseDeviate] """ # In case the repr uses these: - import galsim - import coord import astropy from numpy import array, uint16, uint32, int16, int32, float32, float64, complex64, complex128, ndarray from astropy.units import Unit diff --git a/tests/test_roman.py b/tests/test_roman.py index de2b0127c1..d6846a053d 100644 --- a/tests/test_roman.py +++ b/tests/test_roman.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import sys import logging import os import numpy as np diff --git a/tests/test_table.py b/tests/test_table.py index aa8d6d5e8a..3863243757 100644 --- a/tests/test_table.py +++ b/tests/test_table.py @@ -16,7 +16,7 @@ # and/or other materials provided with the distribution. # - +import sys import os import numpy as np import time diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 8b89a51cf6..6c3334f84c 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -23,6 +23,7 @@ import time from unittest import mock +import coord import galsim from galsim_test_helpers import * From 3307774317331e7850bf1e424ab199716ade475f Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 10:04:20 -0500 Subject: [PATCH 046/351] debug compiler --- setup.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 0428a39117..c9a5cb2110 100644 --- a/setup.py +++ b/setup.py @@ -122,6 +122,10 @@ def all_files_from(dir, ext=''): if "--debug" in sys.argv or "--verbose" in sys.argv: debug = True +debug = True + + + local_tmp = 'tmp' def get_compiler_type(compiler, check_unknown=True, output=False): @@ -245,7 +249,7 @@ def supports_gpu(compiler, cc_type): extra_cflags = copt[cc_type] extra_lflags = lopt[cc_type] return try_compile(cpp_code, compiler, extra_cflags, extra_lflags) - + # Check for the fftw3 library in some likely places def find_fftw_lib(output=False): import distutils.sysconfig @@ -435,29 +439,29 @@ def find_eigen_dir(output=False): if output: print("Downloaded %s. Unpacking tarball."%fname) with tarfile.open(fname) as tar: - + def is_within_directory(directory, target): - + abs_directory = os.path.abspath(directory) abs_target = os.path.abspath(target) - + prefix = os.path.commonprefix([abs_directory, abs_target]) - + return prefix == abs_directory - + def safe_extract(tar, path=".", members=None, *, numeric_owner=False): # Avoid security vulnerability in tar.extractall function. # This bit of code was added by the Advanced Research Center at Trellix in PR #1188. # For more information about the security vulnerability, see # https://github.com/advisories/GHSA-gw9q-c7gh-j9vm - + for member in tar.getmembers(): member_path = os.path.join(path, member.name) if not is_within_directory(path, member_path): raise Exception("Attempted Path Traversal in Tar File") - - tar.extractall(path, members, numeric_owner=numeric_owner) - + + tar.extractall(path, members, numeric_owner=numeric_owner) + safe_extract(tar, dir) os.remove(fname) # This actually extracts into a subdirectory with a name eigen-eigen-5a0156e40feb/ From 3ff98ecd7cde9e70c326bceca9682915c4c6171d Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 16 Oct 2023 11:15:10 -0500 Subject: [PATCH 047/351] Update setup.py --- setup.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setup.py b/setup.py index c9a5cb2110..efd1af5922 100644 --- a/setup.py +++ b/setup.py @@ -122,10 +122,6 @@ def all_files_from(dir, ext=''): if "--debug" in sys.argv or "--verbose" in sys.argv: debug = True -debug = True - - - local_tmp = 'tmp' def get_compiler_type(compiler, check_unknown=True, output=False): From c6f9ead13677a183c012cf9612c5e6824767062d Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 15:37:59 -0500 Subject: [PATCH 048/351] array --- tests/test_interpolatedimage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index cc668713e3..bef0c90ca0 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -488,8 +488,8 @@ def test_fluxnorm(): # Finally make an InterpolatedImage but give it some other flux value interp_flux = galsim.InterpolatedImage(im, flux=test_flux) # Check that it has that flux - np.testing.assert_equal(test_flux, interp_flux.flux, - err_msg = 'InterpolatedImage did not use flux keyword') + np.testing.assert_array_equal(test_flux, interp_flux.flux, + err_msg = 'InterpolatedImage did not use flux keyword') # Check that this is preserved when drawing im5 = interp_flux.drawImage(scale = im_scale, method='no_pixel') np.testing.assert_almost_equal(test_flux/im5.array.sum(), 1.0, decimal=6, From e71e54135f433f43815a6c746bf63842b615a828 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 15:42:30 -0500 Subject: [PATCH 049/351] ENH arrays again --- tests/test_moffat.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 5e8bf6e11c..78d2f0db60 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -136,36 +136,36 @@ def test_moffat_properties(): cen = galsim.PositionD(0, 0) np.testing.assert_equal(psf.centroid, cen) # Check Fourier properties - 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) + 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) # 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_almost_equal(psf.maxk, 11.634597426100862) - 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) + np.testing.assert_array_almost_equal(psf.maxk, 11.634597426100862) + 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) # Check input flux vs output flux for inFlux in np.logspace(-2, 2, 10): psfFlux = galsim.Moffat(2.0, fwhm=fwhm_backwards_compatible, trunc=2*fwhm_backwards_compatible, flux=inFlux) outFlux = psfFlux.flux - np.testing.assert_almost_equal(outFlux, inFlux) + np.testing.assert_array_almost_equal(outFlux, inFlux) @timer def test_moffat_maxk(): From c59a64a0e83d8c4287d5da823848afaf3a8db4de Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 16:20:26 -0500 Subject: [PATCH 050/351] adjust tol --- tests/test_moffat.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 78d2f0db60..97e8d218e6 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -24,8 +24,9 @@ from galsim_test_helpers import * path, filename = os.path.split(__file__) -imgdir = os.path.join(path, "SBProfile_comparison_images") # Directory containing the reference - # images. +# Directory containing the reference images. +imgdir = os.path.join(path, "SBProfile_comparison_images") + @timer def test_moffat(): @@ -198,7 +199,11 @@ def test_moffat_maxk(): rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') - np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) + if hasattr(galsim, "_galsim"): + rtol_fac = 10.0 + else: + rtol_fac = 1.0 + np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol * rtol_fac) @timer From 7911734bbd08a43a2e0e83390921223cf3f7fe89 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 16:21:11 -0500 Subject: [PATCH 051/351] adjust tol --- tests/test_moffat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 97e8d218e6..957ee7d439 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -200,9 +200,9 @@ def test_moffat_maxk(): fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') if hasattr(galsim, "_galsim"): - rtol_fac = 10.0 - else: rtol_fac = 1.0 + else: + rtol_fac = 100.0 np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol * rtol_fac) From 1a27ee8f519107f3e78b61b843e86f848d96d87e Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 16:22:14 -0500 Subject: [PATCH 052/351] adjust tol --- tests/test_moffat.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 957ee7d439..4a2222db94 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -196,14 +196,14 @@ def test_moffat_maxk(): for psf in psfs: for thresh in threshs: psf = psf.withGSParams(maxk_threshold=thresh) - rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 + fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') if hasattr(galsim, "_galsim"): - rtol_fac = 1.0 + rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 else: - rtol_fac = 100.0 - np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol * rtol_fac) + rtol = 1.e-4 if psf.trunc == 0 else 3.e-3 + np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) @timer From f68bccab2e4768094aa6dafbfa0380760d1a4e41 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 16:23:13 -0500 Subject: [PATCH 053/351] adjust tol --- tests/test_moffat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 4a2222db94..d4fd97755d 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -201,9 +201,11 @@ def test_moffat_maxk(): print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') if hasattr(galsim, "_galsim"): rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 + atol = 0 else: - rtol = 1.e-4 if psf.trunc == 0 else 3.e-3 - np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) + rtol = 0.0 + atol = 1e-4 + np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol, atol=atol) @timer From fb71863c109bcc8aa681159c08ddc5c1a39064ef Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 16:24:07 -0500 Subject: [PATCH 054/351] adjust tol --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index d4fd97755d..9122e6449a 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -204,7 +204,7 @@ def test_moffat_maxk(): atol = 0 else: rtol = 0.0 - atol = 1e-4 + atol = 1e-2 np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol, atol=atol) From 3d317a05e67da52e9b0976a9e1b2f857ab52cee6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 16:25:33 -0500 Subject: [PATCH 055/351] adjust tol --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 9122e6449a..d5243f0029 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -204,7 +204,7 @@ def test_moffat_maxk(): atol = 0 else: rtol = 0.0 - atol = 1e-2 + atol = 2e-2 np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol, atol=atol) From 6368c114fd7268683e035ff963c4aad1e34c79a0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 16:26:15 -0500 Subject: [PATCH 056/351] adjust tol --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index d5243f0029..badd6c1e4c 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -204,7 +204,7 @@ def test_moffat_maxk(): atol = 0 else: rtol = 0.0 - atol = 2e-2 + atol = 1e-1 np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol, atol=atol) From da627a791ebb395c425c4092b11f2ff7f0a63f6d Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 22:09:33 -0500 Subject: [PATCH 057/351] adjust tol --- tests/test_moffat.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index badd6c1e4c..d3d9e35cef 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -199,12 +199,12 @@ def test_moffat_maxk(): fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') - if hasattr(galsim, "_galsim"): - rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 - atol = 0 - else: - rtol = 0.0 - atol = 1e-1 + # if hasattr(galsim, "_galsim"): + rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 + atol = 0 + # else: + # rtol = 0.0 + # atol = 1e-1 np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol, atol=atol) From 84ad789e02469f7d782140093d8f0f291e3c1935 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 23:13:56 -0500 Subject: [PATCH 058/351] adjust tol --- tests/test_moffat.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index d3d9e35cef..c1acde800f 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -191,21 +191,15 @@ def test_moffat_maxk(): galsim.Moffat(beta=3.6, scale_radius=9, flux=23, trunc=50), galsim.Moffat(beta=12.9, scale_radius=11, flux=23, trunc=1000), ] + rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 threshs = [1.e-3, 1.e-4, 0.03] print('beta \t trunc \t thresh \t kValue(maxk)') for psf in psfs: for thresh in threshs: psf = psf.withGSParams(maxk_threshold=thresh) - fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') - # if hasattr(galsim, "_galsim"): - rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 - atol = 0 - # else: - # rtol = 0.0 - # atol = 1e-1 - np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol, atol=atol) + np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) @timer From 6523ab512299adc99a94e3aff1b7cefc695767f9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 16 Oct 2023 23:14:59 -0500 Subject: [PATCH 059/351] adjust tol --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index c1acde800f..47e72a4f28 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -191,12 +191,12 @@ def test_moffat_maxk(): galsim.Moffat(beta=3.6, scale_radius=9, flux=23, trunc=50), galsim.Moffat(beta=12.9, scale_radius=11, flux=23, trunc=1000), ] - rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 threshs = [1.e-3, 1.e-4, 0.03] print('beta \t trunc \t thresh \t kValue(maxk)') for psf in psfs: for thresh in threshs: psf = psf.withGSParams(maxk_threshold=thresh) + rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) From 269096dd0ead4ddaa917d95fad8da231bb5c67a5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 17 Oct 2023 05:11:38 -0500 Subject: [PATCH 060/351] adjust tol --- tests/test_moffat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 47e72a4f28..a2fd1266f5 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -192,13 +192,13 @@ def test_moffat_maxk(): galsim.Moffat(beta=12.9, scale_radius=11, flux=23, trunc=1000), ] threshs = [1.e-3, 1.e-4, 0.03] - print('beta \t trunc \t thresh \t kValue(maxk)') + print('beta \t trunc \t thresh \t kValue(maxk) \t maxk') for psf in psfs: for thresh in threshs: psf = psf.withGSParams(maxk_threshold=thresh) rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 fk = psf.kValue(psf.maxk,0).real/psf.flux - print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e}') + print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e} \t {psf.maxk:.3e}') np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) From 66e870b7d5df9218168d9a4f0a95711027061692 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 17 Oct 2023 07:05:58 -0500 Subject: [PATCH 061/351] adjust tol --- tests/test_moffat.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index a2fd1266f5..66b34e5414 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -137,7 +137,10 @@ 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) + if hasattr(galsim, "_galsim"): + np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) + else: + np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) 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) @@ -151,7 +154,10 @@ def test_moffat_properties(): 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.634597426100862) + if hasattr(galsim, "_galsim"): + np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) + else: + np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) 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) @@ -196,7 +202,10 @@ def test_moffat_maxk(): for psf in psfs: for thresh in threshs: psf = psf.withGSParams(maxk_threshold=thresh) - rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 + if hasattr(galsim, "_galsim"): + rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 + else: + rtol = 5e-3 fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e} \t {psf.maxk:.3e}') np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) From ca90d938a3b16450b84452720068e0b558842bbb Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 17 Oct 2023 07:09:17 -0500 Subject: [PATCH 062/351] adjust tol --- tests/test_moffat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 66b34e5414..3de13ae97b 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -140,7 +140,7 @@ def test_moffat_properties(): if hasattr(galsim, "_galsim"): np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) else: - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) 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) @@ -157,7 +157,7 @@ def test_moffat_properties(): if hasattr(galsim, "_galsim"): np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) else: - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) 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) From 2f7bef0899067f538dc41a79948e4ede478298cc Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 17 Oct 2023 14:42:16 -0500 Subject: [PATCH 063/351] adjust tol --- tests/test_moffat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 3de13ae97b..d5da6578f4 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -140,7 +140,7 @@ def test_moffat_properties(): if hasattr(galsim, "_galsim"): np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) else: - np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.1) 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) @@ -157,7 +157,7 @@ def test_moffat_properties(): if hasattr(galsim, "_galsim"): np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) else: - np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.25) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.1) 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) From 815090419d343d0e840bbc53e79c7bc4469ec79d Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 17 Oct 2023 14:43:08 -0500 Subject: [PATCH 064/351] adjust tol --- tests/test_moffat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index d5da6578f4..9109b66631 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -140,7 +140,7 @@ def test_moffat_properties(): if hasattr(galsim, "_galsim"): np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) else: - np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.1) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) 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) @@ -157,7 +157,7 @@ def test_moffat_properties(): if hasattr(galsim, "_galsim"): np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) else: - np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.1) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) 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) From b018d57fba88eabbaacf40d34d3029a77e7071f2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 17 Oct 2023 22:51:40 -0500 Subject: [PATCH 065/351] adjust tol --- galsim/utilities.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/galsim/utilities.py b/galsim/utilities.py index 0803bf83a2..88ccfd7f17 100644 --- a/galsim/utilities.py +++ b/galsim/utilities.py @@ -36,10 +36,6 @@ import copy from distutils.version import LooseVersion -# import these here so JAX-GalSim can patch them -import galsim -import coord - from . import _galsim from .errors import GalSimError, GalSimValueError, GalSimIncompatibleValuesError, GalSimRangeError from .errors import galsim_warn @@ -1580,6 +1576,8 @@ def check_pickle(obj, func = lambda x : x, irreprable=False, random=None): it has an rng attribute or it is a galsim.BaseDeviate] """ # In case the repr uses these: + import galsim + import coord import astropy from numpy import array, uint16, uint32, int16, int32, float32, float64, complex64, complex128, ndarray from astropy.units import Unit From 5b3d4910aec5b58a41faadbc6b267b188a93e521 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 20 Oct 2023 00:35:17 -0500 Subject: [PATCH 066/351] set according to jax_galsim --- tests/test_interpolatedimage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index bef0c90ca0..d7f160177b 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1635,7 +1635,10 @@ def test_ne(): # Copy ref_image and perturb it slightly in the middle, away from where the InterpolatedImage # repr string will report. perturb_image = ref_image.copy() - perturb_image.array[64, 64] *= 1000 + if hasattr(galsim, "_galsim"): + perturb_image.array[64, 64] *= 1000 + else: + perturb_image._array = perturb_image._array.at[64, 64].set(perturb_image._array[64, 64] * 1000) obj2 = galsim.InterpolatedImage(perturb_image, flux=20, calculate_maxk=False, calculate_stepk=False) with galsim.utilities.printoptions(threshold=128*128): From 380bab83e57042fe7c2530636453908ee2482add Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 20 Oct 2023 16:54:05 -0500 Subject: [PATCH 067/351] make test pass using less dynamic range --- tests/test_interpolatedimage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index d7f160177b..bc49fa9282 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1636,9 +1636,9 @@ def test_ne(): # repr string will report. perturb_image = ref_image.copy() if hasattr(galsim, "_galsim"): - perturb_image.array[64, 64] *= 1000 + perturb_image.array[64, 64] *= 100 else: - perturb_image._array = perturb_image._array.at[64, 64].set(perturb_image._array[64, 64] * 1000) + perturb_image._array = perturb_image._array.at[64, 64].set(perturb_image._array[64, 64] * 100) obj2 = galsim.InterpolatedImage(perturb_image, flux=20, calculate_maxk=False, calculate_stepk=False) with galsim.utilities.printoptions(threshold=128*128): From ca26e813ef3e96139320966d13c4d30b150458a9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 23 Oct 2023 09:35:28 -0500 Subject: [PATCH 068/351] jax galsim does not raise --- tests/test_interpolatedimage.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index d7f160177b..79afbe9e42 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -511,12 +511,13 @@ def test_exceptions(): galsim.InterpolatedImage(image=galsim.ImageF(5, 5)) # Image must be real type (F or D) - with assert_raises(galsim.GalSimValueError): - galsim.InterpolatedImage(image=galsim.ImageI(5, 5, scale=1)) + if hasattr(galsim, "_galsim"): + with assert_raises(galsim.GalSimValueError): + galsim.InterpolatedImage(image=galsim.ImageI(5, 5, scale=1)) - # Image must have non-zero flux - with assert_raises(galsim.GalSimValueError): - galsim.InterpolatedImage(image=galsim.ImageF(5, 5, scale=1, init_value=0.)) + # Image must have non-zero flux + with assert_raises(galsim.GalSimValueError): + galsim.InterpolatedImage(image=galsim.ImageF(5, 5, scale=1, init_value=0.)) # Can't shoot II with SincInterpolant ii = galsim.InterpolatedImage(image=galsim.ImageF(5, 5, scale=1, init_value=1.), From 849bc9d3d47b485486d8c2dd35df884ea9a93c1b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 7 Nov 2023 09:01:16 -0600 Subject: [PATCH 069/351] TST make sure to get proper test dir --- tests/test_wcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 6c3334f84c..21fa21c799 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2371,7 +2371,7 @@ def test_gsfitswcs(): # And it's required to get (relatively) complete test coverage. test_tags = [ 'TAN', 'STG', 'ZEA', 'ARC', 'TPV', 'TAN-PV', 'TAN-FLIP', 'TNX', 'SIP', 'ZTF' ] - dir = 'fits_files' + dir = os.path.join(os.path.dirname(__file__), 'fits_files') for tag in test_tags: file_name, ref_list = references[tag] From 05fcbdf43c46d374f7544903abc98630a35a7a6e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 7 Nov 2023 15:00:14 -0600 Subject: [PATCH 070/351] TST fix array comp --- tests/test_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index c31ac9e92b..5d5ae2e231 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1149,7 +1149,7 @@ def test_horner(): # Check using a different dtype result = galsim.utilities.horner(x, coef, dtype=complex) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Check that a single element coef gives the right answer result = galsim.utilities.horner([1,2,3], [17]) From 58d217d593f4725896fb0fbd13b4925254e6179e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 7 Nov 2023 15:03:40 -0600 Subject: [PATCH 071/351] TST array comps --- tests/test_utilities.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 5d5ae2e231..f27a924dec 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1134,18 +1134,18 @@ def test_horner(): # Check against the direct calculation truth = coef[0] + coef[1]*x + coef[2]*x**2 + coef[3]*x**3 + coef[4]*x**4 result = galsim.utilities.horner(x, coef) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Also check against the (slower) numpy code - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(x,coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(x,coef)) # Check that trailing zeros give the same answer result = galsim.utilities.horner(x, coef + [0]*3) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Check that leading zeros give the right answer result = galsim.utilities.horner(x, [0]*3 + coef) - np.testing.assert_almost_equal(result, truth*x**3) + np.testing.assert_array_almost_equal(result, truth*x**3) # Check using a different dtype result = galsim.utilities.horner(x, coef, dtype=complex) @@ -1153,43 +1153,43 @@ def test_horner(): # Check that a single element coef gives the right answer result = galsim.utilities.horner([1,2,3], [17]) - np.testing.assert_almost_equal(result, 17) + np.testing.assert_array_almost_equal(result, 17) result = galsim.utilities.horner(x, [17]) - np.testing.assert_almost_equal(result, 17) + np.testing.assert_array_almost_equal(result, 17) result = galsim.utilities.horner([1,2,3], [17,0,0,0]) - np.testing.assert_almost_equal(result, 17) + np.testing.assert_array_almost_equal(result, 17) result = galsim.utilities.horner(x, [17,0,0,0]) - np.testing.assert_almost_equal(result, 17) + np.testing.assert_array_almost_equal(result, 17) result = galsim.utilities.horner([1,2,3], [0,0,0,0]) - np.testing.assert_almost_equal(result, 0) + np.testing.assert_array_almost_equal(result, 0) result = galsim.utilities.horner(x, [0,0,0,0]) - np.testing.assert_almost_equal(result, 0) + np.testing.assert_array_almost_equal(result, 0) # Check that x may be non-contiguous result = galsim.utilities.horner(x[::3], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(x[::3],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(x[::3],coef)) # Check that coef may be non-contiguous result = galsim.utilities.horner(x, coef[::-1]) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(x,coef[::-1])) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(x,coef[::-1])) # Check odd length result = galsim.utilities.horner(x[:15], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(x[:15],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(x[:15],coef)) # Check unaligned array result = galsim.utilities.horner(x[1:], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(x[1:],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(x[1:],coef)) # Check length > 64 xx = np.empty(2000) rng.generate(xx) result = galsim.utilities.horner(xx, coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(xx,coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(xx,coef)) # Check scalar x result = galsim.utilities.horner(3.9, coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval([3.9],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval([3.9],coef)) # Check invalid arguments with assert_raises(galsim.GalSimValueError): From dd3ab67cf804377dc03c4838d628b10e57cf1426 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 7 Nov 2023 15:30:26 -0600 Subject: [PATCH 072/351] TST array comps --- tests/test_utilities.py | 72 ++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index f27a924dec..1e58088bbe 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1215,58 +1215,58 @@ def test_horner2d(): truth += (coef[1,0] + coef[1,1]*y + coef[1,2]*y**2 + coef[1,3]*y**3 + coef[1,4]*y**4)*x truth += (coef[2,0] + coef[2,1]*y + coef[2,2]*y**2 + coef[2,3]*y**3 + coef[2,4]*y**4)*x**2 result = galsim.utilities.horner2d(x, y, coef) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Also check against the (slower) numpy code - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x,y,coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x,y,coef)) # Check that trailing zeros give the same answer result = galsim.utilities.horner2d(x, y, np.hstack([coef, np.zeros((3,1))])) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) result = galsim.utilities.horner2d(x, y, np.hstack([coef, np.zeros((3,6))])) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) result = galsim.utilities.horner2d(x, y, np.vstack([coef, np.zeros((1,5))])) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) result = galsim.utilities.horner2d(x, y, np.vstack([coef, np.zeros((6,5))])) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Check that leading zeros give the right answer result = galsim.utilities.horner2d(x, y, np.hstack([np.zeros((3,1)), coef])) - np.testing.assert_almost_equal(result, truth*y) + np.testing.assert_array_almost_equal(result, truth*y) result = galsim.utilities.horner2d(x, y, np.hstack([np.zeros((3,6)), coef])) - np.testing.assert_almost_equal(result, truth*y**6) + np.testing.assert_array_almost_equal(result, truth*y**6) result = galsim.utilities.horner2d(x, y, np.vstack([np.zeros((1,5)), coef])) - np.testing.assert_almost_equal(result, truth*x) + np.testing.assert_array_almost_equal(result, truth*x) result = galsim.utilities.horner2d(x, y, np.vstack([np.zeros((6,5)), coef])) - np.testing.assert_almost_equal(result, truth*x**6) + np.testing.assert_array_almost_equal(result, truth*x**6) # Check using a different dtype result = galsim.utilities.horner2d(x, y, coef, dtype=complex) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Check that x,y may be non-contiguous result = galsim.utilities.horner2d(x[::3], y[:7], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x[::3],y[:7],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x[::3],y[:7],coef)) result = galsim.utilities.horner2d(x[:7], y[::-3], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x[:7],y[::-3],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x[:7],y[::-3],coef)) # Check that coef may be non-contiguous result = galsim.utilities.horner2d(x, y, coef[:,::-1]) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x,y,coef[:,::-1])) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x,y,coef[:,::-1])) result = galsim.utilities.horner2d(x, y, coef[::-1,:]) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x,y,coef[::-1,:])) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x,y,coef[::-1,:])) # Check odd length result = galsim.utilities.horner2d(x[:15], y[:15], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x[:15],y[:15],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x[:15],y[:15],coef)) # Check unaligned array result = galsim.utilities.horner2d(x[1:], y[1:], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x[1:],y[1:],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x[1:],y[1:],coef)) result = galsim.utilities.horner2d(x[1:], y[:-1], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x[1:],y[:-1],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x[1:],y[:-1],coef)) result = galsim.utilities.horner2d(x[:-1], y[1:], coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x[:-1],y[1:],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x[:-1],y[1:],coef)) # Check length > 64 xx = np.empty(2000) @@ -1274,11 +1274,11 @@ def test_horner2d(): rng.generate(xx) rng.generate(yy) result = galsim.utilities.horner2d(xx, yy, coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(xx,yy,coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(xx,yy,coef)) # Check scalar x, y result = galsim.utilities.horner2d(3.9, 1.7, coef) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d([3.9],[1.7],coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d([3.9],[1.7],coef)) # Check the triangle = True option @@ -1292,13 +1292,13 @@ def test_horner2d(): truth += coef[1,0]*x + coef[1,1]*x*y truth += coef[2,0]*x**2 result = galsim.utilities.horner2d(x, y, coef) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) result = galsim.utilities.horner2d(x, y, coef, triangle=True) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Check using a different dtype result = galsim.utilities.horner2d(x, y, coef, dtype=complex, triangle=True) - np.testing.assert_almost_equal(result, truth) + np.testing.assert_array_almost_equal(result, truth) # Check invalid arguments with assert_raises(galsim.GalSimValueError): @@ -1342,45 +1342,45 @@ def test_horner_complex(): # Check all combinations of which things are complex and which are real. # First, just 1 of the three complex: result = galsim.utilities.horner2d(rx, ry, coef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(rx, ry, coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(rx, ry, coef)) result = galsim.utilities.horner2d(rx, y, rcoef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(rx, y, rcoef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(rx, y, rcoef)) result = galsim.utilities.horner2d(x, ry, rcoef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x, ry, rcoef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x, ry, rcoef)) # Now two complex: result = galsim.utilities.horner2d(rx, y, coef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(rx, y, coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(rx, y, coef)) result = galsim.utilities.horner2d(x, ry, coef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x, ry, coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x, ry, coef)) result = galsim.utilities.horner2d(x, y, rcoef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x, y, rcoef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x, y, rcoef)) # All three complex result = galsim.utilities.horner2d(x, y, coef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d(x, y, coef)) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(x, y, coef)) # Check scalar complex x, y result = galsim.utilities.horner2d(3.9+2.1j, 1.7-0.9j, coef, dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval2d( + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d( [3.9+2.1j],[1.7-0.9j],coef)) # Repeast for 1d result = galsim.utilities.horner(rx, coef[0], dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(rx, coef[0])) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(rx, coef[0])) result = galsim.utilities.horner(x, rcoef[0], dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(x, rcoef[0])) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(x, rcoef[0])) result = galsim.utilities.horner(x, coef[0], dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval(x, coef[0])) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(x, coef[0])) result = galsim.utilities.horner(3.9+2.1j, coef[0], dtype=complex) - np.testing.assert_almost_equal(result, np.polynomial.polynomial.polyval([3.9+2.1j],coef[0])) + np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval([3.9+2.1j],coef[0])) def test_merge_sorted(): from galsim.utilities import merge_sorted From ebe75de9ebd8d6f98500f2fe43625dd548c9adbc Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 7 Nov 2023 15:53:50 -0600 Subject: [PATCH 073/351] TST array comps --- tests/test_utilities.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 1e58088bbe..1fb8eb1ffa 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1207,8 +1207,8 @@ def test_horner2d(): x = np.empty(20) y = np.empty(20) rng = galsim.UniformDeviate(1234) - rng.generate(x) - rng.generate(y) + x = rng.generate(x) + y = rng.generate(y) # Check against the direct calculation truth = coef[0,0] + coef[0,1]*y + coef[0,2]*y**2 + coef[0,3]*y**3 + coef[0,4]*y**4 @@ -1271,8 +1271,8 @@ def test_horner2d(): # Check length > 64 xx = np.empty(2000) yy = np.empty(2000) - rng.generate(xx) - rng.generate(yy) + xx = rng.generate(xx) + yy = rng.generate(yy) result = galsim.utilities.horner2d(xx, yy, coef) np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(xx,yy,coef)) From decbe3334932829fc705aea2d59cb68175454fa5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 7 Nov 2023 16:06:58 -0600 Subject: [PATCH 074/351] TST array comps --- tests/test_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 1fb8eb1ffa..7e8fd0fb84 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1183,7 +1183,7 @@ def test_horner(): # Check length > 64 xx = np.empty(2000) - rng.generate(xx) + xx = rng.generate(xx) result = galsim.utilities.horner(xx, coef) np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(xx,coef)) From 312bbe3adb8f71b49b6089833c85f125918659fd Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 06:26:38 -0600 Subject: [PATCH 075/351] support real list --- tests/test_wcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 21fa21c799..b39dddff99 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2470,7 +2470,7 @@ def test_inverseab_convergence(): x, y = wcs.radecToxy(ra, dec, units="radians") except galsim.GalSimError as e: print('Error message is\n',e) - assert "[0,]" in str(e) + assert "[0,]" in str(e) or "[0]" in str(e) # Check as part of a longer list (longer than 256 is important) ra = np.random.uniform(2.185, 2.186, 1000) @@ -2485,7 +2485,7 @@ def test_inverseab_convergence(): x, y = wcs.radecToxy(ra, dec, units="radians") except galsim.GalSimError as e: print('Error message is\n',e) - assert "[1000,1001,]" in str(e) + assert "[1000,1001,]" in str(e) or "[1000,1001]" in str(e) # We don't currently do this for the user, but it's not too hard to get a python list # of the bad indices. Included here as an example for users who may need this. bad = eval(str(e)[str(e).rfind('['):]) From 2daffb06b2bc574faee4a5d51c3b819608423257 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 06:32:59 -0600 Subject: [PATCH 076/351] support real list --- tests/test_wcs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index b39dddff99..82517163b7 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2473,8 +2473,9 @@ def test_inverseab_convergence(): assert "[0,]" in str(e) or "[0]" in str(e) # Check as part of a longer list (longer than 256 is important) - ra = np.random.uniform(2.185, 2.186, 1000) - dec = np.random.uniform(-0.501, -0.499, 1000) + rng = np.random.RandomState(1234) + ra = rng.uniform(2.185, 2.186, 1000) + dec = rng.uniform(-0.501, -0.499, 1000) ra = np.append(ra, [2.1, 2.9]) dec = np.append(dec, [-0.45, 0.2]) print('ra = ',ra) From 65db5347d857687e4f5c1c6c534a984959ee9f16 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 06:34:35 -0600 Subject: [PATCH 077/351] support real list --- tests/test_wcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 82517163b7..2da63fac1f 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2486,7 +2486,7 @@ def test_inverseab_convergence(): x, y = wcs.radecToxy(ra, dec, units="radians") except galsim.GalSimError as e: print('Error message is\n',e) - assert "[1000,1001,]" in str(e) or "[1000,1001]" in str(e) + assert "[1000,1001,]" in str(e) or "[1000, 1001]" in str(e) # We don't currently do this for the user, but it's not too hard to get a python list # of the bad indices. Included here as an example for users who may need this. bad = eval(str(e)[str(e).rfind('['):]) From 1e1b36c9681ca2566b03929513bc212f2f605b0b Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 06:51:28 -0600 Subject: [PATCH 078/351] support real list --- tests/test_wcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 2da63fac1f..e51942430d 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -3163,7 +3163,7 @@ def test_int_args(): # Along the way, check issue #1024 where Erin noticed that reading the WCS from the # header of a compressed file was spending lots of time decompressing the data, which # is unnecessary. - dir = 'des_data' + dir = os.path.join(os.path.dirname(__file__), 'des_data') file_name = 'DECam_00158414_01.fits.fz' with Profile(): t0 = time.time() From dcbe92095ba251cade7460a031ffaa295ce96d69 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 16:36:13 -0600 Subject: [PATCH 079/351] adjust tests for nans --- tests/test_wcs.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index e51942430d..7a6007ff44 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2464,13 +2464,17 @@ def test_inverseab_convergence(): # Now one that should fail, since it's well outside the applicable area for the SIP polynomials. ra = 2.1 dec = -0.45 - with assert_raises(galsim.GalSimError): - x, y = wcs.radecToxy(ra, dec, units="radians") - try: - x, y = wcs.radecToxy(ra, dec, units="radians") - except galsim.GalSimError as e: - print('Error message is\n',e) - assert "[0,]" in str(e) or "[0]" in str(e) + if hasattr(galsim, "_galsim"): + with assert_raises(galsim.GalSimError): + x, y = wcs.radecToxy(ra, dec, units="radians") + try: + x, y = wcs.radecToxy(ra, dec, units="radians") + except galsim.GalSimError as e: + print('Error message is\n',e) + assert "[0,]" in str(e) or "[0]" in str(e) + else: + assert np.all(np.isnan(x)) + assert np.all(np.isnan(y)) # Check as part of a longer list (longer than 256 is important) rng = np.random.RandomState(1234) From 761f215dac99f999b2a31bb64d52bbe0bd161797 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 16:41:36 -0600 Subject: [PATCH 080/351] adjust tests for nans --- tests/test_wcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 7a6007ff44..6c7861d792 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2462,8 +2462,8 @@ def test_inverseab_convergence(): assert np.isclose(dec1, dec) # Now one that should fail, since it's well outside the applicable area for the SIP polynomials. - ra = 2.1 - dec = -0.45 + ra = -2.1 + dec = 0.45 if hasattr(galsim, "_galsim"): with assert_raises(galsim.GalSimError): x, y = wcs.radecToxy(ra, dec, units="radians") From 9e0064a84a221128209a082171100995dc7039df Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 16:42:26 -0600 Subject: [PATCH 081/351] adjust tests for nans --- tests/test_wcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 6c7861d792..701e5e77d0 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2462,8 +2462,8 @@ def test_inverseab_convergence(): assert np.isclose(dec1, dec) # Now one that should fail, since it's well outside the applicable area for the SIP polynomials. - ra = -2.1 - dec = 0.45 + ra = -200.1 + dec = 70.45 if hasattr(galsim, "_galsim"): with assert_raises(galsim.GalSimError): x, y = wcs.radecToxy(ra, dec, units="radians") From b338b5d6fa708bc97a2c467e97549bdc49609449 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 18:49:24 -0600 Subject: [PATCH 082/351] adjust tests for nans --- tests/test_wcs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 701e5e77d0..25ec9046a5 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2473,6 +2473,7 @@ def test_inverseab_convergence(): print('Error message is\n',e) assert "[0,]" in str(e) or "[0]" in str(e) else: + x, y = wcs.radecToxy(ra, dec, units="radians") assert np.all(np.isnan(x)) assert np.all(np.isnan(y)) From 1ed5131a54b4dbee384fee6b82b5e2e478ef0492 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 8 Nov 2023 18:52:22 -0600 Subject: [PATCH 083/351] adjust tests for nans --- tests/test_wcs.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 25ec9046a5..96b07dfbe7 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2485,17 +2485,23 @@ def test_inverseab_convergence(): dec = np.append(dec, [-0.45, 0.2]) print('ra = ',ra) print('dec = ',dec) - with assert_raises(galsim.GalSimError): - x, y = wcs.radecToxy(ra, dec, units="radians") - try: + if hasattr(galsim, "_galsim"): + with assert_raises(galsim.GalSimError): + x, y = wcs.radecToxy(ra, dec, units="radians") + try: + x, y = wcs.radecToxy(ra, dec, units="radians") + except galsim.GalSimError as e: + print('Error message is\n',e) + assert "[1000,1001,]" in str(e) or "[1000, 1001]" in str(e) + # We don't currently do this for the user, but it's not too hard to get a python list + # of the bad indices. Included here as an example for users who may need this. + bad = eval(str(e)[str(e).rfind('['):]) + print('as a python list: ',bad) + else: x, y = wcs.radecToxy(ra, dec, units="radians") - except galsim.GalSimError as e: - print('Error message is\n',e) - assert "[1000,1001,]" in str(e) or "[1000, 1001]" in str(e) - # We don't currently do this for the user, but it's not too hard to get a python list - # of the bad indices. Included here as an example for users who may need this. - bad = eval(str(e)[str(e).rfind('['):]) - print('as a python list: ',bad) + assert np.sum(np.isnan(x)) >= 2 + assert np.sum(np.isnan(y)) >= 2 + @timer def test_tanwcs(): From 3e308a2194f8a3d08e811046634d5f115fc54356 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 14 Nov 2023 07:52:13 -0600 Subject: [PATCH 084/351] print at top --- tests/test_interpolatedimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index b5f92cbcc0..47047584d5 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1594,9 +1594,9 @@ def test_ii_shoot(): else: flux = 1.e4 for interp in interp_list: + print('interp = ',interp) obj = galsim.InterpolatedImage(image_in, x_interpolant=interp, scale=3.3, flux=flux) added_flux, photons = obj.drawPhot(im, poisson_flux=False, rng=rng.duplicate()) - print('interp = ',interp) print('obj.flux = ',obj.flux) print('added_flux = ',added_flux) print('photon fluxes = ',photons.flux.min(),'..',photons.flux.max()) From 3d50c4ebb4bcfa380ea935a3e572178e3bd62a89 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 17 Nov 2023 10:16:15 -0600 Subject: [PATCH 085/351] numerics --- tests/test_exponential.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_exponential.py b/tests/test_exponential.py index af0d806d1a..86123efe88 100644 --- a/tests/test_exponential.py +++ b/tests/test_exponential.py @@ -227,7 +227,9 @@ def test_exponential_shoot(): assert np.isclose(added_flux, obj.flux) assert np.isclose(im.array.sum(), obj.flux) photons2 = obj.makePhot(poisson_flux=False, rng=rng) - assert photons2 == photons, "Exponential makePhot not equivalent to drawPhot" + np.testing.assert_allclose(photons2.x, photons.x) + np.testing.assert_allclose(photons2.y, photons.y) + np.testing.assert_allclose(photons2.flux, photons.flux) @timer From 710cca286c5fcd229d1c309aaf6e5c61ec81f9dc Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 17 Nov 2023 11:57:33 -0600 Subject: [PATCH 086/351] numerics --- tests/test_interpolatedimage.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 47047584d5..169becc6e0 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -1614,7 +1614,9 @@ def test_ii_shoot(): assert np.isclose(added_flux, obj.flux, rtol=rtol) assert np.isclose(im.array.sum(), obj.flux, rtol=rtol) photons2 = obj.makePhot(poisson_flux=False, rng=rng.duplicate()) - assert photons2 == photons, "InterpolatedImage makePhot not equivalent to drawPhot" + np.testing.assert_allclose(photons2.x, photons.x) + np.testing.assert_allclose(photons2.y, photons.y) + np.testing.assert_allclose(photons2.flux, photons.flux) # Can treat as a convolution of a delta function and put it in a photon_ops list. delta = galsim.DeltaFunction(flux=flux) From 46bb464bdc44716414501df056bdb88dcf09aca6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 20 Nov 2023 13:01:44 -0600 Subject: [PATCH 087/351] numerics --- tests/galsim_test_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 9197a84ccd..7a05245302 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -337,7 +337,7 @@ def do_shoot(prof, img, name): # uncertainty = rtol * flux_max # => N_tot = flux_tot / flux_max / rtol**2 # Then we multiply by 10 to get a 3 sigma buffer - rtol = 2.e-2 + rtol = 2.e-2 * 3 test_flux = 1.8 @@ -356,7 +356,7 @@ def do_shoot(prof, img, name): print('flux_max = ',flux_max) flux_tot = img.array.sum(dtype=float) print('flux_tot = ',flux_tot) - atol = flux_max * rtol * 3 + atol = flux_max * rtol nphot = flux_tot / flux_max / rtol**2 print('nphot = ',nphot) From 9e8d6565e88260586911339d1b3d8f32a7a8e1ba Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 20 Nov 2023 13:03:05 -0600 Subject: [PATCH 088/351] numerics --- tests/galsim_test_helpers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 7a05245302..4890d18218 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -337,7 +337,7 @@ def do_shoot(prof, img, name): # uncertainty = rtol * flux_max # => N_tot = flux_tot / flux_max / rtol**2 # Then we multiply by 10 to get a 3 sigma buffer - rtol = 2.e-2 * 3 + rtol = 2.e-2 test_flux = 1.8 @@ -356,12 +356,14 @@ def do_shoot(prof, img, name): print('flux_max = ',flux_max) flux_tot = img.array.sum(dtype=float) print('flux_tot = ',flux_tot) - atol = flux_max * rtol + atol = flux_max * rtol * 3 nphot = flux_tot / flux_max / rtol**2 print('nphot = ',nphot) img2 = img.copy() + rtol *= 3 + # Use a deterministic random number generator so we don't fail tests because of rare flukes # in the random numbers. rng = galsim.UniformDeviate(12345) From d632cb3a0e23a757f0dddc2e5869ce23f6e9a1f3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:11:05 -0600 Subject: [PATCH 089/351] unique test file name --- tests/{test_celestial.py => test_celestial_galsim.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{test_celestial.py => test_celestial_galsim.py} (100%) diff --git a/tests/test_celestial.py b/tests/test_celestial_galsim.py similarity index 100% rename from tests/test_celestial.py rename to tests/test_celestial_galsim.py From 3bfcdddf986b44570bbae16741345075f2f6ba44 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:32:27 -0600 Subject: [PATCH 090/351] array assert --- tests/test_celestial_galsim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index 4839d9b46c..48cdaffebe 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -158,7 +158,7 @@ def test_celestialcoord_basic(): x, y, z = c1.get_xyz() print('c1 is at x,y,z = ',x,y,z) - np.testing.assert_equal((x,y,z), (1,0,0)) + np.testing.assert_array_equal((x,y,z), (1,0,0)) assert c1 == galsim.CelestialCoord.from_xyz(x,y,z) x, y, z = c2.get_xyz() From 1a02359115e8208f8edffc5d0c933ad8143a22e6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:35:51 -0600 Subject: [PATCH 091/351] allclose --- tests/test_celestial_galsim.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index 48cdaffebe..31789a9528 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -346,7 +346,10 @@ def test_projection(): # First the trivial case p0 = center.project(center, projection='lambert') - assert p0 == (0.0 * galsim.arcsec, 0.0 * galsim.arcsec) + np.testing.assert_allclose( + (p0[0].rad, p0[1].rad), + (0.0, 0.0) + ) c0 = center.deproject(*p0, projection='lambert') assert c0 == center np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='lambert').ravel(), From 8c3f294ae074e85a01e8a3f61173dd924ec6d9b5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:39:52 -0600 Subject: [PATCH 092/351] allclose --- tests/test_celestial_galsim.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index 31789a9528..8c5fd30661 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -348,7 +348,9 @@ def test_projection(): p0 = center.project(center, projection='lambert') np.testing.assert_allclose( (p0[0].rad, p0[1].rad), - (0.0, 0.0) + (0.0, 0.0), + rtol=0, + atol=1e-16, ) c0 = center.deproject(*p0, projection='lambert') assert c0 == center From b14d1e4f7f1bc4dffe3f5dd3b66b2d9c64c9c899 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:42:15 -0600 Subject: [PATCH 093/351] allclose --- tests/test_celestial_galsim.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index 8c5fd30661..ef5b7f2634 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -353,7 +353,10 @@ def test_projection(): atol=1e-16, ) c0 = center.deproject(*p0, projection='lambert') - assert c0 == center + np.testing.assert_allclose( + c0.rad, + center.rad, + ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='lambert').ravel(), (1,0,0,1)) From 8f9802396a46e26f708ffc85b35c518f8e698af2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:43:52 -0600 Subject: [PATCH 094/351] allclose --- tests/test_celestial_galsim.py | 36 ++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index ef5b7f2634..c868a38660 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -409,9 +409,17 @@ def test_projection(): # First the trivial case p0 = center.project(center, projection='stereographic') - assert p0 == (0.0 * galsim.arcsec, 0.0 * galsim.arcsec) + np.testing.assert_allclose( + (p0[0].rad, p0[1].rad), + (0.0, 0.0), + rtol=0, + atol=1e-16, + ) c0 = center.deproject(*p0, projection='stereographic') - assert c0 == center + np.testing.assert_allclose( + c0.rad, + center.rad, + ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='stereographic').ravel(), (1,0,0,1)) @@ -467,9 +475,17 @@ def test_projection(): # First the trivial case p0 = center.project(center, projection='gnomonic') - assert p0 == (0.0 * galsim.arcsec, 0.0 * galsim.arcsec) + np.testing.assert_allclose( + (p0[0].rad, p0[1].rad), + (0.0, 0.0), + rtol=0, + atol=1e-16, + ) c0 = center.deproject(*p0, projection='gnomonic') - assert c0 == center + np.testing.assert_allclose( + c0.rad, + center.rad, + ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='gnomonic').ravel(), (1,0,0,1)) @@ -521,9 +537,17 @@ def test_projection(): # First the trivial case p0 = center.project(center, projection='postel') - assert p0 == (0.0 * galsim.arcsec, 0.0 * galsim.arcsec) + np.testing.assert_allclose( + (p0[0].rad, p0[1].rad), + (0.0, 0.0), + rtol=0, + atol=1e-16, + ) c0 = center.deproject(*p0, projection='postel') - assert c0 == center + np.testing.assert_allclose( + c0.rad, + center.rad, + ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='postel').ravel(), (1,0,0,1)) From 15d55d001841a737f76d950edb1307e53fa15ecc Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:50:39 -0600 Subject: [PATCH 095/351] allclose --- tests/test_deprecated.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 3d95280d07..9e22c89a91 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -540,7 +540,8 @@ def test_photon_array_depr(): # Using the getter is allowed, but deprecated. photon_array = galsim.PhotonArray(nphotons) - dxdz = check_dep(getattr, photon_array, 'dxdz') + # jax-galsim always sets these additional properties + # dxdz = check_dep(getattr, photon_array, 'dxdz') assert photon_array.hasAllocatedAngles() assert photon_array.hasAllocatedAngles() assert len(photon_array.dxdz) == nphotons From 6904635138165d009cf5a8e0ba7a53855ef5bcd6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:52:14 -0600 Subject: [PATCH 096/351] photon array test fixes --- tests/test_deprecated.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 9e22c89a91..2920ecbde2 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -542,11 +542,13 @@ def test_photon_array_depr(): photon_array = galsim.PhotonArray(nphotons) # jax-galsim always sets these additional properties # dxdz = check_dep(getattr, photon_array, 'dxdz') - assert photon_array.hasAllocatedAngles() - assert photon_array.hasAllocatedAngles() + # however jax-galsim sets them to NaN so they are not allocated + assert not photon_array.hasAllocatedAngles() assert len(photon_array.dxdz) == nphotons assert len(photon_array.dydz) == nphotons dxdz[:] = 0.17 + # non-nan means allocated for jax-galsim + assert photon_array.hasAllocatedAngles() np.testing.assert_array_equal(photon_array.dxdz, 0.17) np.testing.assert_array_equal(photon_array.dydz, 0.) From 17b8cf783a64428dd4721b495c33009f080e8aee Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:53:49 -0600 Subject: [PATCH 097/351] photon array test fixes --- tests/test_deprecated.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 2920ecbde2..b4dfaa3bad 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -545,15 +545,17 @@ def test_photon_array_depr(): # however jax-galsim sets them to NaN so they are not allocated assert not photon_array.hasAllocatedAngles() assert len(photon_array.dxdz) == nphotons - assert len(photon_array.dydz) == nphotons - dxdz[:] = 0.17 + # 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() np.testing.assert_array_equal(photon_array.dxdz, 0.17) np.testing.assert_array_equal(photon_array.dydz, 0.) - dydz = photon_array.dydz # Allowed now. - dydz[:] = 0.59 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.dydz = 0.59 np.testing.assert_array_equal(photon_array.dydz, 0.59) wave = check_dep(getattr, photon_array, 'wavelength') From 689c5fd9f99f95ffabd671e1d2b23a5f30caa273 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:55:46 -0600 Subject: [PATCH 098/351] photon array test fixes --- tests/test_deprecated.py | 597 +++++++++++++++++++++++---------------- 1 file changed, 359 insertions(+), 238 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index b4dfaa3bad..c6f554b1ac 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -25,8 +25,7 @@ def check_dep(f, *args, **kwargs): - """Check that some function raises a GalSimDeprecationWarning as a warning, but not an error. - """ + """Check that some function raises a GalSimDeprecationWarning as a warning, but not an error.""" # Check that f() raises a warning, but not an error. with assert_warns(galsim.GalSimDeprecationWarning): res = f(*args, **kwargs) @@ -37,70 +36,89 @@ def check_dep(f, *args, **kwargs): def test_gsparams(): 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) + check_dep(galsim.GSParams, small_fraction_of_flux=1.0e-6) @timer def test_phase_psf(): - atm = galsim.Atmosphere(screen_size=10.0, altitude=0, r0_500=0.15, suppress_warning=True) + atm = galsim.Atmosphere( + screen_size=10.0, altitude=0, r0_500=0.15, suppress_warning=True + ) psf = atm.makePSF(exptime=0.02, time_step=0.01, diam=1.1, lam=1000.0) check_dep(galsim.PhaseScreenPSF.__getattribute__, psf, "img") check_dep(galsim.PhaseScreenPSF.__getattribute__, psf, "finalized") + @timer def test_interpolant(): - d = check_dep(galsim.Delta, tol=1.e-2) - assert d.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, d, 'tol') == d.gsparams.kvalue_accuracy - n = check_dep(galsim.Nearest, tol=1.e-2) - assert n.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, n, 'tol') == n.gsparams.kvalue_accuracy - s = check_dep(galsim.SincInterpolant, tol=1.e-2) - assert s.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, s, 'tol') == s.gsparams.kvalue_accuracy - l = check_dep(galsim.Linear, tol=1.e-2) - assert l.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, l, 'tol') == l.gsparams.kvalue_accuracy - c = check_dep(galsim.Cubic, tol=1.e-2) - assert c.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, c, 'tol') == c.gsparams.kvalue_accuracy - q = check_dep(galsim.Quintic, tol=1.e-2) - assert q.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, q, 'tol') == q.gsparams.kvalue_accuracy - l3 = check_dep(galsim.Lanczos, 3, tol=1.e-2) - assert l3.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, l3, 'tol') == l3.gsparams.kvalue_accuracy - ldc = check_dep(galsim.Lanczos, 3, False, tol=1.e-2) - assert ldc.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, ldc, 'tol') == ldc.gsparams.kvalue_accuracy - l8 = check_dep(galsim.Lanczos, 8, tol=1.e-2) - assert l8.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, l8, 'tol') == l8.gsparams.kvalue_accuracy - l11 = check_dep(galsim.Interpolant.from_name, 'lanczos11', tol=1.e-2) - assert l11.gsparams.kvalue_accuracy == 1.e-2 - assert check_dep(getattr, l11, 'tol') == l11.gsparams.kvalue_accuracy + d = check_dep(galsim.Delta, tol=1.0e-2) + assert d.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, d, "tol") == d.gsparams.kvalue_accuracy + n = check_dep(galsim.Nearest, tol=1.0e-2) + assert n.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, n, "tol") == n.gsparams.kvalue_accuracy + s = check_dep(galsim.SincInterpolant, tol=1.0e-2) + assert s.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, s, "tol") == s.gsparams.kvalue_accuracy + l = check_dep(galsim.Linear, tol=1.0e-2) + assert l.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, l, "tol") == l.gsparams.kvalue_accuracy + c = check_dep(galsim.Cubic, tol=1.0e-2) + assert c.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, c, "tol") == c.gsparams.kvalue_accuracy + q = check_dep(galsim.Quintic, tol=1.0e-2) + assert q.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, q, "tol") == q.gsparams.kvalue_accuracy + l3 = check_dep(galsim.Lanczos, 3, tol=1.0e-2) + assert l3.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, l3, "tol") == l3.gsparams.kvalue_accuracy + ldc = check_dep(galsim.Lanczos, 3, False, tol=1.0e-2) + assert ldc.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, ldc, "tol") == ldc.gsparams.kvalue_accuracy + l8 = check_dep(galsim.Lanczos, 8, tol=1.0e-2) + assert l8.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, l8, "tol") == l8.gsparams.kvalue_accuracy + l11 = check_dep(galsim.Interpolant.from_name, "lanczos11", tol=1.0e-2) + assert l11.gsparams.kvalue_accuracy == 1.0e-2 + assert check_dep(getattr, l11, "tol") == l11.gsparams.kvalue_accuracy + @timer def test_noise(): - real_gal_dir = os.path.join('..','examples','data') - real_gal_cat = 'real_galaxy_catalog_23.5_example.fits' + real_gal_dir = os.path.join("..", "examples", "data") + real_gal_cat = "real_galaxy_catalog_23.5_example.fits" real_cat = galsim.RealGalaxyCatalog( - dir=real_gal_dir, file_name=real_gal_cat, preload=True) + dir=real_gal_dir, file_name=real_gal_cat, preload=True + ) - test_seed=987654 + test_seed = 987654 test_index = 17 cf_1 = real_cat.getNoise(test_index, rng=galsim.BaseDeviate(test_seed)) im_2, pix_scale_2, var_2 = real_cat.getNoiseProperties(test_index) # Check the variance: var_1 = cf_1.getVariance() - assert var_1==var_2,'Inconsistent noise variance from getNoise and getNoiseProperties' + assert ( + var_1 == var_2 + ), "Inconsistent noise variance from getNoise and getNoiseProperties" # Check the image: - ii = galsim.InterpolatedImage(im_2, normalization='sb', calculate_stepk=False, - calculate_maxk=False, x_interpolant='linear') - cf_2 = check_dep(galsim.correlatednoise._BaseCorrelatedNoise, - galsim.BaseDeviate(test_seed), ii, im_2.wcs) + ii = galsim.InterpolatedImage( + im_2, + normalization="sb", + calculate_stepk=False, + calculate_maxk=False, + x_interpolant="linear", + ) + cf_2 = check_dep( + galsim.correlatednoise._BaseCorrelatedNoise, + galsim.BaseDeviate(test_seed), + ii, + im_2.wcs, + ) cf_2 = cf_2.withVariance(var_2) - assert cf_1==cf_2,'Inconsistent noise properties from getNoise and getNoiseProperties' + assert ( + cf_1 == cf_2 + ), "Inconsistent noise properties from getNoise and getNoiseProperties" + @timer def test_randwalk_defaults(): @@ -110,26 +128,33 @@ def test_randwalk_defaults(): """ # try constructing with mostly defaults - npoints=100 + npoints = 100 hlr = 8.0 rng = galsim.BaseDeviate(1234) - rw=check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng) + rw = check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng) - assert rw.npoints==npoints,"expected npoints==%d, got %d" % (npoints, rw.npoints) - assert rw.input_half_light_radius==hlr,\ - "expected hlr==%g, got %g" % (hlr, rw.input_half_light_radius) + assert rw.npoints == npoints, "expected npoints==%d, got %d" % (npoints, rw.npoints) + assert rw.input_half_light_radius == hlr, "expected hlr==%g, got %g" % ( + hlr, + rw.input_half_light_radius, + ) - nobj=len(rw.points) - assert nobj == npoints,"expected %d objects, got %d" % (npoints, nobj) + nobj = len(rw.points) + assert nobj == npoints, "expected %d objects, got %d" % (npoints, nobj) - pts=rw.points - assert pts.shape == (npoints,2),"expected (%d,2) shape for points, got %s" % (npoints, pts.shape) - np.testing.assert_almost_equal(rw.centroid.x, np.mean(pts[:,0])) - np.testing.assert_almost_equal(rw.centroid.y, np.mean(pts[:,1])) + pts = rw.points + assert pts.shape == (npoints, 2), "expected (%d,2) shape for points, got %s" % ( + npoints, + pts.shape, + ) + np.testing.assert_almost_equal(rw.centroid.x, np.mean(pts[:, 0])) + np.testing.assert_almost_equal(rw.centroid.y, np.mean(pts[:, 1])) - gsp = galsim.GSParams(xvalue_accuracy=1.e-8, kvalue_accuracy=1.e-8) + gsp = galsim.GSParams(xvalue_accuracy=1.0e-8, kvalue_accuracy=1.0e-8) rng2 = galsim.BaseDeviate(1234) - rw2 = check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng2, gsparams=gsp) + rw2 = check_dep( + galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng2, gsparams=gsp + ) assert rw2 != rw assert rw2 == rw.withGSParams(gsp) @@ -143,7 +168,7 @@ def test_randwalk_defaults(): # Check that image is not sensitive to use of rng by other objects. rng3 = galsim.BaseDeviate(1234) - rw3=check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng3) + rw3 = check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng3) rng3.discard(523) conv1 = galsim.Convolve(rw, psf) conv3 = galsim.Convolve(rw3, psf) @@ -153,7 +178,7 @@ def test_randwalk_defaults(): # Run some basic tests of correctness check_basic(conv1, "RandomWalk") - im = galsim.ImageD(64,64, scale=0.5) + im = galsim.ImageD(64, 64, scale=0.5) do_shoot(conv1, im, "RandomWalk") do_kvalue(conv1, im, "RandomWalk") check_pickle(rw) @@ -168,38 +193,45 @@ def test_randwalk_repr(): using eval """ - npoints=100 + npoints = 100 hlr = 8.0 - flux=1 - rw1=check_dep(galsim.RandomWalk, + flux = 1 + rw1 = check_dep( + galsim.RandomWalk, npoints, half_light_radius=hlr, flux=flux, ) - rw2=check_dep(galsim.RandomWalk, + rw2 = check_dep( + galsim.RandomWalk, npoints, profile=galsim.Exponential(half_light_radius=hlr, flux=flux), ) for rw in (rw1, rw2): - - # just make sure str() works, don't require eval to give # a consistent object back - st=str(rw) + st = str(rw) # require eval(repr(rw)) to give a consistent object back new_rw = eval(repr(rw)) - assert new_rw.npoints == rw.npoints,\ - "expected npoints=%d got %d" % (rw.npoints,new_rw.npoints) + assert new_rw.npoints == rw.npoints, "expected npoints=%d got %d" % ( + rw.npoints, + new_rw.npoints, + ) + + mess = "expected input_half_light_radius=%.16g got %.16g" + assert new_rw.input_half_light_radius == rw.input_half_light_radius, mess % ( + rw.input_half_light_radius, + new_rw.input_half_light_radius, + ) + assert new_rw.flux == rw.flux, "expected flux=%.16g got %.16g" % ( + rw.flux, + new_rw.flux, + ) - mess="expected input_half_light_radius=%.16g got %.16g" - assert new_rw.input_half_light_radius == rw.input_half_light_radius,\ - mess % (rw.input_half_light_radius,new_rw.input_half_light_radius) - assert new_rw.flux == rw.flux,\ - "expected flux=%.16g got %.16g" % (rw.flux,new_rw.flux) @timer def test_randwalk_config(): @@ -208,136 +240,177 @@ def test_randwalk_config(): explicit constructor """ - hlr=2.0 - flux=np.pi + hlr = 2.0 + flux = np.pi gal_config1 = { - 'type':'RandomWalk', - 'npoints':100, - 'half_light_radius':hlr, - 'flux':flux, + "type": "RandomWalk", + "npoints": 100, + "half_light_radius": hlr, + "flux": flux, } gal_config2 = { - 'type':'RandomWalk', - 'npoints':150, - 'profile': { - 'type': 'Exponential', - 'half_light_radius': hlr, - 'flux': flux, - } + "type": "RandomWalk", + "npoints": 150, + "profile": { + "type": "Exponential", + "half_light_radius": hlr, + "flux": flux, + }, } for gal_config in (gal_config1, gal_config2): - config={ - 'gal':gal_config, - 'rng':galsim.BaseDeviate(31415), + config = { + "gal": gal_config, + "rng": galsim.BaseDeviate(31415), } - rwc = check_dep(galsim.config.BuildGSObject, config, 'gal')[0] + rwc = check_dep(galsim.config.BuildGSObject, config, "gal")[0] print(repr(rwc._profile)) - rw = check_dep(galsim.RandomWalk, - gal_config['npoints'], + rw = check_dep( + galsim.RandomWalk, + gal_config["npoints"], half_light_radius=hlr, flux=flux, ) - assert rw.npoints==rwc.npoints,\ - "expected npoints==%d, got %d" % (rw.npoints, rwc.npoints) + assert rw.npoints == rwc.npoints, "expected npoints==%d, got %d" % ( + rw.npoints, + rwc.npoints, + ) - assert rw.input_half_light_radius==rwc.input_half_light_radius,\ - "expected hlr==%g, got %g" % (rw.input_half_light_radius, rw.input_half_light_radius) + assert ( + rw.input_half_light_radius == rwc.input_half_light_radius + ), "expected hlr==%g, got %g" % ( + rw.input_half_light_radius, + rw.input_half_light_radius, + ) - nobj=len(rw.points) - nobjc=len(rwc.points) - assert nobj==nobjc,"expected %d objects, got %d" % (nobj,nobjc) + nobj = len(rw.points) + nobjc = len(rwc.points) + assert nobj == nobjc, "expected %d objects, got %d" % (nobj, nobjc) + + pts = rw.points + ptsc = rwc.points + assert pts.shape == ptsc.shape, "expected %s shape for points, got %s" % ( + pts.shape, + ptsc.shape, + ) - pts=rw.points - ptsc=rwc.points - assert (pts.shape == ptsc.shape),\ - "expected %s shape for points, got %s" % (pts.shape,ptsc.shape) def test_withOrigin(): from test_wcs import Cubic # First EuclideantWCS types: - wcs_list = [ galsim.OffsetWCS(0.3, galsim.PositionD(1,1), galsim.PositionD(10,23)), - galsim.OffsetShearWCS(0.23, galsim.Shear(g1=0.1,g2=0.3), galsim.PositionD(12,43)), - galsim.AffineTransform(0.01,0.26,-0.26,0.02, galsim.PositionD(12,43)), - galsim.UVFunction(ufunc = lambda x,y: 0.2*x, vfunc = lambda x,y: 0.2*y), - galsim.UVFunction(ufunc = lambda x,y: 0.2*x, vfunc = lambda x,y: 0.2*y, - xfunc = lambda u,v: u / scale, yfunc = lambda u,v: v / scale), - galsim.UVFunction(ufunc='0.2*x + 0.03*y', vfunc='0.01*x + 0.2*y'), - ] + wcs_list = [ + galsim.OffsetWCS(0.3, galsim.PositionD(1, 1), galsim.PositionD(10, 23)), + galsim.OffsetShearWCS( + 0.23, galsim.Shear(g1=0.1, g2=0.3), galsim.PositionD(12, 43) + ), + galsim.AffineTransform(0.01, 0.26, -0.26, 0.02, galsim.PositionD(12, 43)), + galsim.UVFunction(ufunc=lambda x, y: 0.2 * x, vfunc=lambda x, y: 0.2 * y), + galsim.UVFunction( + ufunc=lambda x, y: 0.2 * x, + vfunc=lambda x, y: 0.2 * y, + xfunc=lambda u, v: u / scale, + yfunc=lambda u, v: v / scale, + ), + galsim.UVFunction(ufunc="0.2*x + 0.03*y", vfunc="0.01*x + 0.2*y"), + ] color = 0.3 for wcs in wcs_list: # Original version of the shiftOrigin tests in do_nonlocal_wcs using deprecated name. - new_origin = galsim.PositionI(123,321) + new_origin = galsim.PositionI(123, 321) wcs3 = check_dep(wcs.withOrigin, new_origin) - assert wcs != wcs3, name+' is not != wcs.withOrigin(pos)' + assert wcs != wcs3, name + " is not != wcs.withOrigin(pos)" wcs4 = wcs.local(wcs.origin, color=color) - assert wcs != wcs4, name+' is not != wcs.local()' - assert wcs4 != wcs, name+' is not != wcs.local() (reverse)' + assert wcs != wcs4, name + " is not != wcs.local()" + assert wcs4 != wcs, name + " is not != wcs.local() (reverse)" world_origin = wcs.toWorld(wcs.origin, color=color) if wcs.isUniform(): - if wcs.world_origin == galsim.PositionD(0,0): + if wcs.world_origin == galsim.PositionD(0, 0): wcs2 = wcs.local(wcs.origin, color=color).withOrigin(wcs.origin) - assert wcs == wcs2, name+' is not equal after wcs.local().withOrigin(origin)' - wcs2 = wcs.local(wcs.origin, color=color).withOrigin(wcs.origin, wcs.world_origin) - assert wcs == wcs2, name+' not equal after wcs.local().withOrigin(origin,world_origin)' - world_pos1 = wcs.toWorld(galsim.PositionD(0,0), color=color) + assert wcs == wcs2, ( + name + " is not equal after wcs.local().withOrigin(origin)" + ) + wcs2 = wcs.local(wcs.origin, color=color).withOrigin( + wcs.origin, wcs.world_origin + ) + assert wcs == wcs2, ( + name + " not equal after wcs.local().withOrigin(origin,world_origin)" + ) + world_pos1 = wcs.toWorld(galsim.PositionD(0, 0), color=color) wcs3 = check_dep(wcs.withOrigin, new_origin) world_pos2 = wcs3.toWorld(new_origin, color=color) np.testing.assert_almost_equal( - world_pos2.x, world_pos1.x, 7, - 'withOrigin(new_origin) returned wrong world position') + world_pos2.x, + world_pos1.x, + 7, + "withOrigin(new_origin) returned wrong world position", + ) np.testing.assert_almost_equal( - world_pos2.y, world_pos1.y, 7, - 'withOrigin(new_origin) returned wrong world position') + world_pos2.y, + world_pos1.y, + 7, + "withOrigin(new_origin) returned wrong world position", + ) new_world_origin = galsim.PositionD(5352.7, 9234.3) wcs5 = check_dep(wcs.withOrigin, new_origin, new_world_origin, color=color) world_pos3 = wcs5.toWorld(new_origin, color=color) np.testing.assert_almost_equal( - world_pos3.x, new_world_origin.x, 7, - 'withOrigin(new_origin, new_world_origin) returned wrong position') + world_pos3.x, + new_world_origin.x, + 7, + "withOrigin(new_origin, new_world_origin) returned wrong position", + ) np.testing.assert_almost_equal( - world_pos3.y, new_world_origin.y, 7, - 'withOrigin(new_origin, new_world_origin) returned wrong position') + world_pos3.y, + new_world_origin.y, + 7, + "withOrigin(new_origin, new_world_origin) returned wrong position", + ) # Now some CelestialWCS types - cubic_u = Cubic(2.9e-5, 2000., 'u') - cubic_v = Cubic(-3.7e-5, 2000., 'v') + cubic_u = Cubic(2.9e-5, 2000.0, "u") + cubic_v = Cubic(-3.7e-5, 2000.0, "v") center = galsim.CelestialCoord(23 * galsim.degrees, -13 * galsim.degrees) - radec = lambda x,y: center.deproject_rad(cubic_u(x,y)*0.2, cubic_v(x,y)*0.2, - projection='lambert') - wcs_list = [ galsim.RaDecFunction(radec), - galsim.AstropyWCS('1904-66_TAN.fits', dir='fits_files'), - galsim.GSFitsWCS('tpv.fits', dir='fits_files'), - galsim.FitsWCS('sipsample.fits', dir='fits_files'), - ] + radec = lambda x, y: center.deproject_rad( + cubic_u(x, y) * 0.2, cubic_v(x, y) * 0.2, projection="lambert" + ) + wcs_list = [ + galsim.RaDecFunction(radec), + galsim.AstropyWCS("1904-66_TAN.fits", dir="fits_files"), + galsim.GSFitsWCS("tpv.fits", dir="fits_files"), + galsim.FitsWCS("sipsample.fits", dir="fits_files"), + ] for wcs in wcs_list: # Original version of the shiftOrigin tests in do_celestial_wcs using deprecated name. - new_origin = galsim.PositionI(123,321) + new_origin = galsim.PositionI(123, 321) wcs3 = wcs.shiftOrigin(new_origin) - assert wcs != wcs3, name+' is not != wcs.shiftOrigin(pos)' + assert wcs != wcs3, name + " is not != wcs.shiftOrigin(pos)" wcs4 = wcs.local(wcs.origin) - assert wcs != wcs4, name+' is not != wcs.local()' - assert wcs4 != wcs, name+' is not != wcs.local() (reverse)' - world_pos1 = wcs.toWorld(galsim.PositionD(0,0)) + assert wcs != wcs4, name + " is not != wcs.local()" + assert wcs4 != wcs, name + " is not != wcs.local() (reverse)" + world_pos1 = wcs.toWorld(galsim.PositionD(0, 0)) wcs3 = wcs.shiftOrigin(new_origin) world_pos2 = wcs3.toWorld(new_origin) np.testing.assert_almost_equal( - world_pos2.distanceTo(world_pos1) / galsim.arcsec, 0, 7, - 'shiftOrigin(new_origin) returned wrong world position') + world_pos2.distanceTo(world_pos1) / galsim.arcsec, + 0, + 7, + "shiftOrigin(new_origin) returned wrong world position", + ) + @timer def test_wfirst(): - """Test that the deprecated wfirst module works like the new roman module. - """ + """Test that the deprecated wfirst module works like the new roman module.""" import galsim.roman - check_dep(__import__, 'galsim.wfirst') + + check_dep(__import__, "galsim.wfirst") assert galsim.wfirst.gain == galsim.roman.gain assert galsim.wfirst.pixel_scale == galsim.roman.pixel_scale @@ -357,10 +430,13 @@ def test_wfirst(): assert galsim.wfirst.pupil_plane_scale == galsim.roman.pupil_plane_scale assert galsim.wfirst.stray_light_fraction == galsim.roman.stray_light_fraction np.testing.assert_array_equal(galsim.wfirst.ipc_kernel, galsim.roman.ipc_kernel) - np.testing.assert_array_equal(galsim.wfirst.persistence_coefficients, - galsim.roman.persistence_coefficients) - np.testing.assert_array_equal(galsim.wfirst.persistence_fermi_parameters, - galsim.roman.persistence_fermi_parameters) + np.testing.assert_array_equal( + galsim.wfirst.persistence_coefficients, galsim.roman.persistence_coefficients + ) + np.testing.assert_array_equal( + galsim.wfirst.persistence_fermi_parameters, + galsim.roman.persistence_fermi_parameters, + ) assert galsim.wfirst.n_sca == galsim.roman.n_sca assert galsim.wfirst.n_pix_tot == galsim.roman.n_pix_tot assert galsim.wfirst.n_pix == galsim.roman.n_pix @@ -382,42 +458,49 @@ def test_wfirst(): assert galsim.wfirst.allDetectorEffects is galsim.roman.allDetectorEffects assert galsim.wfirst.NLfunc is galsim.roman.NLfunc + @timer def test_roman_psfs(): - """Test the deprecated high_accuracy and approximate_struts options. - """ + """Test the deprecated high_accuracy and approximate_struts options.""" import galsim.roman test_kwargs = [ - ({ 'approximate_struts':True, 'high_accuracy':False }, - { 'pupil_bin':8 }), - ({ 'approximate_struts':True, 'high_accuracy':True }, - { 'pupil_bin':4, 'gsparams':galsim.GSParams(folding_threshold=2.e-3) }), - ({ 'approximate_struts':False, 'high_accuracy':False }, - { 'pupil_bin':4 }), + ({"approximate_struts": True, "high_accuracy": False}, {"pupil_bin": 8}), + ( + {"approximate_struts": True, "high_accuracy": True}, + {"pupil_bin": 4, "gsparams": galsim.GSParams(folding_threshold=2.0e-3)}, + ), + ({"approximate_struts": False, "high_accuracy": False}, {"pupil_bin": 4}), ] if __name__ == "__main__": test_kwargs.append( - ({ 'approximate_struts':False, 'high_accuracy':True }, - { 'pupil_bin':1, 'gsparams':galsim.GSParams(folding_threshold=2.e-3) }), + ( + {"approximate_struts": False, "high_accuracy": True}, + {"pupil_bin": 1, "gsparams": galsim.GSParams(folding_threshold=2.0e-3)}, + ), ) use_sca = 5 for kwargs1, kwargs2 in test_kwargs: - psf1 = check_dep(galsim.roman.getPSF, use_sca, 'Y106', **kwargs1) - psf2 = galsim.roman.getPSF(use_sca, 'Y106', **kwargs2) + psf1 = check_dep(galsim.roman.getPSF, use_sca, "Y106", **kwargs1) + psf2 = galsim.roman.getPSF(use_sca, "Y106", **kwargs2) assert psf1 == psf2 # Cheat to get coverage of False,True option without spending a long time doing the # pupil plane FFT for that one. with assert_raises(TypeError): - check_dep(galsim.roman.getPSF, SCA=use_sca, bandpass='Z087', - approximate_struts=False, high_accuracy=True, - wavelength='Z087') + check_dep( + galsim.roman.getPSF, + SCA=use_sca, + bandpass="Z087", + approximate_struts=False, + high_accuracy=True, + wavelength="Z087", + ) + @timer def test_surface_ops(): - # Based on test_sensor.py:test_wavelengths_and_angles, but massively simplified. rng = galsim.BaseDeviate(1234) @@ -426,14 +509,20 @@ def test_surface_ops(): obscuration = 0.2 assigner = check_dep(galsim.FRatioAngles, fratio, obscuration, rng=rng) - sed = galsim.SED('CWW_E_ext.sed', 'nm', 'flambda').thin() - bandpass = galsim.Bandpass('LSST_i.dat', 'nm').thin() + sed = galsim.SED("CWW_E_ext.sed", "nm", "flambda").thin() + bandpass = galsim.Bandpass("LSST_i.dat", "nm").thin() sampler = check_dep(galsim.WavelengthSampler, sed, bandpass, rng=rng) obj = galsim.Gaussian(flux=353, sigma=0.3) - im = galsim.Image(63,63, scale=1) - check_dep(obj.drawImage, im, method='phot', surface_ops=[sampler, assigner], rng=rng, - save_photons=True) + im = galsim.Image(63, 63, scale=1) + check_dep( + obj.drawImage, + im, + method="phot", + surface_ops=[sampler, assigner], + rng=rng, + save_photons=True, + ) rng.reset(1234) assigner.rng.reset(rng) @@ -444,41 +533,53 @@ def test_surface_ops(): rng.reset(1234) assigner.rng.reset(rng) sampler.rng.reset(rng) - _, photons2 = check_dep(obj.drawPhot, image=im.copy(), surface_ops=[sampler, assigner], rng=rng) + _, photons2 = check_dep( + obj.drawPhot, image=im.copy(), surface_ops=[sampler, assigner], rng=rng + ) assert photons2 == im.photons @timer def test_midpoint_basic(): - """Test the basic functionality of the midpt() method. - """ + """Test the basic functionality of the midpt() method.""" # This shouldn't be super accurate, but just make sure it's not really broken. - x = 0.01*np.arange(1000) + x = 0.01 * np.arange(1000) f = x**2 result = check_dep(galsim.integ.midpt, f, x) - expected_val = 10**3./3. + expected_val = 10**3.0 / 3.0 np.testing.assert_almost_equal( - result/expected_val, 1.0, decimal=2, verbose=True, - err_msg='Simple test of midpt() method failed for f(x)=x^2 from 0 to 10') + result / expected_val, + 1.0, + decimal=2, + verbose=True, + err_msg="Simple test of midpt() method failed for f(x)=x^2 from 0 to 10", + ) @timer def test_trapz_basic(): - """Test the basic functionality of the trapz() method. - """ + """Test the basic functionality of the trapz() method.""" # This shouldn't be super accurate, but just make sure it's not really broken. func = lambda x: x**2 result = check_dep(galsim.integ.trapz, func, 0, 1) - expected_val = 1.**3./3. + expected_val = 1.0**3.0 / 3.0 np.testing.assert_almost_equal( - result/expected_val, 1.0, decimal=6, verbose=True, - err_msg='Simple test of trapz() method failed for f(x)=x^2 from 0 to 1') + result / expected_val, + 1.0, + decimal=6, + verbose=True, + err_msg="Simple test of trapz() method failed for f(x)=x^2 from 0 to 1", + ) result = check_dep(galsim.integ.trapz, func, 0, 1, np.linspace(0, 1, 100000)) - expected_val = 1.**3./3. + expected_val = 1.0**3.0 / 3.0 np.testing.assert_almost_equal( - result/expected_val, 1.0, decimal=6, verbose=True, - err_msg='Test of trapz() with points failed for f(x)=x^2 from 0 to 1') + result / expected_val, + 1.0, + decimal=6, + verbose=True, + err_msg="Test of trapz() with points failed for f(x)=x^2 from 0 to 1", + ) with assert_raises(ValueError): check_dep(galsim.integ.trapz, func, 0, 1, points=np.linspace(0, 1.1, 100)) @@ -487,10 +588,12 @@ def test_trapz_basic(): with assert_raises(TypeError): check_dep(galsim.integ.trapz, func, 0.1, 1, points=2.3) + @timer def test_hsm_depr(): hsmp = check_dep(galsim.hsm.HSMParams, max_moment_nsig2=25.0) - assert hsmp.max_moment_nsig2 == 0. + assert hsmp.max_moment_nsig2 == 0.0 + @timer def test_photon_array_depr(): @@ -512,7 +615,7 @@ def test_photon_array_depr(): assert len(photon_array.dxdz) == nphotons assert len(photon_array.dydz) == nphotons np.testing.assert_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_equal(photon_array.dydz, 0.) + np.testing.assert_array_equal(photon_array.dydz, 0.0) photon_array.dydz = 0.59 assert photon_array.hasAllocatedAngles() @@ -521,7 +624,7 @@ def test_photon_array_depr(): np.testing.assert_array_equal(photon_array.dxdz, 0.17) np.testing.assert_array_equal(photon_array.dydz, 0.59) - photon_array.wavelength = 500. + photon_array.wavelength = 500.0 assert photon_array.hasAllocatedWavelengths() assert len(photon_array.wavelength) == nphotons np.testing.assert_array_equal(photon_array.wavelength, 500) @@ -551,31 +654,39 @@ def test_photon_array_depr(): # non-nan means allocated for jax-galsim assert photon_array.hasAllocatedAngles() np.testing.assert_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_equal(photon_array.dydz, 0.) + np.testing.assert_array_equal(photon_array.dydz, 0.0) # JAX-Galsim does not allow by reference setting - changed this # to make tests below run photon_array.dydz = 0.59 np.testing.assert_array_equal(photon_array.dydz, 0.59) - wave = check_dep(getattr, photon_array, 'wavelength') - assert photon_array.hasAllocatedWavelengths() + # 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() assert len(photon_array.wavelength) == nphotons - wave[:] = 500. + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.wave = 500.0 np.testing.assert_array_equal(photon_array.wavelength, 500) - u = check_dep(getattr, photon_array, 'pupil_u') - assert photon_array.hasAllocatedPupil() - assert len(photon_array.pupil_u) == nphotons + # 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() assert len(photon_array.pupil_v) == nphotons - u[:] = 6.0 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.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) - v = photon_array.pupil_v - v[:] = 10.0 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.pupil_v = 10.0 np.testing.assert_array_equal(photon_array.pupil_v, 10.0) - 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) @@ -584,20 +695,20 @@ def test_photon_array_depr(): # For coverage, also need to test the two pair ones in other order. photon_array = galsim.PhotonArray(nphotons) - dydz = check_dep(getattr, photon_array, 'dydz') + 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 dydz[:] = 0.59 - np.testing.assert_array_equal(photon_array.dxdz, 0.) + np.testing.assert_array_equal(photon_array.dxdz, 0.0) np.testing.assert_array_equal(photon_array.dydz, 0.59) dxdz = photon_array.dxdz # Allowed now. dxdz[:] = 0.17 np.testing.assert_array_equal(photon_array.dxdz, 0.17) - v = check_dep(getattr, photon_array, 'pupil_v') + 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 @@ -608,73 +719,83 @@ def test_photon_array_depr(): u[:] = 6.0 np.testing.assert_array_equal(photon_array.pupil_u, 6.0) + @timer def test_chromatic_flux(): # This is based on a snippet of test_chromatic_flux in test_chromatic.py. - bulge_SED = galsim.SED('CWW_E_ext.sed', wave_type='ang', flux_type='flambda') + bulge_SED = galsim.SED("CWW_E_ext.sed", wave_type="ang", flux_type="flambda") star = galsim.Gaussian(fwhm=1e-8) * bulge_SED mono_PSF = galsim.Gaussian(half_light_radius=0.8) zenith_angle = 20 * galsim.degrees - bandpass = galsim.Bandpass('LSST_i.dat', 'nm').thin() - PSF = galsim.ChromaticAtmosphere(mono_PSF, base_wavelength=500, - zenith_angle=zenith_angle) + bandpass = galsim.Bandpass("LSST_i.dat", "nm").thin() + PSF = galsim.ChromaticAtmosphere( + mono_PSF, base_wavelength=500, zenith_angle=zenith_angle + ) PSF = PSF * 1.0 - PSF1 = PSF.interpolate(waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), - use_exact_sed=False) + PSF1 = PSF.interpolate( + waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), + use_exact_sed=False, + ) # Check deprecated use_exact_SED kwarg - PSF2 = check_dep(PSF.interpolate, - waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), - use_exact_SED=False) + PSF2 = check_dep( + PSF.interpolate, + waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), + use_exact_SED=False, + ) assert PSF2 == PSF1 # Also do this manually with the InterpolatedChromaticObject class - PSF3 = check_dep(galsim.InterpolatedChromaticObject, PSF, - waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), - use_exact_SED=False) + PSF3 = check_dep( + galsim.InterpolatedChromaticObject, + PSF, + waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), + use_exact_SED=False, + ) assert PSF3 == PSF1 # And check deprecated SED attribute. - sed = check_dep(getattr, PSF, 'SED') + sed = check_dep(getattr, PSF, "SED") assert sed == PSF.sed - sed1 = check_dep(getattr, PSF1, 'SED') + sed1 = check_dep(getattr, PSF1, "SED") assert sed1 == PSF1.sed - sed2 = check_dep(getattr, mono_PSF, 'SED') - assert sed1 == mono_PSF.sed == galsim.SED(1, 'nm', '1') + sed2 = check_dep(getattr, mono_PSF, "SED") + assert sed1 == mono_PSF.sed == galsim.SED(1, "nm", "1") + @timer def test_W149(): # Based on test_config_psf, using old W149 name. config = { - 'modules' : ['galsim.roman'], - 'psf' : { 'type' : 'RomanPSF', 'SCA': 4, 'bandpass': 'W149' } + "modules": ["galsim.roman"], + "psf": {"type": "RomanPSF", "SCA": 4, "bandpass": "W149"}, } galsim.config.ImportModules(config) - psf1 = check_dep(galsim.config.BuildGSObject, config, 'psf')[0] - psf2 = check_dep(galsim.roman.getPSF, SCA=4, bandpass='W149') - print('psf1 = ',str(psf1)) - print('psf2 = ',str(psf2)) + psf1 = check_dep(galsim.config.BuildGSObject, config, "psf")[0] + psf2 = check_dep(galsim.roman.getPSF, SCA=4, bandpass="W149") + print("psf1 = ", str(psf1)) + print("psf2 = ", str(psf2)) assert psf1 == psf2 config = galsim.config.CleanConfig(config) - config['image'] = { - 'bandpass' : { 'type' : 'RomanBandpass', 'name' : 'W149' } - } - config['psf']['wavelength'] = 985 - config['psf']['pupil_bin'] = 8 - bp = check_dep(galsim.config.BuildBandpass, config['image'], 'bandpass', config)[0] - config['bandpass'] = bp - psf1 = check_dep(galsim.config.BuildGSObject, config, 'psf')[0] - psf2 = check_dep(galsim.roman.getPSF, SCA=4, bandpass='W149', pupil_bin=8, wavelength=985.) - print('psf1 = ',str(psf1)) - print('psf2 = ',str(psf2)) + config["image"] = {"bandpass": {"type": "RomanBandpass", "name": "W149"}} + config["psf"]["wavelength"] = 985 + config["psf"]["pupil_bin"] = 8 + bp = check_dep(galsim.config.BuildBandpass, config["image"], "bandpass", config)[0] + config["bandpass"] = bp + psf1 = check_dep(galsim.config.BuildGSObject, config, "psf")[0] + psf2 = check_dep( + galsim.roman.getPSF, SCA=4, bandpass="W149", pupil_bin=8, wavelength=985.0 + ) + print("psf1 = ", str(psf1)) + print("psf2 = ", str(psf2)) assert psf1 == psf2 if __name__ == "__main__": - testfns = [v for k, v in vars().items() if k[:5] == 'test_' and callable(v)] + testfns = [v for k, v in vars().items() if k[:5] == "test_" and callable(v)] for testfn in testfns: testfn() From 3a75d7e465ca8e6ffe7c2569fab59a39c28be570 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:56:24 -0600 Subject: [PATCH 099/351] photon array test fixes --- tests/test_deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index c6f554b1ac..e6e7ba64b0 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -668,7 +668,7 @@ def test_photon_array_depr(): assert len(photon_array.wavelength) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run - photon_array.wave = 500.0 + photon_array.wavelength = 500.0 np.testing.assert_array_equal(photon_array.wavelength, 500) # jax-galsim always sets these additional properties From f3216f060051e2c60f79f5a2911c54850f421a3f Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 06:56:50 -0600 Subject: [PATCH 100/351] photon array test fixes --- tests/test_deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index e6e7ba64b0..4a9ce40d5c 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -678,7 +678,7 @@ def test_photon_array_depr(): assert len(photon_array.pupil_v) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run - photon_array.u = 6.0 + photon_array.pupil_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) # JAX-Galsim does not allow by reference setting - changed this From a884bcdc198896240cbf09d584cd2f8600fddb8c Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 07:00:02 -0600 Subject: [PATCH 101/351] photon array test fixes --- tests/test_deprecated.py | 41 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 4a9ce40d5c..b0fd6b5d55 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -686,37 +686,48 @@ def test_photon_array_depr(): photon_array.pupil_v = 10.0 np.testing.assert_array_equal(photon_array.pupil_v, 10.0) - t = check_dep(getattr, photon_array, "time") - assert photon_array.hasAllocatedTimes() + # 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() assert len(photon_array.time) == nphotons np.testing.assert_array_equal(photon_array.time, 0.0) - t[:] = 10 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.time = 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) - dydz = check_dep(getattr, photon_array, "dydz") - assert photon_array.hasAllocatedAngles() - assert photon_array.hasAllocatedAngles() + # 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() assert len(photon_array.dxdz) == nphotons - assert len(photon_array.dydz) == nphotons - dydz[:] = 0.59 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.dydz = 0.59 np.testing.assert_array_equal(photon_array.dxdz, 0.0) np.testing.assert_array_equal(photon_array.dydz, 0.59) - dxdz = photon_array.dxdz # Allowed now. - dxdz[:] = 0.17 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.dxdz = 0.17 np.testing.assert_array_equal(photon_array.dxdz, 0.17) + # jax-galsim always sets these additional properties v = check_dep(getattr, photon_array, "pupil_v") - assert photon_array.hasAllocatedPupil() - assert len(photon_array.pupil_u) == nphotons + # however jax-galsim sets them to NaN so they are not allocated + assert not photon_array.hasAllocatedPupil() assert len(photon_array.pupil_v) == nphotons - v[:] = 10.0 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.pupil_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) - u = photon_array.pupil_u - u[:] = 6.0 + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.pupil_u = 6.0 np.testing.assert_array_equal(photon_array.pupil_u, 6.0) From 47fea3d40367526fe82dabf21c4c6451917e0aca Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 07:02:49 -0600 Subject: [PATCH 102/351] photon array test fixes --- tests/test_deprecated.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index b0fd6b5d55..d6b0163565 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -679,6 +679,8 @@ def test_photon_array_depr(): # 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() np.testing.assert_array_equal(photon_array.pupil_u, 6.0) np.testing.assert_array_equal(photon_array.pupil_v, 0.0) # JAX-Galsim does not allow by reference setting - changed this @@ -691,6 +693,10 @@ def test_photon_array_depr(): # however jax-galsim sets them to NaN so they are not allocated assert not photon_array.hasAllocatedTimes() assert len(photon_array.time) == nphotons + # jax-galsim needs to set 0 + photon_array.time = 0.0 + # jax-galsim is allocated now + assert photon_array.hasAllocatedTimes() np.testing.assert_array_equal(photon_array.time, 0.0) # JAX-Galsim does not allow by reference setting - changed this # to make tests below run From f4da2e13592b7d94bd9dc92b48c2d7585a2a4267 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 07:03:13 -0600 Subject: [PATCH 103/351] photon array test fixes --- tests/test_deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index d6b0163565..a72e9c932c 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -722,7 +722,7 @@ def test_photon_array_depr(): np.testing.assert_array_equal(photon_array.dxdz, 0.17) # jax-galsim always sets these additional properties - v = check_dep(getattr, photon_array, "pupil_v") + # 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() assert len(photon_array.pupil_v) == nphotons From aee1d8c73f846b405dd0af4112b0125a941d69e2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 09:34:21 -0600 Subject: [PATCH 104/351] file paths --- tests/test_des.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_des.py b/tests/test_des.py index 1191cc7541..eab3a1125a 100644 --- a/tests/test_des.py +++ b/tests/test_des.py @@ -491,7 +491,7 @@ def test_nan_fits(): if not hasattr(pyfits, 'verify'): return # The problematic file: - file_name = "des_data/DECam_00158414_01.fits.fz" + file_name = os.path.join(os.path.dirname(__file__), "des_data/DECam_00158414_01.fits.fz") # These are the values we should be reading in: ref_bounds = galsim.BoundsI(xmin=1, xmax=2048, ymin=1, ymax=4096) From 8905ef7dcba94dc5fc73f2ee13239190c83077f5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 09:35:45 -0600 Subject: [PATCH 105/351] file paths --- tests/test_des.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_des.py b/tests/test_des.py index eab3a1125a..294492d739 100644 --- a/tests/test_des.py +++ b/tests/test_des.py @@ -549,7 +549,7 @@ def test_nan_fits(): def test_psf(): """Test the two kinds of PSF files we have in DES. """ - data_dir = 'des_data' + data_dir = os.path.join(os.path.dirname(__file__), 'des_data') psfex_file = "DECam_00154912_12_psfcat.psf" fitpsf_file = "DECam_00154912_12_fitpsf.fits" wcs_file = "DECam_00154912_12_header.fits" From 3b7020ce8919fc769a878730423d19f14275141f Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 09:40:53 -0600 Subject: [PATCH 106/351] file paths --- tests/test_draw.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index b6892568e8..937e813b48 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -377,7 +377,8 @@ def test_drawImage(): assert_raises(TypeError, obj.drawImage, bounds=bounds, scale=scale, wcs=galsim.PixelScale(3)) assert_raises(TypeError, obj.drawImage, bounds=bounds, wcs=scale) assert_raises(TypeError, obj.drawImage, image=im10.array) - assert_raises(TypeError, obj.drawImage, wcs=galsim.FitsWCS('fits_files/tpv.fits')) + assert_raises(TypeError, obj.drawImage, wcs=galsim.FitsWCS( + os.path.join(os.path.dirname(__file__), 'fits_files/tpv.fits'))) assert_raises(ValueError, obj.drawImage, bounds=galsim.BoundsI()) assert_raises(ValueError, obj.drawImage, image=im10, gain=0.) From a01cc059b87608495a114a6c8682e152c53fb632 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 09:50:53 -0600 Subject: [PATCH 107/351] file paths --- tests/test_draw.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 937e813b48..1aa75b1098 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -381,12 +381,13 @@ def test_drawImage(): os.path.join(os.path.dirname(__file__), 'fits_files/tpv.fits'))) assert_raises(ValueError, obj.drawImage, bounds=galsim.BoundsI()) - assert_raises(ValueError, obj.drawImage, image=im10, gain=0.) - assert_raises(ValueError, obj.drawImage, image=im10, gain=-1.) - assert_raises(ValueError, obj.drawImage, image=im10, area=0.) - assert_raises(ValueError, obj.drawImage, image=im10, area=-1.) - assert_raises(ValueError, obj.drawImage, image=im10, exptime=0.) - assert_raises(ValueError, obj.drawImage, image=im10, exptime=-1.) + if hasattr(galsim, "_galsim"): + assert_raises(ValueError, obj.drawImage, image=im10, gain=0.) + assert_raises(ValueError, obj.drawImage, image=im10, gain=-1.) + assert_raises(ValueError, obj.drawImage, image=im10, area=0.) + assert_raises(ValueError, obj.drawImage, image=im10, area=-1.) + assert_raises(ValueError, obj.drawImage, image=im10, exptime=0.) + assert_raises(ValueError, obj.drawImage, image=im10, exptime=-1.) assert_raises(ValueError, obj.drawImage, image=im10, method='invalid') # These options are invalid unless metho=phot From 41482af68cce37063d4d69e6c9525b09c5913d7d Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 09:59:12 -0600 Subject: [PATCH 108/351] draw exceptions --- tests/test_draw.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 1aa75b1098..a235de3ad0 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -393,7 +393,8 @@ def test_drawImage(): # These options are invalid unless metho=phot assert_raises(TypeError, obj.drawImage, image=im10, n_photons=3) assert_raises(TypeError, obj.drawImage, rng=galsim.BaseDeviate(234)) - assert_raises(TypeError, obj.drawImage, max_extra_noise=23) + if hasattr(galsim, "_galsim"): + assert_raises(TypeError, obj.drawImage, max_extra_noise=23) assert_raises(TypeError, obj.drawImage, poisson_flux=True) assert_raises(TypeError, obj.drawImage, maxN=10000) assert_raises(TypeError, obj.drawImage, save_photons=True) From 1561a152e61a18d89151cd5b916311e0b65d5613 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:02:00 -0600 Subject: [PATCH 109/351] array tests --- tests/test_draw.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index a235de3ad0..4a9ff1de5c 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -763,7 +763,7 @@ def test_drawKImage(): np.testing.assert_equal( im6.array.shape, (ny//4+1, nx//3+1), "obj.drawKImage(bounds,scale,recenter=False) produced image with wrong shape") - np.testing.assert_almost_equal( + np.testing.assert_array_almost_equal( im6.array, im4[bounds6].array, 9, "obj.drawKImage(recenter=False) produced different values than recenter=True") @@ -773,7 +773,7 @@ def test_drawKImage(): np.testing.assert_almost_equal( im6.scale, scale, 9, "obj.drawKImage(image,recenter=False) produced image with wrong scale") - np.testing.assert_almost_equal( + np.testing.assert_array_almost_equal( im6.array, im4[bounds6].array, 9, "obj.drawKImage(image,recenter=False) produced different values than recenter=True") @@ -783,7 +783,7 @@ def test_drawKImage(): np.testing.assert_almost_equal( im6.scale, scale, 9, "obj.drawKImage(image,add_to_image=True) produced image with wrong scale") - np.testing.assert_almost_equal( + np.testing.assert_array_almost_equal( im6.array, im4[bounds6].array, 9, "obj.drawKImage(image,add_to_image=True) produced different values than recenter=True") @@ -795,7 +795,7 @@ def test_drawKImage(): np.testing.assert_almost_equal( im7.scale, scale, 9, "obj.drawKImage(image,add_to_image=True) produced image with wrong scale") - np.testing.assert_almost_equal( + np.testing.assert_array_almost_equal( im7.array, im4.array, 9, "obj.drawKImage(image,add_to_image=True) produced different values than recenter=True") From 1bf8ca9ea9c891bcdede3746d863afd05100a884 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:04:47 -0600 Subject: [PATCH 110/351] array tests --- tests/test_draw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 4a9ff1de5c..bca2445488 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -956,7 +956,7 @@ def test_offset(): # Can also use center to explicitly say we want to use the true_center. im3 = obj.drawImage(im.copy(), method='sb', center=im.true_center) - np.testing.assert_almost_equal(im3.array, im.array) + np.testing.assert_array_almost_equal(im3.array, im.array) # Test that a few pixel values match xValue. # Note: we don't expect the FFT drawn image to match the xValues precisely, since the @@ -1044,14 +1044,14 @@ def test_offset(): # Test that the center parameter can be used to do the same thing. center = galsim.PositionD(cenx + offx, ceny + offy) im3 = obj.drawImage(im.copy(), method='sb', center=center) - np.testing.assert_almost_equal(im3.array, im.array) + np.testing.assert_array_almost_equal(im3.array, im.array) assert im3.bounds == im.bounds assert im3.wcs == im.wcs # Can also use both offset and center im3 = obj.drawImage(im.copy(), method='sb', center=(cenx-1, ceny+1), offset=(offx+1, offy-1)) - np.testing.assert_almost_equal(im3.array, im.array) + np.testing.assert_array_almost_equal(im3.array, im.array) assert im3.bounds == im.bounds assert im3.wcs == im.wcs From 4bb3fd9ad3edd2aad3cc11170711ebdc031b416d Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:07:38 -0600 Subject: [PATCH 111/351] array tests --- tests/test_draw.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index bca2445488..0f25aa4be0 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1101,19 +1101,31 @@ def test_shoot(): # in exact arithmetic. We had an assert there which blew up in a not very nice way. obj = galsim.Gaussian(sigma=0.2398318) + 0.1*galsim.Gaussian(sigma=0.47966352) obj = obj.withFlux(100001) - image1 = galsim.ImageF(32,32, init_value=100) + if hasattr(galsim, "_galsim"): + image1 = galsim.ImageF(32,32, init_value=100) + else: + # jax galsim needs double images here + image1 = galsim.ImageD(32,32, init_value=100) rng = galsim.BaseDeviate(1234) obj.drawImage(image1, method='phot', poisson_flux=False, add_to_image=True, rng=rng, maxN=100000) # The test here is really just that it doesn't crash. # But let's do something to check correctness. - image2 = galsim.ImageF(32,32) + if hasattr(galsim, "_galsim"): + image2 = galsim.ImageF(32,32) + else: + # jax galsim needs double images here + image2 = galsim.ImageD(32,32) rng = galsim.BaseDeviate(1234) obj.drawImage(image2, method='phot', poisson_flux=False, add_to_image=False, rng=rng, maxN=100000) image2 += 100 - np.testing.assert_almost_equal(image2.array, image1.array, decimal=12) + if hasattr(galsim, "_galsim"): + np.testing.assert_array_almost_equal(image2.array, image1.array, decimal=12) + else: + # jax galsim works not as well + np.testing.assert_array_almost_equal(image2.array, image1.array, decimal=10) # Also check that you get the same answer with a smaller maxN. image3 = galsim.ImageF(32,32, init_value=100) From e7778a01a629ea5e55b9ce41b4cd59102a77be24 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:08:35 -0600 Subject: [PATCH 112/351] array tests --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 0f25aa4be0..9a88069120 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1136,7 +1136,7 @@ def test_shoot(): # Test that shooting with 0.0 flux makes a zero-photons image. image4 = (obj*0).drawImage(method='phot') - np.testing.assert_equal(image4.array, 0) + np.testing.assert_array_equal(image4.array, 0) # Warns if flux is 1 and n_photons not given. psf = galsim.Gaussian(sigma=3) From caa88d9bc488a9cc2b804fd172416ec5ccaa05d7 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:09:45 -0600 Subject: [PATCH 113/351] jax no warn --- tests/test_draw.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 9a88069120..d82073368f 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1140,12 +1140,13 @@ def test_shoot(): # Warns if flux is 1 and n_photons not given. psf = galsim.Gaussian(sigma=3) - with assert_warns(galsim.GalSimWarning): - psf.drawImage(method='phot') - with assert_warns(galsim.GalSimWarning): - psf.drawPhot(image4) - with assert_warns(galsim.GalSimWarning): - psf.makePhot() + if hasattr(galsim, "_galsim"): + with assert_warns(galsim.GalSimWarning): + psf.drawImage(method='phot') + with assert_warns(galsim.GalSimWarning): + psf.drawPhot(image4) + with assert_warns(galsim.GalSimWarning): + psf.makePhot() # With n_photons=1, it's fine. psf.drawImage(method='phot', n_photons=1) psf.drawPhot(image4, n_photons=1) From a4cb713b719002afa356bc77c30809de11b27f67 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:10:38 -0600 Subject: [PATCH 114/351] jax no warn --- tests/test_draw.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index d82073368f..c383d8d180 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1205,8 +1205,9 @@ def test_drawImage_area_exptime(): # Shooting with flux=1 raises a warning. obj1 = obj.withFlux(1) - with assert_warns(galsim.GalSimWarning): - obj1.drawImage(method='phot') + if hasattr(galsim, "_galsim"): + with assert_warns(galsim.GalSimWarning): + obj1.drawImage(method='phot') # But not if we explicitly tell it to shoot 1 photon with assert_raises(AssertionError): assert_warns(galsim.GalSimWarning, obj1.drawImage, method='phot', n_photons=1) From 60424b8dee3edd241d88e543fcd656a1a5aed8b8 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:11:16 -0600 Subject: [PATCH 115/351] jax no warn --- tests/test_draw.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index c383d8d180..6aa8df6db2 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1212,8 +1212,9 @@ def test_drawImage_area_exptime(): with assert_raises(AssertionError): assert_warns(galsim.GalSimWarning, obj1.drawImage, method='phot', n_photons=1) # Likewise for makePhot - with assert_warns(galsim.GalSimWarning): - obj1.makePhot() + if hasattr(galsim, "_galsim"): + with assert_warns(galsim.GalSimWarning): + obj1.makePhot() with assert_raises(AssertionError): assert_warns(galsim.GalSimWarning, obj1.makePhot, n_photons=1) # And drawPhot From efd15fc3ee42f43f262ca8a4d5dda979dd8d7351 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:11:45 -0600 Subject: [PATCH 116/351] jax no warn --- tests/test_draw.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 6aa8df6db2..c2f5b2b134 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1218,8 +1218,9 @@ def test_drawImage_area_exptime(): with assert_raises(AssertionError): assert_warns(galsim.GalSimWarning, obj1.makePhot, n_photons=1) # And drawPhot - with assert_warns(galsim.GalSimWarning): - obj1.drawPhot(im1) + if hasattr(galsim, "_galsim"): + with assert_warns(galsim.GalSimWarning): + obj1.drawPhot(im1) with assert_raises(AssertionError): assert_warns(galsim.GalSimWarning, obj1.drawPhot, im1, n_photons=1) From 011944cdf187ee50caf6499e8bdbfd7ffa3f0d48 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:12:45 -0600 Subject: [PATCH 117/351] jax no warn --- tests/test_draw.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index c2f5b2b134..382539dc54 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1241,7 +1241,7 @@ def test_fft(): xmin=-2, ymin=-2, dtype=dt, scale=0.1) kim = xim.calculate_fft() xim2 = kim.calculate_inverse_fft() - np.testing.assert_almost_equal(xim.array, xim2.array) + np.testing.assert_array_almost_equal(xim.array, xim2.array) # Now the other way, starting with a (real) k-space image. kim = galsim.Image([ [4,2,0], @@ -1251,7 +1251,7 @@ def test_fft(): xmin=0, ymin=-2, dtype=dt, scale=0.1) xim = kim.calculate_inverse_fft() kim2 = xim.calculate_fft() - np.testing.assert_almost_equal(kim.array, kim2.array) + np.testing.assert_array_almost_equal(kim.array, kim2.array) # Test starting with a larger image that gets wrapped. kim3 = galsim.Image([ [0,1,2,1,0], @@ -1262,7 +1262,7 @@ def test_fft(): xmin=-2, ymin=-2, dtype=dt, scale=0.1) xim = kim3.calculate_inverse_fft() kim2 = xim.calculate_fft() - np.testing.assert_almost_equal(kim.array, kim2.array) + np.testing.assert_array_almost_equal(kim.array, kim2.array) # Test padding X Image with zeros xim = galsim.Image([ [0,0,0,0], @@ -1275,7 +1275,7 @@ def test_fft(): xmin=-2, ymin=-1, dtype=dt, scale=0.1) kim = xim.calculate_fft() kim2 = xim2.calculate_fft() - np.testing.assert_almost_equal(kim.array, kim2.array) + np.testing.assert_array_almost_equal(kim.array, kim2.array) # Test padding K Image with zeros kim = galsim.Image([ [4,2,0], @@ -1290,7 +1290,7 @@ def test_fft(): xmin=0, ymin=-1, dtype=dt, scale=0.1) xim = kim.calculate_inverse_fft() xim2 = kim2.calculate_inverse_fft() - np.testing.assert_almost_equal(xim.array, xim2.array) + np.testing.assert_array_almost_equal(xim.array, xim2.array) # Now use drawKImage (as above in test_drawKImage) to get a more realistic k-space image obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) From a7503db1a19ba9258f024d16abd88abb9d2dd396 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:16:08 -0600 Subject: [PATCH 118/351] jax no fwd fft complex --- tests/test_draw.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 382539dc54..51f8ec1203 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1239,9 +1239,10 @@ def test_fft(): [4,6,8,4], [2,4,6,6] ], xmin=-2, ymin=-2, dtype=dt, scale=0.1) - kim = xim.calculate_fft() - xim2 = kim.calculate_inverse_fft() - np.testing.assert_array_almost_equal(xim.array, xim2.array) + if hasattr(galsim, "_galsim") or type not in [np.complex128, complex]: + kim = xim.calculate_fft() + xim2 = kim.calculate_inverse_fft() + np.testing.assert_array_almost_equal(xim.array, xim2.array) # Now the other way, starting with a (real) k-space image. kim = galsim.Image([ [4,2,0], From 7131c51d4d10f84b1705cc084c07fa4555f97c61 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:16:43 -0600 Subject: [PATCH 119/351] jax no fwd fft complex --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 51f8ec1203..86697f1c93 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1239,7 +1239,7 @@ def test_fft(): [4,6,8,4], [2,4,6,6] ], xmin=-2, ymin=-2, dtype=dt, scale=0.1) - if hasattr(galsim, "_galsim") or type not in [np.complex128, complex]: + if hasattr(galsim, "_galsim") or 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) From da8ae43c22fe14a7880a3c1d00a958d5b1a7113a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:21:37 -0600 Subject: [PATCH 120/351] jax no fwd fft complex --- tests/test_draw.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 86697f1c93..070aff0947 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1274,9 +1274,10 @@ def test_fft(): xim2 = galsim.Image([ [2,4,6], [4,6,8] ], xmin=-2, ymin=-1, dtype=dt, scale=0.1) - kim = xim.calculate_fft() - kim2 = xim2.calculate_fft() - np.testing.assert_array_almost_equal(kim.array, kim2.array) + if hasattr(galsim, "_galsim") or dt not in [np.complex128, complex]: + kim = xim.calculate_fft() + kim2 = xim2.calculate_fft() + np.testing.assert_array_almost_equal(kim.array, kim2.array) # Test padding K Image with zeros kim = galsim.Image([ [4,2,0], From 3d32477d72031c9a5ece8f8f458259309263db21 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:22:44 -0600 Subject: [PATCH 121/351] array compare --- tests/test_draw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 070aff0947..ef2ea1f4b6 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1319,7 +1319,7 @@ def test_fft(): np.testing.assert_almost_equal( im1_real.scale, im1_alt_real.scale, 3, "inverse_fft produce a different scale than obj2.drawImage(method='sb')") - np.testing.assert_almost_equal( + np.testing.assert_array_almost_equal( im1_real.array, im1_alt_real.array, 3, "inverse_fft produce a different array than obj2.drawImage(method='sb')") @@ -1338,7 +1338,7 @@ def test_fft(): np.testing.assert_almost_equal( im2_real.scale, im2_alt_real.scale, 9, "inverse_fft produce a different scale than obj2.drawImage(nx,ny,method='sb')") - np.testing.assert_almost_equal( + np.testing.assert_array_almost_equal( im2_real.array, im2_alt_real.array, 9, "inverse_fft produce a different array than obj2.drawImage(nx,ny,method='sb')") From 8b2544323ea1e1fb0b6badfa1556a89fa8c70a4b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:24:13 -0600 Subject: [PATCH 122/351] array compare --- tests/test_draw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index ef2ea1f4b6..1fce02caff 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1573,13 +1573,13 @@ def test_types(): "wrong scale when drawing onto dt=%s"%dt) np.testing.assert_equal(im.bounds, ref_im.bounds, "wrong bounds when drawing onto dt=%s"%dt) - np.testing.assert_almost_equal(im.array, round_cast(ref_im.array, dt), 6, + np.testing.assert_array_almost_equal(im.array, round_cast(ref_im.array, dt), 6, "wrong array when drawing onto dt=%s"%dt) if method == 'phot': rng.reset(1234) obj.drawImage(im, method=method, add_to_image=True, rng=rng) - np.testing.assert_almost_equal(im.array, round_cast(ref_im.array, dt) * 2, 6, + np.testing.assert_array_almost_equal(im.array, round_cast(ref_im.array, dt) * 2, 6, "wrong array when adding to image with dt=%s"%dt) @timer From 0515ad8d872be74b91677b114d3a4cb9f26bcf9f Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:39:55 -0600 Subject: [PATCH 123/351] jax rounds a bit different --- tests/test_draw.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 1fce02caff..f42b471ad9 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1546,7 +1546,8 @@ def test_np_fft(): def round_cast(array, dt): # array.astype(dt) doesn't round to the nearest for integer types. # This rounds first if dt is integer and then casts. - if dt(0.5) != 0.5: + # NOTE JAX doesn't round to the nearest int when drawing + if hasattr(galsim, "_galsim") and dt(0.5) != 0.5: array = np.around(array) return array.astype(dt) From 19471acfacee7ac3037dd080e51fefaf405eb75a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:49:18 -0600 Subject: [PATCH 124/351] jax rounds a bit different --- tests/test_draw.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index f42b471ad9..a4c2de240c 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1620,13 +1620,13 @@ def test_direct_scale(): obj.dilate(1.0).drawReal(im4) obj.rotate(0.3*galsim.radians).drawReal(im5) print('no_pixel: max diff = ',np.max(np.abs(im1.array - im2.array))) - np.testing.assert_almost_equal(im1.array, im2.array, 15, + np.testing.assert_array_almost_equal(im1.array, im2.array, 15, "drawReal made different image than method='no_pixel'") - np.testing.assert_almost_equal(im3.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im3.array, im2[im3.bounds].array, 15, "drawReal made different image when off-center") - np.testing.assert_almost_equal(im4.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im4.array, im2[im3.bounds].array, 15, "drawReal made different image when jac is not None") - np.testing.assert_almost_equal(im5.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im5.array, im2[im3.bounds].array, 15, "drawReal made different image when jac is not diagonal") obj.drawImage(im1, method='sb') @@ -1635,13 +1635,13 @@ def test_direct_scale(): obj_sb.dilate(1.0).drawReal(im4) obj_sb.rotate(0.3*galsim.radians).drawReal(im5) print('sb: max diff = ',np.max(np.abs(im1.array - im2.array))) - np.testing.assert_almost_equal(im1.array, im2.array, 15, + np.testing.assert_array_almost_equal(im1.array, im2.array, 15, "drawReal made different image than method='sb'") - np.testing.assert_almost_equal(im3.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im3.array, im2[im3.bounds].array, 15, "drawReal made different image when off-center") - np.testing.assert_almost_equal(im4.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im4.array, im2[im3.bounds].array, 15, "drawReal made different image when jac is not None") - np.testing.assert_almost_equal(im5.array, im2[im3.bounds].array, 14, + np.testing.assert_array_almost_equal(im5.array, im2[im3.bounds].array, 14, "drawReal made different image when jac is not diagonal") obj.drawImage(im1, method='fft') @@ -1650,13 +1650,13 @@ def test_direct_scale(): obj_with_pixel.dilate(1.0).drawFFT(im4) obj_with_pixel.rotate(90 * galsim.degrees).drawFFT(im5) print('fft: max diff = ',np.max(np.abs(im1.array - im2.array))) - np.testing.assert_almost_equal(im1.array, im2.array, 15, + np.testing.assert_array_almost_equal(im1.array, im2.array, 15, "drawFFT made different image than method='fft'") - np.testing.assert_almost_equal(im3.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im3.array, im2[im3.bounds].array, 15, "drawFFT made different image when off-center") - np.testing.assert_almost_equal(im4.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im4.array, im2[im3.bounds].array, 15, "drawFFT made different image when jac is not None") - np.testing.assert_almost_equal(im5.array, im2[im3.bounds].array, 14, + np.testing.assert_array_almost_equal(im5.array, im2[im3.bounds].array, 14, "drawFFT made different image when jac is not diagonal") obj.drawImage(im1, method='real_space') @@ -1667,13 +1667,13 @@ def test_direct_scale(): print('real_space: max diff = ',np.max(np.abs(im1.array - im2.array))) # I'm not sure why this one comes out a bit less precisely equal. But 12 digits is still # plenty accurate enough. - np.testing.assert_almost_equal(im1.array, im2.array, 12, + np.testing.assert_array_almost_equal(im1.array, im2.array, 12, "drawReal made different image than method='real_space'") - np.testing.assert_almost_equal(im3.array, im2[im3.bounds].array, 14, + np.testing.assert_array_almost_equal(im3.array, im2[im3.bounds].array, 14, "drawReal made different image when off-center") - np.testing.assert_almost_equal(im4.array, im2[im3.bounds].array, 14, + np.testing.assert_array_almost_equal(im4.array, im2[im3.bounds].array, 14, "drawReal made different image when jac is not None") - np.testing.assert_almost_equal(im5.array, im2[im3.bounds].array, 14, + np.testing.assert_array_almost_equal(im5.array, im2[im3.bounds].array, 14, "drawReal made different image when jac is not diagonal") obj.drawImage(im1, method='phot', rng=rng.duplicate()) @@ -1683,18 +1683,18 @@ def test_direct_scale(): phot3.scaleXY(1./scale) phot4 = im3.wcs.toImage(obj).makePhot(rng=rng.duplicate()) print('phot: max diff = ',np.max(np.abs(im1.array - im2.array))) - np.testing.assert_almost_equal(im1.array, im2.array, 15, + np.testing.assert_array_almost_equal(im1.array, im2.array, 15, "drawPhot made different image than method='phot'") - np.testing.assert_almost_equal(im3.array, im2[im3.bounds].array, 15, + np.testing.assert_array_almost_equal(im3.array, im2[im3.bounds].array, 15, "drawPhot made different image when off-center") assert phot2 == phot1, "drawPhot made different photons than method='phot'" assert phot3 == phot1, "makePhot made different photons than method='phot'" # phot4 has a different order of operations for the math, so it doesn't come out exact. - np.testing.assert_almost_equal(phot4.x, phot3.x, 15, + np.testing.assert_array_almost_equal(phot4.x, phot3.x, 15, "two ways to have makePhot apply scale have different x") - np.testing.assert_almost_equal(phot4.y, phot3.y, 15, + np.testing.assert_array_almost_equal(phot4.y, phot3.y, 15, "two ways to have makePhot apply scale have different y") - np.testing.assert_almost_equal(phot4.flux, phot3.flux, 15, + np.testing.assert_array_almost_equal(phot4.flux, phot3.flux, 15, "two ways to have makePhot apply scale have different flux") # Check images with invalid wcs raise ValueError From 6bcd68f524b8ead255d8fc27d69d8b8d5b0a7684 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 10:51:55 -0600 Subject: [PATCH 125/351] jax rounds a bit different --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index a4c2de240c..6a6926c174 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1635,7 +1635,7 @@ def test_direct_scale(): obj_sb.dilate(1.0).drawReal(im4) obj_sb.rotate(0.3*galsim.radians).drawReal(im5) print('sb: max diff = ',np.max(np.abs(im1.array - im2.array))) - np.testing.assert_array_almost_equal(im1.array, im2.array, 15, + np.testing.assert_array_almost_equal(im1.array, im2.array, 14, "drawReal made different image than method='sb'") np.testing.assert_array_almost_equal(im3.array, im2[im3.bounds].array, 15, "drawReal made different image when off-center") From e3c5280b8c2ffeacf9b2d46daa1f93e6f284e835 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:00:36 -0600 Subject: [PATCH 126/351] make_const not supported --- tests/test_errors.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_errors.py b/tests/test_errors.py index ba0e016682..7785e68bea 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -149,7 +149,10 @@ def test_galsim_undefined_bounds_error(): def test_galsim_immutable_error(): """Test basic usage of GalSimImmutableError """ - im = galsim.ImageD(np.array([[0]]), make_const=True) + if hasattr(galsim, '_galsim'): + im = galsim.ImageD(np.array([[0]]), make_const=True) + else: + im = galsim.ImageD(np.array([[0]])) err = galsim.GalSimImmutableError("Test", im) print('str = ',str(err)) print('repr = ',repr(err)) From 5f55582535631d03b992c4be4940f26fbbb66046 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:13:17 -0600 Subject: [PATCH 127/351] paths --- tests/test_hsm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_hsm.py b/tests/test_hsm.py index a5b19e8479..a85b7b7ef1 100644 --- a/tests/test_hsm.py +++ b/tests/test_hsm.py @@ -46,7 +46,7 @@ test_timing = False # define inputs and expected results for tests that use real SDSS galaxies -img_dir = os.path.join(".","HSM_precomputed") +img_dir = os.path.join(os.path.dirname(__file__), "HSM_precomputed") gal_file_prefix = "image." psf_file_prefix = "psf." img_suff = ".fits" From 0d3ca1a9903ff9040aba5746a543736749cad692 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:29:03 -0600 Subject: [PATCH 128/351] paths --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index db752372cb..a69ea492bb 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -82,7 +82,7 @@ # it helps speed things up. nimages = 3 -datadir = os.path.join(".", "Image_comparison_images") +datadir = os.path.join(os.path.dirname(__file__), "Image_comparison_images") @timer From c1aa75317a0ec6b2a0e470ac57d1782dcfe15d19 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:29:46 -0600 Subject: [PATCH 129/351] paths --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index a69ea492bb..648164b03e 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -691,7 +691,7 @@ def test_Image_FITS_IO(): assert_raises(OSError, galsim.fits.read, test_file, compression='none') # Check a file with no WCS information - nowcs_file = 'fits_files/blankimg.fits' + nowcs_file = os.path.join(os.path.dirname(__file__), 'fits_files/blankimg.fits') im = galsim.fits.read(nowcs_file) assert im.wcs == galsim.PixelScale(1.0) From ac7d4d91b9dab792c6eb17824bcf71d604dc419b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:30:12 -0600 Subject: [PATCH 130/351] paths --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 648164b03e..2dc3728ee2 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -1017,7 +1017,7 @@ def test_Image_MultiFITS_IO(): assert_raises(OSError, galsim.fits.readMulti, test_multi_file, compression='none') # Check a file with no WCS information - nowcs_file = 'fits_files/blankimg.fits' + nowcs_file = os.path.join(os.path.dirname(__file__), 'fits_files/blankimg.fits') ims = galsim.fits.readMulti(nowcs_file) assert ims[0].wcs == galsim.PixelScale(1.0) From 51151af495dc1895a340f1e5655bae367fd36b6e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:30:45 -0600 Subject: [PATCH 131/351] paths --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 2dc3728ee2..dcb69b3c66 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -1347,7 +1347,7 @@ def test_Image_CubeFITS_IO(): assert_raises(OSError, galsim.fits.readCube, test_cube_file, compression='none') # Check a file with no WCS information - nowcs_file = 'fits_files/blankimg.fits' + nowcs_file = os.path.join(os.path.dirname(__file__), 'fits_files/blankimg.fits') ims = galsim.fits.readCube(nowcs_file) assert ims[0].wcs == galsim.PixelScale(1.0) From b7cad5b1d40514daf0b9f25bd9bd0df64e6fe74a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:31:31 -0600 Subject: [PATCH 132/351] paths --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index dcb69b3c66..317bbe36b7 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2134,7 +2134,7 @@ def test_subImage_persistence(): """Test that a subimage is properly accessible even if the original image has gone out of scope. """ - file_name = os.path.join('fits_files','tpv.fits') + file_name = os.path.join(os.path.dirname(__file__), os.path.join('fits_files','tpv.fits')) bounds = galsim.BoundsI(123, 133, 45, 55) # Something random # In this case, the original image has gone out of scope. At least on some systems, From 030bda017a7063715958b7e9bc4b77e6eafb202b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:33:00 -0600 Subject: [PATCH 133/351] paths --- tests/test_image.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 317bbe36b7..e74c9caf9f 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2242,7 +2242,10 @@ def test_ConstImage_array_constness(): attributes, and that if this is attempted a GalSimImmutableError is raised. """ for i in range(ntypes): - image = galsim.Image(ref_array.astype(types[i]), make_const=True) + if hasattr(galsim, "_galsim"): + image = galsim.Image(ref_array.astype(types[i]), make_const=True) + else: + image = galsim.Image(ref_array.astype(types[i])) # Apparently older numpy versions might raise a RuntimeError, a ValueError, or a TypeError # when trying to write to arrays that have writeable=False. # From the numpy 1.7.0 release notes: From c07af19593e1f5afa6544c13ee60bbb7d9ff21e9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 11:50:44 -0600 Subject: [PATCH 134/351] support make const --- tests/test_errors.py | 5 +---- tests/test_image.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/test_errors.py b/tests/test_errors.py index 7785e68bea..ba0e016682 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -149,10 +149,7 @@ def test_galsim_undefined_bounds_error(): def test_galsim_immutable_error(): """Test basic usage of GalSimImmutableError """ - if hasattr(galsim, '_galsim'): - im = galsim.ImageD(np.array([[0]]), make_const=True) - else: - im = galsim.ImageD(np.array([[0]])) + im = galsim.ImageD(np.array([[0]]), make_const=True) err = galsim.GalSimImmutableError("Test", im) print('str = ',str(err)) print('repr = ',repr(err)) diff --git a/tests/test_image.py b/tests/test_image.py index e74c9caf9f..317bbe36b7 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2242,10 +2242,7 @@ def test_ConstImage_array_constness(): attributes, and that if this is attempted a GalSimImmutableError is raised. """ for i in range(ntypes): - if hasattr(galsim, "_galsim"): - image = galsim.Image(ref_array.astype(types[i]), make_const=True) - else: - image = galsim.Image(ref_array.astype(types[i])) + image = galsim.Image(ref_array.astype(types[i]), make_const=True) # Apparently older numpy versions might raise a RuntimeError, a ValueError, or a TypeError # when trying to write to arrays that have writeable=False. # From the numpy 1.7.0 release notes: From 394046780bfadfa85399f6b761b5b6708eefb442 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:08:54 -0600 Subject: [PATCH 135/351] support make const --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 317bbe36b7..6676c3f05a 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2416,7 +2416,11 @@ def test_Image_view(): assert imv.bounds == im.bounds imv.setValue(11,19, 20) assert imv(11,19) == 20 - assert im(11,19) == 20 + if hasattr(galsim, "_galsim"): + assert im(11,19) == 20 + else: + # jax-galsim does not support views + assert im(11,19) != 20 check_pickle(im) check_pickle(imv) From 0a92bc44525410d25b119c0f0fb09edd56fd254c Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:09:56 -0600 Subject: [PATCH 136/351] support make const --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 6676c3f05a..1b13aff43e 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2432,7 +2432,11 @@ def test_Image_view(): assert imv.bounds == galsim.BoundsI(0,24,0,24) imv.setValue(10,18, 30) assert imv(10,18) == 30 - assert im(11,19) == 30 + if hasattr(galsim, "_galsim"): + assert im(11,19) == 30 + else: + # jax-galsim does not support views + assert im(11,19) != 20 imv2 = im.view() imv2.setOrigin(0,0) assert imv.bounds == imv2.bounds From 86682d24f0b07bf489c00afe8b4441ee9dd4f283 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:10:29 -0600 Subject: [PATCH 137/351] support make const --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 1b13aff43e..51d7e41f21 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2452,7 +2452,11 @@ def test_Image_view(): assert imv.bounds == galsim.BoundsI(-12,12,-12,12) imv.setValue(-2,6, 40) assert imv(-2,6) == 40 - assert im(11,19) == 40 + if hasattr(galsim, "_galsim"): + assert im(11,19) == 40 + else: + # jax-galsim does not support views + assert im(11,19) != 40 imv2 = im.view() imv2.setCenter(0,0) assert imv.bounds == imv2.bounds From 163687f1738c292c781f9d90ed3444ba1f59b3d3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:11:10 -0600 Subject: [PATCH 138/351] support make const --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 51d7e41f21..cbeb6e4c4f 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2473,7 +2473,11 @@ def test_Image_view(): assert imv.bounds == im.bounds imv.setValue(11,19, 50) assert imv(11,19) == 50 - assert im(11,19) == 50 + if hasattr(galsim, "_galsim"): + assert im(11,19) == 50 + else: + # jax-galsim does not support views + assert im(11,19) != 50 imv2 = im.view() with assert_raises(galsim.GalSimError): imv2.scale = 0.17 # Invalid if wcs is not PixelScale From 4cd1536b721cfacfbee2d25a46e730fd23df5921 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:11:46 -0600 Subject: [PATCH 139/351] support make const --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index cbeb6e4c4f..2529c514c2 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2495,7 +2495,11 @@ def test_Image_view(): assert imv.bounds == im.bounds imv.setValue(11,19, 60) assert imv(11,19) == 60 - assert im(11,19) == 60 + if hasattr(galsim, "_galsim"): + assert im(11,19) == 60 + else: + # jax-galsim does not support views + assert im(11,19) != 60 imv2 = im.view() imv2.wcs = galsim.JacobianWCS(0.,0.23,-0.23,0.) assert imv.bounds == imv2.bounds From 0952f29bc3b93e62065503c6e21a97e162a698b3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:16:59 -0600 Subject: [PATCH 140/351] no references --- tests/test_image.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 2529c514c2..1f1f9715db 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2590,13 +2590,15 @@ def test_copy(): assert im(3,8) != 11. # If copy=False is specified, then it shares the same array - im3b = galsim.Image(im, copy=False) - assert im3b.wcs == im.wcs - assert im3b.bounds == im.bounds - np.testing.assert_array_equal(im3b.array, im.array) - im3b.setValue(2,3,2.) - assert im3b(2,3) == 2. - assert im(2,3) == 2. + if hasattr(galsim, "_galsim"): + # jax-galsim does not support references + im3b = galsim.Image(im, copy=False) + assert im3b.wcs == im.wcs + assert im3b.bounds == im.bounds + np.testing.assert_array_equal(im3b.array, im.array) + im3b.setValue(2,3,2.) + assert im3b(2,3) == 2. + assert im(2,3) == 2. # Constructor can change the wcs im4 = galsim.Image(im, scale=0.6) From f3a65d33cf0a55c96b298eeecaba563f90124bde Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:17:51 -0600 Subject: [PATCH 141/351] no references --- tests/test_image.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 1f1f9715db..d12eda3220 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2649,13 +2649,15 @@ def test_copy(): assert im_slice(2,3) != 11. # Can also copy by giving the array and specify copy=True - im10 = galsim.Image(im.array, bounds=im.bounds, wcs=im.wcs, copy=False) - assert im10.wcs == im.wcs - assert im10.bounds == im.bounds - np.testing.assert_array_equal(im10.array, im.array) - im10[2,3] = 17 - assert im10(2,3) == 17. - assert im(2,3) == 17. + if hasattr(galsim, "_galsim"): + # jax-galsim does not support references + im10 = galsim.Image(im.array, bounds=im.bounds, wcs=im.wcs, copy=False) + assert im10.wcs == im.wcs + assert im10.bounds == im.bounds + np.testing.assert_array_equal(im10.array, im.array) + im10[2,3] = 17 + assert im10(2,3) == 17. + assert im(2,3) == 17. im10b = galsim.Image(im.array, bounds=im.bounds, wcs=im.wcs, copy=True) assert im10b.wcs == im.wcs From 7786e37533b67d7b8fbce934dea41fb257e84858 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:32:45 -0600 Subject: [PATCH 142/351] no references --- tests/test_image.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index d12eda3220..d1c0ab3302 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2708,9 +2708,11 @@ def test_complex_image(): assert im1(x,y) == value assert im1.view()(x,y) == value assert im1.view(make_const=True)(x,y) == value - assert im2(x,y) == value + # jax galsim does not support views + assert im2(x,y) != value assert im2_view(x,y) == value - assert im2_cview(x,y) == value + # jax galsim does not support views + assert im2_cview(x,y) != value assert im1.conjugate(x,y) == np.conjugate(value) # complex conjugate is not a view into the original. From be2e75f0ee50bc80e6955a06950bb7fe8c524b3d Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:34:10 -0600 Subject: [PATCH 143/351] no references --- tests/test_image.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index d1c0ab3302..4f5d495deb 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2717,7 +2717,8 @@ def test_complex_image(): # complex conjugate is not a view into the original. assert im2_conj(x,y) == 23 - assert im2.conjugate(x,y) == np.conjugate(value) + # jax galsim does not support views + assert im2.conjugate(x,y) != np.conjugate(value) value2 = 10*x + y + 20j*x + 2j*y im1.setValue(x,y, value2) From 2169160c55f72af79acecf8c947d14298765139c Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:34:45 -0600 Subject: [PATCH 144/351] no references --- tests/test_image.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 4f5d495deb..66029d100a 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2726,9 +2726,11 @@ def test_complex_image(): assert im1(x,y) == value2 assert im1.view()(x,y) == value2 assert im1.view(make_const=True)(x,y) == value2 - assert im2(x,y) == value2 + # jax galsim does not support views + assert im2(x,y) != value2 assert im2_view(x,y) == value2 - assert im2_cview(x,y) == value2 + # jax galsim does not support views + assert im2_cview(x,y) != value2 assert im1.real(x,y) == value2.real assert im1.view().real(x,y) == value2.real From bcee24210910357409827c7e345810fe94105a5e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:35:43 -0600 Subject: [PATCH 145/351] no references --- tests/test_image.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 66029d100a..5da738420a 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2735,15 +2735,19 @@ def test_complex_image(): assert im1.real(x,y) == value2.real assert im1.view().real(x,y) == value2.real assert im1.view(make_const=True).real(x,y) == value2.real - assert im2.real(x,y) == value2.real + # jax galsim does not support views + assert im2.real(x,y) != value2.real assert im2_view.real(x,y) == value2.real - assert im2_cview.real(x,y) == value2.real + # jax galsim does not support views + assert im2_cview.real(x,y) != value2.real assert im1.imag(x,y) == value2.imag assert im1.view().imag(x,y) == value2.imag assert im1.view(make_const=True).imag(x,y) == value2.imag - assert im2.imag(x,y) == value2.imag + # jax galsim does not support views + assert im2.imag(x,y) != value2.imag assert im2_view.imag(x,y) == value2.imag - assert im2_cview.imag(x,y) == value2.imag + # jax galsim does not support views + assert im2_cview.imag(x,y) != value2.imag assert im1.conjugate(x,y) == np.conjugate(value2) assert im2.conjugate(x,y) == np.conjugate(value2) From cb757254fc5f1b8eed1dcca1e8252fc18a77c2a9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:36:57 -0600 Subject: [PATCH 146/351] no references --- tests/test_image.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 5da738420a..fb40cee9f1 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2709,16 +2709,25 @@ def test_complex_image(): assert im1.view()(x,y) == value assert im1.view(make_const=True)(x,y) == value # jax galsim does not support views - assert im2(x,y) != value + if hasattr(galsim, "_galsim"): + assert im2(x,y) == value + else: + assert im2(x,y) != value assert im2_view(x,y) == value # jax galsim does not support views - assert im2_cview(x,y) != value + if hasattr(galsim, "_galsim"): + assert im2_cview(x,y) == value + else: + assert im2_cview(x,y) != value assert im1.conjugate(x,y) == np.conjugate(value) # complex conjugate is not a view into the original. assert im2_conj(x,y) == 23 # jax galsim does not support views - assert im2.conjugate(x,y) != np.conjugate(value) + if hasattr(galsim, "_galsim"): + assert im2.conjugate(x,y) == np.conjugate(value) + else: + assert im2.conjugate(x,y) != np.conjugate(value) value2 = 10*x + y + 20j*x + 2j*y im1.setValue(x,y, value2) From 6214b62639c809f66b3642d8eaac4a9a52b902fb Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:38:48 -0600 Subject: [PATCH 147/351] no references --- tests/test_image.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index fb40cee9f1..e5acd98d08 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2736,27 +2736,45 @@ def test_complex_image(): assert im1.view()(x,y) == value2 assert im1.view(make_const=True)(x,y) == value2 # jax galsim does not support views - assert im2(x,y) != value2 + if hasattr(galsim, "_galsim"): + assert im2(x,y) == value2 + else: + assert im2(x,y) != value2 assert im2_view(x,y) == value2 # jax galsim does not support views - assert im2_cview(x,y) != value2 + if hasattr(galsim, "_galsim"): + assert im2_cview(x,y) == value2 + else: + assert im2_cview(x,y) != value2 assert im1.real(x,y) == value2.real assert im1.view().real(x,y) == value2.real assert im1.view(make_const=True).real(x,y) == value2.real # jax galsim does not support views - assert im2.real(x,y) != value2.real + if hasattr(galsim, "_galsim"): + assert im2.real(x,y) == value2.real + else: + assert im2.real(x,y) != value2.real assert im2_view.real(x,y) == value2.real # jax galsim does not support views - assert im2_cview.real(x,y) != value2.real + if hasattr(galsim, "_galsim"): + assert im2_cview.real(x,y) == value2.real + else: + assert im2_cview.real(x,y) != value2.real assert im1.imag(x,y) == value2.imag assert im1.view().imag(x,y) == value2.imag assert im1.view(make_const=True).imag(x,y) == value2.imag # jax galsim does not support views - assert im2.imag(x,y) != value2.imag + if hasattr(galsim, "_galsim"): + assert im2.imag(x,y) == value2.imag + else: + assert im2.imag(x,y) != value2.imag assert im2_view.imag(x,y) == value2.imag # jax galsim does not support views - assert im2_cview.imag(x,y) != value2.imag + if hasattr(galsim, "_galsim"): + assert im2_cview.imag(x,y) == value2.imag + else: + assert im2_cview.imag(x,y) != value2.imag assert im1.conjugate(x,y) == np.conjugate(value2) assert im2.conjugate(x,y) == np.conjugate(value2) From 5e5b57d2b82ca5e60e5f934580df158b53d5ef87 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:39:18 -0600 Subject: [PATCH 148/351] no references --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index e5acd98d08..c1d71d1d26 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2776,7 +2776,11 @@ def test_complex_image(): else: assert im2_cview.imag(x,y) != value2.imag assert im1.conjugate(x,y) == np.conjugate(value2) - assert im2.conjugate(x,y) == np.conjugate(value2) + # jax galsim does not support views + if hasattr(galsim, "_galsim"): + assert im2.conjugate(x,y) == np.conjugate(value2) + else: + assert im2.conjugate(x,y) != np.conjugate(value2) rvalue3 = 12*x + y ivalue3 = x + 21*y From 1d988d1d40d46d140e1a0ff8dde4f670c96a939c Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:40:51 -0600 Subject: [PATCH 149/351] no references --- tests/test_image.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index c1d71d1d26..c071758e8b 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2789,9 +2789,15 @@ def test_complex_image(): im1.imag.setValue(x,y, ivalue3) im2_view.real.setValue(x,y, rvalue3) im2_view.imag.setValue(x,y, ivalue3) - assert im1(x,y) == value3 - assert im1.view()(x,y) == value3 - assert im1.view(make_const=True)(x,y) == value3 + # jax galsim does not support views + if hasattr(galsim, "_galsim"): + assert im1(x,y) == value3 + assert im1.view()(x,y) == value3 + assert im1.view(make_const=True)(x,y) == value3 + else: + assert im1(x,y) != value3 + assert im1.view()(x,y) != value3 + assert im1.view(make_const=True)(x,y) != value3 assert im2(x,y) == value3 assert im2_view(x,y) == value3 assert im2_cview(x,y) == value3 From 7191fa036ce7cef7bb49cf395bf6a15a4568d1ef Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:42:04 -0600 Subject: [PATCH 150/351] no references --- tests/test_image.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index c071758e8b..98e862c3cf 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2794,15 +2794,20 @@ def test_complex_image(): assert im1(x,y) == value3 assert im1.view()(x,y) == value3 assert im1.view(make_const=True)(x,y) == value3 + assert im2(x,y) == value3 + assert im2_view(x,y) == value3 + assert im2_cview(x,y) == value3 + assert im1.conjugate(x,y) == np.conjugate(value3) + assert im2.conjugate(x,y) == np.conjugate(value3) else: assert im1(x,y) != value3 assert im1.view()(x,y) != value3 assert im1.view(make_const=True)(x,y) != value3 - assert im2(x,y) == value3 - assert im2_view(x,y) == value3 - assert im2_cview(x,y) == value3 - assert im1.conjugate(x,y) == np.conjugate(value3) - assert im2.conjugate(x,y) == np.conjugate(value3) + assert im2(x,y) != value3 + assert im2_view(x,y) != value3 + assert im2_cview(x,y) != value3 + assert im1.conjugate(x,y) != np.conjugate(value3) + assert im2.conjugate(x,y) != np.conjugate(value3) # Check view of given data im3_view = galsim.Image((1+2j)*ref_array.astype(complex)) From 90791a62b6f29028c070587203e3de7e98ad6a77 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:46:05 -0600 Subject: [PATCH 151/351] weird failure --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 98e862c3cf..2093890065 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2729,7 +2729,7 @@ def test_complex_image(): else: assert im2.conjugate(x,y) != np.conjugate(value) - value2 = 10*x + y + 20j*x + 2j*y + value2 = 400000 + 10*x + y + 20j*x + 2j*y im1.setValue(x,y, value2) im2_view.setValue(x=x, y=y, value=value2) assert im1(x,y) == value2 From 0505fc7cdcf7634652d2a2b7b6ff3f07edf1a8e6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:47:35 -0600 Subject: [PATCH 152/351] weird failure --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 2093890065..d948c13a32 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2844,7 +2844,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image2.array, ref_array * (2+5j), err_msg="ImageD * complex is not correct") image2 = image1 / (2+5j) - np.testing.assert_array_equal(image2.array, ref_array / (2+5j), + np.testing.assert_array_allclose(image2.array, ref_array / (2+5j), err_msg="ImageD / complex is not correct") # Binary complex scalar op ImageD From 6b5fa527d3498584e1d0f1e128fd7a2dc2b372b1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:47:57 -0600 Subject: [PATCH 153/351] weird failure --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index d948c13a32..d62ef6c018 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2844,7 +2844,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image2.array, ref_array * (2+5j), err_msg="ImageD * complex is not correct") image2 = image1 / (2+5j) - np.testing.assert_array_allclose(image2.array, ref_array / (2+5j), + np.testing.assert_allclose(image2.array, ref_array / (2+5j), err_msg="ImageD / complex is not correct") # Binary complex scalar op ImageD From 5c838bb7aefd7ffe10b771b01687c99040ba880a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:48:35 -0600 Subject: [PATCH 154/351] weird failure --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index d62ef6c018..a1720729e5 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2858,7 +2858,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image2.array, ref_array * (2+5j), err_msg="complex * ImageD is not correct") image2 = (2+5j) / image1 - np.testing.assert_array_equal(image2.array, (2+5j) / ref_array.astype(float), + np.testing.assert_allclose(image2.array, (2+5j) / ref_array.astype(float), err_msg="complex / ImageD is not correct") image2 = image1 * (3+1j) From b2700bbcf148c4916e5ba0c97207a1898cae4306 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:48:57 -0600 Subject: [PATCH 155/351] weird failure --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index a1720729e5..07289967e5 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2874,7 +2874,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image3.array, (3+1j)*ref_array * (2+5j), err_msg="ImageCD * complex is not correct") image3 = image2 / (2+5j) - np.testing.assert_array_equal(image3.array, (3+1j)*ref_array / (2+5j), + np.testing.assert_allclose(image3.array, (3+1j)*ref_array / (2+5j), err_msg="ImageCD / complex is not correct") # Binary complex scalar op ImageCD From ff23b6d77e5a806925fff99c918e26865f049c29 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:49:26 -0600 Subject: [PATCH 156/351] weird failure --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 07289967e5..fde4535211 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2888,7 +2888,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image3.array, (3+1j)*ref_array * (2+5j), err_msg="complex * ImageCD is not correct") image3 = (2+5j) / image2 - np.testing.assert_array_equal(image3.array, (2+5j) / ((3+1j)*ref_array), + np.testing.assert_allclose(image3.array, (2+5j) / ((3+1j)*ref_array), err_msg="complex / ImageCD is not correct") # Binary ImageD op ImageCD From 6539ce160de698ad03a285e5b6f4d422cf52d7f7 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:50:24 -0600 Subject: [PATCH 157/351] weird failure --- tests/test_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index fde4535211..6bf92804ef 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2902,7 +2902,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image3.array, (3+1j)*ref_array**2, err_msg="ImageD * ImageCD is not correct") image3 = image1 / image2 - np.testing.assert_almost_equal(image3.array, 1./(3+1j), decimal=12, + np.testing.assert_array_almost_equal(image3.array, 1./(3+1j), decimal=12, err_msg="ImageD / ImageCD is not correct") # Binary ImageCD op ImageD @@ -2916,7 +2916,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image3.array, (3+1j)*ref_array**2, err_msg="ImageD * ImageCD is not correct") image3 = image2 / image1 - np.testing.assert_almost_equal(image3.array, (3+1j), decimal=12, + np.testing.assert_array_almost_equal(image3.array, (3+1j), decimal=12, err_msg="ImageD / ImageCD is not correct") # Binary ImageCD op ImageCD @@ -2931,7 +2931,7 @@ def test_complex_image_arith(): np.testing.assert_array_equal(image4.array, (15-5j)*ref_array**2, err_msg="ImageCD * ImageCD is not correct") image4 = image2 / image3 - np.testing.assert_almost_equal(image4.array, (9+13j)/25., decimal=12, + np.testing.assert_array_almost_equal(image4.array, (9+13j)/25., decimal=12, err_msg="ImageCD / ImageCD is not correct") # In place ImageCD op complex scalar From 46a0e1010ba4b5772cf97b2fd1ad3a9bef3dbfab Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:51:03 -0600 Subject: [PATCH 158/351] weird failure --- tests/test_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 6bf92804ef..14e7c1d387 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -2949,7 +2949,7 @@ def test_complex_image_arith(): err_msg="ImageCD * complex is not correct") image4 = image2.copy() image4 /= (2+5j) - np.testing.assert_array_equal(image4.array, (3+1j)*ref_array / (2+5j), + np.testing.assert_allclose(image4.array, (3+1j)*ref_array / (2+5j), err_msg="ImageCD / complex is not correct") # In place ImageCD op ImageD @@ -2967,7 +2967,7 @@ def test_complex_image_arith(): err_msg="ImageD * ImageCD is not correct") image4 = image2.copy() image4 /= image1 - np.testing.assert_almost_equal(image4.array, (3+1j), decimal=12, + np.testing.assert_array_almost_equal(image4.array, (3+1j), decimal=12, err_msg="ImageD / ImageCD is not correct") # In place ImageCD op ImageCD @@ -2985,7 +2985,7 @@ def test_complex_image_arith(): err_msg="ImageCD * ImageCD is not correct") image4 = image2.copy() image4 /= image3 - np.testing.assert_almost_equal(image4.array, (9+13j)/25., decimal=12, + np.testing.assert_array_almost_equal(image4.array, (9+13j)/25., decimal=12, err_msg="ImageCD / ImageCD is not correct") @timer From 56dc7885ea1bee9681b0ee9b75047ca382c59801 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:51:53 -0600 Subject: [PATCH 159/351] weird failure --- tests/test_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 14e7c1d387..11f84bd45d 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -3334,7 +3334,7 @@ def test_wrap(): b = galsim.BoundsI(1,4,1,4) im_quad = im_orig[b] im_wrap = im.wrap(b) - np.testing.assert_almost_equal(im_wrap.array, 4.*im_quad.array, 12, + np.testing.assert_array_almost_equal(im_wrap.array, 4.*im_quad.array, 12, "image.wrap() into first quadrant did not match expectation") # The same thing should work no matter where the lower left corner is: @@ -3343,7 +3343,7 @@ def test_wrap(): im_quad = im_orig[b] im = im_orig.copy() im_wrap = im.wrap(b) - np.testing.assert_almost_equal(im_wrap.array, 4.*im_quad.array, 12, + np.testing.assert_array_almost_equal(im_wrap.array, 4.*im_quad.array, 12, "image.wrap(%s) did not match expectation"%b) np.testing.assert_array_equal(im_wrap.array, im[b].array, "image.wrap(%s) did not return the right subimage") @@ -3365,7 +3365,7 @@ def test_wrap(): jj = (j-b.ymin) % (b.ymax-b.ymin+1) + b.ymin im_test.addValue(ii,jj,val) im_wrap = im.wrap(b) - np.testing.assert_almost_equal(im_wrap.array, im_test.array, 12, + np.testing.assert_array_almost_equal(im_wrap.array, im_test.array, 12, "image.wrap(%s) did not match expectation"%b) np.testing.assert_array_equal(im_wrap.array, im[b].array, "image.wrap(%s) did not return the right subimage") From 0035409a0dc35ade97c3742ddcf0f52f71a2bde5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 12:52:43 -0600 Subject: [PATCH 160/351] weird failure --- tests/test_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 11f84bd45d..7ba4aa09a1 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -3412,7 +3412,7 @@ def test_wrap(): im_wrap = im.wrap(b) #print("im_wrap = ",im_wrap.array) - np.testing.assert_almost_equal(im_wrap.array, im_test.array, 12, + np.testing.assert_array_almost_equal(im_wrap.array, im_test.array, 12, "image.wrap(%s) did not match expectation"%b) np.testing.assert_array_equal(im_wrap.array, im[b].array, "image.wrap(%s) did not return the right subimage") @@ -3423,7 +3423,7 @@ def test_wrap(): #print('im_test = ',im_test[b2].array) #print('im2_wrap = ',im2_wrap.array) #print('diff = ',im2_wrap.array-im_test[b2].array) - np.testing.assert_almost_equal(im2_wrap.array, im_test[b2].array, 12, + np.testing.assert_array_almost_equal(im2_wrap.array, im_test[b2].array, 12, "image.wrap(%s) did not match expectation"%b) np.testing.assert_array_equal(im2_wrap.array, im2[b2].array, "image.wrap(%s) did not return the right subimage") @@ -3434,7 +3434,7 @@ def test_wrap(): #print('im_test = ',im_test[b3].array) #print('im3_wrap = ',im3_wrap.array) #print('diff = ',im3_wrap.array-im_test[b3].array) - np.testing.assert_almost_equal(im3_wrap.array, im_test[b3].array, 12, + np.testing.assert_array_almost_equal(im3_wrap.array, im_test[b3].array, 12, "image.wrap(%s) did not match expectation"%b) np.testing.assert_array_equal(im3_wrap.array, im3[b3].array, "image.wrap(%s) did not return the right subimage") From b2c451f8d21bb8140d9d5d3f540d1b6904a9b7d3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:00:18 -0600 Subject: [PATCH 161/351] paths --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 7ba4aa09a1..dc6f43ecfe 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -3612,7 +3612,7 @@ def test_fpack(): """Test the functionality that we advertise as being equivalent to fpack/funpack """ from astropy.io import fits - file_name0 = os.path.join('des_data','DECam_00158414_01.fits.fz') + file_name0 = os.path.join(os.path.dirname(__file__), 'des_data','DECam_00158414_01.fits.fz') hdulist = fits.open(file_name0) # Remove a few invalid header keys in the DECam fits file From ed7dae24b646658866fcd18a71b73ecb9e53bc2e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:08:17 -0600 Subject: [PATCH 162/351] paths --- tests/test_inclined.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_inclined.py b/tests/test_inclined.py index 7221e007b7..ed35d333c5 100644 --- a/tests/test_inclined.py +++ b/tests/test_inclined.py @@ -109,7 +109,10 @@ def test_regression(): for (flux, _sersic_n, inc_angle, scale_radius, scale_height, _trunc_factor, pos_angle) in inclined_exponential_test_parameters: - image_filename = "galaxy_" + inc_angle + "_" + scale_radius + "_" + scale_height + "_" + pos_angle + ".fits" + image_filename = os.path.join( + os.path.dirname(__file__), + "galaxy_" + inc_angle + "_" + scale_radius + "_" + scale_height + "_" + pos_angle + ".fits" + ) print("Comparing " + mode + " against " + image_filename + "...") # Get float values for the details From 27bfe2bcf45fb46441ec5b169a2f724557fe168e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:09:36 -0600 Subject: [PATCH 163/351] paths --- tests/test_inclined.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/test_inclined.py b/tests/test_inclined.py index ed35d333c5..0f7b4671d5 100644 --- a/tests/test_inclined.py +++ b/tests/test_inclined.py @@ -30,7 +30,7 @@ # set up any necessary info for tests # Note that changes here should match changes to test image files -image_dir = './inclined_exponential_images' +image_dir = os.path.join(os.path.dirname(__file__), './inclined_exponential_images') # Values here are strings, so the filenames will be sure to work (without truncating zeros) @@ -109,10 +109,7 @@ def test_regression(): for (flux, _sersic_n, inc_angle, scale_radius, scale_height, _trunc_factor, pos_angle) in inclined_exponential_test_parameters: - image_filename = os.path.join( - os.path.dirname(__file__), - "galaxy_" + inc_angle + "_" + scale_radius + "_" + scale_height + "_" + pos_angle + ".fits" - ) + image_filename = "galaxy_" + inc_angle + "_" + scale_radius + "_" + scale_height + "_" + pos_angle + ".fits" print("Comparing " + mode + " against " + image_filename + "...") # Get float values for the details From cc94ba845c818a6e0bd041b1d1e85a4324e18f36 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:12:31 -0600 Subject: [PATCH 164/351] paths --- tests/test_lensing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lensing.py b/tests/test_lensing.py index 68e83625cf..0923571bfb 100644 --- a/tests/test_lensing.py +++ b/tests/test_lensing.py @@ -25,7 +25,7 @@ from galsim_test_helpers import * -refdir = os.path.join(".", "lensing_reference_data") # Directory containing the reference +refdir = os.path.join(os.path.dirname(__file__), ".", "lensing_reference_data") # Directory containing the reference klim_test = 0.00175 # Value of klim for flat (up to klim, then zero beyond) power spectrum test tolerance_var = 0.03 # fractional error allowed in the variance of shear - calculation is not exact From ad4395dd8ffb7d956c30335e415c277996ddd1d0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:16:28 -0600 Subject: [PATCH 165/351] norefs --- tests/test_noise.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index fb6e3506f1..3159819e99 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -39,7 +39,11 @@ def test_deviate_noise(): """ u = galsim.UniformDeviate(testseed) uResult = np.empty((10,10)) - u.generate(uResult) + # jax-galsim cannot fill arrays so it returns + if hasattr(galsim, "_galsim"): + u.generate(uResult) + else: + uResult = u.generate(uResult) noise = galsim.DeviateNoise(galsim.UniformDeviate(testseed)) From f3aefd27dd217e97574812efa2b46d370cad043a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:17:05 -0600 Subject: [PATCH 166/351] norefs --- tests/test_noise.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 3159819e99..52325dd669 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -106,7 +106,11 @@ def test_gaussian_noise(): gSigma = 17.23 g = galsim.GaussianDeviate(testseed, sigma=gSigma) gResult = np.empty((10,10)) - g.generate(gResult) + # jax-galsim cannot fill arrays so it returns + if hasattr(galsim, "_galsim"): + g.generate(gResult) + else: + gResult = g.generate(gResult) noise = galsim.DeviateNoise(g) # Test filling an image From 5158546912e8ea353b75219a56ace3d915dddbbe Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:18:38 -0600 Subject: [PATCH 167/351] norefs --- tests/test_noise.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 52325dd669..66260c9e6c 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -286,8 +286,13 @@ def test_variable_gaussian_noise(): gSigma2 = 28.55 var_image = galsim.ImageD(galsim.BoundsI(0,9,0,9)) coords = np.ogrid[0:10, 0:10] - var_image.array[ (coords[0] + coords[1]) % 2 == 1 ] = gSigma1**2 - var_image.array[ (coords[0] + coords[1]) % 2 == 0 ] = gSigma2**2 + # jax does not support titem assignment + if hasattr(galsim, "_galsim"): + var_image.array[ (coords[0] + coords[1]) % 2 == 1 ] = gSigma1**2 + var_image.array[ (coords[0] + coords[1]) % 2 == 0 ] = gSigma2**2 + else: + var_image._array = var_image.array.at[(coords[0] + coords[1]) % 2 == 1].set(gSigma1**2) + var_image._array = var_image.array.at[(coords[0] + coords[1]) % 2 == 0].set(gSigma2**2) print('var_image.array = ',var_image.array) g = galsim.GaussianDeviate(testseed, sigma=1.) From 54cffecb2dfd0aabcf4401b65d581455abfa6ba8 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:19:47 -0600 Subject: [PATCH 168/351] norefs --- tests/test_noise.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 66260c9e6c..462c034b9e 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -297,7 +297,11 @@ def test_variable_gaussian_noise(): g = galsim.GaussianDeviate(testseed, sigma=1.) vgResult = np.empty((10,10)) - g.generate(vgResult) + # jax-galsim cannot fill arrays so it returns + if hasattr(galsim, "_galsim"): + g.generate(vgResult) + else: + vgResult = g.generate(vgResult) vgResult *= np.sqrt(var_image.array) # Test filling an image From ebf552ce0c9e3ef32546fa08ddd074c5bfce8701 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:20:39 -0600 Subject: [PATCH 169/351] norefs --- tests/test_noise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 462c034b9e..3a02e534b8 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -321,7 +321,7 @@ def test_variable_gaussian_noise(): err_msg="Wrong VariableGaussian noise generated for Fortran-ordered Image") # Check var_image property - np.testing.assert_almost_equal( + np.testing.assert_array_almost_equal( vgn.var_image.array, var_image.array, precision, err_msg="VariableGaussianNoise var_image returns wrong var_image") From da90aaca2bb3f1aaa8cd65360f3a5edb1e53c868 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:22:04 -0600 Subject: [PATCH 170/351] norefs --- tests/test_noise.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 3a02e534b8..43705b1bad 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -286,7 +286,7 @@ def test_variable_gaussian_noise(): gSigma2 = 28.55 var_image = galsim.ImageD(galsim.BoundsI(0,9,0,9)) coords = np.ogrid[0:10, 0:10] - # jax does not support titem assignment + # jax does not support item assignment if hasattr(galsim, "_galsim"): var_image.array[ (coords[0] + coords[1]) % 2 == 1 ] = gSigma1**2 var_image.array[ (coords[0] + coords[1]) % 2 == 0 ] = gSigma2**2 @@ -330,8 +330,13 @@ def test_variable_gaussian_noise(): big_coords = np.ogrid[0:2048, 0:2048] mask1 = (big_coords[0] + big_coords[1]) % 2 == 0 mask2 = (big_coords[0] + big_coords[1]) % 2 == 1 - big_var_image.array[mask1] = gSigma1**2 - big_var_image.array[mask2] = gSigma2**2 + # jax does not support item assignment + if hasattr(galsim, "_galsim"): + big_var_image.array[mask1] = gSigma1**2 + big_var_image.array[mask2] = gSigma2**2 + else: + big_var_image._array = big_var_image.array.at[mask1].set(gSigma1**2) + big_var_image._array = big_var_image.array.at[mask2].set(gSigma2**2) big_vgn = galsim.VariableGaussianNoise(galsim.BaseDeviate(testseed), big_var_image) big_im = galsim.Image(2048,2048,dtype=float) From 51a85832d26168da95f9d2ef76fdfc5fd9ed2ad0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:23:24 -0600 Subject: [PATCH 171/351] norefs --- tests/test_noise.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 43705b1bad..348fe17305 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -344,8 +344,9 @@ def test_variable_gaussian_noise(): var = np.var(big_im.array) print('variance = ',var) print('getVar = ',big_vgn.var_image.array.mean()) + # jax galsim has a different RNG np.testing.assert_almost_equal( - var, big_vgn.var_image.array.mean(), 1, + var, big_vgn.var_image.array.mean(), 1 if hasattr(galsim, "_galsim") else 0, err_msg='Realized variance for VariableGaussianNoise did not match var_image') # Check realized variance in each mask From 3fbe8d414f83e878f2490c289462ea0788d339ce Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:24:14 -0600 Subject: [PATCH 172/351] norefs --- tests/test_noise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 348fe17305..6d4f61a7a6 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -363,7 +363,7 @@ def test_variable_gaussian_noise(): gal.withFlux(-1.e4).drawImage(image=big_im, add_to_image=True) var = np.var(big_im.array) np.testing.assert_almost_equal( - var, big_vgn.var_image.array.mean(), 1, + var, big_vgn.var_image.array.mean(), 1 if hasattr(galsim, "_galsim") else 0, err_msg='VariableGaussianNoise wrong when already an object drawn on the image') # Check picklability From e2cfddde3a6de0c0f927747d0dd00a3c7ec75319 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:25:17 -0600 Subject: [PATCH 173/351] norefs --- tests/test_noise.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 6d4f61a7a6..3390ca0186 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -401,7 +401,11 @@ def test_poisson_noise(): pMean = 17 p = galsim.PoissonDeviate(testseed, mean=pMean) pResult = np.empty((10,10)) - p.generate(pResult) + # jax does not support item assignment + if hasattr(galsim, "_galsim"): + p.generate(pResult) + else: + pResult = p.generate(pResult) noise = galsim.DeviateNoise(p) # Test filling an image From 93632dff4903d63bf9417f89103d865aa46d1172 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:53:11 -0600 Subject: [PATCH 174/351] norefs --- tests/test_noise.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 3390ca0186..02b43ce927 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -574,11 +574,24 @@ def test_ccdnoise(): sky = 50 # Tabulated results for the above settings and testseed value. - cResultS = np.array([[44, 47], [50, 49]], dtype=np.int16) - cResultI = np.array([[44, 47], [50, 49]], dtype=np.int32) - cResultF = np.array([[44.45332718, 47.79725266], [50.67744064, 49.58272934]], dtype=np.float32) - cResultD = np.array([[44.453328440057618, 47.797254142519577], - [50.677442088335162, 49.582730949808081]],dtype=np.float64) + if hasattr(galsim, "_galsim"): + cResultS = np.array([[44, 47], [50, 49]], dtype=np.int16) + cResultI = np.array([[44, 47], [50, 49]], dtype=np.int32) + cResultF = np.array([[44.45332718, 47.79725266], [50.67744064, 49.58272934]], dtype=np.float32) + cResultD = np.array([[44.453328440057618, 47.797254142519577], + [50.677442088335162, 49.582730949808081]],dtype=np.float64) + else: + # jax-galsim has a different RNG + cResultS = np.array([[42, 52], [49, 45]], dtype=np.int16) # noqa: F841 + cResultI = np.array([[42, 52], [49, 45]], dtype=np.int32) # noqa: F841 + cResultF = np.array([ # noqa: F841 + [42.4286994934082, 52.42875671386719], + [49.016048431396484, 45.61003875732422] + ], dtype=np.float32) + cResultD = np.array([ # noqa: F841 + [42.42870031326479, 52.42875718917211], + [49.016050296441094, 45.61003745208172] + ], dtype=np.float64) for i in range(4): prec = eval("precision"+typestrings[i]) From 4ba61f6ab246804e6dfa3ffd720510c04739dc2e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:54:32 -0600 Subject: [PATCH 175/351] paths --- tests/test_optics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_optics.py b/tests/test_optics.py index 790f15fc32..b9c5df5c31 100644 --- a/tests/test_optics.py +++ b/tests/test_optics.py @@ -22,7 +22,7 @@ import galsim from galsim_test_helpers import * -imgdir = os.path.join(".", "Optics_comparison_images") # Directory containing the reference images. +imgdir = os.path.join(os.path.dirname(__file__), "Optics_comparison_images") # Directory containing the reference images. testshape = (512, 512) # shape of image arrays for all tests From f6cfcd60f32edfaf344a5c401bb72fc88e71006a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:55:52 -0600 Subject: [PATCH 176/351] paths --- tests/test_optics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_optics.py b/tests/test_optics.py index b9c5df5c31..97c0d3b868 100644 --- a/tests/test_optics.py +++ b/tests/test_optics.py @@ -745,7 +745,11 @@ def test_OpticalPSF_pupil_plane_size(): im = galsim.Image(512, 512) x = y = np.arange(512) - 256 y, x = np.meshgrid(y, x) - im.array[x**2+y**2 < 230**2] = 1.0 + if hasattr(galsim, "_galsim"): + im.array[x**2+y**2 < 230**2] = 1.0 + else: + # no refs in jax-galsim + im._array = im.array.at[x**2+y**2 < 230**2].set(1.0) # The following still fails (uses deprecated optics framework): # galsim.optics.OpticalPSF(aberrations=[0,0,0,0,0.5], diam=4.0, lam=700.0, pupil_plane_im=im) # But using the new framework, should work. From 53cd860cfb36ea5ca1ee38f0a3dcf7ebfcdfbb23 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 13:57:06 -0600 Subject: [PATCH 177/351] paths --- tests/test_phase_psf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_phase_psf.py b/tests/test_phase_psf.py index b4aa75122d..1b3fd78be5 100644 --- a/tests/test_phase_psf.py +++ b/tests/test_phase_psf.py @@ -24,7 +24,7 @@ from galsim_test_helpers import * -imgdir = os.path.join(".", "Optics_comparison_images") # Directory containing the reference images. +imgdir = os.path.join(os.path.dirname(__file__), "Optics_comparison_images") # Directory containing the reference images. pp_file = 'sample_pupil_rolled.fits' theta0 = (0*galsim.arcmin, 0*galsim.arcmin) From f50323f1fb1ca114af83613b5c2d64ec6475a672 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:10:19 -0600 Subject: [PATCH 178/351] norefs --- tests/test_photon_array.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 729a791bf7..18abd538ce 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -61,12 +61,14 @@ def test_photon_array(): check_pickle(photon_array) # Check assignment via numpy [:] - photon_array.x[:] = 5 - photon_array.y[:] = 17 - photon_array.flux[:] = 23 - np.testing.assert_array_equal(photon_array.x, 5.) - np.testing.assert_array_equal(photon_array.y, 17.) - np.testing.assert_array_equal(photon_array.flux, 23.) + # jax does not support direct assignment + if hasattr(galsim, "_galsim"): + photon_array.x[:] = 5 + photon_array.y[:] = 17 + photon_array.flux[:] = 23 + np.testing.assert_array_equal(photon_array.x, 5.) + np.testing.assert_array_equal(photon_array.y, 17.) + np.testing.assert_array_equal(photon_array.flux, 23.) # Check assignment directly to the attributes photon_array.x = 25 From 2100ade6ad2fc47068c2d33563c5202c44122035 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:11:34 -0600 Subject: [PATCH 179/351] norefs --- tests/test_photon_array.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 18abd538ce..efedbb6529 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -97,9 +97,9 @@ def test_photon_array(): photon_array.x *= 5 photon_array.y += 17 photon_array.flux /= 23 - np.testing.assert_almost_equal(photon_array.x, orig_x * 5.) - np.testing.assert_almost_equal(photon_array.y, orig_y + 17.) - np.testing.assert_almost_equal(photon_array.flux, orig_flux / 23.) + np.testing.assert_array_almost_equal(photon_array.x, orig_x * 5.) + np.testing.assert_array_almost_equal(photon_array.y, orig_y + 17.) + np.testing.assert_array_almost_equal(photon_array.flux, orig_flux / 23.) # Check picklability again with non-zero values check_pickle(photon_array) @@ -108,12 +108,12 @@ def test_photon_array(): photon_array.dxdz = 0.17 assert photon_array.hasAllocatedAngles() assert not photon_array.hasAllocatedWavelengths() - np.testing.assert_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_equal(photon_array.dydz, 0.) + np.testing.assert_array_array_equal(photon_array.dxdz, 0.17) + np.testing.assert_array_array_equal(photon_array.dydz, 0.) photon_array.dydz = 0.59 - np.testing.assert_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_equal(photon_array.dydz, 0.59) + np.testing.assert_array_array_equal(photon_array.dxdz, 0.17) + np.testing.assert_array_array_equal(photon_array.dydz, 0.59) # Check shooting negative flux obj = galsim.Exponential(flux=-1.7, scale_radius=2.3) From 9e69cc101d854cccbbfebe855ac0bf34357e7d3e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:12:03 -0600 Subject: [PATCH 180/351] norefs --- tests/test_photon_array.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index efedbb6529..8c372ff2ee 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -108,12 +108,12 @@ def test_photon_array(): photon_array.dxdz = 0.17 assert photon_array.hasAllocatedAngles() assert not photon_array.hasAllocatedWavelengths() - np.testing.assert_array_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_array_equal(photon_array.dydz, 0.) + np.testing.assert_array_equal(photon_array.dxdz, 0.17) + np.testing.assert_array_equal(photon_array.dydz, 0.) photon_array.dydz = 0.59 - np.testing.assert_array_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_array_equal(photon_array.dydz, 0.59) + np.testing.assert_array_equal(photon_array.dxdz, 0.17) + np.testing.assert_array_equal(photon_array.dydz, 0.59) # Check shooting negative flux obj = galsim.Exponential(flux=-1.7, scale_radius=2.3) From b2bcdc9669f14e69dea61246f10729222d6f4f7e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:12:44 -0600 Subject: [PATCH 181/351] norefs --- tests/test_photon_array.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 8c372ff2ee..963450132e 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -194,8 +194,8 @@ def test_photon_array(): x = photon_array.x.copy() y = photon_array.y.copy() photon_array.scaleXY(1.9) - np.testing.assert_almost_equal(photon_array.x, 1.9*x) - np.testing.assert_almost_equal(photon_array.y, 1.9*y) + np.testing.assert_array_almost_equal(photon_array.x, 1.9*x) + np.testing.assert_array_almost_equal(photon_array.y, 1.9*y) # Check ways to assign to photons pa1 = galsim.PhotonArray(50) From 2ef3457729074798effd9a7e3ee49686c6ff6ffc Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:13:57 -0600 Subject: [PATCH 182/351] norefs --- tests/test_photon_array.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 963450132e..e0b0684d7e 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -200,8 +200,11 @@ def test_photon_array(): # Check ways to assign to photons pa1 = galsim.PhotonArray(50) pa1.x = photon_array.x[:50] - for i in range(50): - pa1.y[i] = photon_array.y[i] + if hasattr(galsim, "_galsim"): + for i in range(50): + pa1.y[i] = photon_array.y[i] + else: + pa1.y = photon_array.y[:50] pa1.flux[0:50] = photon_array.flux[:50] pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] From 0994337f435c16cc4602325009c804039fe8455d Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:14:32 -0600 Subject: [PATCH 183/351] norefs --- tests/test_photon_array.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index e0b0684d7e..3ef7615559 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -205,7 +205,10 @@ def test_photon_array(): pa1.y[i] = photon_array.y[i] else: pa1.y = photon_array.y[:50] - pa1.flux[0:50] = photon_array.flux[:50] + if hasattr(galsim, "_galsim"): + pa1.flux[0:50] = photon_array.flux[:50] + else: + pa1.flux = photon_array.flux[:50] pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] pa1.wavelength = photon_array.wavelength[:50] From 458cabba3c11a17604d5cbe84c8cfb478090e447 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:15:14 -0600 Subject: [PATCH 184/351] norefs --- tests/test_photon_array.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 3ef7615559..3cd4cac439 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -215,15 +215,15 @@ def test_photon_array(): pa1.pupil_u = photon_array.pupil_u[:50] pa1.pupil_v = photon_array.pupil_v[:50] pa1.time = photon_array.time[:50] - np.testing.assert_almost_equal(pa1.x, photon_array.x[:50]) - np.testing.assert_almost_equal(pa1.y, photon_array.y[:50]) - np.testing.assert_almost_equal(pa1.flux, photon_array.flux[:50]) - np.testing.assert_almost_equal(pa1.dxdz, photon_array.dxdz[:50]) - np.testing.assert_almost_equal(pa1.dydz, photon_array.dydz[:50]) - np.testing.assert_almost_equal(pa1.wavelength, photon_array.wavelength[:50]) - np.testing.assert_almost_equal(pa1.pupil_u, photon_array.pupil_u[:50]) - np.testing.assert_almost_equal(pa1.pupil_v, photon_array.pupil_v[:50]) - np.testing.assert_almost_equal(pa1.time, photon_array.time[:50]) + np.testing.assert_array_almost_equal(pa1.x, photon_array.x[:50]) + np.testing.assert_array_almost_equal(pa1.y, photon_array.y[:50]) + np.testing.assert_array_almost_equal(pa1.flux, photon_array.flux[:50]) + np.testing.assert_array_almost_equal(pa1.dxdz, photon_array.dxdz[:50]) + np.testing.assert_array_almost_equal(pa1.dydz, photon_array.dydz[:50]) + np.testing.assert_array_almost_equal(pa1.wavelength, photon_array.wavelength[:50]) + np.testing.assert_array_almost_equal(pa1.pupil_u, photon_array.pupil_u[:50]) + np.testing.assert_array_almost_equal(pa1.pupil_v, photon_array.pupil_v[:50]) + np.testing.assert_array_almost_equal(pa1.time, photon_array.time[:50]) # Check assignAt pa2 = galsim.PhotonArray(100) From d2f41ff1a705b7bc95ffcf7c92070484ef4064fd Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:16:22 -0600 Subject: [PATCH 185/351] norefs --- tests/test_photon_array.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 3cd4cac439..e6ee4db7a9 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -229,24 +229,24 @@ def test_photon_array(): pa2 = galsim.PhotonArray(100) pa2.assignAt(0, pa1) pa2.assignAt(50, pa1) - 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.wavelength[:50], pa1.wavelength) - 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.time[:50], pa1.time) - 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.wavelength[50:], pa1.wavelength) - 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.time[50:], pa1.time) + 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.wavelength[:50], pa1.wavelength) + 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.time[:50], pa1.time) + 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.wavelength[50:], pa1.wavelength) + 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.time[50:], pa1.time) # Error if it doesn't fit. assert_raises(ValueError, pa2.assignAt, 90, pa1) From 52b9910b0f941925564a9c6f8ce6048af625842e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:42:00 -0600 Subject: [PATCH 186/351] norefs --- tests/test_photon_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index e6ee4db7a9..a13e261324 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -262,7 +262,7 @@ def test_photon_array(): photons = galsim.PhotonArray.makeFromImage(ones) print('photons = ',photons) assert len(photons) == 16 - np.testing.assert_almost_equal(photons.flux, 1.) + np.testing.assert_array_almost_equal(photons.flux, 1.) tens = galsim.Image(4,4,init_value=8) photons = galsim.PhotonArray.makeFromImage(tens, max_flux=5.) From 8427e0bf45eb8d6b9aa31ac75659698bfa40d98c Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:42:30 -0600 Subject: [PATCH 187/351] norefs --- tests/test_photon_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index a13e261324..bad286c5ba 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -268,7 +268,7 @@ def test_photon_array(): photons = galsim.PhotonArray.makeFromImage(tens, max_flux=5.) print('photons = ',photons) assert len(photons) == 32 - np.testing.assert_almost_equal(photons.flux, 4.) + np.testing.assert_array_almost_equal(photons.flux, 4.) assert_raises(ValueError, galsim.PhotonArray.makeFromImage, zero, max_flux=0.) assert_raises(ValueError, galsim.PhotonArray.makeFromImage, zero, max_flux=-2) From 5e4036a32b62b8120f34d0a57421df0c82593549 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:44:16 -0600 Subject: [PATCH 188/351] norefs --- tests/test_photon_array.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index bad286c5ba..06b96df547 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -1434,9 +1434,15 @@ def test_fromArrays(): flux[Nsplit:] ) - assert pa_batch.x is x - assert pa_batch.y is y - assert pa_batch.flux is flux + if hasattr(galsim, "_galsim"): + assert pa_batch.x is x + assert pa_batch.y is y + assert pa_batch.flux is flux + else: + # jax-galsim never copies + assert pa_batch.x is not x + assert pa_batch.y is not y + assert pa_batch.flux is not flux np.testing.assert_array_equal(pa_batch.x, x) np.testing.assert_array_equal(pa_batch.y, y) np.testing.assert_array_equal(pa_batch.flux, flux) From b2a33fb01fa53e4c4d45317c6bd1fdb8f68b3eb0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:46:03 -0600 Subject: [PATCH 189/351] norefs --- tests/test_random.py | 110 +++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 36 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 8c4bbbece1..e987271e8e 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -47,42 +47,80 @@ testseed = 1000 # seed used for UniformDeviate for all tests # Warning! If you change testseed, then all of the *Result variables below must change as well. -# the right answer for the first three uniform deviates produced from testseed -uResult = (0.11860922840423882, 0.21456799632869661, 0.43088198406621814) - -# mean, sigma to use for Gaussian tests -gMean = 4.7 -gSigma = 3.2 -# the right answer for the first three Gaussian deviates produced from testseed -gResult = (6.3344979808161215, 6.2082355273987861, -0.069894693358302007) - -# N, p to use for binomial tests -bN = 10 -bp = 0.7 -# the right answer for the first three binomial deviates produced from testseed -bResult = (9, 8, 7) - -# mean to use for Poisson tests -pMean = 7 -# the right answer for the first three Poisson deviates produced from testseed -pResult = (4, 5, 6) - -# a & b to use for Weibull tests -wA = 4. -wB = 9. -# Tabulated results for Weibull -wResult = (5.3648053017485591, 6.3093033550873878, 7.7982696798921074) - -# k & theta to use for Gamma tests -gammaK = 1.5 -gammaTheta = 4.5 -# Tabulated results for Gamma -gammaResult = (4.7375613139927157, 15.272973580418618, 21.485016362839747) - -# n to use for Chi2 tests -chi2N = 30 -# Tabulated results for Chi2 -chi2Result = (32.209933900954049, 50.040002656028513, 24.301442486313896) +if hasattr(galsim, "_galsim"): + # the right answer for the first three uniform deviates produced from testseed + uResult = (0.11860922840423882, 0.21456799632869661, 0.43088198406621814) + + # mean, sigma to use for Gaussian tests + gMean = 4.7 + gSigma = 3.2 + # the right answer for the first three Gaussian deviates produced from testseed + gResult = (6.3344979808161215, 6.2082355273987861, -0.069894693358302007) + + # N, p to use for binomial tests + bN = 10 + bp = 0.7 + # the right answer for the first three binomial deviates produced from testseed + bResult = (9, 8, 7) + + # mean to use for Poisson tests + pMean = 7 + # the right answer for the first three Poisson deviates produced from testseed + pResult = (4, 5, 6) + + # a & b to use for Weibull tests + wA = 4. + wB = 9. + # Tabulated results for Weibull + wResult = (5.3648053017485591, 6.3093033550873878, 7.7982696798921074) + + # k & theta to use for Gamma tests + gammaK = 1.5 + gammaTheta = 4.5 + # Tabulated results for Gamma + gammaResult = (4.7375613139927157, 15.272973580418618, 21.485016362839747) + + # n to use for Chi2 tests + chi2N = 30 + # Tabulated results for Chi2 + chi2Result = (32.209933900954049, 50.040002656028513, 24.301442486313896) +else: + # the right answer for the first three uniform deviates produced from testseed + uResult = (0.0160653916, 0.228817832, 0.1609966951) + + # mean, sigma to use for Gaussian tests + gMean = 4.7 + gSigma = 3.2 + # the right answer for the first three Gaussian deviates produced from testseed + gResult = (-2.1568953985, 2.3232138032, 1.5308165692) + + # N, p to use for binomial tests + bN = 10 + bp = 0.7 + # the right answer for the first three binomial deviates produced from testseed + bResult = (5, 8, 7) + + # mean to use for Poisson tests + pMean = 7 + # the right answer for the first three Poisson deviates produced from testseed + pResult = (6, 11, 4) + + # a & b to use for Weibull tests + wA = 4.0 + wB = 9.0 + # Tabulated results for Weibull + wResult = (3.2106530102, 6.4256210259, 5.8255498741) + + # k & theta to use for Gamma tests + gammaK = 1.5 + gammaTheta = 4.5 + # Tabulated results for Gamma + gammaResult = (10.9318881415, 7.6074550007, 2.0526795529) + + # n to use for Chi2 tests + chi2N = 30 + # Tabulated results for Chi2 + chi2Result = (36.7583415337, 32.7223187231, 23.1555198334) #function and min&max to use for DistDeviate function call tests dmin=0.0 From a534b6f09baae146ae666581594fc20cfa8f4dab Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:47:21 -0600 Subject: [PATCH 190/351] norefs --- tests/test_random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index e987271e8e..058a3381d5 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -47,7 +47,7 @@ testseed = 1000 # seed used for UniformDeviate for all tests # Warning! If you change testseed, then all of the *Result variables below must change as well. -if hasattr(galsim, "_galsim"): +if not hasattr(galsim, "_galsim"): # the right answer for the first three uniform deviates produced from testseed uResult = (0.11860922840423882, 0.21456799632869661, 0.43088198406621814) From eb019129438af7a43c04b606e71becf2cc1c629b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:52:12 -0600 Subject: [PATCH 191/351] norefs --- tests/test_random.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 058a3381d5..f6d05752f0 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -252,14 +252,20 @@ def test_uniform(): # Test generate u.seed(testseed) test_array = np.empty(3) - u.generate(test_array) + if hasattr(galsim, "_galsim"): + u.generate(test_array) + else: + test_array = u.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(uResult), precision, err_msg='Wrong uniform random number sequence from generate.') # Test add_generate u.seed(testseed) - u.add_generate(test_array) + if hasattr(galsim, "_galsim"): + u.add_generate(test_array) + else: + test_array = u.add_generate(test_array) np.testing.assert_array_almost_equal( test_array, 2.*np.array(uResult), precision, err_msg='Wrong uniform random number sequence from generate.') @@ -267,13 +273,20 @@ def test_uniform(): # Test generate with a float32 array u.seed(testseed) test_array = np.empty(3, dtype=np.float32) - u.generate(test_array) + if hasattr(galsim, "_galsim"): + u.generate(test_array) + else: + test_array = u.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(uResult), precisionF, err_msg='Wrong uniform random number sequence from generate.') # Test add_generate u.seed(testseed) + if hasattr(galsim, "_galsim"): + u.add_generate(test_array) + else: + test_array = u.add_generate(test_array) u.add_generate(test_array) np.testing.assert_array_almost_equal( test_array, 2.*np.array(uResult), precisionF, @@ -443,7 +456,10 @@ def test_gaussian(): # Test generate g.seed(testseed) test_array = np.empty(3) - g.generate(test_array) + if hasattr(galsim, "_galsim"): + g.generate(test_array) + else: + test_array = g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult), precision, err_msg='Wrong Gaussian random number sequence from generate.') From 88d7404df74383ae44d5b3deb76f06014039bcd0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:53:58 -0600 Subject: [PATCH 192/351] norefs --- tests/test_random.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index f6d05752f0..bc165a05e7 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -298,14 +298,26 @@ def test_uniform(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - u1.generate(v1) + if hasattr(galsim, "_galsim") + u1.generate(v1) + else: + v1 = u1.generate(v1) with single_threaded(num_threads=10): - u2.generate(v2) + if hasattr(galsim, "_galsim") + u2.generate(v2) + else: + v2 = u2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - u1.add_generate(v1) + if hasattr(galsim, "_galsim") + u1.add_generate(v1) + else: + v1 = u1.add_generate(v1) with single_threaded(num_threads=10): - u2.add_generate(v2) + if hasattr(galsim, "_galsim") + u2.add_generate(v2) + else: + v2 = u2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability From a6c0b3ddfb11fe6acb34e82a6ffc66f2a60c76d6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:54:19 -0600 Subject: [PATCH 193/351] norefs --- tests/test_random.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index bc165a05e7..cf21281426 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -298,23 +298,23 @@ def test_uniform(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - if hasattr(galsim, "_galsim") + if hasattr(galsim, "_galsim"): u1.generate(v1) else: v1 = u1.generate(v1) with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim") + if hasattr(galsim, "_galsim"): u2.generate(v2) else: v2 = u2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - if hasattr(galsim, "_galsim") + if hasattr(galsim, "_galsim"): u1.add_generate(v1) else: v1 = u1.add_generate(v1) with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim") + if hasattr(galsim, "_galsim"): u2.add_generate(v2) else: v2 = u2.add_generate(v2) From 913aa521a079db667f06cba06baf63693df18c13 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 14:57:54 -0600 Subject: [PATCH 194/351] norefs --- tests/test_random.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index cf21281426..b17144cb95 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -338,12 +338,14 @@ def test_uniform(): assert u1 != u2, "Consecutive UniformDeviate(None) compared equal!" # We shouldn't be able to construct a UniformDeviate from anything but a BaseDeviate, int, str, # or None. - assert_raises(TypeError, galsim.UniformDeviate, dict()) - assert_raises(TypeError, galsim.UniformDeviate, list()) - assert_raises(TypeError, galsim.UniformDeviate, set()) + if hasattr(galsim, "_galsim"): + # jax galsim doesn't test this + assert_raises(TypeError, galsim.UniformDeviate, dict()) + assert_raises(TypeError, galsim.UniformDeviate, list()) + assert_raises(TypeError, galsim.UniformDeviate, set()) - assert_raises(TypeError, u.seed, '123') - assert_raises(TypeError, u.seed, 12.3) + assert_raises(TypeError, u.seed, '123') + assert_raises(TypeError, u.seed, 12.3) @timer From 213823c02fd218bc3d8f8eea02cc66d084a4037e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:00:14 -0600 Subject: [PATCH 195/351] norefs --- tests/test_random.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index b17144cb95..9f54a9f2b4 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -388,14 +388,18 @@ def test_gaussian(): v1,v2 = g(),g2() print('after %d vals, next one is %s, %s'%(nvals,v1,v2)) assert v1 == v2 - # Note: For Gaussian, this only works if nvals is even. - g2 = galsim.GaussianDeviate(testseed, mean=gMean, sigma=gSigma) - g2.discard(nvals+1, suppress_warnings=True) - v1,v2 = g(),g2() - print('after %d vals, next one is %s, %s'%(nvals+1,v1,v2)) - assert v1 != v2 - assert g.has_reliable_discard - assert g.generates_in_pairs + if hasattr(galsim, "_galsim"): + # Note: For Gaussian, this only works if nvals is even. + g2 = galsim.GaussianDeviate(testseed, mean=gMean, sigma=gSigma) + g2.discard(nvals+1, suppress_warnings=True) + v1,v2 = g(),g2() + print('after %d vals, next one is %s, %s'%(nvals+1,v1,v2)) + assert v1 != v2 + assert g.has_reliable_discard + assert g.generates_in_pairs + else: + assert g.has_reliable_discard + assert not g.generates_in_pairs # If don't explicitly suppress the warning, then a warning is emitted when n is odd. g2 = galsim.GaussianDeviate(testseed, mean=gMean, sigma=gSigma) From cbcf0ec996343ac1bde4a0e3c338225fb46eac4a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:01:14 -0600 Subject: [PATCH 196/351] norefs --- tests/test_random.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 9f54a9f2b4..b75537f24a 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -398,13 +398,16 @@ def test_gaussian(): assert g.has_reliable_discard assert g.generates_in_pairs else: + # jax doesn't have this issue assert g.has_reliable_discard assert not g.generates_in_pairs # If don't explicitly suppress the warning, then a warning is emitted when n is odd. g2 = galsim.GaussianDeviate(testseed, mean=gMean, sigma=gSigma) - with assert_warns(galsim.GalSimWarning): - g2.discard(nvals+1) + if hasattr(galsim, "_galsim"): + # jax doesn't do this + with assert_warns(galsim.GalSimWarning): + g2.discard(nvals+1) # Check seed, reset g.seed(testseed) From e222d5e8ed9eee6759fbabd06659c181bb6c3a68 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:05:30 -0600 Subject: [PATCH 197/351] norefs --- tests/test_random.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_random.py b/tests/test_random.py index b75537f24a..2bc08927fc 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -488,6 +488,7 @@ def test_gaussian(): # Test generate_from_variance. g2 = galsim.GaussianDeviate(testseed, mean=5, sigma=0.3) g3 = galsim.GaussianDeviate(testseed, mean=5, sigma=0.3) + test_array = np.empty(3) test_array.fill(gSigma**2) g2.generate_from_variance(test_array) np.testing.assert_array_almost_equal( From 5dd48a08f85cef79642ef5fa9a76c634b36ec9bc Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:08:43 -0600 Subject: [PATCH 198/351] norefs --- tests/test_random.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index 2bc08927fc..9f046b5c1c 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -511,7 +511,10 @@ def test_gaussian(): # Test generate_from_variance. g2.seed(testseed) test_array.fill(gSigma**2) - g2.generate_from_variance(test_array) + if hasattr(galsim, "_galsim"): + g2.generate_from_variance(test_array) + else: + test_array = g2.generate_from_variance(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult)-gMean, precisionF, err_msg='Wrong Gaussian random number sequence from generate_from_variance.') From 2cbb070c2f54994a6ee82401673d099e83651f25 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:09:45 -0600 Subject: [PATCH 199/351] norefs --- tests/test_random.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index 9f046b5c1c..6a7d717f77 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -490,7 +490,10 @@ def test_gaussian(): g3 = galsim.GaussianDeviate(testseed, mean=5, sigma=0.3) test_array = np.empty(3) test_array.fill(gSigma**2) - g2.generate_from_variance(test_array) + if hasattr(galsim, "_galsim"): + g2.generate_from_variance(test_array) + else: + test_array = g2.generate_from_variance(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult)-gMean, precision, err_msg='Wrong Gaussian random number sequence from generate_from_variance.') From 0d1dad34b623e8bccae1f011204e494a47657aba Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:11:38 -0600 Subject: [PATCH 200/351] norefs --- tests/test_random.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index 6a7d717f77..f729ed69bc 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -499,7 +499,10 @@ def test_gaussian(): err_msg='Wrong Gaussian random number sequence from generate_from_variance.') # After running generate_from_variance, it should be back to using the specified mean, sigma. # Note: need to round up to even number for discard, since gd generates 2 at a time. - g3.discard((len(test_array)+1)//2 * 2) + if hasattr(galsim, "_galsim"): + g3.discard((len(test_array)+1)//2 * 2) + else: + g3.discard(len(test_array)) print('g2,g3 = ',g2(),g3()) assert g2() == g3() From ffe9e8a36aa3a9afa4bb2a8ee966ea241bcf483a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:17:46 -0600 Subject: [PATCH 201/351] norefs --- tests/test_random.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index f729ed69bc..c7d96971ae 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -509,7 +509,10 @@ def test_gaussian(): # Test generate with a float32 array. g.seed(testseed) test_array = np.empty(3, dtype=np.float32) - g.generate(test_array) + if hasattr(galsim, "_galsim"): + g.generate(test_array) + else: + test_array = g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult), precisionF, err_msg='Wrong Gaussian random number sequence from generate.') From caecb719eb3392c8ccc9f04df390deb8a9ad56f2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:18:19 -0600 Subject: [PATCH 202/351] norefs --- tests/test_random.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_random.py b/tests/test_random.py index c7d96971ae..c9efc7c2c8 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -519,6 +519,7 @@ def test_gaussian(): # Test generate_from_variance. g2.seed(testseed) + test_array = np.empty(3, dtype=np.float32) test_array.fill(gSigma**2) if hasattr(galsim, "_galsim"): g2.generate_from_variance(test_array) From 92a0f0c48635634da0879749402933469b1800a5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:19:57 -0600 Subject: [PATCH 203/351] norefs --- tests/test_random.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index c9efc7c2c8..adcd9edaee 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -535,23 +535,41 @@ def test_gaussian(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - g1.generate(v1) + if hasattr(galsim, "_galsim"): + g1.generate(v1) + else: + v1 = g1.generate(v1) with single_threaded(num_threads=10): - g2.generate(v2) + if hasattr(galsim, "_galsim"): + g2.generate(v2) + else: + v2 = g2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - g1.add_generate(v1) + if hasattr(galsim, "_galsim"): + g1.add_generate(v1) + else: + v1 = g1.add_generate(v1) with single_threaded(num_threads=10): - g2.add_generate(v2) + if hasattr(galsim, "_galsim"): + g2.add_generate(v2) + else: + v2 = g2.add_generate(v2) np.testing.assert_array_equal(v1, v2) ud = galsim.UniformDeviate(testseed + 3) ud.generate(v1) v1 += 6.7 v2[:] = v1 with single_threaded(): - g1.generate_from_variance(v1) + if hasattr(galsim, "_galsim"): + g1.generate_from_variance(v1) + else: + v1 = g1.generate_from_variance(v1) with single_threaded(num_threads=10): - g2.generate_from_variance(v2) + if hasattr(galsim, "_galsim"): + g2.generate_from_variance(v2) + else: + v2 = g2.generate_from_variance(v2) np.testing.assert_array_equal(v1, v2) # Check picklability From 7e24347a93cd81b19c8f597ba6bd08044bbc0de8 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:20:59 -0600 Subject: [PATCH 204/351] norefs --- tests/test_random.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index adcd9edaee..8523c493d7 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -559,7 +559,11 @@ def test_gaussian(): ud = galsim.UniformDeviate(testseed + 3) ud.generate(v1) v1 += 6.7 - v2[:] = v1 + if hasattr(galsim, "_galsim"): + v2[:] = v1 + else: + # jax galsim makes a copy + v2 = v1.copy() with single_threaded(): if hasattr(galsim, "_galsim"): g1.generate_from_variance(v1) From ac7876a93db6e6b7cc77ba4ceedec37427afcd71 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:24:45 -0600 Subject: [PATCH 205/351] norefs --- tests/test_random.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 8523c493d7..28e0ae6dd6 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -591,11 +591,13 @@ def test_gaussian(): assert g1 != g2, "Consecutive GaussianDeviate(None) compared equal!" # We shouldn't be able to construct a GaussianDeviate from anything but a BaseDeviate, int, str, # or None. - assert_raises(TypeError, galsim.GaussianDeviate, dict()) - assert_raises(TypeError, galsim.GaussianDeviate, list()) - assert_raises(TypeError, galsim.GaussianDeviate, set()) + if hasattr(galsim, "_galsim"): + # jax-galsim doesn't test for these things + assert_raises(TypeError, galsim.GaussianDeviate, dict()) + assert_raises(TypeError, galsim.GaussianDeviate, list()) + assert_raises(TypeError, galsim.GaussianDeviate, set()) - assert_raises(ValueError, galsim.GaussianDeviate, testseed, mean=1, sigma=-1) + assert_raises(ValueError, galsim.GaussianDeviate, testseed, mean=1, sigma=-1) @timer From ad828a4e58605fe9133ef405c2d04aa92ca7a8f1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:27:26 -0600 Subject: [PATCH 206/351] norefs --- tests/test_random.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 28e0ae6dd6..d57b4b64dd 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -710,7 +710,10 @@ def test_binomial(): # Test generate b.seed(testseed) test_array = np.empty(3) - b.generate(test_array) + if hasattr(galsim, "_galsim"): + b.generate(test_array) + else: + test_array = b.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(bResult), precision, err_msg='Wrong binomial random number sequence from generate.') @@ -718,7 +721,10 @@ def test_binomial(): # Test generate with an int array b.seed(testseed) test_array = np.empty(3, dtype=int) - b.generate(test_array) + if hasattr(galsim, "_galsim"): + b.generate(test_array) + else: + test_array = b.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(bResult), precisionI, err_msg='Wrong binomial random number sequence from generate.') From 98346bfacf5774321f16b61d1dba4b1694a84df8 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:30:43 -0600 Subject: [PATCH 207/351] norefs --- tests/test_random.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index d57b4b64dd..34cd651957 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -735,14 +735,26 @@ def test_binomial(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - b1.generate(v1) + if hasattr(galsim, "_galsim"): + b1.generate(v1) + else: + v1 = b1.generate(v1) with single_threaded(num_threads=10): - b2.generate(v2) + if hasattr(galsim, "_galsim"): + b2.generate(v2) + else: + v2 = b2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - b1.add_generate(v1) + if hasattr(galsim, "_galsim"): + b1.add_generate(v1) + else: + v1 = b1.add_generate(v1) with single_threaded(num_threads=10): - b2.add_generate(v2) + if hasattr(galsim, "_galsim"): + b2.add_generate(v2) + else: + v2 = b2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability From bdeeb71905ba5ad6b9935a540c543b33e0b4a76a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:31:25 -0600 Subject: [PATCH 208/351] norefs --- tests/test_random.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 34cd651957..e32d979719 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -772,9 +772,11 @@ def test_binomial(): assert b1 != b2, "Consecutive BinomialDeviate(None) compared equal!" # We shouldn't be able to construct a BinomialDeviate from anything but a BaseDeviate, int, str, # or None. - assert_raises(TypeError, galsim.BinomialDeviate, dict()) - assert_raises(TypeError, galsim.BinomialDeviate, list()) - assert_raises(TypeError, galsim.BinomialDeviate, set()) + if hasattr(galsim, "_galsim"): + # jax does not raise for this + assert_raises(TypeError, galsim.BinomialDeviate, dict()) + assert_raises(TypeError, galsim.BinomialDeviate, list()) + assert_raises(TypeError, galsim.BinomialDeviate, set()) @timer From b4ad42eb5f8e5e53ae140ab1abb6a2991033408b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:50:02 -0600 Subject: [PATCH 209/351] norefs --- tests/test_random.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index e32d979719..3c24a4eb20 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -830,8 +830,12 @@ def test_poisson(): p2.discard(nvals, suppress_warnings=True) v1,v2 = p(),p2() print('With mean = %d, after %d vals, next one is %s, %s'%(high_mean,nvals,v1,v2)) - assert v1 != v2 - assert not p.has_reliable_discard + if hasattr(galsim, "_galsim"): + assert v1 != v2 + assert not p.has_reliable_discard + else: + assert v1 == v2 + assert p.has_reliable_discard assert not p.generates_in_pairs # Discard normally emits a warning for Poisson From 13b55be27961b270888b1a5fef0c928484800ac1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:50:55 -0600 Subject: [PATCH 210/351] norefs --- tests/test_random.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index 3c24a4eb20..7e01248ad1 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -834,13 +834,18 @@ def test_poisson(): assert v1 != v2 assert not p.has_reliable_discard else: + # jax always discards reliably assert v1 == v2 assert p.has_reliable_discard assert not p.generates_in_pairs # Discard normally emits a warning for Poisson p2 = galsim.PoissonDeviate(testseed, mean=pMean) - with assert_warns(galsim.GalSimWarning): + if hasattr(galsim, "_galsim"): + with assert_warns(galsim.GalSimWarning): + p2.discard(nvals) + else: + # jax always discards reliably p2.discard(nvals) # Check seed, reset From 856169c421a5a5cdfcecf465b25d4126f4826b94 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:52:48 -0600 Subject: [PATCH 211/351] norefs --- tests/test_random.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 7e01248ad1..b3213a1280 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -916,7 +916,10 @@ def test_poisson(): # Test generate p.seed(testseed) test_array = np.empty(3) - p.generate(test_array) + if hasattr(galsim, "_galsim"): + p.generate(test_array) + else: + test_array = p.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(pResult), precision, err_msg='Wrong poisson random number sequence from generate.') @@ -924,7 +927,10 @@ def test_poisson(): # Test generate with an int array p.seed(testseed) test_array = np.empty(3, dtype=int) - p.generate(test_array) + if hasattr(galsim, "_galsim"): + p.generate(test_array) + else: + test_array = p.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(pResult), precisionI, err_msg='Wrong poisson random number sequence from generate.') @@ -932,7 +938,10 @@ def test_poisson(): # Test generate_from_expectation p2 = galsim.PoissonDeviate(testseed, mean=77) test_array = np.array([pMean]*3, dtype=int) - p2.generate_from_expectation(test_array) + if hasattr(galsim, "_galsim"): + p2.generate_from_expectation(test_array) + else: + test_array = p2.generate_from_expectation(test_array) np.testing.assert_array_almost_equal( test_array, np.array(pResult), precisionI, err_msg='Wrong poisson random number sequence from generate_from_expectation.') From 3524b8ca7b571aec6fc697362b572feaf5ca3836 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 15:54:13 -0600 Subject: [PATCH 212/351] norefs --- tests/test_random.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index b3213a1280..e62f96dece 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -958,14 +958,26 @@ def test_poisson(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - p1.generate(v1) + if hasattr(galsim, "_galsim"): + p1.generate(v1) + else: + v1 = p1.generate(v1) with single_threaded(num_threads=10): - p2.generate(v2) + if hasattr(galsim, "_galsim"): + p2.generate(v2) + else: + v2 = p2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - p1.add_generate(v1) + if hasattr(galsim, "_galsim"): + p1.add_generate(v1) + else: + v1 = p1.add_generate(v1) with single_threaded(num_threads=10): - p2.add_generate(v2) + if hasattr(galsim, "_galsim"): + p2.add_generate(v2) + else: + v2 = p2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability @@ -983,9 +995,10 @@ def test_poisson(): assert p1 != p2, "Consecutive PoissonDeviate(None) compared equal!" # We shouldn't be able to construct a PoissonDeviate from anything but a BaseDeviate, int, str, # or None. - assert_raises(TypeError, galsim.PoissonDeviate, dict()) - assert_raises(TypeError, galsim.PoissonDeviate, list()) - assert_raises(TypeError, galsim.PoissonDeviate, set()) + if hasattr(galsim, "_galsim"): + assert_raises(TypeError, galsim.PoissonDeviate, dict()) + assert_raises(TypeError, galsim.PoissonDeviate, list()) + assert_raises(TypeError, galsim.PoissonDeviate, set()) @timer From 6c497dc3e3f9cd41ea7c917562bd49c0f9d8d27a Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:08:21 -0600 Subject: [PATCH 213/351] norefs --- tests/test_random.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index e62f96dece..d2e37ee900 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -1130,11 +1130,20 @@ def test_poisson_zeromean(): # Test generate test_array = np.empty(3, dtype=int) - p.generate(test_array) + if hasattr(galsim, "_galsim"): + p.generate(test_array) + else: + test_array = p.generate(test_array) np.testing.assert_array_equal(test_array, 0) - p2.generate(test_array) + if hasattr(galsim, "_galsim"): + p2.generate(test_array) + else: + test_array = p2.generate(test_array) np.testing.assert_array_equal(test_array, 0) - p3.generate(test_array) + if hasattr(galsim, "_galsim"): + p3.generate(test_array) + else: + test_array = p3.generate(test_array) np.testing.assert_array_equal(test_array, 0) # Test generate_from_expectation @@ -1146,16 +1155,18 @@ def test_poisson_zeromean(): assert test_array[2] != 0 # Error raised if mean<0 - with assert_raises(ValueError): - p = galsim.PoissonDeviate(testseed, mean=-0.1) - with assert_raises(ValueError): - p = galsim.PoissonDeviate(testseed, mean=-10) - test_array = np.array([-1,1,4]) - with assert_raises(ValueError): - p.generate_from_expectation(test_array) - test_array = np.array([1,-1,-4]) - with assert_raises(ValueError): - p.generate_from_expectation(test_array) + # jax doesn't raise here + if hasattr(galsim, "_galsim"): + with assert_raises(ValueError): + p = galsim.PoissonDeviate(testseed, mean=-0.1) + with assert_raises(ValueError): + p = galsim.PoissonDeviate(testseed, mean=-10) + test_array = np.array([-1,1,4]) + with assert_raises(ValueError): + p.generate_from_expectation(test_array) + test_array = np.array([1,-1,-4]) + with assert_raises(ValueError): + p.generate_from_expectation(test_array) @timer def test_weibull(): From 3d402a96741dcc3d730ea246c9e6ff7ecd35bf43 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:09:49 -0600 Subject: [PATCH 214/351] norefs --- tests/test_random.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index d2e37ee900..32cc8408f5 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -1278,7 +1278,10 @@ def test_weibull(): # Test generate w.seed(testseed) test_array = np.empty(3) - w.generate(test_array) + if hasattr(galsim, "_galsim"): + w.generate(test_array) + else: + test_array = w.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(wResult), precision, err_msg='Wrong weibull random number sequence from generate.') @@ -1286,7 +1289,10 @@ def test_weibull(): # Test generate with a float32 array w.seed(testseed) test_array = np.empty(3, dtype=np.float32) - w.generate(test_array) + if hasattr(galsim, "_galsim"): + w.generate(test_array) + else: + test_array = w.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(wResult), precisionF, err_msg='Wrong weibull random number sequence from generate.') @@ -1297,14 +1303,26 @@ def test_weibull(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - w1.generate(v1) + if hasattr(galsim, "_galsim"): + w1.generate(v1) + else: + v1 = w1.generate(v1) with single_threaded(num_threads=10): - w2.generate(v2) + if hasattr(galsim, "_galsim"): + w2.generate(v2) + else: + v2 = w2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - w1.add_generate(v1) + if hasattr(galsim, "_galsim"): + w1.add_generate(v1) + else: + v1 = w1.add_generate(v1) with single_threaded(num_threads=10): - w2.add_generate(v2) + if hasattr(galsim, "_galsim"): + w2.add_generate(v2) + else: + v2 = w2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability @@ -1322,9 +1340,10 @@ def test_weibull(): assert w1 != w2, "Consecutive WeibullDeviate(None) compared equal!" # We shouldn't be able to construct a WeibullDeviate from anything but a BaseDeviate, int, str, # or None. - assert_raises(TypeError, galsim.WeibullDeviate, dict()) - assert_raises(TypeError, galsim.WeibullDeviate, list()) - assert_raises(TypeError, galsim.WeibullDeviate, set()) + if hasattr(galsim, "_galsim"): + assert_raises(TypeError, galsim.WeibullDeviate, dict()) + assert_raises(TypeError, galsim.WeibullDeviate, list()) + assert_raises(TypeError, galsim.WeibullDeviate, set()) @timer From db25fdb150a9375fece01b075c243e71878550bf Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:11:34 -0600 Subject: [PATCH 215/351] norefs --- tests/test_random.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 32cc8408f5..d3ae1e25da 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -1386,13 +1386,21 @@ def test_gamma(): v1,v2 = g(),g2() print('after %d vals, next one is %s, %s'%(nvals,v1,v2)) # Gamma uses at least 2 rngs per value, but can use arbitrarily more than this. - assert v1 != v2 - assert not g.has_reliable_discard + if hasattr(galsim, "_galsim"): + assert v1 != v2 + assert not g.has_reliable_discard + else: + assert v1 == v2 + assert g.has_reliable_discard assert not g.generates_in_pairs # Discard normally emits a warning for Gamma g2 = galsim.GammaDeviate(testseed, k=gammaK, theta=gammaTheta) - with assert_warns(galsim.GalSimWarning): + if hasattr(galsim, "_galsim"): + with assert_warns(galsim.GalSimWarning): + g2.discard(nvals) + else: + # jax always discards reliably g2.discard(nvals) # Check seed, reset @@ -1460,7 +1468,10 @@ def test_gamma(): # Test generate g.seed(testseed) test_array = np.empty(3) - g.generate(test_array) + if hasattr(galsim, "_galsim"): + g.generate(test_array) + else: + test_array = g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gammaResult), precision, err_msg='Wrong gamma random number sequence from generate.') @@ -1468,7 +1479,10 @@ def test_gamma(): # Test generate with a float32 array g.seed(testseed) test_array = np.empty(3, dtype=np.float32) - g.generate(test_array) + if hasattr(galsim, "_galsim"): + g.generate(test_array) + else: + test_array = g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gammaResult), precisionF, err_msg='Wrong gamma random number sequence from generate.') @@ -1488,9 +1502,10 @@ def test_gamma(): assert g1 != g2, "Consecutive GammaDeviate(None) compared equal!" # We shouldn't be able to construct a GammaDeviate from anything but a BaseDeviate, int, str, # or None. - assert_raises(TypeError, galsim.GammaDeviate, dict()) - assert_raises(TypeError, galsim.GammaDeviate, list()) - assert_raises(TypeError, galsim.GammaDeviate, set()) + if hasattr(galsim, "_galsim"): + assert_raises(TypeError, galsim.GammaDeviate, dict()) + assert_raises(TypeError, galsim.GammaDeviate, list()) + assert_raises(TypeError, galsim.GammaDeviate, set()) @timer From 0c97449ca140155a23b6b254281fd0f120f04e40 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:12:47 -0600 Subject: [PATCH 216/351] norefs --- tests/test_random.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index d3ae1e25da..0e3a05f43b 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -1548,13 +1548,21 @@ def test_chi2(): v1,v2 = c(),c2() print('after %d vals, next one is %s, %s'%(nvals,v1,v2)) # Chi2 uses at least 2 rngs per value, but can use arbitrarily more than this. - assert v1 != v2 - assert not c.has_reliable_discard + if hasattr(galsim, "_galsim"): + assert v1 != v2 + assert not c.has_reliable_discard + else: + assert v1 == v2 + assert c.has_reliable_discard assert not c.generates_in_pairs # Discard normally emits a warning for Chi2 c2 = galsim.Chi2Deviate(testseed, n=chi2N) - with assert_warns(galsim.GalSimWarning): + if hasattr(galsim, "_galsim"): + with assert_warns(galsim.GalSimWarning): + c2.discard(nvals) + else: + # jax always discards reliably c2.discard(nvals) # Check seed, reset @@ -1622,7 +1630,10 @@ def test_chi2(): # Test generate c.seed(testseed) test_array = np.empty(3) - c.generate(test_array) + if hasattr(galsim, "_galsim"): + c.generate(test_array) + else: + test_array = c.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(chi2Result), precision, err_msg='Wrong Chi^2 random number sequence from generate.') @@ -1630,7 +1641,10 @@ def test_chi2(): # Test generate with a float32 array c.seed(testseed) test_array = np.empty(3, dtype=np.float32) - c.generate(test_array) + if hasattr(galsim, "_galsim"): + c.generate(test_array) + else: + test_array = c.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(chi2Result), precisionF, err_msg='Wrong Chi^2 random number sequence from generate.') @@ -1650,9 +1664,10 @@ def test_chi2(): assert c1 != c2, "Consecutive Chi2Deviate(None) compared equal!" # We shouldn't be able to construct a Chi2Deviate from anything but a BaseDeviate, int, str, # or None. - assert_raises(TypeError, galsim.Chi2Deviate, dict()) - assert_raises(TypeError, galsim.Chi2Deviate, list()) - assert_raises(TypeError, galsim.Chi2Deviate, set()) + if hasattr(galsim, "_galsim"): + assert_raises(TypeError, galsim.Chi2Deviate, dict()) + assert_raises(TypeError, galsim.Chi2Deviate, list()) + assert_raises(TypeError, galsim.Chi2Deviate, set()) @timer From d6982b96a7e98bc0ed5c60452175eac8c3b2f134 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:15:12 -0600 Subject: [PATCH 217/351] norefs --- tests/test_random.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 0e3a05f43b..0e377d5372 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -2125,7 +2125,11 @@ def test_permute(): ind_list = list(range(n_list)) # Permute both at the same time. - galsim.random.permute(312, my_list, ind_list) + if hasattr(galsim, "_galsim"): + galsim.random.permute(312, my_list, ind_list) + else: + # jax requires arrays + galsim.random.permute(312, np.array(my_list), np.array(ind_list)) # Make sure that everything is sensible for ind in range(n_list): @@ -2133,7 +2137,10 @@ def test_permute(): # Repeat with same seed, should do same permutation. my_list = copy.deepcopy(my_list_copy) - galsim.random.permute(312, my_list) + if hasattr(galsim, "_galsim"): + galsim.random.permute(312, my_list) + else: + galsim.random.permute(312, np.array(my_list)) for ind in range(n_list): assert my_list_copy[ind_list[ind]] == my_list[ind] From 322b3db491386f5e41cc31e00f2ee2ec62fe5832 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:15:44 -0600 Subject: [PATCH 218/351] norefs --- tests/test_random.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 0e377d5372..c995e2c2d6 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -2145,8 +2145,10 @@ def test_permute(): assert my_list_copy[ind_list[ind]] == my_list[ind] # permute with no lists should raise TypeError - with assert_raises(TypeError): - galsim.random.permute(312) + # jax galsim does not raise + if hasattr(galsim, "_galsim"): + with assert_raises(TypeError): + galsim.random.permute(312) @timer From b030c3bdafcba7e2fb07646346b790ae214a5322 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:17:42 -0600 Subject: [PATCH 219/351] norefs --- tests/test_random.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index c995e2c2d6..20bc0a8e34 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -2156,8 +2156,12 @@ def test_ne(): """ Check that inequality works as expected for corner cases where the reprs of two unequal BaseDeviates may be the same due to truncation. """ - a = galsim.BaseDeviate(seed='1 2 3 4 5 6 7 8 9 10') - b = galsim.BaseDeviate(seed='1 2 3 7 6 5 4 8 9 10') + if hasattr(galsim, "_galsim"): + a = galsim.BaseDeviate(seed='1 2 3 4 5 6 7 8 9 10') + b = galsim.BaseDeviate(seed='1 2 3 7 6 5 4 8 9 10') + else: + a = galsim.BaseDeviate(seed="(0, 10)") + b = galsim.BaseDeviate(seed="(0, 11)") assert repr(a) == repr(b) assert a != b From 16402d31565a83f3acac64ae32f9a810b0a320da Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:18:33 -0600 Subject: [PATCH 220/351] norefs --- tests/test_random.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 20bc0a8e34..07c2f1633f 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -2159,11 +2159,13 @@ def test_ne(): if hasattr(galsim, "_galsim"): a = galsim.BaseDeviate(seed='1 2 3 4 5 6 7 8 9 10') b = galsim.BaseDeviate(seed='1 2 3 7 6 5 4 8 9 10') + assert repr(a) == repr(b) + assert a != b else: a = galsim.BaseDeviate(seed="(0, 10)") b = galsim.BaseDeviate(seed="(0, 11)") - assert repr(a) == repr(b) - assert a != b + assert repr(a) != repr(b) + assert a != b # Check DistDeviate separately, since it overrides __repr__ and __eq__ d1 = galsim.DistDeviate(seed=a, function=galsim.LookupTable([1, 2, 3], [4, 5, 6])) From 34b37d1c1e2b0842440f42a2714ca5a040fc4271 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:20:54 -0600 Subject: [PATCH 221/351] norefs --- tests/test_real.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_real.py b/tests/test_real.py index 1d31763f09..fadb38c54c 100644 --- a/tests/test_real.py +++ b/tests/test_real.py @@ -29,7 +29,7 @@ # set up any necessary info for tests ### Note: changes to either of the tests below might require regeneration of the catalog and image ### files that are saved here. Modify with care!!! -image_dir = './real_comparison_images' +image_dir = os.path.join(os.path.dirname(__file__), './real_comparison_images') catalog_file = 'test_catalog.fits' # some helper functions @@ -962,7 +962,7 @@ def test_sys_share_dir(): import galsim print(galsim.meta_data.share_dir) """) - script_file = os.path.join('scratch_space', 'sys_share_dir.py') + script_file = os.path.join(os.path.dirname(__file__), os.path.join('scratch_space', 'sys_share_dir.py')) with open(script_file, 'w') as f: f.write(script) env = os.environ.copy() From 53d54eedf84cd1500e8207e22cda2a581c69a015 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:21:39 -0600 Subject: [PATCH 222/351] norefs --- tests/test_roman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_roman.py b/tests/test_roman.py index d6846a053d..ff1b785892 100644 --- a/tests/test_roman.py +++ b/tests/test_roman.py @@ -148,7 +148,7 @@ def test_roman_wcs(): # we compare that with the GalSim routines for finding SCAs. import datetime date = datetime.datetime(2025, 1, 12) - test_data_file = os.path.join('roman_files','chris_comparison.txt') + test_data_file = os.path.join(os.path.dirname(__file__), os.path.join('roman_files','chris_comparison.txt')) test_data = np.loadtxt(test_data_file).transpose() ra_cen = test_data[0,:] From f59823322700c15cab50514366084f291cfb48bf Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:30:26 -0600 Subject: [PATCH 223/351] norefs --- tests/test_utilities.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 7e8fd0fb84..5d0e2bba98 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1129,7 +1129,10 @@ def test_horner(): # Make a random list of values to test x = np.empty(20) rng = galsim.UniformDeviate(1234) - rng.generate(x) + if hasattr(galsim, "_galsim"): + rng.generate(x) + else: + x = rng.generate(x) # Check against the direct calculation truth = coef[0] + coef[1]*x + coef[2]*x**2 + coef[3]*x**3 + coef[4]*x**4 From 944505b0657ad34461ab582c1fcab3a5b191e920 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:32:49 -0600 Subject: [PATCH 224/351] norefs --- tests/test_utilities.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 5d0e2bba98..4a2112622b 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1186,7 +1186,10 @@ def test_horner(): # Check length > 64 xx = np.empty(2000) - xx = rng.generate(xx) + if hasattr(galsim, "_galsim"): + rng.generate(xx) + else: + xx = rng.generate(xx) result = galsim.utilities.horner(xx, coef) np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(xx,coef)) @@ -1210,8 +1213,12 @@ def test_horner2d(): x = np.empty(20) y = np.empty(20) rng = galsim.UniformDeviate(1234) - x = rng.generate(x) - y = rng.generate(y) + if hasattr(galsim, "_galsim"): + rng.generate(x) + rng.generate(y) + else: + x = rng.generate(x) + y = rng.generate(y) # Check against the direct calculation truth = coef[0,0] + coef[0,1]*y + coef[0,2]*y**2 + coef[0,3]*y**3 + coef[0,4]*y**4 @@ -1274,8 +1281,12 @@ def test_horner2d(): # Check length > 64 xx = np.empty(2000) yy = np.empty(2000) - xx = rng.generate(xx) - yy = rng.generate(yy) + if hasattr(galsim, "_galsim"): + rng.generate(xx) + rng.generate(yy) + else: + xx = rng.generate(xx) + yy = rng.generate(yy) result = galsim.utilities.horner2d(xx, yy, coef) np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(xx,yy,coef)) @@ -1330,15 +1341,22 @@ def test_horner_complex(): rx = np.empty(20) ry = np.empty(20) rng = galsim.UniformDeviate(1234) - rng.generate(rx) - rng.generate(ry) + if hasattr(galsim, "_galsim"): + rng.generate(rx) + rng.generate(ry) + else: + rx = rng.generate(rx) + ry = rng.generate(ry) ix = np.empty(20) iy = np.empty(20) rng = galsim.UniformDeviate(1234) - rng.generate(ix) - rng.generate(iy) - + if hasattr(galsim, "_galsim"): + rng.generate(ix) + rng.generate(iy) + else: + ix = rng.generate(ix) + iy = rng.generate(iy) x = rx + 1j*ix y = ry + 1j*iy From 7641057ce3f4b0ddf981cb31f629c4f8808e9329 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:35:07 -0600 Subject: [PATCH 225/351] norefs --- tests/test_zernike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index beeeeb359a..ca242240f9 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -299,7 +299,7 @@ def test_fit(): [u()-0.5, 0, 0, 0, 0]] z = galsim.utilities.horner2d(x, y, cartesian_coefs) z2 = galsim.utilities.horner2d(x, y, cartesian_coefs, triangle=True) - np.testing.assert_equal(z,z2) + np.testing.assert_array_equal(z,z2) basis = galsim.zernike.zernikeBasis(21, x, y, R_outer=R_outer, R_inner=R_inner) coefs, _, _, _ = np.linalg.lstsq(basis.T, z, rcond=-1.) From f2cab46050e1bfcad8c3ce52c8d4731e52ec022f Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:36:49 -0600 Subject: [PATCH 226/351] norefs --- tests/test_zernike.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index ca242240f9..f5a514cefa 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -497,9 +497,15 @@ def test_sum(): c2 = u() coefSum = c2*np.array(z2.coef) - coefSum[:len(z1.coef)] += c1*z1.coef + if hasattr(galsim, "_galsim"): + coefSum[:len(z1.coef)] += c1*z1.coef + else: + coefSum = coefSum.at[:len(z1.coef)].add(c1*z1.coef) coefDiff = c2*np.array(z2.coef) - coefDiff[:len(z1.coef)] -= c1*z1.coef + if hasattr(galsim, "_galsim"): + coefDiff[:len(z1.coef)] -= c1*z1.coef + else: + coefDiff = coefDiff.at[:len(z1.coef)].subtract(c1*z1.coef) np.testing.assert_allclose(coefSum, (c1*z1 + c2*z2).coef) np.testing.assert_allclose(coefDiff, -(c1*z1 - c2*z2).coef) From dbe4829ee2bb98e7ff705a107bc88972b3b95371 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:37:30 -0600 Subject: [PATCH 227/351] norefs --- tests/test_zernike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index f5a514cefa..bb5ea2aebd 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -505,7 +505,7 @@ def test_sum(): if hasattr(galsim, "_galsim"): coefDiff[:len(z1.coef)] -= c1*z1.coef else: - coefDiff = coefDiff.at[:len(z1.coef)].subtract(c1*z1.coef) + coefDiff = coefDiff.at[:len(z1.coef)].add(-c1*z1.coef) np.testing.assert_allclose(coefSum, (c1*z1 + c2*z2).coef) np.testing.assert_allclose(coefDiff, -(c1*z1 - c2*z2).coef) From e675f727bd77c6a035c4f94bcad1e526fc82b269 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:42:16 -0600 Subject: [PATCH 228/351] norefs --- tests/test_zernike.py | 143 +++++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index bb5ea2aebd..a1803cd3a4 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -19,7 +19,6 @@ import numpy as np import galsim -from galsim.zernike import Zernike, DoubleZernike from galsim_test_helpers import timer, check_pickle, assert_raises, check_all_diff @@ -41,10 +40,10 @@ def test_Zernike_orthonormality(): y = y[w].ravel() area = np.pi*R_outer**2 for j1 in range(1, jmax+1): - Z1 = Zernike([0]*(j1+1)+[1], R_outer=R_outer) + Z1 = galsim.zernike.Zernike([0]*(j1+1)+[1], R_outer=R_outer) val1 = Z1.evalCartesian(x, y) for j2 in range(j1, jmax+1): - Z2 = Zernike([0]*(j2+1)+[1], R_outer=R_outer) + Z2 = galsim.zernike.Zernike([0]*(j2+1)+[1], R_outer=R_outer) val2 = Z2.evalCartesian(x, y) integral = np.dot(val1, val2) * dx**2 if j1 == j2: @@ -73,10 +72,10 @@ def test_Zernike_orthonormality(): y = y[w].ravel() area = np.pi*(R_outer**2 - R_inner**2) for j1 in range(1, jmax+1): - Z1 = Zernike([0]*(j1+1)+[1], R_outer=R_outer, R_inner=R_inner) + Z1 = galsim.zernike.Zernike([0]*(j1+1)+[1], R_outer=R_outer, R_inner=R_inner) val1 = Z1.evalCartesian(x, y) for j2 in range(j1, jmax+1): - Z2 = Zernike([0]*(j2+1)+[1], R_outer=R_outer, R_inner=R_inner) + Z2 = galsim.zernike.Zernike([0]*(j2+1)+[1], R_outer=R_outer, R_inner=R_inner) val2 = Z2.evalCartesian(x, y) integral = np.dot(val1, val2) * dx**2 if j1 == j2: @@ -93,7 +92,7 @@ def test_Zernike_orthonormality(): check_pickle(Z1, lambda z: tuple(z.evalCartesian(x, y))) with assert_raises(ValueError): - Z1 = Zernike([0]*4 + [0.1]*7, R_outer=R_inner, R_inner=R_outer) + Z1 = galsim.zernike.Zernike([0]*4 + [0.1]*7, R_outer=R_inner, R_inner=R_outer) val1 = Z1.evalCartesian(x, y) @@ -202,13 +201,13 @@ def test_Zernike_rotate(): R_inner = R_outer*eps coefs = [u() for _ in range(jmax+1)] - Z = Zernike(coefs, R_outer=R_outer, R_inner=R_inner) + Z = galsim.zernike.Zernike(coefs, R_outer=R_outer, R_inner=R_inner) check_pickle(Z) for theta in [0.0, 0.1, 1.0, np.pi, 4.0]: R = galsim.zernike.zernikeRotMatrix(jmax, theta) rotCoefs = np.dot(R, coefs) - Zrot = Zernike(rotCoefs, R_outer=R_outer, R_inner=R_inner) + Zrot = galsim.zernike.Zernike(rotCoefs, R_outer=R_outer, R_inner=R_inner) print('j,theta: ',jmax,theta) print('Z: ',Z.evalPolar(rhos, thetas)) print('Zrot: ',Zrot.evalPolar(rhos, thetas+theta)) @@ -232,16 +231,16 @@ def test_Zernike_rotate(): @timer def test_ne(): objs = [ - Zernike([0, 1, 2]), - Zernike([0, 1, 2, 3]), - Zernike([0, 1, 2, 3], R_outer=0.2), - Zernike([0, 1, 2, 3], R_outer=0.2, R_inner=0.1), - DoubleZernike(np.eye(3)), - DoubleZernike(np.ones((4, 4))), - DoubleZernike(np.ones((4, 4)), xy_outer=1.1), - DoubleZernike(np.ones((4, 4)), xy_outer=1.1, xy_inner=0.9), - DoubleZernike(np.ones((4, 4)), xy_outer=1.1, xy_inner=0.9, uv_outer=1.1), - DoubleZernike(np.ones((4, 4)), xy_outer=1.1, xy_inner=0.9, uv_outer=1.1, uv_inner=0.9) + galsim.zernike.Zernike([0, 1, 2]), + galsim.zernike.Zernike([0, 1, 2, 3]), + galsim.zernike.Zernike([0, 1, 2, 3], R_outer=0.2), + galsim.zernike.Zernike([0, 1, 2, 3], R_outer=0.2, R_inner=0.1), + galsim.zernike.DoubleZernike(np.eye(3)), + galsim.zernike.DoubleZernike(np.ones((4, 4))), + galsim.zernike.DoubleZernike(np.ones((4, 4)), xy_outer=1.1), + galsim.zernike.DoubleZernike(np.ones((4, 4)), xy_outer=1.1, xy_inner=0.9), + galsim.zernike.DoubleZernike(np.ones((4, 4)), xy_outer=1.1, xy_inner=0.9, uv_outer=1.1), + galsim.zernike.DoubleZernike(np.ones((4, 4)), xy_outer=1.1, xy_inner=0.9, uv_outer=1.1, uv_inner=0.9) ] check_all_diff(objs) @@ -267,7 +266,7 @@ def test_Zernike_basis(): # Compare to basis vectors generated one at a time for j in range(1, jmax): - Z = Zernike([0]*j+[1], R_outer=R_outer, R_inner=R_inner) + Z = galsim.zernike.Zernike([0]*j+[1], R_outer=R_outer, R_inner=R_inner) zBasis = Z.evalCartesian(x, y) np.testing.assert_allclose( zBases[j], @@ -303,7 +302,7 @@ def test_fit(): basis = galsim.zernike.zernikeBasis(21, x, y, R_outer=R_outer, R_inner=R_inner) coefs, _, _, _ = np.linalg.lstsq(basis.T, z, rcond=-1.) - resids = (Zernike(coefs, R_outer=R_outer, R_inner=R_inner) + resids = (galsim.zernike.Zernike(coefs, R_outer=R_outer, R_inner=R_inner) .evalCartesian(x, y) - z) resids2 = np.dot(basis.T, coefs).T - z @@ -352,7 +351,7 @@ def test_fit(): assert basis.shape == (22, 25, 40) # lstsq doesn't handle the extra dimension though... coefs, _, _, _ = np.linalg.lstsq(basis.reshape(21+1, 1000).T, z.ravel(), rcond=-1.) - resids = (Zernike(coefs, R_outer=R_outer, R_inner=R_inner) + resids = (galsim.zernike.Zernike(coefs, R_outer=R_outer, R_inner=R_inner) .evalCartesian(x, y) - z) resids2 = np.dot(basis.T, coefs).T - z @@ -368,7 +367,7 @@ def test_gradient(): """ # Start with a few that just quote the literature, e.g., Stephenson (2014). - Z11 = Zernike([0]*11+[1]) + Z11 = galsim.zernike.Zernike([0]*11+[1]) x = np.linspace(-1, 1, 100) x, y = np.meshgrid(x, x) @@ -392,7 +391,7 @@ def Z11_grad(x, y): np.testing.assert_allclose(Z11.evalCartesianGrad(x, y), Z11_grad(x, y), rtol=0, atol=1e-12) - Z28 = Zernike([0]*28+[1]) + Z28 = galsim.zernike.Zernike([0]*28+[1]) def Z28_grad(x, y): # Z28 = sqrt(14) (x^6 - 15 x^4 y^2 + 15 x^2 y^4 - y^6) @@ -417,7 +416,7 @@ def finite_difference_gradient(Z, x, y): nj = 1+int(u()*55) R_inner = 0.2+0.6*u() R_outer = R_inner + 0.2+0.6*u() - Z = Zernike([0]+[u() for _ in range(nj)], R_inner=R_inner, R_outer=R_outer) + Z = galsim.zernike.Zernike([0]+[u() for _ in range(nj)], R_inner=R_inner, R_outer=R_outer) np.testing.assert_allclose( finite_difference_gradient(Z, x, y), @@ -425,7 +424,7 @@ def finite_difference_gradient(Z, x, y): rtol=1e-5, atol=1e-5) # Make sure the gradient of the zero-Zernike works - Z = Zernike([0]) + Z = galsim.zernike.Zernike([0]) assert Z == Z.gradX == Z.gradX.gradX == Z.gradY == Z.gradY.gradY @@ -451,7 +450,7 @@ def test_gradient_bases(): # Compare to basis vectors generated one at a time for j in range(1, jmax+1): - Z = Zernike([0]*j+[1], R_outer=R_outer, R_inner=R_inner) + Z = galsim.zernike.Zernike([0]*j+[1], R_outer=R_outer, R_inner=R_inner) ZX = Z.gradX ZY = Z.gradY @@ -490,8 +489,8 @@ def test_sum(): a2 = np.empty(n2, dtype=float) u.generate(a1) u.generate(a2) - z1 = Zernike(a1, R_outer=R_outer, R_inner=R_inner) - z2 = Zernike(a2, R_outer=R_outer, R_inner=R_inner) + z1 = galsim.zernike.Zernike(a1, R_outer=R_outer, R_inner=R_inner) + z2 = galsim.zernike.Zernike(a2, R_outer=R_outer, R_inner=R_inner) c1 = u() c2 = u() @@ -532,13 +531,13 @@ def test_sum(): with np.testing.assert_raises(TypeError): z1 - 3 with np.testing.assert_raises(ValueError): - z1 + Zernike([0,1], R_outer=z1.R_outer*2) + z1 + galsim.zernike.Zernike([0,1], R_outer=z1.R_outer*2) with np.testing.assert_raises(ValueError): - z1 + Zernike([0,1], R_outer=z1.R_outer, R_inner=z1.R_inner*2) + z1 + galsim.zernike.Zernike([0,1], R_outer=z1.R_outer, R_inner=z1.R_inner*2) # Commutative with integer coefficients - z1 = Zernike([0,1,2,3,4]) - z2 = Zernike([1,2,3,4,5,6]) + z1 = galsim.zernike.Zernike([0,1,2,3,4]) + z2 = galsim.zernike.Zernike([1,2,3,4,5,6]) assert z1+z2 == z2+z1 assert (z2-z1) == z2 + -z1 == -(z1-z2) @@ -562,8 +561,8 @@ def test_product(): a2 = np.empty(n2, dtype=float) u.generate(a1) u.generate(a2) - z1 = Zernike(a1, R_outer=R_outer, R_inner=R_inner) - z2 = Zernike(a2, R_outer=R_outer, R_inner=R_inner) + z1 = galsim.zernike.Zernike(a1, R_outer=R_outer, R_inner=R_inner) + z2 = galsim.zernike.Zernike(a2, R_outer=R_outer, R_inner=R_inner) np.testing.assert_allclose( z1(x, y) * z2(x, y), @@ -606,15 +605,15 @@ def test_product(): with np.testing.assert_raises(TypeError): z1 * galsim.Gaussian(fwhm=1) with np.testing.assert_raises(ValueError): - z1 * Zernike([0,1], R_outer=z1.R_outer*2) + z1 * galsim.zernike.Zernike([0,1], R_outer=z1.R_outer*2) with np.testing.assert_raises(ValueError): - z1 * Zernike([0,1], R_outer=z1.R_outer, R_inner=z1.R_inner*2) + z1 * galsim.zernike.Zernike([0,1], R_outer=z1.R_outer, R_inner=z1.R_inner*2) with np.testing.assert_raises(TypeError): z1 / z2 # Commutative with integer coefficients - z1 = Zernike([0,1,2,3,4,5]) - z2 = Zernike([1,2,3,4,5,6]) + z1 = galsim.zernike.Zernike([0,1,2,3,4,5]) + z2 = galsim.zernike.Zernike([1,2,3,4,5,6]) assert z1*z2 == z2*z1 @@ -634,7 +633,7 @@ def test_laplacian(): u.generate(a) R_outer = 1+0.1*u() R_inner = 0.1*u() - z = Zernike(a, R_outer=R_outer, R_inner=R_inner) + z = galsim.zernike.Zernike(a, R_outer=R_outer, R_inner=R_inner) np.testing.assert_allclose( z.laplacian(x, y), @@ -655,7 +654,7 @@ def test_laplacian(): # implies laplacian = 4 sqrt(3) + 4 sqrt(3) = 8 sqrt(3) # which is 8 sqrt(3) Z1 np.testing.assert_allclose( - Zernike([0,0,0,0,1]).laplacian.coef, + galsim.zernike.Zernike([0,0,0,0,1]).laplacian.coef, np.array([0,8*np.sqrt(3)]) ) @@ -665,7 +664,7 @@ def test_laplacian(): # implies laplacian = 24 sqrt(8) y # which is 12*sqrt(8) * Z3 since Z3 = 2 y np.testing.assert_allclose( - Zernike([0,0,0,0,0,0,0,1]).laplacian.coef, + galsim.zernike.Zernike([0,0,0,0,0,0,0,1]).laplacian.coef, np.array([0,0,0,12*np.sqrt(8)]) ) @@ -686,7 +685,7 @@ def test_hessian(): u.generate(a) R_outer = 1+0.1*u() R_inner = 0.1*u() - z = Zernike(a, R_outer=R_outer, R_inner=R_inner) + z = galsim.zernike.Zernike(a, R_outer=R_outer, R_inner=R_inner) np.testing.assert_allclose( z.hessian(x, y), @@ -707,7 +706,7 @@ def test_hessian(): # implies hessian = 4 sqrt(3) * 4 sqrt(3) - 0 * 0 = 16*3 = 48 # which is 48 Z1 np.testing.assert_allclose( - Zernike([0,0,0,0,1]).hessian.coef, + galsim.zernike.Zernike([0,0,0,0,1]).hessian.coef, np.array([0,48]) ) @@ -720,7 +719,7 @@ def test_hessian(): # That's a little inconvenient to decompose into Zernikes by hand, but we can test against # an array of (x,y) values. np.testing.assert_allclose( - Zernike([0,0,0,0,0,0,0,1]).hessian(x, y), + galsim.zernike.Zernike([0,0,0,0,0,0,0,1]).hessian(x, y), 864*y*y - 288*x*x ) @@ -762,7 +761,7 @@ def test_lazy_coef(): zarr = [0]+[u() for i in range(jmax)] R_inner = u()*0.5+0.2 R_outer = u()*2.0+2.0 - Z = Zernike(zarr, R_outer=R_outer, R_inner=R_inner) + Z = galsim.zernike.Zernike(zarr, R_outer=R_outer, R_inner=R_inner) Z._coef_array_xy del Z.coef np.testing.assert_allclose(zarr, Z.coef, rtol=0, atol=1e-12) @@ -772,7 +771,7 @@ def test_lazy_coef(): zarr = [0]+[u() for i in range(jmax)] R_inner = u()*0.5+0.2 R_outer = u()*2.0+2.0 - Z = Zernike(zarr, R_outer=R_outer, R_inner=R_inner) + Z = galsim.zernike.Zernike(zarr, R_outer=R_outer, R_inner=R_inner) Z._coef_array_xy del Z.coef np.testing.assert_allclose(zarr, Z.coef[:len(zarr)], rtol=0, atol=1e-12) @@ -791,7 +790,7 @@ def test_dz_val(): uv_outer = rng.uniform(1.3, 1.7) xy_inner = rng.uniform(0.4, 0.7) xy_outer = rng.uniform(1.3, 1.7) - dz = DoubleZernike( + dz = galsim.zernike.DoubleZernike(( coef, uv_inner=uv_inner, uv_outer=uv_outer, @@ -870,7 +869,7 @@ def test_dz_val(): dz([0.0, 1.0], [0.0, 1.0], x=[1.0], y=[1.0]) # Try pickle/repr with default domain - dz = DoubleZernike(coef) + dz = galsim.zernike.DoubleZernike((coef) check_pickle(dz) @@ -886,7 +885,7 @@ def test_dz_coef_uvxy(): uv_outer = rng.uniform(1.3, 1.7) xy_inner = rng.uniform(0.4, 0.7) xy_outer = rng.uniform(1.3, 1.7) - dz = DoubleZernike( + dz = galsim.zernike.DoubleZernike(( coef, uv_inner=uv_inner, uv_outer=uv_outer, @@ -965,12 +964,12 @@ def test_dz_sum(): coef2[0] = 0.0 coef2[:, 0] = 0.0 - dz1 = DoubleZernike( + dz1 = galsim.zernike.DoubleZernike(( coef1, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer ) - dz2 = DoubleZernike( + dz2 = galsim.zernike.DoubleZernike(( coef2, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1025,25 +1024,25 @@ def test_dz_sum(): with np.testing.assert_raises(TypeError): dz1 - 3 with np.testing.assert_raises(ValueError): - dz1 + DoubleZernike( + dz1 + galsim.zernike.DoubleZernike(( coef1, uv_outer=2*uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 + DoubleZernike( + dz1 + galsim.zernike.DoubleZernike(( coef1, uv_outer=uv_outer, uv_inner=2*uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 + DoubleZernike( + dz1 + galsim.zernike.DoubleZernike(( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=2*xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 + DoubleZernike( + dz1 + galsim.zernike.DoubleZernike(( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=2*xy_inner ) # Commutative with integer coefficients - dz1 = DoubleZernike(np.eye(3, dtype=int)) - dz2 = DoubleZernike(np.ones((4, 4), dtype=int)) + dz1 = galsim.zernike.DoubleZernike((np.eye(3, dtype=int)) + dz2 = galsim.zernike.DoubleZernike((np.ones((4, 4), dtype=int)) assert dz1 + dz2 == dz2 + dz1 assert (dz2 - dz1) == dz2 + (-dz1) == -(dz1 - dz2) @@ -1081,12 +1080,12 @@ def test_dz_product(): coef2[0] = 0.0 coef2[:, 0] = 0.0 - dz1 = DoubleZernike( + dz1 = galsim.zernike.DoubleZernike(( coef1, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer ) - dz2 = DoubleZernike( + dz2 = galsim.zernike.DoubleZernike(( coef2, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1131,27 +1130,27 @@ def test_dz_product(): with np.testing.assert_raises(TypeError): dz1 * galsim.Gaussian(sigma=1.0) with np.testing.assert_raises(ValueError): - dz1 * DoubleZernike( + dz1 * galsim.zernike.DoubleZernike(( coef1, uv_outer=2*uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 * DoubleZernike( + dz1 * galsim.zernike.DoubleZernike(( coef1, uv_outer=uv_outer, uv_inner=2*uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 * DoubleZernike( + dz1 * galsim.zernike.DoubleZernike(( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=2*xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 * DoubleZernike( + dz1 * galsim.zernike.DoubleZernike(( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=2*xy_inner ) with np.testing.assert_raises(TypeError): dz1 / dz2 # Commutative with integer coefficients - dz1 = DoubleZernike(np.eye(3, dtype=int)) - dz2 = DoubleZernike(np.ones((4, 4), dtype=int)) + dz1 = galsim.zernike.DoubleZernike((np.eye(3, dtype=int)) + dz2 = galsim.zernike.DoubleZernike((np.ones((4, 4), dtype=int)) assert dz1 * dz2 == dz2 * dz1 assert (dz2 * 3) == (3 * dz2) @@ -1178,7 +1177,7 @@ def test_dz_grad(): coef[0] = 0.0 coef[:, 0] = 0.0 - dz = DoubleZernike( + dz = galsim.zernike.DoubleZernike(( coef, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1196,7 +1195,7 @@ def test_dz_grad(): # U and V are trickier, since we aren't including a way to turn a DZ evaluated # at (x, y) into a single Zernike of (u, v). We can mock that though up by # transposing the DZ coefficients and swapping the domain parameters. - dz_xyuv = DoubleZernike( + dz_xyuv = galsim.zernike.DoubleZernike(( np.transpose(coef, axes=(1, 0)), uv_inner=xy_inner, uv_outer=xy_outer, xy_inner=uv_inner, xy_outer=uv_outer @@ -1258,7 +1257,7 @@ def test_dz_to_T(): coef[0] = 0.0 coef[:, 0] = 0.0 - W = DoubleZernike( + W = galsim.zernike.DoubleZernike(( coef, uv_inner=uv_inner, uv_outer=uv_outer, # field xy_inner=xy_inner, xy_outer=xy_outer # pupil @@ -1364,7 +1363,7 @@ def test_dz_rotate(): coef[0] = 0.0 coef[:, 0] = 0.0 - dz = DoubleZernike( + dz = galsim.zernike.DoubleZernike(( coef, uv_inner=uv_inner, uv_outer=uv_outer, # field xy_inner=xy_inner, xy_outer=xy_outer # pupil @@ -1421,7 +1420,7 @@ def test_dz_basis(): for k in range(1, k1): coef = np.zeros((k1, j1)) coef[k, j] = 1.0 - DZ = DoubleZernike( + DZ = galsim.zernike.DoubleZernike(( coef, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1450,7 +1449,7 @@ def test_dz_mean(): coef[0] = 0.0 coef[:, 0] = 0.0 - dz = DoubleZernike( + dz = galsim.zernike.DoubleZernike(( coef, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1458,7 +1457,7 @@ def test_dz_mean(): # We don't have a function that returns a Zernike over uv at a given xy # point, but we can mimic that by transposing xy an uv in a new # DoubleZernike object. - dzT = DoubleZernike( + dzT = galsim.zernike.DoubleZernike( coef.T, uv_inner=xy_inner, uv_outer=xy_outer, xy_inner=uv_inner, xy_outer=uv_outer From a4a183bc3df4fb5b0d4467dc024636ebfc147646 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:42:59 -0600 Subject: [PATCH 229/351] norefs --- tests/test_zernike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index a1803cd3a4..4381d724b7 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -790,7 +790,7 @@ def test_dz_val(): uv_outer = rng.uniform(1.3, 1.7) xy_inner = rng.uniform(0.4, 0.7) xy_outer = rng.uniform(1.3, 1.7) - dz = galsim.zernike.DoubleZernike(( + dz = galsim.zernike.DoubleZernike( coef, uv_inner=uv_inner, uv_outer=uv_outer, From a68288d8157eecc5d8e870a5e320d292ad62eb73 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 21 Nov 2023 16:43:44 -0600 Subject: [PATCH 230/351] norefs --- tests/test_zernike.py | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index 4381d724b7..36fc0c1b5b 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -869,7 +869,7 @@ def test_dz_val(): dz([0.0, 1.0], [0.0, 1.0], x=[1.0], y=[1.0]) # Try pickle/repr with default domain - dz = galsim.zernike.DoubleZernike((coef) + dz = galsim.zernike.DoubleZernike(coef) check_pickle(dz) @@ -885,7 +885,7 @@ def test_dz_coef_uvxy(): uv_outer = rng.uniform(1.3, 1.7) xy_inner = rng.uniform(0.4, 0.7) xy_outer = rng.uniform(1.3, 1.7) - dz = galsim.zernike.DoubleZernike(( + dz = galsim.zernike.DoubleZernike( coef, uv_inner=uv_inner, uv_outer=uv_outer, @@ -964,12 +964,12 @@ def test_dz_sum(): coef2[0] = 0.0 coef2[:, 0] = 0.0 - dz1 = galsim.zernike.DoubleZernike(( + dz1 = galsim.zernike.DoubleZernike( coef1, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer ) - dz2 = galsim.zernike.DoubleZernike(( + dz2 = galsim.zernike.DoubleZernike( coef2, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1024,25 +1024,25 @@ def test_dz_sum(): with np.testing.assert_raises(TypeError): dz1 - 3 with np.testing.assert_raises(ValueError): - dz1 + galsim.zernike.DoubleZernike(( + dz1 + galsim.zernike.DoubleZernike( coef1, uv_outer=2*uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 + galsim.zernike.DoubleZernike(( + dz1 + galsim.zernike.DoubleZernike( coef1, uv_outer=uv_outer, uv_inner=2*uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 + galsim.zernike.DoubleZernike(( + dz1 + galsim.zernike.DoubleZernike( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=2*xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 + galsim.zernike.DoubleZernike(( + dz1 + galsim.zernike.DoubleZernike( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=2*xy_inner ) # Commutative with integer coefficients - dz1 = galsim.zernike.DoubleZernike((np.eye(3, dtype=int)) - dz2 = galsim.zernike.DoubleZernike((np.ones((4, 4), dtype=int)) + dz1 = galsim.zernike.DoubleZernike(np.eye(3, dtype=int)) + dz2 = galsim.zernike.DoubleZernike(np.ones((4, 4), dtype=int)) assert dz1 + dz2 == dz2 + dz1 assert (dz2 - dz1) == dz2 + (-dz1) == -(dz1 - dz2) @@ -1080,12 +1080,12 @@ def test_dz_product(): coef2[0] = 0.0 coef2[:, 0] = 0.0 - dz1 = galsim.zernike.DoubleZernike(( + dz1 = galsim.zernike.DoubleZernike( coef1, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer ) - dz2 = galsim.zernike.DoubleZernike(( + dz2 = galsim.zernike.DoubleZernike( coef2, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1130,27 +1130,27 @@ def test_dz_product(): with np.testing.assert_raises(TypeError): dz1 * galsim.Gaussian(sigma=1.0) with np.testing.assert_raises(ValueError): - dz1 * galsim.zernike.DoubleZernike(( + dz1 * galsim.zernike.DoubleZernike( coef1, uv_outer=2*uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 * galsim.zernike.DoubleZernike(( + dz1 * galsim.zernike.DoubleZernike( coef1, uv_outer=uv_outer, uv_inner=2*uv_inner, xy_outer=xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 * galsim.zernike.DoubleZernike(( + dz1 * galsim.zernike.DoubleZernike( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=2*xy_outer, xy_inner=xy_inner ) with np.testing.assert_raises(ValueError): - dz1 * galsim.zernike.DoubleZernike(( + dz1 * galsim.zernike.DoubleZernike( coef1, uv_outer=uv_outer, uv_inner=uv_inner, xy_outer=xy_outer, xy_inner=2*xy_inner ) with np.testing.assert_raises(TypeError): dz1 / dz2 # Commutative with integer coefficients - dz1 = galsim.zernike.DoubleZernike((np.eye(3, dtype=int)) - dz2 = galsim.zernike.DoubleZernike((np.ones((4, 4), dtype=int)) + dz1 = galsim.zernike.DoubleZernike(np.eye(3, dtype=int)) + dz2 = galsim.zernike.DoubleZernike(np.ones((4, 4), dtype=int)) assert dz1 * dz2 == dz2 * dz1 assert (dz2 * 3) == (3 * dz2) @@ -1177,7 +1177,7 @@ def test_dz_grad(): coef[0] = 0.0 coef[:, 0] = 0.0 - dz = galsim.zernike.DoubleZernike(( + dz = galsim.zernike.DoubleZernike( coef, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1195,7 +1195,7 @@ def test_dz_grad(): # U and V are trickier, since we aren't including a way to turn a DZ evaluated # at (x, y) into a single Zernike of (u, v). We can mock that though up by # transposing the DZ coefficients and swapping the domain parameters. - dz_xyuv = galsim.zernike.DoubleZernike(( + dz_xyuv = galsim.zernike.DoubleZernike( np.transpose(coef, axes=(1, 0)), uv_inner=xy_inner, uv_outer=xy_outer, xy_inner=uv_inner, xy_outer=uv_outer @@ -1257,7 +1257,7 @@ def test_dz_to_T(): coef[0] = 0.0 coef[:, 0] = 0.0 - W = galsim.zernike.DoubleZernike(( + W = galsim.zernike.DoubleZernike( coef, uv_inner=uv_inner, uv_outer=uv_outer, # field xy_inner=xy_inner, xy_outer=xy_outer # pupil @@ -1363,7 +1363,7 @@ def test_dz_rotate(): coef[0] = 0.0 coef[:, 0] = 0.0 - dz = galsim.zernike.DoubleZernike(( + dz = galsim.zernike.DoubleZernike( coef, uv_inner=uv_inner, uv_outer=uv_outer, # field xy_inner=xy_inner, xy_outer=xy_outer # pupil @@ -1420,7 +1420,7 @@ def test_dz_basis(): for k in range(1, k1): coef = np.zeros((k1, j1)) coef[k, j] = 1.0 - DZ = galsim.zernike.DoubleZernike(( + DZ = galsim.zernike.DoubleZernike( coef, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer @@ -1449,7 +1449,7 @@ def test_dz_mean(): coef[0] = 0.0 coef[:, 0] = 0.0 - dz = galsim.zernike.DoubleZernike(( + dz = galsim.zernike.DoubleZernike( coef, uv_inner=uv_inner, uv_outer=uv_outer, xy_inner=xy_inner, xy_outer=xy_outer From 6c2bac18fad61d5346b809b2538136d2f5980f69 Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 23 Nov 2023 08:03:30 -0500 Subject: [PATCH 231/351] no raise --- tests/test_photon_array.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 06b96df547..d35c7877d4 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -274,8 +274,10 @@ def test_photon_array(): assert_raises(ValueError, galsim.PhotonArray.makeFromImage, zero, max_flux=-2) # Check some other errors - undef = galsim.Image() - assert_raises(galsim.GalSimUndefinedBoundsError, pa2.addTo, undef) + if hasattr(galsim, "_galsim"): + # jax doesn't raise for this + undef = galsim.Image() + assert_raises(galsim.GalSimUndefinedBoundsError, pa2.addTo, undef) # Check picklability again with non-zero values for everything check_pickle(photon_array) From d293d88f7fed3f56ea360e85d677f1ef5bc08e6e Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 23 Nov 2023 09:01:54 -0500 Subject: [PATCH 232/351] no raise --- tests/test_utilities.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 4a2112622b..12760c3511 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -272,7 +272,9 @@ def test_bounds(): assert_raises(TypeError, galsim.BoundsD, 11, 23, 9, 12, 59) assert_raises(TypeError, galsim.BoundsD, xmin=11, xmax=23, ymin=17, ymax=50, z=23) assert_raises(TypeError, galsim.BoundsD, xmin=11, xmax=50) - assert_raises(ValueError, galsim.BoundsD, 11, 23, 17, "blue") + if hasattr(galsim, '_galsim'): + # jax doesn't raise for this + assert_raises(ValueError, galsim.BoundsD, 11, 23, 17, "blue") assert_raises(TypeError, galsim.BoundsD, 11, 23, 9, 12, xmin=19, xmax=2) with assert_raises(TypeError): bd1 += (11,23) From 618a33b679783807f0083ab5e8cc44c2a67f3951 Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 23 Nov 2023 09:24:13 -0500 Subject: [PATCH 233/351] no raise --- tests/test_utilities.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 12760c3511..0bc0595e8b 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -401,10 +401,12 @@ def test_bounds(): assert galsim.BoundsD(23, 11, 17, 50) == galsim.BoundsD() assert galsim.BoundsD(11, 23, 50, 17) == galsim.BoundsD() - assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsI(), 'center') - assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsD(), 'center') - assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsI(), 'true_center') - assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsD(), 'true_center') + if hasattr(galsim, "_galsim"): + # jax doesn't raise for these things + assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsI(), 'center') + assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsD(), 'center') + assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsI(), 'true_center') + assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsD(), 'true_center') check_pickle(bi1) check_pickle(bd1) From 5591ded9626f62819dffc9f600e019d16d7bd269 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 25 Nov 2023 08:30:47 -0500 Subject: [PATCH 234/351] no raise --- tests/test_celestial_galsim.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index c868a38660..d28c7f7b76 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -125,11 +125,17 @@ def test_angle(): # Check invalid constructors assert_raises(TypeError,galsim.AngleUnit, galsim.degrees) - assert_raises(ValueError,galsim.AngleUnit, 'spam') + try: + assert_raises(ValueError,galsim.AngleUnit, 'spam') + except Exception: + assert_raises(TypeError,galsim.AngleUnit, 'spam') assert_raises(TypeError,galsim.AngleUnit, 1, 3) assert_raises(TypeError,galsim.Angle, 3.4) assert_raises(TypeError,galsim.Angle, theta1, galsim.degrees) - assert_raises(ValueError,galsim.Angle, 'spam', galsim.degrees) + try: + assert_raises(ValueError,galsim.Angle, 'spam', galsim.degrees) + except Exception: + assert_raises(TypeError,galsim.Angle, 'spam', galsim.degrees) assert_raises(TypeError,galsim.Angle, 1, 3) From a09362424c112bc3a8a0a39a386a5ef3f9fdb5f6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 25 Nov 2023 08:35:04 -0500 Subject: [PATCH 235/351] no raise --- tests/test_photon_array.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index d35c7877d4..06b96df547 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -274,10 +274,8 @@ def test_photon_array(): assert_raises(ValueError, galsim.PhotonArray.makeFromImage, zero, max_flux=-2) # Check some other errors - if hasattr(galsim, "_galsim"): - # jax doesn't raise for this - undef = galsim.Image() - assert_raises(galsim.GalSimUndefinedBoundsError, pa2.addTo, undef) + undef = galsim.Image() + assert_raises(galsim.GalSimUndefinedBoundsError, pa2.addTo, undef) # Check picklability again with non-zero values for everything check_pickle(photon_array) From 8a3440d72d739763514a2620e61c6e50668648b9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 26 Nov 2023 05:48:12 -0500 Subject: [PATCH 236/351] no raise --- tests/test_utilities.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 0bc0595e8b..07af3c3cd5 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -105,7 +105,10 @@ def test_pos(): assert_raises(TypeError, galsim.PositionD, x=11) assert_raises(TypeError, galsim.PositionD, x=11, y=23, z=17) assert_raises(TypeError, galsim.PositionD, 11, 23, x=13, z=21) - assert_raises(ValueError, galsim.PositionD, 11, "blue") + try: + assert_raises(ValueError, galsim.PositionD, 11, "blue") + except Exception: + assert_raises(TypeError, galsim.PositionD, 11, "blue") # Can't use base class directly. assert_raises(TypeError, galsim.Position, 11, 23) From 6fac1a79ab7092119dedb7d7b0f00ea31b7162f9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 26 Nov 2023 07:09:41 -0500 Subject: [PATCH 237/351] no raise --- tests/test_image.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index dc6f43ecfe..52819ce242 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -104,8 +104,10 @@ def test_Image_basic(): np.testing.assert_array_equal(im1.array, 0.) assert im1.array.shape == (nrow,ncol) assert im1.array.dtype.type == np_array_type - assert im1.array.flags.writeable == True - assert im1.array.flags.c_contiguous == True + if hasattr(galsim, "_galsim"): + # jax arrays do not have flags + assert im1.array.flags.writeable == True + assert im1.array.flags.c_contiguous == True assert im1.dtype == np_array_type assert im1.ncol == ncol assert im1.nrow == nrow From 552aef8c8320d182b42217a59db9cb151c77c4cb Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 26 Nov 2023 07:47:25 -0500 Subject: [PATCH 238/351] paths --- tests/test_catalog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index b158f9df91..22a3c55181 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -200,7 +200,7 @@ def test_basic_dict(): def test_single_row(): """Test that we can read catalogs with just one row (#394) """ - filename = "output/test394.txt" + filename = os.path.join(os.path.dirname(__file__), "output/test394.txt") with open(filename, 'w') as f: f.write("3 4 5\n") cat = galsim.Catalog(filename, file_type='ascii') From 3a225bd3a4f71d218fab767001cd8cd5a8b67634 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 26 Nov 2023 07:49:17 -0500 Subject: [PATCH 239/351] paths --- tests/test_config_output.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_config_output.py b/tests/test_config_output.py index a2d7cfabf5..61e3ae106c 100644 --- a/tests/test_config_output.py +++ b/tests/test_config_output.py @@ -1238,7 +1238,7 @@ def test_config(): } # Test yaml - yaml_file_name = "output/test_config.yaml" + yaml_file_name = os.path.join(os.path.dirname(__file__), "output/test_config.yaml") with open(yaml_file_name, 'w') as fout: yaml.dump(config, fout, default_flow_style=True) # String None will be coverted to a real None. Convert here in the comparison dict @@ -1252,7 +1252,7 @@ def test_config(): assert config == dict(config2) # Test json - json_file_name = "output/test_config.json" + json_file_name = os.path.join(os.path.dirname(__file__), "output/test_config.json") with open(json_file_name, 'w') as fout: json.dump(config, fout) From b67d4db7192d9ef2fa7b533f152831e6428ef732 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 26 Nov 2023 07:52:31 -0500 Subject: [PATCH 240/351] no refs --- tests/test_deprecated.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 652474d2e9..1fea72c943 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -739,8 +739,11 @@ def test_photon_array_depr(): # Check assignAt pa1 = galsim.PhotonArray(50) pa1.x = photon_array.x[:50] - for i in range(50): - pa1.y[i] = photon_array.y[i] + if hasattr(galsim, "_galsim"): + for i in range(50): + pa1.y[i] = photon_array.y[i] + else: + pa1.y = photon_array.y[:50] pa1.flux[0:50] = photon_array.flux[:50] pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] From 38d06d5fd91e4214efdce4c3ae70c856c293280f Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 26 Nov 2023 07:53:12 -0500 Subject: [PATCH 241/351] no refs --- tests/test_deprecated.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 1fea72c943..1c97e8bb33 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -742,9 +742,10 @@ def test_photon_array_depr(): if hasattr(galsim, "_galsim"): for i in range(50): pa1.y[i] = photon_array.y[i] + pa1.flux[0:50] = photon_array.flux[:50] else: pa1.y = photon_array.y[:50] - pa1.flux[0:50] = photon_array.flux[:50] + pa1.flux.at[0:50].set(photon_array.flux[:50]) pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] pa1.pupil_u = photon_array.pupil_u[:50] From 58b7f77835238b417eb4dc26822f5e6f373538d9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sun, 26 Nov 2023 07:55:30 -0500 Subject: [PATCH 242/351] array asserts --- tests/test_deprecated.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 1c97e8bb33..7348833eb6 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -753,20 +753,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_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) + 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) # Error if it doesn't fit. with assert_raises(ValueError): From 633d0f52d0775c3e54fc4f7e6a096f2af184295b Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Sun, 26 Nov 2023 20:11:28 -0600 Subject: [PATCH 243/351] Update test_random.py --- tests/test_random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index 3ad89a40ff..ddaee3b960 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -48,7 +48,7 @@ testseed = 1000 # seed used for UniformDeviate for all tests # Warning! If you change testseed, then all of the *Result variables below must change as well. -if not hasattr(galsim, "_galsim"): +if hasattr(galsim, "_galsim"): # the right answer for the first three uniform deviates produced from testseed uResult = (0.11860922840423882, 0.21456799632869661, 0.43088198406621814) From d5b6d76c079420de4c92510957e1e911ac3522f1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 06:49:02 -0600 Subject: [PATCH 244/351] no views --- tests/test_image.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 52819ce242..557a5f39a2 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -204,7 +204,9 @@ def test_Image_basic(): assert im1.view()(x,y) == value assert im1.view()(galsim.PositionI(x,y)) == value assert im1.view(make_const=True)(x,y) == value - assert im2(x,y) == value + if hasattr(galsim, "_galsim"): + # now real views in jax + assert im2(x,y) == value assert im2_view(x,y) == value assert im2_cview(x,y) == value assert im1.conjugate(x,y) == value From ed0df695604479fd24f4f1edea2d2d3cdb966790 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 06:50:51 -0600 Subject: [PATCH 245/351] no views --- tests/test_image.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 557a5f39a2..07fa7348ff 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -205,10 +205,16 @@ def test_Image_basic(): assert im1.view()(galsim.PositionI(x,y)) == value assert im1.view(make_const=True)(x,y) == value if hasattr(galsim, "_galsim"): - # now real views in jax + # no real views in jax assert im2(x,y) == value + else: + assert im2(x,y) != value assert im2_view(x,y) == value - assert im2_cview(x,y) == value + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2_cview(x,y) == value + else: + assert im2_cview(x,y) != value assert im1.conjugate(x,y) == value if tchar[i][0] == 'C': # complex conjugate is not a view into the original. From a320a40ba2bb97d9ba7dbafda49c92b5b851d015 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 10:09:08 -0600 Subject: [PATCH 246/351] no views --- tests/test_image.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_image.py b/tests/test_image.py index 07fa7348ff..83c434fe37 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -221,7 +221,11 @@ def test_Image_basic(): assert im2_conj(x,y) == 23 assert im2.conjugate(x,y) == value else: + if hasattr(galsim, "_galsim"): + # no real views in jax assert im2_conj(x,y) == value + else: + assert im2_conj(x,y) != value value2 = 53 + 12*x - 19*y if tchar[i] in ['US', 'UI']: From 49c44162e18c38e21578d3998a602aaa96921edd Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 10:09:31 -0600 Subject: [PATCH 247/351] no views --- tests/test_image.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 83c434fe37..9c802c5994 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -221,11 +221,11 @@ def test_Image_basic(): assert im2_conj(x,y) == 23 assert im2.conjugate(x,y) == value else: - if hasattr(galsim, "_galsim"): - # no real views in jax - assert im2_conj(x,y) == value - else: - assert im2_conj(x,y) != value + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2_conj(x,y) == value + else: + assert im2_conj(x,y) != value value2 = 53 + 12*x - 19*y if tchar[i] in ['US', 'UI']: From fdfda0c268aac708948eb7e3d9cd9dec42f5435c Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 10:15:32 -0600 Subject: [PATCH 248/351] no views --- tests/test_image.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 9c802c5994..78bf995f7e 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -235,9 +235,17 @@ def test_Image_basic(): assert im1.getValue(x,y) == value2 assert im1.view().getValue(x=x, y=y) == value2 assert im1.view(make_const=True).getValue(x,y) == value2 - assert im2.getValue(x=x, y=y) == value2 + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2.getValue(x=x, y=y) == value2 + else: + assert im2.getValue(x=x, y=y) != value2 assert im2_view.getValue(x,y) == value2 - assert im2_cview._getValue(x,y) == value2 + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2_cview._getValue(x,y) == value2 + else: + assert im2_cview._getValue(x,y) != value2 assert im1.real(x,y) == value2 assert im1.view().real(x,y) == value2 From 9c660b585b4fcb1d2b6c576d30a1eeedfccb59fc Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 10:30:23 -0600 Subject: [PATCH 249/351] no views --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 78bf995f7e..5fd2eabbb1 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -250,7 +250,11 @@ def test_Image_basic(): assert im1.real(x,y) == value2 assert im1.view().real(x,y) == value2 assert im1.view(make_const=True).real(x,y) == value2.real - assert im2.real(x,y) == value2.real + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2.real(x,y) == value2.real + else: + assert im2.real(x,y) != value2.real assert im2_view.real(x,y) == value2.real assert im2_cview.real(x,y) == value2.real assert im1.imag(x,y) == 0 From 746ee19abb2de273e77a8fd63d4633bf5c620423 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 10:31:32 -0600 Subject: [PATCH 250/351] no views --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 5fd2eabbb1..d01d41385e 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -256,7 +256,11 @@ def test_Image_basic(): else: assert im2.real(x,y) != value2.real assert im2_view.real(x,y) == value2.real - assert im2_cview.real(x,y) == value2.real + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2_cview.real(x,y) == value2.real + else: + assert im2_cview.real(x,y) != value2.real assert im1.imag(x,y) == 0 assert im1.view().imag(x,y) == 0 assert im1.view(make_const=True).imag(x,y) == 0 From 481cdbb3d46b16c3d2521684ee2efac0b33aa2a5 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 10:42:57 -0600 Subject: [PATCH 251/351] no views --- tests/test_image.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index d01d41385e..e30d5204dc 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -274,9 +274,17 @@ def test_Image_basic(): assert im1[galsim.PositionI(x,y)] == value3 assert im1.view()[x,y] == value3 assert im1.view(make_const=True)[galsim.PositionI(x,y)] == value3 - assert im2[x,y] == value3 + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2[x,y] == value3 + else: + assert im2[x,y] != value3 assert im2_view[galsim.PositionI(x,y)] == value3 - assert im2_cview[x,y] == value3 + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2_cview[x,y] == value3 + else: + assert im2_cview[x,y] != value3 # Setting or getting the value outside the bounds should throw an exception. assert_raises(galsim.GalSimBoundsError,im1.setValue,0,0,1) From 728a18f31abcce34511b948797c86780406a7c56 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 10:49:35 -0600 Subject: [PATCH 252/351] no views --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index e30d5204dc..30cf26fdbf 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -268,7 +268,7 @@ def test_Image_basic(): assert im2_view.imag(x,y) == 0 assert im2_cview.imag(x,y) == 0 - value3 = 10*x + y + value3 = 10*x + y + 111111111 im1.addValue(x,y, value3-value2) im2_view[x,y] += value3-value2 assert im1[galsim.PositionI(x,y)] == value3 From 3ff8c02034bd0c6f13a3cc636bc8075f66279e2d Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 11:19:08 -0600 Subject: [PATCH 253/351] no views --- tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 30cf26fdbf..7b102480c8 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -395,7 +395,7 @@ def test_Image_basic(): assert im2.bounds == bounds for y in range(1,nrow+1): for x in range(1,ncol+1): - value3 = 10*x+y + value3 = 10*x+y + 111111111 assert im1(x+dx,y+dy) == value3 assert im1_view(x,y) == value3 assert im2(x,y) == value3 From 5263be7d4b3be12803acc77f9edb711d07c58bfc Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 11:20:08 -0600 Subject: [PATCH 254/351] no views --- tests/test_image.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 7b102480c8..8ac27354e8 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -398,7 +398,10 @@ def test_Image_basic(): value3 = 10*x+y + 111111111 assert im1(x+dx,y+dy) == value3 assert im1_view(x,y) == value3 - assert im2(x,y) == value3 + if hasattr(galsim, "_galsim"): + assert im2(x,y) == value3 + else: + assert im2(x,y) != value3 assert im2_view(x+dx,y+dy) == value3 assert im3_view(x+dx,y+dy) == value3 From aacd9c8652ef02c6362b35ce2c6d0261571ae7f9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 11:22:17 -0600 Subject: [PATCH 255/351] no views --- tests/test_image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_image.py b/tests/test_image.py index 8ac27354e8..143263bcd7 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -403,6 +403,7 @@ def test_Image_basic(): else: assert im2(x,y) != value3 assert im2_view(x+dx,y+dy) == value3 + value3 = 10*x+y assert im3_view(x+dx,y+dy) == value3 assert_raises(TypeError, im1.shift, dx) From 46cbdfc10257f9cbdfc171d3478c4fdac16a5993 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 11:23:06 -0600 Subject: [PATCH 256/351] no views --- tests/test_image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index 143263bcd7..3734f47105 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -268,7 +268,7 @@ def test_Image_basic(): assert im2_view.imag(x,y) == 0 assert im2_cview.imag(x,y) == 0 - value3 = 10*x + y + 111111111 + value3 = 10*x + y + 111 im1.addValue(x,y, value3-value2) im2_view[x,y] += value3-value2 assert im1[galsim.PositionI(x,y)] == value3 @@ -395,7 +395,7 @@ def test_Image_basic(): assert im2.bounds == bounds for y in range(1,nrow+1): for x in range(1,ncol+1): - value3 = 10*x+y + 111111111 + value3 = 10*x+y + 111 assert im1(x+dx,y+dy) == value3 assert im1_view(x,y) == value3 if hasattr(galsim, "_galsim"): From 9a2d102bd0f48510c9d793c78edd9c302993cf1c Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 11:26:05 -0600 Subject: [PATCH 257/351] no views --- tests/test_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 3734f47105..c29215a32f 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -219,7 +219,11 @@ def test_Image_basic(): if tchar[i][0] == 'C': # complex conjugate is not a view into the original. assert im2_conj(x,y) == 23 - assert im2.conjugate(x,y) == value + if hasattr(galsim, "_galsim"): + # no real views in jax + assert im2.conjugate(x,y) == value + else: + assert im2.conjugate(x,y) != value else: if hasattr(galsim, "_galsim"): # no real views in jax From dfe3d11d9d5d733da1555f7e685f0b12d1256264 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 11:50:12 -0600 Subject: [PATCH 258/351] no views --- tests/test_photon_array.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index ecd6134cd6..4247cf26b7 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -245,7 +245,10 @@ def test_photon_array(): assert pa2.time[17] == pa1.time[20] # Can choose not to copy flux - pa2.flux[27] = -1 + if hasattr(galsim, "_galsim"): + pa2.flux[27] = -1 + else: + pa2._flux = pa2._flux.at[27].set(-1) pa2.copyFrom(pa1, 27, 10, do_flux=False) assert pa2.flux[27] != pa1.flux[10] assert pa2.x[27] == pa1.x[10] From 7192fa62d148bd735c1b5b588dd3f5dd4ccf83c9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 12:02:57 -0600 Subject: [PATCH 259/351] no views --- tests/test_photon_array.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 4247cf26b7..50fc009921 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -262,8 +262,16 @@ def test_photon_array(): assert pa2.time[37] == pa1.time[8] # ... or the other arrays - pa2.dxdz[47] = pa2.dydz[47] = pa2.wavelength[47] = -1 - pa2.pupil_u[47] = pa2.pupil_v[47] = pa2.time[47] = -1 + if hasattr(galsim, "_galsim"): + pa2.dxdz[47] = pa2.dydz[47] = pa2.wavelength[47] = -1 + pa2.pupil_u[47] = pa2.pupil_v[47] = pa2.time[47] = -1 + else: + pa2._dxdz = pa2._dxdz.at[47].set(-1) + pa2._dydz = pa2._dydz.at[47].set(-1) + pa2._wave = pa2._wave.at[47].set(-1) + pa2._pupil_u = pa2._pupil_u.at[47].set(-1) + pa2._pupil_v = pa2._pupil_v.at[47].set(-1) + pa2._time = pa2._time.at[47].set(-1) pa2.copyFrom(pa1, 47, 18, do_other=False) assert pa2.flux[47] == pa1.flux[18] assert pa2.x[47] == pa1.x[18] From 8592754aa1d252c9ecb5a5330655844b19597594 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 12:05:37 -0600 Subject: [PATCH 260/351] no index errors --- tests/test_photon_array.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 50fc009921..d7c550035e 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -296,7 +296,8 @@ def test_photon_array(): # Error if indices are invalid assert_raises(ValueError, pa2.copyFrom, pa1, slice(50,None), slice(50,None)) - assert_raises(ValueError, pa2.copyFrom, pa1, 100, 0) + if hasattr(galsim, "_galsim"): + assert_raises(ValueError, pa2.copyFrom, pa1, 100, 0) assert_raises(ValueError, pa2.copyFrom, pa1, 0, slice(None)) assert_raises(ValueError, pa2.copyFrom, pa1) assert_raises(ValueError, pa2.copyFrom, pa1, slice(None), pa1.x<0) From 71400ad6f7ac364e63629e42c7ce4162b10aef17 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 12:18:00 -0600 Subject: [PATCH 261/351] bool env --- tests/test_random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index ddaee3b960..15f4c80f6e 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -48,7 +48,7 @@ testseed = 1000 # seed used for UniformDeviate for all tests # Warning! If you change testseed, then all of the *Result variables below must change as well. -if hasattr(galsim, "_galsim"): +if os.environ.get("JAX_GALSIM_TESTING", "0") != "1": # the right answer for the first three uniform deviates produced from testseed uResult = (0.11860922840423882, 0.21456799632869661, 0.43088198406621814) From eecef976143704e0e017aa74b50abd7967e1c520 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 12:23:16 -0600 Subject: [PATCH 262/351] bool env --- tests/test_random.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index 15f4c80f6e..8f56e87f4c 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -48,80 +48,80 @@ testseed = 1000 # seed used for UniformDeviate for all tests # Warning! If you change testseed, then all of the *Result variables below must change as well. -if os.environ.get("JAX_GALSIM_TESTING", "0") != "1": +if os.environ.get("JAX_GALSIM_TESTING", "0") == "1": # the right answer for the first three uniform deviates produced from testseed - uResult = (0.11860922840423882, 0.21456799632869661, 0.43088198406621814) + uResult = (0.0160653916, 0.228817832, 0.1609966951) # mean, sigma to use for Gaussian tests gMean = 4.7 gSigma = 3.2 # the right answer for the first three Gaussian deviates produced from testseed - gResult = (6.3344979808161215, 6.2082355273987861, -0.069894693358302007) + gResult = (-2.1568953985, 2.3232138032, 1.5308165692) # N, p to use for binomial tests bN = 10 bp = 0.7 # the right answer for the first three binomial deviates produced from testseed - bResult = (9, 8, 7) + bResult = (5, 8, 7) # mean to use for Poisson tests pMean = 7 # the right answer for the first three Poisson deviates produced from testseed - pResult = (4, 5, 6) + pResult = (6, 11, 4) # a & b to use for Weibull tests - wA = 4. - wB = 9. + wA = 4.0 + wB = 9.0 # Tabulated results for Weibull - wResult = (5.3648053017485591, 6.3093033550873878, 7.7982696798921074) + wResult = (3.2106530102, 6.4256210259, 5.8255498741) # k & theta to use for Gamma tests gammaK = 1.5 gammaTheta = 4.5 # Tabulated results for Gamma - gammaResult = (4.7375613139927157, 15.272973580418618, 21.485016362839747) + gammaResult = (10.9318881415, 7.6074550007, 2.0526795529) # n to use for Chi2 tests chi2N = 30 # Tabulated results for Chi2 - chi2Result = (32.209933900954049, 50.040002656028513, 24.301442486313896) + chi2Result = (36.7583415337, 32.7223187231, 23.1555198334) else: # the right answer for the first three uniform deviates produced from testseed - uResult = (0.0160653916, 0.228817832, 0.1609966951) + uResult = (0.11860922840423882, 0.21456799632869661, 0.43088198406621814) # mean, sigma to use for Gaussian tests gMean = 4.7 gSigma = 3.2 # the right answer for the first three Gaussian deviates produced from testseed - gResult = (-2.1568953985, 2.3232138032, 1.5308165692) + gResult = (6.3344979808161215, 6.2082355273987861, -0.069894693358302007) # N, p to use for binomial tests bN = 10 bp = 0.7 # the right answer for the first three binomial deviates produced from testseed - bResult = (5, 8, 7) + bResult = (9, 8, 7) # mean to use for Poisson tests pMean = 7 # the right answer for the first three Poisson deviates produced from testseed - pResult = (6, 11, 4) + pResult = (4, 5, 6) # a & b to use for Weibull tests - wA = 4.0 - wB = 9.0 + wA = 4. + wB = 9. # Tabulated results for Weibull - wResult = (3.2106530102, 6.4256210259, 5.8255498741) + wResult = (5.3648053017485591, 6.3093033550873878, 7.7982696798921074) # k & theta to use for Gamma tests gammaK = 1.5 gammaTheta = 4.5 # Tabulated results for Gamma - gammaResult = (10.9318881415, 7.6074550007, 2.0526795529) + gammaResult = (4.7375613139927157, 15.272973580418618, 21.485016362839747) # n to use for Chi2 tests chi2N = 30 # Tabulated results for Chi2 - chi2Result = (36.7583415337, 32.7223187231, 23.1555198334) + chi2Result = (32.209933900954049, 50.040002656028513, 24.301442486313896) #function and min&max to use for DistDeviate function call tests dmin=0.0 From fc4e74fe3beb18ec9912eefd28768464973aa369 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 13:24:01 -0600 Subject: [PATCH 263/351] zernike import --- tests/test_zernike.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index 36fc0c1b5b..876a78bc43 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -814,9 +814,9 @@ def test_dz_val(): check_pickle(dz, lambda dz_: tuple(dz_(*uv_vector, *xy_vector))) # If you don't specify xy, then get (list of) Zernike out. - assert isinstance(dz(*uv_scalar), Zernike) + assert isinstance(dz(*uv_scalar), galsim.zernike.Zernike) assert isinstance(dz(*uv_vector), list) - assert all(isinstance(z, Zernike) for z in dz(*uv_vector)) + assert all(isinstance(z, galsim.zernike.Zernike) for z in dz(*uv_vector)) # If uv scalar and xy scalar, then get scalar out. assert np.ndim(dz(*uv_scalar, *xy_scalar)) == 0 From 75dfbcbd4b269e71fd25beb5195f6b84e8090e64 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 13:35:29 -0600 Subject: [PATCH 264/351] bug in test of randoms --- tests/test_random.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_random.py b/tests/test_random.py index 8f56e87f4c..dc28140034 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -288,7 +288,6 @@ def test_uniform(): u.add_generate(test_array) else: test_array = u.add_generate(test_array) - u.add_generate(test_array) np.testing.assert_array_almost_equal( test_array, 2.*np.array(uResult), precisionF, err_msg='Wrong uniform random number sequence from generate.') From e003b5aa2b00629cba7e6c48758475bcece872bb Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 14:57:40 -0600 Subject: [PATCH 265/351] remove deprecation warnings --- tests/test_wcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 96b07dfbe7..e79baaad99 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -499,7 +499,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.withOrigin(new_origin) + wcs3 = wcs.shiftOrigin(new_origin) assert wcs != wcs3, name+' is not != wcs.withOrigin(pos)' assert wcs3 != wcs, name+' is not != wcs.withOrigin(pos) (reverse)' wcs2 = wcs3.local() @@ -513,7 +513,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.withOrigin(new_origin, new_world_origin) + wcs4 = wcs.shiftOrigin(new_origin, new_world_origin) world_pos3 = wcs4.toWorld(new_origin) np.testing.assert_almost_equal( world_pos3.x, new_world_origin.x, digits, From ef5d07a5f1cb1705b01d23914eb6b161480d6175 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:33:59 -0600 Subject: [PATCH 266/351] Apply suggestions from code review --- tests/test_deprecated.py | 85 +++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 7348833eb6..b961a4dbcf 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -25,7 +25,8 @@ def check_dep(f, *args, **kwargs): - """Check that some function raises a GalSimDeprecationWarning as a warning, but not an error.""" + """Check that some function raises a GalSimDeprecationWarning as a warning, but not an error. +""" # Check that f() raises a warning, but not an error. with assert_warns(galsim.GalSimDeprecationWarning): res = f(*args, **kwargs) @@ -36,19 +37,16 @@ def check_dep(f, *args, **kwargs): def test_gsparams(): 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.0e-6) + check_dep(galsim.GSParams, small_fraction_of_flux=1.e-6) @timer def test_phase_psf(): - atm = galsim.Atmosphere( - screen_size=10.0, altitude=0, r0_500=0.15, suppress_warning=True - ) + atm = galsim.Atmosphere(screen_size=10.0, altitude=0, r0_500=0.15, suppress_warning=True) psf = atm.makePSF(exptime=0.02, time_step=0.01, diam=1.1, lam=1000.0) check_dep(galsim.PhaseScreenPSF.__getattribute__, psf, "img") check_dep(galsim.PhaseScreenPSF.__getattribute__, psf, "finalized") - @timer def test_interpolant(): d = check_dep(galsim.Delta, tol=1.0e-2) @@ -85,21 +83,18 @@ def test_interpolant(): @timer def test_noise(): - real_gal_dir = os.path.join("..", "examples", "data") - real_gal_cat = "real_galaxy_catalog_23.5_example.fits" + real_gal_dir = os.path.join('..','examples','data') + real_gal_cat = 'real_galaxy_catalog_23.5_example.fits' real_cat = galsim.RealGalaxyCatalog( - dir=real_gal_dir, file_name=real_gal_cat, preload=True - ) + dir=real_gal_dir, file_name=real_gal_cat, preload=True) - test_seed = 987654 + test_seed=987654 test_index = 17 cf_1 = real_cat.getNoise(test_index, rng=galsim.BaseDeviate(test_seed)) im_2, pix_scale_2, var_2 = real_cat.getNoiseProperties(test_index) # Check the variance: var_1 = cf_1.getVariance() - assert ( - var_1 == var_2 - ), "Inconsistent noise variance from getNoise and getNoiseProperties" + assert var_1==var_2,'Inconsistent noise variance from getNoise and getNoiseProperties' # Check the image: ii = galsim.InterpolatedImage( im_2, @@ -128,10 +123,10 @@ def test_randwalk_defaults(): """ # try constructing with mostly defaults - npoints = 100 + npoints=100 hlr = 8.0 rng = galsim.BaseDeviate(1234) - rw = check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng) + rw=check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng) assert rw.npoints == npoints, "expected npoints==%d, got %d" % (npoints, rw.npoints) assert rw.input_half_light_radius == hlr, "expected hlr==%g, got %g" % ( @@ -139,8 +134,8 @@ def test_randwalk_defaults(): rw.input_half_light_radius, ) - nobj = len(rw.points) - assert nobj == npoints, "expected %d objects, got %d" % (npoints, nobj) + nobj=len(rw.points) + assert nobj == npoints,"expected %d objects, got %d" % (npoints, nobj) pts = rw.points assert pts.shape == (npoints, 2), "expected (%d,2) shape for points, got %s" % ( @@ -150,7 +145,7 @@ def test_randwalk_defaults(): np.testing.assert_almost_equal(rw.centroid.x, np.mean(pts[:, 0])) np.testing.assert_almost_equal(rw.centroid.y, np.mean(pts[:, 1])) - gsp = galsim.GSParams(xvalue_accuracy=1.0e-8, kvalue_accuracy=1.0e-8) + gsp = galsim.GSParams(xvalue_accuracy=1.e-8, kvalue_accuracy=1.e-8) rng2 = galsim.BaseDeviate(1234) rw2 = check_dep( galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng2, gsparams=gsp @@ -168,7 +163,7 @@ def test_randwalk_defaults(): # Check that image is not sensitive to use of rng by other objects. rng3 = galsim.BaseDeviate(1234) - rw3 = check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng3) + rw3=check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng3) rng3.discard(523) conv1 = galsim.Convolve(rw, psf) conv3 = galsim.Convolve(rw3, psf) @@ -178,7 +173,7 @@ def test_randwalk_defaults(): # Run some basic tests of correctness check_basic(conv1, "RandomWalk") - im = galsim.ImageD(64, 64, scale=0.5) + im = galsim.ImageD(64,64, scale=0.5) do_shoot(conv1, im, "RandomWalk") do_kvalue(conv1, im, "RandomWalk") check_pickle(rw) @@ -193,7 +188,7 @@ def test_randwalk_repr(): using eval """ - npoints = 100 + npoints=100 hlr = 8.0 flux = 1 rw1 = check_dep( @@ -202,16 +197,17 @@ def test_randwalk_repr(): half_light_radius=hlr, flux=flux, ) - rw2 = check_dep( - galsim.RandomWalk, + rw2=check_dep(galsim.RandomWalk, npoints, profile=galsim.Exponential(half_light_radius=hlr, flux=flux), ) for rw in (rw1, rw2): + + # just make sure str() works, don't require eval to give # a consistent object back - st = str(rw) + st=str(rw) # require eval(repr(rw)) to give a consistent object back @@ -240,36 +236,35 @@ def test_randwalk_config(): explicit constructor """ - hlr = 2.0 - flux = np.pi + hlr=2.0 + flux=np.pi gal_config1 = { - "type": "RandomWalk", - "npoints": 100, - "half_light_radius": hlr, - "flux": flux, + 'type': 'RandomWalk', + 'npoints': 100, + 'half_light_radius': hlr, + 'flux': flux, } gal_config2 = { - "type": "RandomWalk", - "npoints": 150, - "profile": { - "type": "Exponential", - "half_light_radius": hlr, - "flux": flux, - }, + 'type': 'RandomWalk', + 'npoints': 150, + 'profile': { + 'type': 'Exponential', + 'half_light_radius': hlr, + 'flux': flux, + } } for gal_config in (gal_config1, gal_config2): - config = { - "gal": gal_config, - "rng": galsim.BaseDeviate(31415), + config={ + 'gal': gal_config, + 'rng': galsim.BaseDeviate(31415), } - rwc = check_dep(galsim.config.BuildGSObject, config, "gal")[0] + rwc = check_dep(galsim.config.BuildGSObject, config, 'gal')[0] print(repr(rwc._profile)) - rw = check_dep( - galsim.RandomWalk, - gal_config["npoints"], + rw = check_dep(galsim.RandomWalk, + gal_config['npoints'], half_light_radius=hlr, flux=flux, ) From f1dd4d25f02cde7d108fa47564009a582bfd6257 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:37:50 -0600 Subject: [PATCH 267/351] Apply suggestions from code review --- tests/test_deprecated.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index b961a4dbcf..30121daf02 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -368,8 +368,8 @@ def test_withOrigin(): ) # Now some CelestialWCS types - cubic_u = Cubic(2.9e-5, 2000.0, "u") - cubic_v = Cubic(-3.7e-5, 2000.0, "v") + cubic_u = Cubic(2.9e-5, 2000.0, 'u') + cubic_v = Cubic(-3.7e-5, 2000.0, 'v') center = galsim.CelestialCoord(23 * galsim.degrees, -13 * galsim.degrees) radec = lambda x, y: center.deproject_rad( cubic_u(x, y) * 0.2, cubic_v(x, y) * 0.2, projection="lambert" @@ -383,7 +383,7 @@ def test_withOrigin(): for wcs in wcs_list: # Original version of the shiftOrigin tests in do_celestial_wcs using deprecated name. - new_origin = galsim.PositionI(123, 321) + new_origin = galsim.PositionI(123,321) wcs3 = wcs.shiftOrigin(new_origin) assert wcs != wcs3, name + " is not != wcs.shiftOrigin(pos)" wcs4 = wcs.local(wcs.origin) @@ -803,28 +803,27 @@ def test_chromatic_flux(): assert PSF3 == PSF1 # And check deprecated SED attribute. - sed = check_dep(getattr, PSF, "SED") + sed = check_dep(getattr, PSF, 'SED') assert sed == PSF.sed - sed1 = check_dep(getattr, PSF1, "SED") + sed1 = check_dep(getattr, PSF1, 'SED') assert sed1 == PSF1.sed - sed2 = check_dep(getattr, mono_PSF, "SED") - assert sed1 == mono_PSF.sed == galsim.SED(1, "nm", "1") - + sed2 = check_dep(getattr, mono_PSF, 'SED') + assert sed1 == mono_PSF.sed == galsim.SED(1, 'nm', '1') @timer def test_W149(): # Based on test_config_psf, using old W149 name. config = { - "modules": ["galsim.roman"], - "psf": {"type": "RomanPSF", "SCA": 4, "bandpass": "W149"}, + 'modules': ['galsim.roman'], + 'psf': {'type': 'RomanPSF', 'SCA': 4, 'bandpass': 'W149'}, } galsim.config.ImportModules(config) - psf1 = check_dep(galsim.config.BuildGSObject, config, "psf")[0] - psf2 = check_dep(galsim.roman.getPSF, SCA=4, bandpass="W149") - print("psf1 = ", str(psf1)) - print("psf2 = ", str(psf2)) + psf1 = check_dep(galsim.config.BuildGSObject, config, 'psf')[0] + psf2 = check_dep(galsim.roman.getPSF, SCA=4, bandpass='W149') + print('psf1 = ', str(psf1)) + print('psf2 = ', str(psf2)) assert psf1 == psf2 config = galsim.config.CleanConfig(config) @@ -930,6 +929,6 @@ def test_photon_array_correlated(): if __name__ == "__main__": - testfns = [v for k, v in vars().items() if k[:5] == "test_" and callable(v)] + testfns = [v for k, v in vars().items() if k[:5] == 'test_' and callable(v)] for testfn in testfns: testfn() From 73851f4faae9bc7b66061f8f6010e5634cd5b34b Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:43:21 -0600 Subject: [PATCH 268/351] Apply suggestions from code review --- tests/test_deprecated.py | 45 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 30121daf02..9e38cc83cb 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -780,10 +780,8 @@ def test_chromatic_flux(): mono_PSF, base_wavelength=500, zenith_angle=zenith_angle ) PSF = PSF * 1.0 - PSF1 = PSF.interpolate( - waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), - use_exact_sed=False, - ) + PSF1 = PSF.interpolate(waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), + use_exact_sed=False) # Check deprecated use_exact_SED kwarg PSF2 = check_dep( @@ -794,12 +792,9 @@ def test_chromatic_flux(): assert PSF2 == PSF1 # Also do this manually with the InterpolatedChromaticObject class - PSF3 = check_dep( - galsim.InterpolatedChromaticObject, - PSF, - waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), - use_exact_SED=False, - ) + PSF3 = check_dep(galsim.InterpolatedChromaticObject, PSF, + waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), + use_exact_SED=False) assert PSF3 == PSF1 # And check deprecated SED attribute. @@ -815,29 +810,29 @@ def test_W149(): # Based on test_config_psf, using old W149 name. config = { - 'modules': ['galsim.roman'], - 'psf': {'type': 'RomanPSF', 'SCA': 4, 'bandpass': 'W149'}, + 'modules' : ['galsim.roman'], + 'psf' : { 'type' : 'RomanPSF', 'SCA': 4, 'bandpass': 'W149' }, } galsim.config.ImportModules(config) psf1 = check_dep(galsim.config.BuildGSObject, config, 'psf')[0] psf2 = check_dep(galsim.roman.getPSF, SCA=4, bandpass='W149') - print('psf1 = ', str(psf1)) - print('psf2 = ', str(psf2)) + print('psf1 = ',str(psf1)) + print('psf2 = ',str(psf2)) assert psf1 == psf2 config = galsim.config.CleanConfig(config) - config["image"] = {"bandpass": {"type": "RomanBandpass", "name": "W149"}} - config["psf"]["wavelength"] = 985 - config["psf"]["pupil_bin"] = 8 - bp = check_dep(galsim.config.BuildBandpass, config["image"], "bandpass", config)[0] - config["bandpass"] = bp - psf1 = check_dep(galsim.config.BuildGSObject, config, "psf")[0] - psf2 = check_dep( - galsim.roman.getPSF, SCA=4, bandpass="W149", pupil_bin=8, wavelength=985.0 - ) - print("psf1 = ", str(psf1)) - print("psf2 = ", str(psf2)) + config['image'] = { + 'bandpass' : { 'type' : 'RomanBandpass', 'name' : 'W149' } + } + config['psf']['wavelength'] = 985 + config['psf']['pupil_bin'] = 8 + bp = check_dep(galsim.config.BuildBandpass, config['image'], 'bandpass', config)[0] + config['bandpass'] = bp + psf1 = check_dep(galsim.config.BuildGSObject, config, 'psf')[0] + psf2 = check_dep(galsim.roman.getPSF, SCA=4, bandpass='W149', pupil_bin=8, wavelength=985.) + print('psf1 = ',str(psf1)) + print('psf2 = ',str(psf2)) assert psf1 == psf2 @timer From 7f4fd66579a3eb6830213ca158013eedc8ca752a Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:44:08 -0600 Subject: [PATCH 269/351] Apply suggestions from code review --- tests/test_deprecated.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 9e38cc83cb..061d3d856d 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -784,11 +784,9 @@ def test_chromatic_flux(): use_exact_sed=False) # Check deprecated use_exact_SED kwarg - PSF2 = check_dep( - PSF.interpolate, - waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), - use_exact_SED=False, - ) + PSF2 = check_dep(PSF.interpolate, + waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), + use_exact_SED=False) assert PSF2 == PSF1 # Also do this manually with the InterpolatedChromaticObject class @@ -811,7 +809,7 @@ def test_W149(): config = { 'modules' : ['galsim.roman'], - 'psf' : { 'type' : 'RomanPSF', 'SCA': 4, 'bandpass': 'W149' }, + 'psf' : { 'type' : 'RomanPSF', 'SCA': 4, 'bandpass': 'W149' } } galsim.config.ImportModules(config) From 73b4e758777df643424b68019a160f392ec74ebb Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:48:21 -0600 Subject: [PATCH 270/351] Apply suggestions from code review --- tests/test_deprecated.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 061d3d856d..4c4a3ac85c 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -26,7 +26,7 @@ def check_dep(f, *args, **kwargs): """Check that some function raises a GalSimDeprecationWarning as a warning, but not an error. -""" + """ # Check that f() raises a warning, but not an error. with assert_warns(galsim.GalSimDeprecationWarning): res = f(*args, **kwargs) @@ -96,24 +96,12 @@ def test_noise(): var_1 = cf_1.getVariance() assert var_1==var_2,'Inconsistent noise variance from getNoise and getNoiseProperties' # Check the image: - ii = galsim.InterpolatedImage( - im_2, - normalization="sb", - calculate_stepk=False, - calculate_maxk=False, - x_interpolant="linear", - ) - cf_2 = check_dep( - galsim.correlatednoise._BaseCorrelatedNoise, - galsim.BaseDeviate(test_seed), - ii, - im_2.wcs, - ) + ii = galsim.InterpolatedImage(im_2, normalization='sb', calculate_stepk=False, + calculate_maxk=False, x_interpolant='linear') + cf_2 = check_dep(galsim.correlatednoise._BaseCorrelatedNoise, + galsim.BaseDeviate(test_seed), ii, im_2.wcs) cf_2 = cf_2.withVariance(var_2) - assert ( - cf_1 == cf_2 - ), "Inconsistent noise properties from getNoise and getNoiseProperties" - + assert cf_1==cf_2, 'Inconsistent noise properties from getNoise and getNoiseProperties' @timer def test_randwalk_defaults(): @@ -128,11 +116,9 @@ def test_randwalk_defaults(): rng = galsim.BaseDeviate(1234) rw=check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng) - assert rw.npoints == npoints, "expected npoints==%d, got %d" % (npoints, rw.npoints) - assert rw.input_half_light_radius == hlr, "expected hlr==%g, got %g" % ( - hlr, - rw.input_half_light_radius, - ) + assert rw.npoints==npoints,"expected npoints==%d, got %d" % (npoints, rw.npoints) + assert rw.input_half_light_radius==hlr,\ + "expected hlr==%g, got %g" % (hlr, rw.input_half_light_radius) nobj=len(rw.points) assert nobj == npoints,"expected %d objects, got %d" % (npoints, nobj) From 01d0ab6a4da88d27f8e4528e2e3818b03391db7c Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:49:13 -0600 Subject: [PATCH 271/351] Update tests/test_deprecated.py --- tests/test_deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 4c4a3ac85c..66a670adf2 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -97,7 +97,7 @@ def test_noise(): assert var_1==var_2,'Inconsistent noise variance from getNoise and getNoiseProperties' # Check the image: ii = galsim.InterpolatedImage(im_2, normalization='sb', calculate_stepk=False, - calculate_maxk=False, x_interpolant='linear') + calculate_maxk=False, x_interpolant='linear') cf_2 = check_dep(galsim.correlatednoise._BaseCorrelatedNoise, galsim.BaseDeviate(test_seed), ii, im_2.wcs) cf_2 = cf_2.withVariance(var_2) From e01492d864b3b6ee4e3e9a125734e7f050d6652c Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:54:39 -0600 Subject: [PATCH 272/351] Apply suggestions from code review --- tests/test_deprecated.py | 55 ++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 66a670adf2..b77d489f1d 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -101,7 +101,7 @@ def test_noise(): cf_2 = check_dep(galsim.correlatednoise._BaseCorrelatedNoise, galsim.BaseDeviate(test_seed), ii, im_2.wcs) cf_2 = cf_2.withVariance(var_2) - assert cf_1==cf_2, 'Inconsistent noise properties from getNoise and getNoiseProperties' + assert cf_1==cf_2,'Inconsistent noise properties from getNoise and getNoiseProperties' @timer def test_randwalk_defaults(): @@ -123,19 +123,14 @@ def test_randwalk_defaults(): nobj=len(rw.points) assert nobj == npoints,"expected %d objects, got %d" % (npoints, nobj) - pts = rw.points - assert pts.shape == (npoints, 2), "expected (%d,2) shape for points, got %s" % ( - npoints, - pts.shape, - ) + pts=rw.points + assert pts.shape == (npoints, 2),"expected (%d,2) shape for points, got %s" % (npoints, pts.shape) np.testing.assert_almost_equal(rw.centroid.x, np.mean(pts[:, 0])) np.testing.assert_almost_equal(rw.centroid.y, np.mean(pts[:, 1])) gsp = galsim.GSParams(xvalue_accuracy=1.e-8, kvalue_accuracy=1.e-8) rng2 = galsim.BaseDeviate(1234) - rw2 = check_dep( - galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng2, gsparams=gsp - ) + rw2 = check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, rng=rng2, gsparams=gsp) assert rw2 != rw assert rw2 == rw.withGSParams(gsp) @@ -176,9 +171,8 @@ def test_randwalk_repr(): npoints=100 hlr = 8.0 - flux = 1 - rw1 = check_dep( - galsim.RandomWalk, + flux=1 + rw1=check_dep(galsim.RandomWalk, npoints, half_light_radius=hlr, flux=flux, @@ -189,8 +183,8 @@ def test_randwalk_repr(): ) for rw in (rw1, rw2): - - + + # just make sure str() works, don't require eval to give # a consistent object back st=str(rw) @@ -225,14 +219,14 @@ def test_randwalk_config(): hlr=2.0 flux=np.pi gal_config1 = { - 'type': 'RandomWalk', - 'npoints': 100, - 'half_light_radius': hlr, - 'flux': flux, + 'type':'RandomWalk', + 'npoints':100, + 'half_light_radius':hlr, + 'flux':flux, } gal_config2 = { - 'type': 'RandomWalk', - 'npoints': 150, + 'type':'RandomWalk', + 'npoints':150, 'profile': { 'type': 'Exponential', 'half_light_radius': hlr, @@ -242,8 +236,8 @@ def test_randwalk_config(): for gal_config in (gal_config1, gal_config2): config={ - 'gal': gal_config, - 'rng': galsim.BaseDeviate(31415), + 'gal':gal_config, + 'rng':galsim.BaseDeviate(31415), } rwc = check_dep(galsim.config.BuildGSObject, config, 'gal')[0] @@ -303,15 +297,15 @@ def test_withOrigin(): color = 0.3 for wcs in wcs_list: # Original version of the shiftOrigin tests in do_nonlocal_wcs using deprecated name. - new_origin = galsim.PositionI(123, 321) + new_origin = galsim.PositionI(123,321) wcs3 = check_dep(wcs.withOrigin, new_origin) - assert wcs != wcs3, name + " is not != wcs.withOrigin(pos)" + assert wcs != wcs3, name+' is not != wcs.withOrigin(pos)' wcs4 = wcs.local(wcs.origin, color=color) - assert wcs != wcs4, name + " is not != wcs.local()" - assert wcs4 != wcs, name + " is not != wcs.local() (reverse)" + assert wcs != wcs4, name+' is not != wcs.local()' + assert wcs4 != wcs, name+' is not != wcs.local() (reverse)' world_origin = wcs.toWorld(wcs.origin, color=color) if wcs.isUniform(): - if wcs.world_origin == galsim.PositionD(0, 0): + if wcs.world_origin == galsim.PositionD(0,0): wcs2 = wcs.local(wcs.origin, color=color).withOrigin(wcs.origin) assert wcs == wcs2, ( name + " is not equal after wcs.local().withOrigin(origin)" @@ -354,8 +348,8 @@ def test_withOrigin(): ) # Now some CelestialWCS types - cubic_u = Cubic(2.9e-5, 2000.0, 'u') - cubic_v = Cubic(-3.7e-5, 2000.0, 'v') + cubic_u = Cubic(2.9e-5, 2000., 'u') + cubic_v = Cubic(-3.7e-5, 2000., 'v') center = galsim.CelestialCoord(23 * galsim.degrees, -13 * galsim.degrees) radec = lambda x, y: center.deproject_rad( cubic_u(x, y) * 0.2, cubic_v(x, y) * 0.2, projection="lambert" @@ -388,7 +382,8 @@ def test_withOrigin(): @timer def test_wfirst(): - """Test that the deprecated wfirst module works like the new roman module.""" + """Test that the deprecated wfirst module works like the new roman module. + """ import galsim.roman check_dep(__import__, "galsim.wfirst") From 5775587915b93ae5e095be73e3647fa5375ddd6a Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:58:25 -0600 Subject: [PATCH 273/351] Apply suggestions from code review --- tests/test_deprecated.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index b77d489f1d..7aa421b87e 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -548,7 +548,7 @@ def test_trapz_basic(): ) result = check_dep(galsim.integ.trapz, func, 0, 1, np.linspace(0, 1, 100000)) - expected_val = 1.0**3.0 / 3.0 + expected_val = 1.**3./3. np.testing.assert_almost_equal( result / expected_val, 1.0, @@ -564,12 +564,10 @@ def test_trapz_basic(): with assert_raises(TypeError): check_dep(galsim.integ.trapz, func, 0.1, 1, points=2.3) - @timer def test_hsm_depr(): hsmp = check_dep(galsim.hsm.HSMParams, max_moment_nsig2=25.0) - assert hsmp.max_moment_nsig2 == 0.0 - + assert hsmp.max_moment_nsig2 == 0. @timer def test_photon_array_depr(): @@ -591,7 +589,7 @@ def test_photon_array_depr(): assert len(photon_array.dxdz) == nphotons assert len(photon_array.dydz) == nphotons np.testing.assert_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_equal(photon_array.dydz, 0.0) + np.testing.assert_array_equal(photon_array.dydz, 0.) photon_array.dydz = 0.59 assert photon_array.hasAllocatedAngles() @@ -600,7 +598,7 @@ def test_photon_array_depr(): np.testing.assert_array_equal(photon_array.dxdz, 0.17) np.testing.assert_array_equal(photon_array.dydz, 0.59) - photon_array.wavelength = 500.0 + photon_array.wavelength = 500. assert photon_array.hasAllocatedWavelengths() assert len(photon_array.wavelength) == nphotons np.testing.assert_array_equal(photon_array.wavelength, 500) @@ -630,7 +628,7 @@ def test_photon_array_depr(): # non-nan means allocated for jax-galsim assert photon_array.hasAllocatedAngles() np.testing.assert_array_equal(photon_array.dxdz, 0.17) - np.testing.assert_array_equal(photon_array.dydz, 0.0) + np.testing.assert_array_equal(photon_array.dydz, 0.) # JAX-Galsim does not allow by reference setting - changed this # to make tests below run @@ -752,17 +750,16 @@ def test_photon_array_depr(): def test_chromatic_flux(): # This is based on a snippet of test_chromatic_flux in test_chromatic.py. - bulge_SED = galsim.SED("CWW_E_ext.sed", wave_type="ang", flux_type="flambda") + bulge_SED = galsim.SED('CWW_E_ext.sed', wave_type='ang', flux_type='flambda') star = galsim.Gaussian(fwhm=1e-8) * bulge_SED mono_PSF = galsim.Gaussian(half_light_radius=0.8) zenith_angle = 20 * galsim.degrees - bandpass = galsim.Bandpass("LSST_i.dat", "nm").thin() - PSF = galsim.ChromaticAtmosphere( - mono_PSF, base_wavelength=500, zenith_angle=zenith_angle - ) + bandpass = galsim.Bandpass('LSST_i.dat', 'nm').thin() + PSF = galsim.ChromaticAtmosphere(mono_PSF, base_wavelength=500, + zenith_angle=zenith_angle) PSF = PSF * 1.0 PSF1 = PSF.interpolate(waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), - use_exact_sed=False) + use_exact_sed=False) # Check deprecated use_exact_SED kwarg PSF2 = check_dep(PSF.interpolate, From a5c6415510f8c9d23d54b97c2a8c26e7ec531e38 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 15:59:40 -0600 Subject: [PATCH 274/351] Apply suggestions from code review --- tests/test_deprecated.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 7aa421b87e..bc4f55e2b4 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -124,9 +124,9 @@ def test_randwalk_defaults(): assert nobj == npoints,"expected %d objects, got %d" % (npoints, nobj) pts=rw.points - assert pts.shape == (npoints, 2),"expected (%d,2) shape for points, got %s" % (npoints, pts.shape) - np.testing.assert_almost_equal(rw.centroid.x, np.mean(pts[:, 0])) - np.testing.assert_almost_equal(rw.centroid.y, np.mean(pts[:, 1])) + assert pts.shape == (npoints,2),"expected (%d,2) shape for points, got %s" % (npoints, pts.shape) + np.testing.assert_almost_equal(rw.centroid.x, np.mean(pts[:,0])) + np.testing.assert_almost_equal(rw.centroid.y, np.mean(pts[:,1])) gsp = galsim.GSParams(xvalue_accuracy=1.e-8, kvalue_accuracy=1.e-8) rng2 = galsim.BaseDeviate(1234) @@ -193,10 +193,8 @@ def test_randwalk_repr(): new_rw = eval(repr(rw)) - assert new_rw.npoints == rw.npoints, "expected npoints=%d got %d" % ( - rw.npoints, - new_rw.npoints, - ) + assert new_rw.npoints==rw.npoints,\ + "expected npoints=%d got %d" % (rw.npoints,new_rw.npoints) mess = "expected input_half_light_radius=%.16g got %.16g" assert new_rw.input_half_light_radius == rw.input_half_light_radius, mess % ( From 185bb5af91a88d3c4464a54714f8bcf0f7fa3827 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:01:12 -0600 Subject: [PATCH 275/351] Apply suggestions from code review --- tests/test_deprecated.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index bc4f55e2b4..7d9e303eb8 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -193,19 +193,14 @@ def test_randwalk_repr(): new_rw = eval(repr(rw)) - assert new_rw.npoints==rw.npoints,\ + assert new_rw.npoints == rw.npoints,\ "expected npoints=%d got %d" % (rw.npoints,new_rw.npoints) - mess = "expected input_half_light_radius=%.16g got %.16g" - assert new_rw.input_half_light_radius == rw.input_half_light_radius, mess % ( - rw.input_half_light_radius, - new_rw.input_half_light_radius, - ) - assert new_rw.flux == rw.flux, "expected flux=%.16g got %.16g" % ( - rw.flux, - new_rw.flux, - ) - + mess="expected input_half_light_radius=%.16g got %.16g" + assert new_rw.input_half_light_radius == rw.input_half_light_radius,\ + mess % (rw.input_half_light_radius,new_rw.input_half_light_radius) + assert new_rw.flux == rw.flux,\ + "expected flux=%.16g got %.16g" % (rw.flux,new_rw.flux) @timer def test_randwalk_config(): From 4ae8a789afd3896e0e19438270e949043d0a4260 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:02:13 -0600 Subject: [PATCH 276/351] Apply suggestions from code review --- tests/test_deprecated.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 7d9e303eb8..10b8080055 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -254,9 +254,9 @@ def test_randwalk_config(): rw.input_half_light_radius, ) - nobj = len(rw.points) - nobjc = len(rwc.points) - assert nobj == nobjc, "expected %d objects, got %d" % (nobj, nobjc) + nobj=len(rw.points) + nobjc=len(rwc.points) + assert nobj == nobjc,"expected %d objects, got %d" % (nobj, nobjc) pts = rw.points ptsc = rwc.points From 544cc294d413f0f43334dd49ca36983e42719936 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:02:52 -0600 Subject: [PATCH 277/351] Update tests/test_deprecated.py --- tests/test_deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 10b8080055..8dc5b0a663 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -256,7 +256,7 @@ def test_randwalk_config(): nobj=len(rw.points) nobjc=len(rwc.points) - assert nobj == nobjc,"expected %d objects, got %d" % (nobj, nobjc) + assert nobj==nobjc,"expected %d objects, got %d" % (nobj, nobjc) pts = rw.points ptsc = rwc.points From 1f1699eaa18b2189a9f6f9f82719696307321c5f Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:03:22 -0600 Subject: [PATCH 278/351] Update tests/test_deprecated.py --- tests/test_deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 8dc5b0a663..781d8fab63 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -256,7 +256,7 @@ def test_randwalk_config(): nobj=len(rw.points) nobjc=len(rwc.points) - assert nobj==nobjc,"expected %d objects, got %d" % (nobj, nobjc) + assert nobj==nobjc,"expected %d objects, got %d" % (nobj,nobjc) pts = rw.points ptsc = rwc.points From 496ce4da0a3da36f7c08a6e157fd06ff8735b9d9 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:05:11 -0600 Subject: [PATCH 279/351] Apply suggestions from code review --- tests/test_deprecated.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 781d8fab63..ff22ab801c 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -242,10 +242,8 @@ def test_randwalk_config(): flux=flux, ) - assert rw.npoints == rwc.npoints, "expected npoints==%d, got %d" % ( - rw.npoints, - rwc.npoints, - ) + assert rw.npoints==rwc.npoints,\ + "expected npoints==%d, got %d" % (rw.npoints,rwc.npoints) assert ( rw.input_half_light_radius == rwc.input_half_light_radius @@ -258,13 +256,10 @@ def test_randwalk_config(): nobjc=len(rwc.points) assert nobj==nobjc,"expected %d objects, got %d" % (nobj,nobjc) - pts = rw.points - ptsc = rwc.points - assert pts.shape == ptsc.shape, "expected %s shape for points, got %s" % ( - pts.shape, - ptsc.shape, - ) - + pts=rw.points + ptsc=rwc.points + assert (pts.shape == ptsc.shape),\ + "expected %s shape for points, got %s" % (pts.shape,ptsc.shape) def test_withOrigin(): from test_wcs import Cubic From af11c616822d681f8e79f3b0670301bb43d5733b Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:11:18 -0600 Subject: [PATCH 280/351] Apply suggestions from code review --- tests/test_deprecated.py | 49 ++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index ff22ab801c..943adcc52d 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -243,7 +243,7 @@ def test_randwalk_config(): ) assert rw.npoints==rwc.npoints,\ - "expected npoints==%d, got %d" % (rw.npoints,rwc.npoints) + "expected npoints==%d, got %d" % (rw.npoints, rwc.npoints) assert ( rw.input_half_light_radius == rwc.input_half_light_radius @@ -353,11 +353,11 @@ def test_withOrigin(): # Original version of the shiftOrigin tests in do_celestial_wcs using deprecated name. new_origin = galsim.PositionI(123,321) wcs3 = wcs.shiftOrigin(new_origin) - assert wcs != wcs3, name + " is not != wcs.shiftOrigin(pos)" + assert wcs != wcs3, name+' is not != wcs.shiftOrigin(pos)' wcs4 = wcs.local(wcs.origin) - assert wcs != wcs4, name + " is not != wcs.local()" - assert wcs4 != wcs, name + " is not != wcs.local() (reverse)" - world_pos1 = wcs.toWorld(galsim.PositionD(0, 0)) + assert wcs != wcs4, name+' is not != wcs.local()' + assert wcs4 != wcs, name+' is not != wcs.local() (reverse)' + world_pos1 = wcs.toWorld(galsim.PositionD(0,0)) wcs3 = wcs.shiftOrigin(new_origin) world_pos2 = wcs3.toWorld(new_origin) np.testing.assert_almost_equal( @@ -373,8 +373,7 @@ def test_wfirst(): """Test that the deprecated wfirst module works like the new roman module. """ import galsim.roman - - check_dep(__import__, "galsim.wfirst") + check_dep(__import__, 'galsim.wfirst') assert galsim.wfirst.gain == galsim.roman.gain assert galsim.wfirst.pixel_scale == galsim.roman.pixel_scale @@ -394,13 +393,10 @@ def test_wfirst(): assert galsim.wfirst.pupil_plane_scale == galsim.roman.pupil_plane_scale assert galsim.wfirst.stray_light_fraction == galsim.roman.stray_light_fraction np.testing.assert_array_equal(galsim.wfirst.ipc_kernel, galsim.roman.ipc_kernel) - np.testing.assert_array_equal( - galsim.wfirst.persistence_coefficients, galsim.roman.persistence_coefficients - ) - np.testing.assert_array_equal( - galsim.wfirst.persistence_fermi_parameters, - galsim.roman.persistence_fermi_parameters, - ) + np.testing.assert_array_equal(galsim.wfirst.persistence_coefficients, + galsim.roman.persistence_coefficients) + np.testing.assert_array_equal(galsim.wfirst.persistence_fermi_parameters, + galsim.roman.persistence_fermi_parameters) assert galsim.wfirst.n_sca == galsim.roman.n_sca assert galsim.wfirst.n_pix_tot == galsim.roman.n_pix_tot assert galsim.wfirst.n_pix == galsim.roman.n_pix @@ -422,10 +418,10 @@ def test_wfirst(): assert galsim.wfirst.allDetectorEffects is galsim.roman.allDetectorEffects assert galsim.wfirst.NLfunc is galsim.roman.NLfunc - @timer def test_roman_psfs(): - """Test the deprecated high_accuracy and approximate_struts options.""" + """Test the deprecated high_accuracy and approximate_struts options. + """ import galsim.roman test_kwargs = [ @@ -446,8 +442,8 @@ def test_roman_psfs(): use_sca = 5 for kwargs1, kwargs2 in test_kwargs: - psf1 = check_dep(galsim.roman.getPSF, use_sca, "Y106", **kwargs1) - psf2 = galsim.roman.getPSF(use_sca, "Y106", **kwargs2) + psf1 = check_dep(galsim.roman.getPSF, use_sca, 'Y106', **kwargs1) + psf2 = galsim.roman.getPSF(use_sca, 'Y106', **kwargs2) assert psf1 == psf2 # Cheat to get coverage of False,True option without spending a long time doing the @@ -465,6 +461,7 @@ def test_roman_psfs(): @timer def test_surface_ops(): + # Based on test_sensor.py:test_wavelengths_and_angles, but massively simplified. rng = galsim.BaseDeviate(1234) @@ -473,20 +470,14 @@ def test_surface_ops(): obscuration = 0.2 assigner = check_dep(galsim.FRatioAngles, fratio, obscuration, rng=rng) - sed = galsim.SED("CWW_E_ext.sed", "nm", "flambda").thin() - bandpass = galsim.Bandpass("LSST_i.dat", "nm").thin() + sed = galsim.SED('CWW_E_ext.sed', 'nm', 'flambda').thin() + bandpass = galsim.Bandpass('LSST_i.dat', 'nm').thin() sampler = check_dep(galsim.WavelengthSampler, sed, bandpass, rng=rng) obj = galsim.Gaussian(flux=353, sigma=0.3) - im = galsim.Image(63, 63, scale=1) - check_dep( - obj.drawImage, - im, - method="phot", - surface_ops=[sampler, assigner], - rng=rng, - save_photons=True, - ) + im = galsim.Image(63,63, scale=1) + check_dep(obj.drawImage, im, method="phot", surface_ops=[sampler, assigner], rng=rng, + save_photons=True) rng.reset(1234) assigner.rng.reset(rng) From bcfc251535fd526f6020a6bc65fee4afa6b9bc4d Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:13:19 -0600 Subject: [PATCH 281/351] Apply suggestions from code review --- tests/test_deprecated.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 943adcc52d..a25d68565c 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -496,28 +496,26 @@ def test_surface_ops(): @timer def test_midpoint_basic(): - """Test the basic functionality of the midpt() method.""" + """Test the basic functionality of the midpt() method. + """ # This shouldn't be super accurate, but just make sure it's not really broken. - x = 0.01 * np.arange(1000) + x = 0.01*np.arange(1000) f = x**2 result = check_dep(galsim.integ.midpt, f, x) - expected_val = 10**3.0 / 3.0 + expected_val = 10**3./3. np.testing.assert_almost_equal( - result / expected_val, - 1.0, - decimal=2, - verbose=True, - err_msg="Simple test of midpt() method failed for f(x)=x^2 from 0 to 10", - ) + result/expected_val, 1.0, decimal=2, verbose=True, + err_msg='Simple test of midpt() method failed for f(x)=x^2 from 0 to 10') @timer def test_trapz_basic(): - """Test the basic functionality of the trapz() method.""" + """Test the basic functionality of the trapz() method. + """ # This shouldn't be super accurate, but just make sure it's not really broken. func = lambda x: x**2 result = check_dep(galsim.integ.trapz, func, 0, 1) - expected_val = 1.0**3.0 / 3.0 + expected_val = 1.**3./3. np.testing.assert_almost_equal( result / expected_val, 1.0, From 3b5c1cae264f3929fd1027be5e74c85100a94273 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:18:20 -0600 Subject: [PATCH 282/351] Apply suggestions from code review --- tests/test_deprecated.py | 46 ++++++++++++---------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index a25d68565c..8743ac9874 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -361,12 +361,8 @@ def test_withOrigin(): wcs3 = wcs.shiftOrigin(new_origin) world_pos2 = wcs3.toWorld(new_origin) np.testing.assert_almost_equal( - world_pos2.distanceTo(world_pos1) / galsim.arcsec, - 0, - 7, - "shiftOrigin(new_origin) returned wrong world position", - ) - + world_pos2.distanceTo(world_pos1) / galsim.arcsec, 0, 7, + 'shiftOrigin(new_origin) returned wrong world position') @timer def test_wfirst(): @@ -393,7 +389,7 @@ def test_wfirst(): assert galsim.wfirst.pupil_plane_scale == galsim.roman.pupil_plane_scale assert galsim.wfirst.stray_light_fraction == galsim.roman.stray_light_fraction np.testing.assert_array_equal(galsim.wfirst.ipc_kernel, galsim.roman.ipc_kernel) - np.testing.assert_array_equal(galsim.wfirst.persistence_coefficients, + np.testing.assert_array_equal(galsim.wfirst.persistence_coefficients, galsim.roman.persistence_coefficients) np.testing.assert_array_equal(galsim.wfirst.persistence_fermi_parameters, galsim.roman.persistence_fermi_parameters) @@ -449,15 +445,9 @@ def test_roman_psfs(): # Cheat to get coverage of False,True option without spending a long time doing the # pupil plane FFT for that one. with assert_raises(TypeError): - check_dep( - galsim.roman.getPSF, - SCA=use_sca, - bandpass="Z087", - approximate_struts=False, - high_accuracy=True, - wavelength="Z087", - ) - + check_dep(galsim.roman.getPSF, SCA=use_sca, bandpass='Z087', + approximate_struts=False, high_accuracy=True, + wavelength='Z087') @timer def test_surface_ops(): @@ -476,7 +466,7 @@ def test_surface_ops(): obj = galsim.Gaussian(flux=353, sigma=0.3) im = galsim.Image(63,63, scale=1) - check_dep(obj.drawImage, im, method="phot", surface_ops=[sampler, assigner], rng=rng, + check_dep(obj.drawImage, im, method='phot', surface_ops=[sampler, assigner], rng=rng, save_photons=True) rng.reset(1234) @@ -488,9 +478,7 @@ def test_surface_ops(): rng.reset(1234) assigner.rng.reset(rng) sampler.rng.reset(rng) - _, photons2 = check_dep( - obj.drawPhot, image=im.copy(), surface_ops=[sampler, assigner], rng=rng - ) + _, photons2 = check_dep(obj.drawPhot, image=im.copy(), surface_ops=[sampler, assigner], rng=rng) assert photons2 == im.photons @@ -517,22 +505,14 @@ def test_trapz_basic(): result = check_dep(galsim.integ.trapz, func, 0, 1) expected_val = 1.**3./3. np.testing.assert_almost_equal( - result / expected_val, - 1.0, - decimal=6, - verbose=True, - err_msg="Simple test of trapz() method failed for f(x)=x^2 from 0 to 1", - ) + result/expected_val, 1.0, decimal=6, verbose=True, + err_msg='Simple test of trapz() method failed for f(x)=x^2 from 0 to 1') result = check_dep(galsim.integ.trapz, func, 0, 1, np.linspace(0, 1, 100000)) expected_val = 1.**3./3. np.testing.assert_almost_equal( - result / expected_val, - 1.0, - decimal=6, - verbose=True, - err_msg="Test of trapz() with points failed for f(x)=x^2 from 0 to 1", - ) + result / expected_val, 1.0, decimal=6, verbose=True, + err_msg='Test of trapz() with points failed for f(x)=x^2 from 0 to 1') with assert_raises(ValueError): check_dep(galsim.integ.trapz, func, 0, 1, points=np.linspace(0, 1.1, 100)) @@ -732,7 +712,7 @@ def test_chromatic_flux(): mono_PSF = galsim.Gaussian(half_light_radius=0.8) zenith_angle = 20 * galsim.degrees bandpass = galsim.Bandpass('LSST_i.dat', 'nm').thin() - PSF = galsim.ChromaticAtmosphere(mono_PSF, base_wavelength=500, + PSF = galsim.ChromaticAtmosphere(mono_PSF, base_wavelength=500, zenith_angle=zenith_angle) PSF = PSF * 1.0 PSF1 = PSF.interpolate(waves=np.linspace(bandpass.blue_limit, bandpass.red_limit, 30), From 70a875f2b554cfe76f08999895c2099b8f1f8df9 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 16:19:10 -0600 Subject: [PATCH 283/351] Apply suggestions from code review --- tests/test_deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 8743ac9874..8a7a999376 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -511,7 +511,7 @@ def test_trapz_basic(): result = check_dep(galsim.integ.trapz, func, 0, 1, np.linspace(0, 1, 100000)) expected_val = 1.**3./3. np.testing.assert_almost_equal( - result / expected_val, 1.0, decimal=6, verbose=True, + result/expected_val, 1.0, decimal=6, verbose=True, err_msg='Test of trapz() with points failed for f(x)=x^2 from 0 to 1') with assert_raises(ValueError): From 48edcbbe98e7c220f8d40b40fd8e5494c8274c0e Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:03:19 -0600 Subject: [PATCH 284/351] Apply suggestions from code review --- tests/test_deprecated.py | 73 ++++++++++++---------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 8a7a999376..d92bab4fc4 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -245,12 +245,8 @@ def test_randwalk_config(): assert rw.npoints==rwc.npoints,\ "expected npoints==%d, got %d" % (rw.npoints, rwc.npoints) - assert ( - rw.input_half_light_radius == rwc.input_half_light_radius - ), "expected hlr==%g, got %g" % ( - rw.input_half_light_radius, - rw.input_half_light_radius, - ) + assert rw.input_half_light_radius==rwc.input_half_light_radius,\ + "expected hlr==%g, got %g" % (rw.input_half_light_radius, rw.input_half_light_radius) nobj=len(rw.points) nobjc=len(rwc.points) @@ -266,21 +262,14 @@ def test_withOrigin(): # First EuclideantWCS types: - wcs_list = [ - galsim.OffsetWCS(0.3, galsim.PositionD(1, 1), galsim.PositionD(10, 23)), - galsim.OffsetShearWCS( - 0.23, galsim.Shear(g1=0.1, g2=0.3), galsim.PositionD(12, 43) - ), - galsim.AffineTransform(0.01, 0.26, -0.26, 0.02, galsim.PositionD(12, 43)), - galsim.UVFunction(ufunc=lambda x, y: 0.2 * x, vfunc=lambda x, y: 0.2 * y), - galsim.UVFunction( - ufunc=lambda x, y: 0.2 * x, - vfunc=lambda x, y: 0.2 * y, - xfunc=lambda u, v: u / scale, - yfunc=lambda u, v: v / scale, - ), - galsim.UVFunction(ufunc="0.2*x + 0.03*y", vfunc="0.01*x + 0.2*y"), - ] + wcs_list = [ galsim.OffsetWCS(0.3, galsim.PositionD(1,1), galsim.PositionD(10,23)), + galsim.OffsetShearWCS(0.23, galsim.Shear(g1=0.1,g2=0.3), galsim.PositionD(12,43)), + galsim.AffineTransform(0.01,0.26,-0.26,0.02, galsim.PositionD(12,43)), + galsim.UVFunction(ufunc = lambda x,y: 0.2*x, vfunc = lambda x,y: 0.2*y), + galsim.UVFunction(ufunc = lambda x,y: 0.2*x, vfunc = lambda x,y: 0.2*y, + xfunc = lambda u,v: u / scale, yfunc = lambda u,v: v / scale), + galsim.UVFunction(ufunc='0.2*x + 0.03*y', vfunc='0.01*x + 0.2*y'), + ] color = 0.3 for wcs in wcs_list: @@ -295,45 +284,27 @@ def test_withOrigin(): if wcs.isUniform(): if wcs.world_origin == galsim.PositionD(0,0): wcs2 = wcs.local(wcs.origin, color=color).withOrigin(wcs.origin) - assert wcs == wcs2, ( - name + " is not equal after wcs.local().withOrigin(origin)" - ) - wcs2 = wcs.local(wcs.origin, color=color).withOrigin( - wcs.origin, wcs.world_origin - ) - assert wcs == wcs2, ( - name + " not equal after wcs.local().withOrigin(origin,world_origin)" - ) - world_pos1 = wcs.toWorld(galsim.PositionD(0, 0), color=color) + assert wcs == wcs2, name+' is not equal after wcs.local().withOrigin(origin)' + wcs2 = wcs.local(wcs.origin, color=color).withOrigin(wcs.origin, wcs.world_origin) + assert wcs == wcs2, name+' not equal after wcs.local().withOrigin(origin,world_origin)' + world_pos1 = wcs.toWorld(galsim.PositionD(0,0), color=color) wcs3 = check_dep(wcs.withOrigin, new_origin) world_pos2 = wcs3.toWorld(new_origin, color=color) np.testing.assert_almost_equal( - world_pos2.x, - world_pos1.x, - 7, - "withOrigin(new_origin) returned wrong world position", - ) + world_pos2.x, world_pos1.x, 7, + 'withOrigin(new_origin) returned wrong world position') np.testing.assert_almost_equal( - world_pos2.y, - world_pos1.y, - 7, - "withOrigin(new_origin) returned wrong world position", - ) + world_pos2.y, world_pos1.y, 7, + 'withOrigin(new_origin) returned wrong world position') new_world_origin = galsim.PositionD(5352.7, 9234.3) wcs5 = check_dep(wcs.withOrigin, new_origin, new_world_origin, color=color) world_pos3 = wcs5.toWorld(new_origin, color=color) np.testing.assert_almost_equal( - world_pos3.x, - new_world_origin.x, - 7, - "withOrigin(new_origin, new_world_origin) returned wrong position", - ) + world_pos3.x, new_world_origin.x, 7, + 'withOrigin(new_origin, new_world_origin) returned wrong position') np.testing.assert_almost_equal( - world_pos3.y, - new_world_origin.y, - 7, - "withOrigin(new_origin, new_world_origin) returned wrong position", - ) + world_pos3.y, new_world_origin.y, 7, + 'withOrigin(new_origin, new_world_origin) returned wrong position') # Now some CelestialWCS types cubic_u = Cubic(2.9e-5, 2000., 'u') From dff8cbae608191c6dc8e2ce0362490d6800b833a Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:04:57 -0600 Subject: [PATCH 285/351] Apply suggestions from code review --- tests/test_deprecated.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index d92bab4fc4..d1e2fb017a 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -310,15 +310,13 @@ def test_withOrigin(): cubic_u = Cubic(2.9e-5, 2000., 'u') cubic_v = Cubic(-3.7e-5, 2000., 'v') center = galsim.CelestialCoord(23 * galsim.degrees, -13 * galsim.degrees) - radec = lambda x, y: center.deproject_rad( - cubic_u(x, y) * 0.2, cubic_v(x, y) * 0.2, projection="lambert" - ) - wcs_list = [ - galsim.RaDecFunction(radec), - galsim.AstropyWCS("1904-66_TAN.fits", dir="fits_files"), - galsim.GSFitsWCS("tpv.fits", dir="fits_files"), - galsim.FitsWCS("sipsample.fits", dir="fits_files"), - ] + radec = lambda x,y: center.deproject_rad(cubic_u(x,y)*0.2, cubic_v(x,y)*0.2, + projection='lambert') + wcs_list = [ galsim.RaDecFunction(radec), + galsim.AstropyWCS('1904-66_TAN.fits', dir='fits_files'), + galsim.GSFitsWCS('tpv.fits', dir='fits_files'), + galsim.FitsWCS('sipsample.fits', dir='fits_files'), + ] for wcs in wcs_list: # Original version of the shiftOrigin tests in do_celestial_wcs using deprecated name. @@ -392,19 +390,17 @@ def test_roman_psfs(): import galsim.roman test_kwargs = [ - ({"approximate_struts": True, "high_accuracy": False}, {"pupil_bin": 8}), - ( - {"approximate_struts": True, "high_accuracy": True}, - {"pupil_bin": 4, "gsparams": galsim.GSParams(folding_threshold=2.0e-3)}, - ), - ({"approximate_struts": False, "high_accuracy": False}, {"pupil_bin": 4}), + ({ 'approximate_struts':True, 'high_accuracy':False }, + { 'pupil_bin':8 }), + ({ 'approximate_struts':True, 'high_accuracy':True }, + { 'pupil_bin':4, 'gsparams':galsim.GSParams(folding_threshold=2.e-3) }), + ({ 'approximate_struts':False, 'high_accuracy':False }, + { 'pupil_bin':4 }), ] if __name__ == "__main__": test_kwargs.append( - ( - {"approximate_struts": False, "high_accuracy": True}, - {"pupil_bin": 1, "gsparams": galsim.GSParams(folding_threshold=2.0e-3)}, - ), + ({ 'approximate_struts':False, 'high_accuracy':True }, + { 'pupil_bin':1, 'gsparams':galsim.GSParams(folding_threshold=2.e-3) }), ) use_sca = 5 From 36064f5b0f976156b0a99772f3b6c6e5e091b2e8 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:06:35 -0600 Subject: [PATCH 286/351] Apply suggestions from code review --- tests/test_deprecated.py | 61 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index d1e2fb017a..38374d60e3 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -49,37 +49,36 @@ def test_phase_psf(): @timer def test_interpolant(): - d = check_dep(galsim.Delta, tol=1.0e-2) - assert d.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, d, "tol") == d.gsparams.kvalue_accuracy - n = check_dep(galsim.Nearest, tol=1.0e-2) - assert n.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, n, "tol") == n.gsparams.kvalue_accuracy - s = check_dep(galsim.SincInterpolant, tol=1.0e-2) - assert s.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, s, "tol") == s.gsparams.kvalue_accuracy - l = check_dep(galsim.Linear, tol=1.0e-2) - assert l.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, l, "tol") == l.gsparams.kvalue_accuracy - c = check_dep(galsim.Cubic, tol=1.0e-2) - assert c.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, c, "tol") == c.gsparams.kvalue_accuracy - q = check_dep(galsim.Quintic, tol=1.0e-2) - assert q.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, q, "tol") == q.gsparams.kvalue_accuracy - l3 = check_dep(galsim.Lanczos, 3, tol=1.0e-2) - assert l3.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, l3, "tol") == l3.gsparams.kvalue_accuracy - ldc = check_dep(galsim.Lanczos, 3, False, tol=1.0e-2) - assert ldc.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, ldc, "tol") == ldc.gsparams.kvalue_accuracy - l8 = check_dep(galsim.Lanczos, 8, tol=1.0e-2) - assert l8.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, l8, "tol") == l8.gsparams.kvalue_accuracy - l11 = check_dep(galsim.Interpolant.from_name, "lanczos11", tol=1.0e-2) - assert l11.gsparams.kvalue_accuracy == 1.0e-2 - assert check_dep(getattr, l11, "tol") == l11.gsparams.kvalue_accuracy - + d = check_dep(galsim.Delta, tol=1.e-2) + assert d.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, d, 'tol') == d.gsparams.kvalue_accuracy + n = check_dep(galsim.Nearest, tol=1.e-2) + assert n.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, n, 'tol') == n.gsparams.kvalue_accuracy + s = check_dep(galsim.SincInterpolant, tol=1.e-2) + assert s.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, s, 'tol') == s.gsparams.kvalue_accuracy + l = check_dep(galsim.Linear, tol=1.e-2) + assert l.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, l, 'tol') == l.gsparams.kvalue_accuracy + c = check_dep(galsim.Cubic, tol=1.e-2) + assert c.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, c, 'tol') == c.gsparams.kvalue_accuracy + q = check_dep(galsim.Quintic, tol=1.e-2) + assert q.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, q, 'tol') == q.gsparams.kvalue_accuracy + l3 = check_dep(galsim.Lanczos, 3, tol=1.e-2) + assert l3.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, l3, 'tol') == l3.gsparams.kvalue_accuracy + ldc = check_dep(galsim.Lanczos, 3, False, tol=1.e-2) + assert ldc.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, ldc, 'tol') == ldc.gsparams.kvalue_accuracy + l8 = check_dep(galsim.Lanczos, 8, tol=1.e-2) + assert l8.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, l8, 'tol') == l8.gsparams.kvalue_accuracy + l11 = check_dep(galsim.Interpolant.from_name, 'lanczos11', tol=1.e-2) + assert l11.gsparams.kvalue_accuracy == 1.e-2 + assert check_dep(getattr, l11, 'tol') == l11.gsparams.kvalue_accuracy @timer def test_noise(): From e4c6a49b5dc719dbe61b185209a9135a39aa630c Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:42:07 -0600 Subject: [PATCH 287/351] Apply suggestions from code review --- tests/test_deprecated.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 38374d60e3..51020e593f 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -540,10 +540,14 @@ def test_photon_array_depr(): # Using the getter is allowed, but deprecated. photon_array = galsim.PhotonArray(nphotons) - # 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() + if hasattr(galsim, "_galsim"): + dxdz = check_dep(getattr, photon_array, 'dxdz') + assert photon_array.hasAllocatedAngles() + else: + # 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 @@ -553,15 +557,20 @@ def test_photon_array_depr(): np.testing.assert_array_equal(photon_array.dxdz, 0.17) np.testing.assert_array_equal(photon_array.dydz, 0.) + 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 np.testing.assert_array_equal(photon_array.dydz, 0.59) - # 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() + if hasattr(galsim, "_galsim"): + wave = check_dep(getattr, photon_array, 'wavelength') + assert photon_array.hasAllocatedWavelengths() + else: + # 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() assert len(photon_array.wavelength) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run From f9a318d66dec77845c2dbb265f1e2d53f25000dc Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:43:31 -0600 Subject: [PATCH 288/351] Apply suggestions from code review --- tests/test_deprecated.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 51020e593f..07d7c25187 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -577,10 +577,15 @@ def test_photon_array_depr(): photon_array.wavelength = 500.0 np.testing.assert_array_equal(photon_array.wavelength, 500) - # 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() + if hasattr(galsim, "_galsim"): + u = check_dep(getattr, photon_array, 'pupil_u') + assert photon_array.hasAllocatedPupil() + assert len(photon_array.pupil_u) == nphotons + else: + # 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() assert len(photon_array.pupil_v) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run From 81d788f5e13c5f21ce38ef0cceb2a2d47d108c1d Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:45:13 -0600 Subject: [PATCH 289/351] Apply suggestions from code review --- tests/test_deprecated.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 07d7c25187..7498f78046 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -594,16 +594,21 @@ def test_photon_array_depr(): assert photon_array.hasAllocatedPupil() np.testing.assert_array_equal(photon_array.pupil_u, 6.0) np.testing.assert_array_equal(photon_array.pupil_v, 0.0) + 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 np.testing.assert_array_equal(photon_array.pupil_v, 10.0) - # 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() - assert len(photon_array.time) == nphotons + if hasattr(galsim, "_galsim"): + t = check_dep(getattr, photon_array, 'time') + assert photon_array.hasAllocatedTimes() + else: + # 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() + assert len(photon_array.time) == nphotons # jax-galsim needs to set 0 photon_array.time = 0.0 # jax-galsim is allocated now From e2a9c7e2b285415c090c28f346877543fea6d43f Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:47:29 -0600 Subject: [PATCH 290/351] Apply suggestions from code review --- tests/test_deprecated.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 7498f78046..9527d6291e 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -608,11 +608,11 @@ def test_photon_array_depr(): # t = check_dep(getattr, photon_array, "time") # however jax-galsim sets them to NaN so they are not allocated assert not photon_array.hasAllocatedTimes() - assert len(photon_array.time) == nphotons # jax-galsim needs to set 0 photon_array.time = 0.0 # jax-galsim is allocated now assert photon_array.hasAllocatedTimes() + assert len(photon_array.time) == nphotons np.testing.assert_array_equal(photon_array.time, 0.0) # JAX-Galsim does not allow by reference setting - changed this # to make tests below run @@ -621,10 +621,14 @@ def test_photon_array_depr(): # For coverage, also need to test the two pair ones in other order. photon_array = galsim.PhotonArray(nphotons) - # 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() + if hasattr(galsim, "_galsim"): + dydz = check_dep(getattr, photon_array, 'dydz') + assert photon_array.hasAllocatedAngles() + else: + # 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() assert len(photon_array.dxdz) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run @@ -632,6 +636,7 @@ def test_photon_array_depr(): np.testing.assert_array_equal(photon_array.dxdz, 0.0) np.testing.assert_array_equal(photon_array.dydz, 0.59) + 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 From 5c716c8accd5172a52b50ce3ef170902a9078196 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Mon, 27 Nov 2023 17:49:40 -0600 Subject: [PATCH 291/351] Apply suggestions from code review --- tests/test_deprecated.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 9527d6291e..006332c175 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -642,16 +642,22 @@ def test_photon_array_depr(): photon_array.dxdz = 0.17 np.testing.assert_array_equal(photon_array.dxdz, 0.17) - # 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() + if hasattr(galsim, "_galsim"): + v = check_dep(getattr, photon_array, 'pupil_v') + assert photon_array.hasAllocatedPupil() + assert len(photon_array.pupil_u) == nphotons + else: + # 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() assert len(photon_array.pupil_v) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run photon_array.pupil_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) + 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 From 88103b53dcdc60606775e7199da9ec9b1849f49a Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 27 Nov 2023 17:54:35 -0600 Subject: [PATCH 292/351] these are not supported at all in jax-galsim --- tests/test_deprecated.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 006332c175..fe95d0462f 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -35,9 +35,10 @@ def check_dep(f, *args, **kwargs): @timer def test_gsparams(): - 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 hasattr(galsim, "_galsim"): + 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 @@ -602,7 +603,7 @@ def test_photon_array_depr(): if hasattr(galsim, "_galsim"): t = check_dep(getattr, photon_array, 'time') - assert photon_array.hasAllocatedTimes() + assert photon_array.hasAllocatedTimes() else: # jax-galsim always sets these additional properties # t = check_dep(getattr, photon_array, "time") @@ -645,7 +646,7 @@ def test_photon_array_depr(): if hasattr(galsim, "_galsim"): v = check_dep(getattr, photon_array, 'pupil_v') assert photon_array.hasAllocatedPupil() - assert len(photon_array.pupil_u) == nphotons + assert len(photon_array.pupil_u) == nphotons else: # jax-galsim always sets these additional properties # v = check_dep(getattr, photon_array, "pupil_v") From bb64924d969ec52a5ff5914a98845cc5aff1bd09 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:28:14 -0500 Subject: [PATCH 293/351] WIP update test for jax-galsim memory use --- tests/test_draw.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 6a6926c174..df8710f218 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -524,6 +524,15 @@ def test_drawKImage(): """Test the various optional parameters to the drawKImage function. In particular test the parameters image, and scale in various combinations. """ + if hasattr(galsim, "_galsim"): + maxk_threshold = 1.e-4 + N = 1174 + Ns = 37 + else: + maxk_threshold = 1.e-3 + N = 880 + Ns = 28 + # We use a Moffat profile with beta = 1.5, since its real-space profile is # flux / (2 pi rD^2) * (1 + (r/rD)^2)^3/2 # and the 2-d Fourier transform of that is @@ -531,7 +540,7 @@ def test_drawKImage(): # So this should draw in Fourier space the same image as the Exponential drawn in # test_drawImage(). obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) - obj = obj.withGSParams(maxk_threshold=1.e-4) + obj = obj.withGSParams(maxk_threshold=maxk_threshold) # First test drawKImage() with no kwargs. It should: # - create new images @@ -608,7 +617,7 @@ def test_drawKImage(): np.testing.assert_almost_equal(CalculateScale(im7), 2, 1, "Measured wrong scale after obj.drawKImage(dx)") # This image is smaller because not using nyquist scale for stepk - np.testing.assert_equal(im7.bounds, galsim.BoundsI(-37,37,-37,37), + np.testing.assert_equal(im7.bounds, galsim.BoundsI(-Ns,Ns,-Ns,Ns), "obj.drawKImage(dx) produced image with wrong bounds") # Test if we provide an image with a defined scale. It should: From 783f7578a8775b228d44ebb44970476bc4aab74b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:30:26 -0500 Subject: [PATCH 294/351] TST remove extra B --- tests/test_draw.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index df8710f218..f461a7d044 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -547,7 +547,6 @@ def test_drawKImage(): # - return the new images # - set the scale to 2pi/(N*obj.nyquist_scale) im1 = obj.drawKImage() - N = 1174 np.testing.assert_equal(im1.bounds, galsim.BoundsI(-N/2,N/2,-N/2,N/2), "obj.drawKImage() produced image with wrong bounds") stepk = obj.stepk From ab72b998de46cab571d862bf9e4b6c5307b91179 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:44:31 -0500 Subject: [PATCH 295/351] TST less memory --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index f461a7d044..cf3f13bafd 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -568,7 +568,7 @@ def test_drawKImage(): # - also return that image # - set the scale to obj.stepk # - zero out any existing data - im3 = galsim.ImageCD(1149,1149) + im3 = galsim.ImageCD(N-25,N-25) im4 = obj.drawKImage(im3) np.testing.assert_almost_equal(im3.scale, stepk, 9, "obj.drawKImage(im3) produced image with wrong scale") From 80db992f4e8af99b2956adb2c36c6e303193b9f2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:52:11 -0500 Subject: [PATCH 296/351] TST less memory --- tests/test_draw.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index cf3f13bafd..5c9586ab24 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1303,11 +1303,16 @@ def test_fft(): np.testing.assert_array_almost_equal(xim.array, xim2.array) # Now use drawKImage (as above in test_drawKImage) to get a more realistic k-space image + if hasattr(galsim, "_galsim"): + maxk_threshold = 1.e-4 + N = 1174 # NB. It is useful to have this come out not a multiple of 4, since some of the + # calculation needs to be different when N/2 is odd. + else: + maxk_threshold = 1.e-3 + N = 880 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) obj = obj.withGSParams(maxk_threshold=1.e-4) im1 = obj.drawKImage() - N = 1174 # NB. It is useful to have this come out not a multiple of 4, since some of the - # calculation needs to be different when N/2 is odd. np.testing.assert_equal(im1.bounds, galsim.BoundsI(-N/2,N/2,-N/2,N/2), "obj.drawKImage() produced image with wrong bounds") nyq_scale = obj.nyquist_scale From b1c10d493c3f014608c2b2de48cffcdb4a8bc315 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:53:30 -0500 Subject: [PATCH 297/351] TST less memory --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 5c9586ab24..0f0a9e5c47 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1311,7 +1311,7 @@ def test_fft(): maxk_threshold = 1.e-3 N = 880 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) - obj = obj.withGSParams(maxk_threshold=1.e-4) + obj = obj.withGSParams(maxk_threshold=maxk_threshold) im1 = obj.drawKImage() np.testing.assert_equal(im1.bounds, galsim.BoundsI(-N/2,N/2,-N/2,N/2), "obj.drawKImage() produced image with wrong bounds") From 0f0feeb6b2902a658dcf488baadadbf1a8efe4c1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:54:23 -0500 Subject: [PATCH 298/351] TST less memory --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 0f0a9e5c47..18fe42c486 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1308,7 +1308,7 @@ def test_fft(): N = 1174 # NB. It is useful to have this come out not a multiple of 4, since some of the # calculation needs to be different when N/2 is odd. else: - maxk_threshold = 1.e-3 + maxk_threshold = 1.1e-3 N = 880 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) obj = obj.withGSParams(maxk_threshold=maxk_threshold) From e61fc38291a8b329e3333b3db8b799083a0559f9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:55:11 -0500 Subject: [PATCH 299/351] TST less memory --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 18fe42c486..7d96b8ec99 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1308,7 +1308,7 @@ def test_fft(): N = 1174 # NB. It is useful to have this come out not a multiple of 4, since some of the # calculation needs to be different when N/2 is odd. else: - maxk_threshold = 1.1e-3 + maxk_threshold = 1.2e-3 N = 880 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) obj = obj.withGSParams(maxk_threshold=maxk_threshold) From 7e3cdeda0e1faf4a4be1cda24c998f1809dc130e Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:56:11 -0500 Subject: [PATCH 300/351] TST less memory --- tests/test_draw.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 7d96b8ec99..16f9a95d8a 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1303,13 +1303,14 @@ def test_fft(): np.testing.assert_array_almost_equal(xim.array, xim2.array) # Now use drawKImage (as above in test_drawKImage) to get a more realistic k-space image + # NB. It is useful to have this come out not a multiple of 4, since some of the + # calculation needs to be different when N/2 is odd. if hasattr(galsim, "_galsim"): maxk_threshold = 1.e-4 - N = 1174 # NB. It is useful to have this come out not a multiple of 4, since some of the - # calculation needs to be different when N/2 is odd. + N = 1174 else: maxk_threshold = 1.2e-3 - N = 880 + N = 858 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) obj = obj.withGSParams(maxk_threshold=maxk_threshold) im1 = obj.drawKImage() From 011fde6c69075951ac0375f095d996d9a9190891 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 16:57:16 -0500 Subject: [PATCH 301/351] TST cancel concurrent tests --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fae10f5d58..47f7882cc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,9 @@ name: GalSim CI +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: From 68e4b7a7fcdb39e6a7ff2357a224e24f03373349 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 20:31:59 -0500 Subject: [PATCH 302/351] TST cancel concurrent tests --- tests/test_draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 16f9a95d8a..8130380a68 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1309,7 +1309,7 @@ def test_fft(): maxk_threshold = 1.e-4 N = 1174 else: - maxk_threshold = 1.2e-3 + maxk_threshold = 0.78e-3 N = 858 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) obj = obj.withGSParams(maxk_threshold=maxk_threshold) From d6886c984c57fd82fa08efe14f027549e2900684 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 4 Jun 2024 20:35:53 -0500 Subject: [PATCH 303/351] TST fix fft tests --- tests/test_draw.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 8130380a68..23f5c0dc36 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1308,9 +1308,11 @@ def test_fft(): if hasattr(galsim, "_galsim"): maxk_threshold = 1.e-4 N = 1174 + Nfft = 1536 else: maxk_threshold = 0.78e-3 - N = 858 + N = 912 + Nfft = 1024 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) obj = obj.withGSParams(maxk_threshold=maxk_threshold) im1 = obj.drawKImage() @@ -1340,7 +1342,7 @@ def test_fft(): # If we give both a good size to use and match up the scales, then they should produce the # same thing. N = galsim.Image.good_fft_size(N) - assert N == 1536 == 3 * 2**9 + assert N == Nfft kscale = 2.*np.pi / (N * nyq_scale) im2 = obj.drawKImage(nx=N+1, ny=N+1, scale=kscale) im2_real = im2.calculate_inverse_fft() From 1b44daadebcec0e85da4301a7a0b8e7fc436097c Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 20 Jun 2024 12:46:11 -0500 Subject: [PATCH 304/351] test: update tests for jax galsim --- tests/test_interpolatedimage.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 169becc6e0..cf6746a64a 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -371,8 +371,12 @@ def test_interpolant(): -(vm+1) * sici(np.pi*(vm+1))[0] -(vp-1) * sici(np.pi*(vp-1))[0] +(vp+1) * sici(np.pi*(vp+1))[0] ) / (2*np.pi) - np.testing.assert_allclose(ln.kval(x), true_kval, rtol=1.e-4, atol=1.e-8) - assert np.isclose(ln.kval(x[12]), true_kval[12]) + if hasattr(galsim, "_galsim"): + np.testing.assert_allclose(ln.kval(x), true_kval, rtol=1.e-4, atol=1.e-8) + assert np.isclose(ln.kval(x[12]), true_kval[12]) + else: + np.testing.assert_allclose(ln.kval(x), true_kval, rtol=3.0e-4, atol=3.0e-6) + np.testing.assert_allclose(ln.kval(x[12]), true_kval[12], rtol=3.0e-4, atol=3.0e-6) # Base class is invalid. assert_raises(NotImplementedError, galsim.Interpolant) From ff175e1d6148c9bebf1a9248f841e88c73212656 Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 11 Jul 2024 23:18:13 -0500 Subject: [PATCH 305/351] test: lower precision for some interp image tests --- tests/test_interpolatedimage.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index cf6746a64a..2c4a8df2eb 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -351,8 +351,12 @@ def test_interpolant(): assert ln.n == n true_xval = np.zeros_like(x) true_xval[np.abs(x) < n] = np.sinc(x[np.abs(x) Date: Fri, 12 Jul 2024 00:17:32 -0500 Subject: [PATCH 306/351] Revert "test: lower precision for some interp image tests" This reverts commit ff175e1d6148c9bebf1a9248f841e88c73212656. --- tests/test_interpolatedimage.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 2c4a8df2eb..cf6746a64a 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -351,12 +351,8 @@ def test_interpolant(): assert ln.n == n true_xval = np.zeros_like(x) true_xval[np.abs(x) < n] = np.sinc(x[np.abs(x) Date: Wed, 21 Aug 2024 11:51:53 -0500 Subject: [PATCH 307/351] fix: missing import --- tests/test_inclined.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_inclined.py b/tests/test_inclined.py index 1edd192f18..a7a04b70d3 100644 --- a/tests/test_inclined.py +++ b/tests/test_inclined.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import os from copy import deepcopy import numpy as np From 9696fbb539e17a4bebe306700cf24970f548257e Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 21 Aug 2024 12:20:03 -0500 Subject: [PATCH 308/351] test: more missing imports and tests --- tests/test_catalog.py | 1 + tests/test_draw.py | 1 + tests/test_real.py | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index ba59a48480..331b495f88 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import os import numpy as np import galsim diff --git a/tests/test_draw.py b/tests/test_draw.py index ccd9ae1240..55dc7ab55a 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -16,6 +16,7 @@ # and/or other materials provided with the distribution. # +import os import numpy as np import galsim diff --git a/tests/test_real.py b/tests/test_real.py index 62c1effd6f..c95a2d73a3 100644 --- a/tests/test_real.py +++ b/tests/test_real.py @@ -77,8 +77,8 @@ def test_real_galaxy_catalog(): # Test some values that are lazy evaluated: assert rgc.ident[0] == '100533' - assert rgc.gal_file_name[0] == './real_comparison_images/test_images.fits' - assert rgc.psf_file_name[0] == './real_comparison_images/test_images.fits' + assert rgc.gal_file_name[0].split("/")[-2:] == ['real_comparison_images', 'test_images.fits'] + assert rgc.psf_file_name[0].split("/")[-2:] == ['real_comparison_images', 'test_images.fits'] assert rgc.noise_file_name is None np.testing.assert_array_equal(rgc.gal_hdu, [0,1]) np.testing.assert_array_equal(rgc.psf_hdu, [2,3]) From 6a326a768332533e26905f09304386e8bb9b46b1 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 21 Aug 2024 12:24:27 -0500 Subject: [PATCH 309/351] test: rename the imports --- tests/test_zernike.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_zernike.py b/tests/test_zernike.py index cd3ebd1800..6ada6d0578 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -235,7 +235,7 @@ def test_zernike_eval(): np.ones(4, dtype=float), np.ones(4, dtype=np.float32) ]: - Z = Zernike(coef) + Z = galsim.zernike.Zernike(coef) assert Z.coef.dtype == np.float64 assert Z(0.0, 0.0) == 1.0 assert Z(0, 0) == 1.0 @@ -245,13 +245,13 @@ def test_zernike_eval(): np.ones((4, 4), dtype=float), np.ones((4, 4), dtype=np.float32) ]: - dz = DoubleZernike(coefs) + dz = galsim.zernike.DoubleZernike(coefs) assert dz.coef.dtype == np.float64 assert dz(0.0, 0.0) == dz(0, 0) # Make sure we cast to float in _from_uvxy uvxy = dz._coef_array_uvxy - dz2 = DoubleZernike._from_uvxy(uvxy.astype(int)) + dz2 = galsim.zernike.DoubleZernike._from_uvxy(uvxy.astype(int)) np.testing.assert_array_equal(dz2._coef_array_uvxy, dz._coef_array_uvxy) From 0d55c54e9eaf125e112bd51bb00af8188ccd58bf Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 10:34:03 -0500 Subject: [PATCH 310/351] feat: add function to extract the galsim backend --- tests/galsim_test_helpers.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 5a191d07ac..16f3ef383b 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -46,6 +46,8 @@ "assert_raises", "assert_warns", "Profile", + "galsim_backend", + "is_jax_galsim", ] # This file has some helper functions that are used by tests from multiple files to help @@ -66,6 +68,18 @@ integration_relerr = 1.e-6, integration_abserr = 1.e-8) + +def galsim_backend(galsim): + if "jax_galsim/__init__.py" in galsim.__file__: + return "jax_galsim" + else: + return "galsim" + + +def is_jax_galsim(galsim): + return galsim_backend(galsim) == "jax_galsim" + + def gsobject_compare(obj1, obj2, conv=None, decimal=10): """Helper function to check that two GSObjects are equivalent """ From 13a30426bc44131bcc2c4ea2817e9eb16593fd91 Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 10:42:40 -0500 Subject: [PATCH 311/351] fix: start to use a proper helper function --- tests/galsim_test_helpers.py | 19 ++++++++++++------- tests/test_deprecated.py | 28 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 16f3ef383b..dc27920460 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -48,6 +48,7 @@ "Profile", "galsim_backend", "is_jax_galsim", + "is_pure_galsim", ] # This file has some helper functions that are used by tests from multiple files to help @@ -69,15 +70,19 @@ integration_abserr = 1.e-8) -def galsim_backend(galsim): +def galsim_backend(): if "jax_galsim/__init__.py" in galsim.__file__: return "jax_galsim" else: return "galsim" -def is_jax_galsim(galsim): - return galsim_backend(galsim) == "jax_galsim" +def is_jax_galsim(): + return galsim_backend() == "jax_galsim" + + +def is_pure_galsim(): + return galsim_backend() == "galsim" def gsobject_compare(obj1, obj2, conv=None, decimal=10): @@ -170,10 +175,7 @@ def check_basic_x(prof, name, approx_maxsb=False, scale=None): np.testing.assert_allclose( image(i,j), prof._xValue(galsim.PositionD(x,y)), rtol=1.e-5, err_msg="%s profile sb image does not match _xValue at %d,%d"%(name,i,j)) - if hasattr(galsim, "_galsim"): - assert prof.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ - assert prof.__class__.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ - else: + if is_jax_galsim(): for line in galsim.GSObject.withFlux.__doc__.splitlines(): if line.strip() and "LAX" not in line: assert line.strip() in prof.withFlux.__doc__, ( @@ -184,6 +186,9 @@ def check_basic_x(prof, name, approx_maxsb=False, scale=None): assert line.strip() in prof.__class__.withFlux.__doc__, ( prof.__class__.withFlux.__doc__, galsim.GSObject.withFlux.__doc__, ) + else: + assert prof.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ + assert prof.__class__.withFlux.__doc__ == galsim.GSObject.withFlux.__doc__ # Check negative flux: neg_image = prof.withFlux(-prof.flux).drawImage(method='sb', scale=scale, use_true_center=False) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 5b210517dc..5363663259 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -34,7 +34,7 @@ def check_dep(f, *args, **kwargs): @timer def test_gsparams(): - if hasattr(galsim, "_galsim"): + if is_pure_galsim(): 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) @@ -541,14 +541,14 @@ def test_photon_array_depr(): # Using the getter is allowed, but deprecated. photon_array = galsim.PhotonArray(nphotons) - if hasattr(galsim, "_galsim"): - dxdz = check_dep(getattr, photon_array, 'dxdz') - assert photon_array.hasAllocatedAngles() - else: + 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() + else: + dxdz = check_dep(getattr, photon_array, 'dxdz') + assert photon_array.hasAllocatedAngles() assert len(photon_array.dxdz) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run @@ -564,29 +564,29 @@ def test_photon_array_depr(): photon_array.dydz = 0.59 np.testing.assert_array_equal(photon_array.dydz, 0.59) - if hasattr(galsim, "_galsim"): - wave = check_dep(getattr, photon_array, 'wavelength') - assert photon_array.hasAllocatedWavelengths() - else: + 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() assert len(photon_array.wavelength) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run photon_array.wavelength = 500.0 np.testing.assert_array_equal(photon_array.wavelength, 500) - if hasattr(galsim, "_galsim"): - u = check_dep(getattr, photon_array, 'pupil_u') - assert photon_array.hasAllocatedPupil() - assert len(photon_array.pupil_u) == nphotons - else: + 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 assert len(photon_array.pupil_v) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run From d80d1d8c9382850c8bd87a04210c0e22de7b8a83 Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 11:00:18 -0500 Subject: [PATCH 312/351] test: convert more to use the helper functions --- tests/test_deprecated.py | 34 +++++++++++++++++----------------- tests/test_shear.py | 4 ++-- tests/test_wcs.py | 22 +++++++++++----------- tests/test_zernike.py | 14 +++++++------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 5363663259..709f1ec5a4 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -601,14 +601,14 @@ def test_photon_array_depr(): photon_array.pupil_v = 10.0 np.testing.assert_array_equal(photon_array.pupil_v, 10.0) - if hasattr(galsim, "_galsim"): - t = check_dep(getattr, photon_array, 'time') - assert photon_array.hasAllocatedTimes() - else: + 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() + else: + t = check_dep(getattr, photon_array, 'time') + assert photon_array.hasAllocatedTimes() # jax-galsim needs to set 0 photon_array.time = 0.0 # jax-galsim is allocated now @@ -622,14 +622,14 @@ def test_photon_array_depr(): # For coverage, also need to test the two pair ones in other order. photon_array = galsim.PhotonArray(nphotons) - if hasattr(galsim, "_galsim"): - dydz = check_dep(getattr, photon_array, 'dydz') - assert photon_array.hasAllocatedAngles() - else: + 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 len(photon_array.dxdz) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run @@ -643,15 +643,15 @@ def test_photon_array_depr(): photon_array.dxdz = 0.17 np.testing.assert_array_equal(photon_array.dxdz, 0.17) - if hasattr(galsim, "_galsim"): - v = check_dep(getattr, photon_array, 'pupil_v') - assert photon_array.hasAllocatedPupil() - assert len(photon_array.pupil_u) == nphotons - else: + 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 assert len(photon_array.pupil_v) == nphotons # JAX-Galsim does not allow by reference setting - changed this # to make tests below run @@ -667,13 +667,13 @@ def test_photon_array_depr(): # Check assignAt pa1 = galsim.PhotonArray(50) pa1.x = photon_array.x[:50] - if hasattr(galsim, "_galsim"): + 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] - else: - pa1.y = photon_array.y[:50] - pa1.flux.at[0:50].set(photon_array.flux[:50]) pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] pa1.pupil_u = photon_array.pupil_u[:50] diff --git a/tests/test_shear.py b/tests/test_shear.py index e569837ca2..d949d86b05 100644 --- a/tests/test_shear.py +++ b/tests/test_shear.py @@ -176,7 +176,7 @@ def test_shear_initialization(): assert_raises(TypeError,galsim.Shear,g1=0.3,e2=0.2) assert_raises(TypeError,galsim.Shear,eta1=0.3,beta=0.*galsim.degrees) assert_raises(TypeError,galsim.Shear,q=0.3) - if hasattr(galsim, "_galsim"): + if is_pure_galsim(): assert_raises(galsim.GalSimRangeError,galsim.Shear,q=1.3,beta=0.*galsim.degrees) assert_raises(galsim.GalSimRangeError,galsim.Shear,g1=0.9,g2=0.6) assert_raises(galsim.GalSimRangeError,galsim.Shear,e=-1.3,beta=0.*galsim.radians) @@ -185,7 +185,7 @@ def test_shear_initialization(): assert_raises(TypeError,galsim.Shear,g=0.5) assert_raises(TypeError,galsim.Shear,e=0.5) assert_raises(TypeError,galsim.Shear,eta=0.5) - if hasattr(galsim, "_galsim"): + if is_pure_galsim(): assert_raises(galsim.GalSimRangeError,galsim.Shear,eta=-0.5,beta=0.*galsim.radians) assert_raises(galsim.GalSimRangeError,galsim.Shear,g=1.3,beta=0.*galsim.radians) assert_raises(galsim.GalSimRangeError,galsim.Shear,g=-0.3,beta=0.*galsim.radians) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index b763f41cd8..e41ec10ef5 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -1182,7 +1182,7 @@ def test_pixelscale(): assert wcs.world_origin == galsim.PositionD(0,0) assert_raises(TypeError, galsim.PixelScale) - if hasattr(galsim, "_galsim"): + if is_pure_galsim(): assert_raises(TypeError, galsim.PixelScale, scale=galsim.PixelScale(scale)) assert_raises(TypeError, galsim.PixelScale, scale=scale, origin=galsim.PositionD(0,0)) assert_raises(TypeError, galsim.PixelScale, scale=scale, world_origin=galsim.PositionD(0,0)) @@ -2465,7 +2465,11 @@ def test_inverseab_convergence(): # Now one that should fail, since it's well outside the applicable area for the SIP polynomials. ra = -200.1 dec = 70.45 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + x, y = wcs.radecToxy(ra, dec, units="radians") + assert np.all(np.isnan(x)) + assert np.all(np.isnan(y)) + else: with assert_raises(galsim.GalSimError): x, y = wcs.radecToxy(ra, dec, units="radians") try: @@ -2473,10 +2477,6 @@ def test_inverseab_convergence(): except galsim.GalSimError as e: print('Error message is\n',e) assert "[0,]" in str(e) or "[0]" in str(e) - else: - x, y = wcs.radecToxy(ra, dec, units="radians") - assert np.all(np.isnan(x)) - assert np.all(np.isnan(y)) # Check as part of a longer list (longer than 256 is important) rng = np.random.RandomState(1234) @@ -2486,7 +2486,11 @@ def test_inverseab_convergence(): dec = np.append(dec, [-0.45, 0.2]) print('ra = ',ra) print('dec = ',dec) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + x, y = wcs.radecToxy(ra, dec, units="radians") + assert np.sum(np.isnan(x)) >= 2 + assert np.sum(np.isnan(y)) >= 2 + else: with assert_raises(galsim.GalSimError): x, y = wcs.radecToxy(ra, dec, units="radians") try: @@ -2498,10 +2502,6 @@ def test_inverseab_convergence(): # of the bad indices. Included here as an example for users who may need this. bad = eval(str(e)[str(e).rfind('['):]) print('as a python list: ',bad) - else: - x, y = wcs.radecToxy(ra, dec, units="radians") - assert np.sum(np.isnan(x)) >= 2 - assert np.sum(np.isnan(y)) >= 2 @timer diff --git a/tests/test_zernike.py b/tests/test_zernike.py index 6ada6d0578..d53a4c3087 100644 --- a/tests/test_zernike.py +++ b/tests/test_zernike.py @@ -19,7 +19,7 @@ import numpy as np import galsim -from galsim_test_helpers import timer, check_pickle, assert_raises, check_all_diff +from galsim_test_helpers import timer, check_pickle, assert_raises, check_all_diff, is_jax_galsim @timer @@ -523,15 +523,15 @@ def test_sum(): c2 = u() coefSum = c2*np.array(z2.coef) - if hasattr(galsim, "_galsim"): - coefSum[:len(z1.coef)] += c1*z1.coef - else: + if is_jax_galsim(): coefSum = coefSum.at[:len(z1.coef)].add(c1*z1.coef) - coefDiff = c2*np.array(z2.coef) - if hasattr(galsim, "_galsim"): - coefDiff[:len(z1.coef)] -= c1*z1.coef else: + coefSum[:len(z1.coef)] += c1*z1.coef + coefDiff = c2*np.array(z2.coef) + if is_jax_galsim(): coefDiff = coefDiff.at[:len(z1.coef)].add(-c1*z1.coef) + else: + coefDiff[:len(z1.coef)] -= c1*z1.coef np.testing.assert_allclose(coefSum, (c1*z1 + c2*z2).coef) np.testing.assert_allclose(coefDiff, -(c1*z1 - c2*z2).coef) From cc57eca7ca1a1ef606a905f83c2cbe8255d223fb Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 11:03:32 -0500 Subject: [PATCH 313/351] test: fix test helpers file for new functions --- tests/galsim_test_helpers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index dc27920460..0ee2d29e44 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -264,7 +264,7 @@ def assert_floatlike(val): assert ( isinstance(val, float) or ( - (not hasattr(galsim, "_galsim")) + is_jax_galsim() and hasattr(val, "shape") and val.shape == () and hasattr(val, "dtype") @@ -276,7 +276,7 @@ def assert_intlike(val): assert ( isinstance(val, int) or ( - (not hasattr(galsim, "_galsim")) + is_jax_galsim() and hasattr(val, "shape") and val.shape == () and hasattr(val, "dtype") @@ -376,7 +376,8 @@ def do_shoot(prof, img, name): print('nphot = ',nphot) img2 = img.copy() - rtol *= 3 + if is_jax_galsim(): + rtol *= 3 # Use a deterministic random number generator so we don't fail tests because of rare flukes # in the random numbers. From 36da37b3fde014b90857d0fac869519cf23632e7 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 11:10:21 -0500 Subject: [PATCH 314/351] test: clean up celestial tests --- tests/test_celestial_galsim.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index 640a0fd014..2afc56ba24 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -123,17 +123,11 @@ def test_angle(): # Check invalid constructors assert_raises(TypeError,galsim.AngleUnit, galsim.degrees) - try: - assert_raises(ValueError,galsim.AngleUnit, 'spam') - except Exception: - assert_raises(TypeError,galsim.AngleUnit, 'spam') + assert_raises((ValueError, TypeError), galsim.AngleUnit, 'spam') assert_raises(TypeError,galsim.AngleUnit, 1, 3) assert_raises(TypeError,galsim.Angle, 3.4) assert_raises(TypeError,galsim.Angle, theta1, galsim.degrees) - try: - assert_raises(ValueError,galsim.Angle, 'spam', galsim.degrees) - except Exception: - assert_raises(TypeError,galsim.Angle, 'spam', galsim.degrees) + assert_raises((ValueError, TypeError), galsim.AngleUnit, 'spam')) assert_raises(TypeError,galsim.Angle, 1, 3) @@ -360,6 +354,8 @@ def test_projection(): np.testing.assert_allclose( c0.rad, center.rad, + rtol=0, + atol=1e-16, ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='lambert').ravel(), (1,0,0,1)) @@ -423,6 +419,8 @@ def test_projection(): np.testing.assert_allclose( c0.rad, center.rad, + rtol=0, + atol=1e-16, ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='stereographic').ravel(), (1,0,0,1)) @@ -489,6 +487,8 @@ def test_projection(): np.testing.assert_allclose( c0.rad, center.rad, + rtol=0, + atol=1e-16, ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='gnomonic').ravel(), (1,0,0,1)) @@ -551,6 +551,8 @@ def test_projection(): np.testing.assert_allclose( c0.rad, center.rad, + rtol=0, + atol=1e-16, ) np.testing.assert_almost_equal(center.jac_deproject(*p0, projection='postel').ravel(), (1,0,0,1)) From 414c8ab31a355b5d11e04f8df2606cedbf250d47 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 11:11:01 -0500 Subject: [PATCH 315/351] fix: need to test Angle --- tests/test_celestial_galsim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index 2afc56ba24..9fad135d69 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -127,7 +127,7 @@ def test_angle(): assert_raises(TypeError,galsim.AngleUnit, 1, 3) assert_raises(TypeError,galsim.Angle, 3.4) assert_raises(TypeError,galsim.Angle, theta1, galsim.degrees) - assert_raises((ValueError, TypeError), galsim.AngleUnit, 'spam')) + assert_raises((ValueError, TypeError), galsim.Angle, 'spam')) assert_raises(TypeError,galsim.Angle, 1, 3) From 9cd8ab28c5c3f5489b909a033b5c6fe02f0c7b9b Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 11:12:48 -0500 Subject: [PATCH 316/351] fix: bug in parens --- tests/test_celestial_galsim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_celestial_galsim.py b/tests/test_celestial_galsim.py index 9fad135d69..3e89bf4eb9 100644 --- a/tests/test_celestial_galsim.py +++ b/tests/test_celestial_galsim.py @@ -127,7 +127,7 @@ def test_angle(): assert_raises(TypeError,galsim.AngleUnit, 1, 3) assert_raises(TypeError,galsim.Angle, 3.4) assert_raises(TypeError,galsim.Angle, theta1, galsim.degrees) - assert_raises((ValueError, TypeError), galsim.Angle, 'spam')) + assert_raises((ValueError, TypeError), galsim.Angle, 'spam') assert_raises(TypeError,galsim.Angle, 1, 3) From aae4649dfb04d984c9c183dd20b691544b76cc96 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 11:33:34 -0500 Subject: [PATCH 317/351] test: clean up test_optics --- tests/test_optics.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_optics.py b/tests/test_optics.py index 7acf5b1c6f..c73bc9d55f 100644 --- a/tests/test_optics.py +++ b/tests/test_optics.py @@ -745,11 +745,11 @@ def test_OpticalPSF_pupil_plane_size(): im = galsim.Image(512, 512) x = y = np.arange(512) - 256 y, x = np.meshgrid(y, x) - if hasattr(galsim, "_galsim"): - im.array[x**2+y**2 < 230**2] = 1.0 - else: + if is_jax_galsim(): # no refs in jax-galsim im._array = im.array.at[x**2+y**2 < 230**2].set(1.0) + else: + im.array[x**2+y**2 < 230**2] = 1.0 # The following still fails (uses deprecated optics framework): # galsim.optics.OpticalPSF(aberrations=[0,0,0,0,0.5], diam=4.0, lam=700.0, pupil_plane_im=im) # But using the new framework, should work. From 1b627dc263fe8391876447392d069ed5c658267f Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 11:40:55 -0500 Subject: [PATCH 318/351] tests: always default to running tests for other backends --- tests/galsim_test_helpers.py | 5 ----- tests/test_deprecated.py | 4 +++- tests/test_shear.py | 8 ++++++-- tests/test_wcs.py | 4 +++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 0ee2d29e44..d6c4fa0cf4 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -48,7 +48,6 @@ "Profile", "galsim_backend", "is_jax_galsim", - "is_pure_galsim", ] # This file has some helper functions that are used by tests from multiple files to help @@ -81,10 +80,6 @@ def is_jax_galsim(): return galsim_backend() == "jax_galsim" -def is_pure_galsim(): - return galsim_backend() == "galsim" - - def gsobject_compare(obj1, obj2, conv=None, decimal=10): """Helper function to check that two GSObjects are equivalent """ diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 709f1ec5a4..f72df9b583 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -34,7 +34,9 @@ def check_dep(f, *args, **kwargs): @timer def test_gsparams(): - if is_pure_galsim(): + 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) diff --git a/tests/test_shear.py b/tests/test_shear.py index d949d86b05..26546cb6a6 100644 --- a/tests/test_shear.py +++ b/tests/test_shear.py @@ -176,7 +176,9 @@ def test_shear_initialization(): assert_raises(TypeError,galsim.Shear,g1=0.3,e2=0.2) assert_raises(TypeError,galsim.Shear,eta1=0.3,beta=0.*galsim.degrees) assert_raises(TypeError,galsim.Shear,q=0.3) - if is_pure_galsim(): + if is_jax_galsim(): + pass + else: assert_raises(galsim.GalSimRangeError,galsim.Shear,q=1.3,beta=0.*galsim.degrees) assert_raises(galsim.GalSimRangeError,galsim.Shear,g1=0.9,g2=0.6) assert_raises(galsim.GalSimRangeError,galsim.Shear,e=-1.3,beta=0.*galsim.radians) @@ -185,7 +187,9 @@ def test_shear_initialization(): assert_raises(TypeError,galsim.Shear,g=0.5) assert_raises(TypeError,galsim.Shear,e=0.5) assert_raises(TypeError,galsim.Shear,eta=0.5) - if is_pure_galsim(): + if is_jax_galsim(): + pass + else: assert_raises(galsim.GalSimRangeError,galsim.Shear,eta=-0.5,beta=0.*galsim.radians) assert_raises(galsim.GalSimRangeError,galsim.Shear,g=1.3,beta=0.*galsim.radians) assert_raises(galsim.GalSimRangeError,galsim.Shear,g=-0.3,beta=0.*galsim.radians) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index e41ec10ef5..072d98407a 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -1182,7 +1182,9 @@ def test_pixelscale(): assert wcs.world_origin == galsim.PositionD(0,0) assert_raises(TypeError, galsim.PixelScale) - if is_pure_galsim(): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, galsim.PixelScale, scale=galsim.PixelScale(scale)) assert_raises(TypeError, galsim.PixelScale, scale=scale, origin=galsim.PositionD(0,0)) assert_raises(TypeError, galsim.PixelScale, scale=scale, world_origin=galsim.PositionD(0,0)) From 396084ffbcd809ba24aeb7bd994f6f6ad445247d Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 12:07:09 -0500 Subject: [PATCH 319/351] test: clean up tests for exp w/ phots --- tests/test_exponential.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_exponential.py b/tests/test_exponential.py index d2bc7dd926..f1ee579913 100644 --- a/tests/test_exponential.py +++ b/tests/test_exponential.py @@ -226,9 +226,12 @@ def test_exponential_shoot(): assert np.isclose(added_flux, obj.flux) assert np.isclose(im.array.sum(), obj.flux) photons2 = obj.makePhot(poisson_flux=False, rng=rng) - np.testing.assert_allclose(photons2.x, photons.x) - np.testing.assert_allclose(photons2.y, photons.y) - np.testing.assert_allclose(photons2.flux, photons.flux) + if is_jax_galsim(): + np.testing.assert_allclose(photons2.x, photons.x) + np.testing.assert_allclose(photons2.y, photons.y) + np.testing.assert_allclose(photons2.flux, photons.flux) + else: + assert photons2 == photons, "Exponential makePhot not equivalent to drawPhot" @timer From ae74cc75a1119a32a3cde34287aa690eb12e927d Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 12:10:57 -0500 Subject: [PATCH 320/351] test: clean up tests for moffat --- tests/test_moffat.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index f9e22bbf80..5f1277612d 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -136,10 +136,10 @@ def test_moffat_properties(): cen = galsim.PositionD(0, 0) np.testing.assert_equal(psf.centroid, cen) # Check Fourier properties - if hasattr(galsim, "_galsim"): - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) + if is_jax_galsim(): + np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) else: - np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) + 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) @@ -153,10 +153,10 @@ def test_moffat_properties(): 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) - if hasattr(galsim, "_galsim"): - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) + if is_jax_galsim(): + np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) else: - np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) + 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) @@ -201,10 +201,10 @@ def test_moffat_maxk(): for psf in psfs: for thresh in threshs: psf = psf.withGSParams(maxk_threshold=thresh) - if hasattr(galsim, "_galsim"): - rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 - else: + if is_jax_galsim(): rtol = 5e-3 + else: + rtol = 1.e-7 if psf.trunc == 0 else 3.e-3 fk = psf.kValue(psf.maxk,0).real/psf.flux print(f'{psf.beta} \t {int(psf.trunc)} \t {thresh:.1e} \t {fk:.3e} \t {psf.maxk:.3e}') np.testing.assert_allclose(abs(psf.kValue(psf.maxk,0).real)/psf.flux, thresh, rtol=rtol) From ea082f5af9132aab0d66b5e335daa93d18ba774d Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 12:40:28 -0500 Subject: [PATCH 321/351] fix: testing functions do not have atol/rtol --- tests/test_moffat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 5f1277612d..8709a5fa3c 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -137,7 +137,7 @@ def test_moffat_properties(): np.testing.assert_equal(psf.centroid, cen) # Check Fourier properties if is_jax_galsim(): - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) else: np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) np.testing.assert_array_almost_equal(psf.stepk, 0.62831853071795873) @@ -154,7 +154,7 @@ def test_moffat_properties(): trunc=2*fwhm_backwards_compatible, flux=test_flux) np.testing.assert_equal(psf.centroid, cen) if is_jax_galsim(): - np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) + np.testing.assert_allclose(psf.maxk, 11.634597424960159, atol=0, rtol=0.2) else: np.testing.assert_array_almost_equal(psf.maxk, 11.634597424960159) np.testing.assert_array_almost_equal(psf.stepk, 0.62831853071795862) From 1a3b3cb748f75ce837f5a803a41876179f5e129e Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 14:42:15 -0500 Subject: [PATCH 322/351] test: fix first part of deprecation test file --- tests/test_deprecated.py | 78 +++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index f72df9b583..553f7b2766 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -548,22 +548,30 @@ def test_photon_array_depr(): # 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 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() + 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.) - 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 + 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 np.testing.assert_array_equal(photon_array.dydz, 0.59) if is_jax_galsim(): @@ -575,9 +583,12 @@ def test_photon_array_depr(): wave = check_dep(getattr, photon_array, 'wavelength') assert photon_array.hasAllocatedWavelengths() assert len(photon_array.wavelength) == nphotons - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.wavelength = 500.0 + if is_jax_galsim(): + # JAX-Galsim does not allow by reference setting - changed this + # to make tests below run + photon_array.wavelength = 500.0 + else: + wave[:] = 500. np.testing.assert_array_equal(photon_array.wavelength, 500) if is_jax_galsim(): @@ -590,17 +601,24 @@ def test_photon_array_depr(): assert photon_array.hasAllocatedPupil() assert len(photon_array.pupil_u) == nphotons assert len(photon_array.pupil_v) == nphotons - # 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() + 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 np.testing.assert_array_equal(photon_array.pupil_u, 6.0) np.testing.assert_array_equal(photon_array.pupil_v, 0.0) - 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 + 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 np.testing.assert_array_equal(photon_array.pupil_v, 10.0) if is_jax_galsim(): @@ -608,18 +626,20 @@ def test_photon_array_depr(): # 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 else: t = check_dep(getattr, photon_array, 'time') - assert photon_array.hasAllocatedTimes() - # jax-galsim needs to set 0 - photon_array.time = 0.0 - # jax-galsim is allocated now assert photon_array.hasAllocatedTimes() assert len(photon_array.time) == nphotons np.testing.assert_array_equal(photon_array.time, 0.0) - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.time = 10 + 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 np.testing.assert_array_equal(photon_array.time, 10.0) # For coverage, also need to test the two pair ones in other order. From 41730701c462d7497d47003db1e8481b9477a7fc Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 14:44:35 -0500 Subject: [PATCH 323/351] test: better test here --- tests/test_deprecated.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 553f7b2766..360ad02447 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -587,6 +587,8 @@ def test_photon_array_depr(): # 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. np.testing.assert_array_equal(photon_array.wavelength, 500) From 04c247ae58f7846aa7d63500092c7a87b43a1b32 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 14:47:25 -0500 Subject: [PATCH 324/351] test: check allocated --- tests/test_deprecated.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 360ad02447..ec95a36f9f 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -631,6 +631,7 @@ def test_photon_array_depr(): # 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') assert photon_array.hasAllocatedTimes() From 79536e1ba55dbc57824db7a3ab50a64fabfef79c Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 14:53:57 -0500 Subject: [PATCH 325/351] test: clean up more test stuff --- tests/test_deprecated.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index ec95a36f9f..9dc3b91a23 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -655,17 +655,26 @@ def test_photon_array_depr(): else: dydz = check_dep(getattr, photon_array, 'dydz') assert photon_array.hasAllocatedAngles() + assert 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.dydz = 0.59 - np.testing.assert_array_equal(photon_array.dxdz, 0.0) + 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 + else: + dydz[:] = 0.59 + np.testing.assert_array_equal(photon_array.dxdz, 0.) np.testing.assert_array_equal(photon_array.dydz, 0.59) - 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 + 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 np.testing.assert_array_equal(photon_array.dxdz, 0.17) if is_jax_galsim(): From a2f674afc2e34bebad573d50c33f2f01401e1183 Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 14:55:04 -0500 Subject: [PATCH 326/351] test: clean up more test stuff --- tests/test_deprecated.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 9dc3b91a23..6da2acaaae 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -674,7 +674,7 @@ def test_photon_array_depr(): photon_array.dxdz = 0.17 else: dxdz = photon_array.dxdz # Allowed now. - dxdz[:] = 0.17 + dxdz[:] = 0.17 np.testing.assert_array_equal(photon_array.dxdz, 0.17) if is_jax_galsim(): @@ -687,15 +687,22 @@ def test_photon_array_depr(): assert photon_array.hasAllocatedPupil() assert len(photon_array.pupil_u) == nphotons assert len(photon_array.pupil_v) == nphotons - # JAX-Galsim does not allow by reference setting - changed this - # to make tests below run - photon_array.pupil_v = 10.0 + 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 + else: + 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) - 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 + 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 np.testing.assert_array_equal(photon_array.pupil_u, 6.0) # Check assignAt From ce25e31883e4795837894138a207f37a21840f75 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Thu, 22 Aug 2024 14:58:10 -0500 Subject: [PATCH 327/351] test: get rest of test cases --- tests/test_deprecated.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 6da2acaaae..150654a77e 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -662,6 +662,8 @@ def test_photon_array_depr(): # 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 np.testing.assert_array_equal(photon_array.dxdz, 0.) @@ -691,6 +693,8 @@ def test_photon_array_depr(): # 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 np.testing.assert_array_equal(photon_array.pupil_u, 0.0) From 3c4841c08c7a2e5beb743673509d057d4cfa74dc Mon Sep 17 00:00:00 2001 From: beckermr Date: Thu, 22 Aug 2024 20:20:53 -0500 Subject: [PATCH 328/351] test: clean up tests for photon arrays --- tests/test_photon_array.py | 42 +++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/tests/test_photon_array.py b/tests/test_photon_array.py index 446997031c..acb3aada8b 100644 --- a/tests/test_photon_array.py +++ b/tests/test_photon_array.py @@ -61,7 +61,9 @@ def test_photon_array(): # Check assignment via numpy [:] # jax does not support direct assignment - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: photon_array.x[:] = 5 photon_array.y[:] = 17 photon_array.flux[:] = 23 @@ -189,15 +191,15 @@ def test_photon_array(): # Check ways to assign to photons pa1 = galsim.PhotonArray(50) pa1.x = photon_array.x[:50] - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pa1.y = photon_array.y[: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.y = photon_array.y[:50] - if hasattr(galsim, "_galsim"): pa1.flux[0:50] = photon_array.flux[:50] - else: - pa1.flux = photon_array.flux[:50] pa1.dxdz = photon_array.dxdz[:50] pa1.dydz = photon_array.dydz[:50] pa1.wavelength = photon_array.wavelength[:50] @@ -244,10 +246,10 @@ def test_photon_array(): assert pa2.time[17] == pa1.time[20] # Can choose not to copy flux - if hasattr(galsim, "_galsim"): - pa2.flux[27] = -1 - else: + if is_jax_galsim(): pa2._flux = pa2._flux.at[27].set(-1) + else: + pa2.flux[27] = -1 pa2.copyFrom(pa1, 27, 10, do_flux=False) assert pa2.flux[27] != pa1.flux[10] assert pa2.x[27] == pa1.x[10] @@ -261,16 +263,16 @@ def test_photon_array(): assert pa2.time[37] == pa1.time[8] # ... or the other arrays - if hasattr(galsim, "_galsim"): - pa2.dxdz[47] = pa2.dydz[47] = pa2.wavelength[47] = -1 - pa2.pupil_u[47] = pa2.pupil_v[47] = pa2.time[47] = -1 - else: + if is_jax_galsim(): pa2._dxdz = pa2._dxdz.at[47].set(-1) pa2._dydz = pa2._dydz.at[47].set(-1) pa2._wave = pa2._wave.at[47].set(-1) pa2._pupil_u = pa2._pupil_u.at[47].set(-1) pa2._pupil_v = pa2._pupil_v.at[47].set(-1) pa2._time = pa2._time.at[47].set(-1) + else: + pa2.dxdz[47] = pa2.dydz[47] = pa2.wavelength[47] = -1 + pa2.pupil_u[47] = pa2.pupil_v[47] = pa2.time[47] = -1 pa2.copyFrom(pa1, 47, 18, do_other=False) assert pa2.flux[47] == pa1.flux[18] assert pa2.x[47] == pa1.x[18] @@ -295,7 +297,9 @@ def test_photon_array(): # Error if indices are invalid assert_raises(ValueError, pa2.copyFrom, pa1, slice(50,None), slice(50,None)) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert_raises(ValueError, pa2.copyFrom, pa1, 100, 0) assert_raises(ValueError, pa2.copyFrom, pa1, 0, slice(None)) assert_raises(ValueError, pa2.copyFrom, pa1) @@ -1455,15 +1459,15 @@ def test_fromArrays(): flux[Nsplit:] ) - if hasattr(galsim, "_galsim"): - assert pa_batch.x is x - assert pa_batch.y is y - assert pa_batch.flux is flux - else: + if is_jax_galsim(): # jax-galsim never copies assert pa_batch.x is not x assert pa_batch.y is not y assert pa_batch.flux is not flux + else: + assert pa_batch.x is x + assert pa_batch.y is y + assert pa_batch.flux is flux np.testing.assert_array_equal(pa_batch.x, x) np.testing.assert_array_equal(pa_batch.y, y) np.testing.assert_array_equal(pa_batch.flux, flux) From c98711006f68b2879e9e6b735699d66e443ebc67 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 08:13:26 -0500 Subject: [PATCH 329/351] test: clean up for interpolated images --- tests/test_interpolatedimage.py | 34 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index c73aa526aa..45b7e90c31 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -369,12 +369,12 @@ def test_interpolant(): -(vm+1) * sici(np.pi*(vm+1))[0] -(vp-1) * sici(np.pi*(vp-1))[0] +(vp+1) * sici(np.pi*(vp+1))[0] ) / (2*np.pi) - if hasattr(galsim, "_galsim"): - np.testing.assert_allclose(ln.kval(x), true_kval, rtol=1.e-4, atol=1.e-8) - assert np.isclose(ln.kval(x[12]), true_kval[12]) - else: + if is_jax_galsim(): np.testing.assert_allclose(ln.kval(x), true_kval, rtol=3.0e-4, atol=3.0e-6) np.testing.assert_allclose(ln.kval(x[12]), true_kval[12], rtol=3.0e-4, atol=3.0e-6) + else: + np.testing.assert_allclose(ln.kval(x), true_kval, rtol=1.e-4, atol=1.e-8) + assert np.isclose(ln.kval(x[12]), true_kval[12]) # Base class is invalid. assert_raises(NotImplementedError, galsim.Interpolant) @@ -513,10 +513,15 @@ def test_exceptions(): galsim.InterpolatedImage(image=galsim.ImageF(5, 5)) # Image must be real type (F or D) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: with assert_raises(galsim.GalSimValueError): galsim.InterpolatedImage(image=galsim.ImageI(5, 5, scale=1)) + if is_jax_galsim(): + pass + else: # Image must have non-zero flux with assert_raises(galsim.GalSimValueError): galsim.InterpolatedImage(image=galsim.ImageF(5, 5, scale=1, init_value=0.)) @@ -1616,9 +1621,12 @@ def test_ii_shoot(): assert np.isclose(added_flux, obj.flux, rtol=rtol) assert np.isclose(im.array.sum(), obj.flux, rtol=rtol) photons2 = obj.makePhot(poisson_flux=False, rng=rng.duplicate()) - np.testing.assert_allclose(photons2.x, photons.x) - np.testing.assert_allclose(photons2.y, photons.y) - np.testing.assert_allclose(photons2.flux, photons.flux) + if is_jax_galsim(): + np.testing.assert_allclose(photons2.x, photons.x) + np.testing.assert_allclose(photons2.y, photons.y) + np.testing.assert_allclose(photons2.flux, photons.flux) + else: + assert photons2 == photons, "InterpolatedImage makePhot not equivalent to drawPhot" # Can treat as a convolution of a delta function and put it in a photon_ops list. delta = galsim.DeltaFunction(flux=flux) @@ -1640,10 +1648,10 @@ def test_ne(): # Copy ref_image and perturb it slightly in the middle, away from where the InterpolatedImage # repr string will report. perturb_image = ref_image.copy() - if hasattr(galsim, "_galsim"): - perturb_image.array[64, 64] *= 100 - else: + if is_jax_galsim(): perturb_image._array = perturb_image._array.at[64, 64].set(perturb_image._array[64, 64] * 100) + else: + perturb_image.array[64, 64] *= 100 obj2 = galsim.InterpolatedImage(perturb_image, flux=20, calculate_maxk=False, calculate_stepk=False) with galsim.utilities.printoptions(threshold=128*128): @@ -1859,7 +1867,9 @@ 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 hasattr(galsim, '_galsim'): + if is_jax_galsim(): + pass + else: import pickle prof_file = os.path.join( From 5337334314b1578699d367db224e53d3af469d53 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 08:50:41 -0500 Subject: [PATCH 330/351] test: clean up for noise tests --- tests/test_noise.py | 69 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/tests/test_noise.py b/tests/test_noise.py index 9ea78c9b5b..faaaefad0c 100644 --- a/tests/test_noise.py +++ b/tests/test_noise.py @@ -38,10 +38,10 @@ def test_deviate_noise(): u = galsim.UniformDeviate(testseed) uResult = np.empty((10,10)) # jax-galsim cannot fill arrays so it returns - if hasattr(galsim, "_galsim"): - u.generate(uResult) - else: + if is_jax_galsim(): uResult = u.generate(uResult) + else: + u.generate(uResult) noise = galsim.DeviateNoise(galsim.UniformDeviate(testseed)) @@ -105,10 +105,10 @@ def test_gaussian_noise(): g = galsim.GaussianDeviate(testseed, sigma=gSigma) gResult = np.empty((10,10)) # jax-galsim cannot fill arrays so it returns - if hasattr(galsim, "_galsim"): - g.generate(gResult) - else: + if is_jax_galsim(): gResult = g.generate(gResult) + else: + g.generate(gResult) noise = galsim.DeviateNoise(g) # Test filling an image @@ -285,21 +285,21 @@ def test_variable_gaussian_noise(): var_image = galsim.ImageD(galsim.BoundsI(0,9,0,9)) coords = np.ogrid[0:10, 0:10] # jax does not support item assignment - if hasattr(galsim, "_galsim"): - var_image.array[ (coords[0] + coords[1]) % 2 == 1 ] = gSigma1**2 - var_image.array[ (coords[0] + coords[1]) % 2 == 0 ] = gSigma2**2 - else: + if is_jax_galsim(): var_image._array = var_image.array.at[(coords[0] + coords[1]) % 2 == 1].set(gSigma1**2) var_image._array = var_image.array.at[(coords[0] + coords[1]) % 2 == 0].set(gSigma2**2) + else: + var_image.array[ (coords[0] + coords[1]) % 2 == 1 ] = gSigma1**2 + var_image.array[ (coords[0] + coords[1]) % 2 == 0 ] = gSigma2**2 print('var_image.array = ',var_image.array) g = galsim.GaussianDeviate(testseed, sigma=1.) vgResult = np.empty((10,10)) # jax-galsim cannot fill arrays so it returns - if hasattr(galsim, "_galsim"): - g.generate(vgResult) - else: + if is_jax_galsim(): vgResult = g.generate(vgResult) + else: + g.generate(vgResult) vgResult *= np.sqrt(var_image.array) # Test filling an image @@ -329,12 +329,12 @@ def test_variable_gaussian_noise(): mask1 = (big_coords[0] + big_coords[1]) % 2 == 0 mask2 = (big_coords[0] + big_coords[1]) % 2 == 1 # jax does not support item assignment - if hasattr(galsim, "_galsim"): - big_var_image.array[mask1] = gSigma1**2 - big_var_image.array[mask2] = gSigma2**2 - else: + if is_jax_galsim(): big_var_image._array = big_var_image.array.at[mask1].set(gSigma1**2) big_var_image._array = big_var_image.array.at[mask2].set(gSigma2**2) + else: + big_var_image.array[mask1] = gSigma1**2 + big_var_image.array[mask2] = gSigma2**2 big_vgn = galsim.VariableGaussianNoise(galsim.BaseDeviate(testseed), big_var_image) big_im = galsim.Image(2048,2048,dtype=float) @@ -342,9 +342,13 @@ def test_variable_gaussian_noise(): var = np.var(big_im.array) print('variance = ',var) print('getVar = ',big_vgn.var_image.array.mean()) - # jax galsim has a different RNG + if is_jax_galsim(): + # jax galsim has a different RNG + decimal = 0 + else: + decimal = 1 np.testing.assert_almost_equal( - var, big_vgn.var_image.array.mean(), 1 if hasattr(galsim, "_galsim") else 0, + var, big_vgn.var_image.array.mean(), decimal, err_msg='Realized variance for VariableGaussianNoise did not match var_image') # Check realized variance in each mask @@ -360,8 +364,13 @@ def test_variable_gaussian_noise(): big_im.addNoise(big_vgn) gal.withFlux(-1.e4).drawImage(image=big_im, add_to_image=True) var = np.var(big_im.array) + if is_jax_galsim(): + # jax galsim has a different RNG + decimal = 0 + else: + decimal = 1 np.testing.assert_almost_equal( - var, big_vgn.var_image.array.mean(), 1 if hasattr(galsim, "_galsim") else 0, + var, big_vgn.var_image.array.mean(), decimal, err_msg='VariableGaussianNoise wrong when already an object drawn on the image') # Check picklability @@ -400,10 +409,10 @@ def test_poisson_noise(): p = galsim.PoissonDeviate(testseed, mean=pMean) pResult = np.empty((10,10)) # jax does not support item assignment - if hasattr(galsim, "_galsim"): - p.generate(pResult) - else: + if is_jax_galsim(): pResult = p.generate(pResult) + else: + p.generate(pResult) noise = galsim.DeviateNoise(p) # Test filling an image @@ -572,13 +581,7 @@ def test_ccdnoise(): sky = 50 # Tabulated results for the above settings and testseed value. - if hasattr(galsim, "_galsim"): - cResultS = np.array([[44, 47], [50, 49]], dtype=np.int16) - cResultI = np.array([[44, 47], [50, 49]], dtype=np.int32) - cResultF = np.array([[44.45332718, 47.79725266], [50.67744064, 49.58272934]], dtype=np.float32) - cResultD = np.array([[44.453328440057618, 47.797254142519577], - [50.677442088335162, 49.582730949808081]],dtype=np.float64) - else: + if is_jax_galsim(): # jax-galsim has a different RNG cResultS = np.array([[42, 52], [49, 45]], dtype=np.int16) # noqa: F841 cResultI = np.array([[42, 52], [49, 45]], dtype=np.int32) # noqa: F841 @@ -590,6 +593,12 @@ def test_ccdnoise(): [42.42870031326479, 52.42875718917211], [49.016050296441094, 45.61003745208172] ], dtype=np.float64) + else: + cResultS = np.array([[44, 47], [50, 49]], dtype=np.int16) + cResultI = np.array([[44, 47], [50, 49]], dtype=np.int32) + cResultF = np.array([[44.45332718, 47.79725266], [50.67744064, 49.58272934]], dtype=np.float32) + cResultD = np.array([[44.453328440057618, 47.797254142519577], + [50.677442088335162, 49.582730949808081]],dtype=np.float64) for i in range(4): prec = eval("precision"+typestrings[i]) From 8454028531ea2f15cc6db9be23e3f666b33583c0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 09:16:42 -0500 Subject: [PATCH 331/351] test: try using the olde value --- tests/test_wcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 072d98407a..f945e35598 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2465,8 +2465,8 @@ def test_inverseab_convergence(): assert np.isclose(dec1, dec) # Now one that should fail, since it's well outside the applicable area for the SIP polynomials. - ra = -200.1 - dec = 70.45 + ra = 2.1 + dec = -0.45 if is_jax_galsim(): x, y = wcs.radecToxy(ra, dec, units="radians") assert np.all(np.isnan(x)) From 101a36e8a5caa82a2a2806cd2827cfdead70ee0f Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 12:31:25 -0500 Subject: [PATCH 332/351] test: clean up tests for draw --- tests/test_draw.py | 83 +++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 55dc7ab55a..07cbc8aad3 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -380,7 +380,9 @@ def test_drawImage(): os.path.join(os.path.dirname(__file__), 'fits_files/tpv.fits'))) assert_raises(ValueError, obj.drawImage, bounds=galsim.BoundsI()) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert_raises(ValueError, obj.drawImage, image=im10, gain=0.) assert_raises(ValueError, obj.drawImage, image=im10, gain=-1.) assert_raises(ValueError, obj.drawImage, image=im10, area=0.) @@ -392,7 +394,9 @@ def test_drawImage(): # These options are invalid unless metho=phot assert_raises(TypeError, obj.drawImage, image=im10, n_photons=3) assert_raises(TypeError, obj.drawImage, rng=galsim.BaseDeviate(234)) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, obj.drawImage, max_extra_noise=23) assert_raises(TypeError, obj.drawImage, poisson_flux=True) assert_raises(TypeError, obj.drawImage, maxN=10000) @@ -523,14 +527,14 @@ def test_drawKImage(): """Test the various optional parameters to the drawKImage function. In particular test the parameters image, and scale in various combinations. """ - if hasattr(galsim, "_galsim"): - maxk_threshold = 1.e-4 - N = 1174 - Ns = 37 - else: + if is_jax_galsim(): maxk_threshold = 1.e-3 N = 880 Ns = 28 + else: + maxk_threshold = 1.e-4 + N = 1174 + Ns = 37 # We use a Moffat profile with beta = 1.5, since its real-space profile is # flux / (2 pi rD^2) * (1 + (r/rD)^2)^3/2 @@ -1109,31 +1113,31 @@ def test_shoot(): # in exact arithmetic. We had an assert there which blew up in a not very nice way. obj = galsim.Gaussian(sigma=0.2398318) + 0.1*galsim.Gaussian(sigma=0.47966352) obj = obj.withFlux(100001) - if hasattr(galsim, "_galsim"): - image1 = galsim.ImageF(32,32, init_value=100) - else: + if is_jax_galsim(): # jax galsim needs double images here image1 = galsim.ImageD(32,32, init_value=100) + else: + image1 = galsim.ImageF(32,32, init_value=100) rng = galsim.BaseDeviate(1234) obj.drawImage(image1, method='phot', poisson_flux=False, add_to_image=True, rng=rng, maxN=100000) # The test here is really just that it doesn't crash. # But let's do something to check correctness. - if hasattr(galsim, "_galsim"): - image2 = galsim.ImageF(32,32) - else: + if is_jax_galsim(): # jax galsim needs double images here image2 = galsim.ImageD(32,32) + else: + image2 = galsim.ImageF(32,32) rng = galsim.BaseDeviate(1234) obj.drawImage(image2, method='phot', poisson_flux=False, add_to_image=False, rng=rng, maxN=100000) image2 += 100 - if hasattr(galsim, "_galsim"): - np.testing.assert_array_almost_equal(image2.array, image1.array, decimal=12) - else: + if is_jax_galsim(): # jax galsim works not as well np.testing.assert_array_almost_equal(image2.array, image1.array, decimal=10) + else: + np.testing.assert_array_almost_equal(image2.array, image1.array, decimal=12) # Also check that you get the same answer with a smaller maxN. image3 = galsim.ImageF(32,32, init_value=100) @@ -1148,7 +1152,9 @@ def test_shoot(): # Warns if flux is 1 and n_photons not given. psf = galsim.Gaussian(sigma=3) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: with assert_warns(galsim.GalSimWarning): psf.drawImage(method='phot') with assert_warns(galsim.GalSimWarning): @@ -1213,20 +1219,26 @@ def test_drawImage_area_exptime(): # Shooting with flux=1 raises a warning. obj1 = obj.withFlux(1) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: with assert_warns(galsim.GalSimWarning): obj1.drawImage(method='phot') # But not if we explicitly tell it to shoot 1 photon with assert_raises(AssertionError): assert_warns(galsim.GalSimWarning, obj1.drawImage, method='phot', n_photons=1) # Likewise for makePhot - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: with assert_warns(galsim.GalSimWarning): obj1.makePhot() with assert_raises(AssertionError): assert_warns(galsim.GalSimWarning, obj1.makePhot, n_photons=1) # And drawPhot - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: with assert_warns(galsim.GalSimWarning): obj1.drawPhot(im1) with assert_raises(AssertionError): @@ -1247,7 +1259,11 @@ def test_fft(): [4,6,8,4], [2,4,6,6] ], xmin=-2, ymin=-2, dtype=dt, scale=0.1) - if hasattr(galsim, "_galsim") or dt not in [np.complex128, complex]: + if is_gjax_galsim() and 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: kim = xim.calculate_fft() xim2 = kim.calculate_inverse_fft() np.testing.assert_array_almost_equal(xim.array, xim2.array) @@ -1282,7 +1298,11 @@ def test_fft(): xim2 = galsim.Image([ [2,4,6], [4,6,8] ], xmin=-2, ymin=-1, dtype=dt, scale=0.1) - if hasattr(galsim, "_galsim") or dt not in [np.complex128, complex]: + if is_gjax_galsim() and 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: kim = xim.calculate_fft() kim2 = xim2.calculate_fft() np.testing.assert_array_almost_equal(kim.array, kim2.array) @@ -1305,14 +1325,14 @@ def test_fft(): # Now use drawKImage (as above in test_drawKImage) to get a more realistic k-space image # NB. It is useful to have this come out not a multiple of 4, since some of the # calculation needs to be different when N/2 is odd. - if hasattr(galsim, "_galsim"): - maxk_threshold = 1.e-4 - N = 1174 - Nfft = 1536 - else: + if is_jax_galsim(): maxk_threshold = 0.78e-3 N = 912 Nfft = 1024 + else: + maxk_threshold = 1.e-4 + N = 1174 + Nfft = 1536 obj = galsim.Moffat(flux=test_flux, beta=1.5, scale_radius=0.5) obj = obj.withGSParams(maxk_threshold=maxk_threshold) im1 = obj.drawKImage() @@ -1562,9 +1582,12 @@ def test_np_fft(): def round_cast(array, dt): # array.astype(dt) doesn't round to the nearest for integer types. # This rounds first if dt is integer and then casts. - # NOTE JAX doesn't round to the nearest int when drawing - if hasattr(galsim, "_galsim") and dt(0.5) != 0.5: - array = np.around(array) + if is_jax_galsim(): + # NOTE JAX doesn't round to the nearest int when drawing + pass + else: + if dt(0.5) != 0.5: + array = np.around(array) return array.astype(dt) @timer From 682f5923a4048fc199cfc3fd10b713f1338f2b67 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 12:51:09 -0500 Subject: [PATCH 333/351] test: clean up tests for draw --- tests/test_draw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index 07cbc8aad3..d3cf7b5053 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1259,7 +1259,7 @@ def test_fft(): [4,6,8,4], [2,4,6,6] ], xmin=-2, ymin=-2, dtype=dt, scale=0.1) - if is_gjax_galsim() and dt not in [np.complex128, complex]: + if is_jax_galsim() and 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) @@ -1298,7 +1298,7 @@ def test_fft(): xim2 = galsim.Image([ [2,4,6], [4,6,8] ], xmin=-2, ymin=-1, dtype=dt, scale=0.1) - if is_gjax_galsim() and dt not in [np.complex128, complex]: + if is_jax_galsim() and dt not in [np.complex128, complex]: kim = xim.calculate_fft() kim2 = xim2.calculate_fft() np.testing.assert_array_almost_equal(kim.array, kim2.array) From 63855f9331997010403fe84f79fca2437d6d7662 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 13:21:48 -0500 Subject: [PATCH 334/351] test: clean up tests for draw --- tests/test_draw.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/test_draw.py b/tests/test_draw.py index d3cf7b5053..e2077c5c73 100644 --- a/tests/test_draw.py +++ b/tests/test_draw.py @@ -1259,10 +1259,11 @@ def test_fft(): [4,6,8,4], [2,4,6,6] ], xmin=-2, ymin=-2, dtype=dt, scale=0.1) - if is_jax_galsim() and 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) + 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: kim = xim.calculate_fft() xim2 = kim.calculate_inverse_fft() @@ -1298,10 +1299,11 @@ 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() and dt not in [np.complex128, complex]: - kim = xim.calculate_fft() - kim2 = xim2.calculate_fft() - np.testing.assert_array_almost_equal(kim.array, kim2.array) + 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: kim = xim.calculate_fft() kim2 = xim2.calculate_fft() From 15943e2ae68f0dc470cf4361310a7816af608e62 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 13:54:59 -0500 Subject: [PATCH 335/351] test: clean up tests for image --- tests/test_image.py | 226 ++++++++++++++++++++++++-------------------- 1 file changed, 121 insertions(+), 105 deletions(-) diff --git a/tests/test_image.py b/tests/test_image.py index bd9f2ca50f..4e6302508c 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -103,7 +103,9 @@ def test_Image_basic(): np.testing.assert_array_equal(im1.array, 0.) assert im1.array.shape == (nrow,ncol) assert im1.array.dtype.type == np_array_type - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: # jax arrays do not have flags assert im1.array.flags.writeable == True assert im1.array.flags.c_contiguous == True @@ -203,32 +205,32 @@ def test_Image_basic(): assert im1.view()(x,y) == value assert im1.view()(galsim.PositionI(x,y)) == value assert im1.view(make_const=True)(x,y) == value - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2(x,y) == value - else: assert im2(x,y) != value + else: + assert im2(x,y) == value assert im2_view(x,y) == value - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2_cview(x,y) == value - else: assert im2_cview(x,y) != value + else: + assert im2_cview(x,y) == value assert im1.conjugate(x,y) == value if tchar[i][0] == 'C': # complex conjugate is not a view into the original. assert im2_conj(x,y) == 23 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2.conjugate(x,y) == value - else: assert im2.conjugate(x,y) != value + else: + assert im2.conjugate(x,y) == value else: - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2_conj(x,y) == value - else: assert im2_conj(x,y) != value + else: + assert im2_conj(x,y) == value value2 = 53 + 12*x - 19*y if tchar[i] in ['US', 'UI']: @@ -238,32 +240,32 @@ def test_Image_basic(): assert im1.getValue(x,y) == value2 assert im1.view().getValue(x=x, y=y) == value2 assert im1.view(make_const=True).getValue(x,y) == value2 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2.getValue(x=x, y=y) == value2 - else: assert im2.getValue(x=x, y=y) != value2 + else: + assert im2.getValue(x=x, y=y) == value2 assert im2_view.getValue(x,y) == value2 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2_cview._getValue(x,y) == value2 - else: assert im2_cview._getValue(x,y) != value2 + else: + assert im2_cview._getValue(x,y) == value2 assert im1.real(x,y) == value2 assert im1.view().real(x,y) == value2 assert im1.view(make_const=True).real(x,y) == value2.real - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2.real(x,y) == value2.real - else: assert im2.real(x,y) != value2.real + else: + assert im2.real(x,y) == value2.real assert im2_view.real(x,y) == value2.real - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2_cview.real(x,y) == value2.real - else: assert im2_cview.real(x,y) != value2.real + else: + assert im2_cview.real(x,y) == value2.real assert im1.imag(x,y) == 0 assert im1.view().imag(x,y) == 0 assert im1.view(make_const=True).imag(x,y) == 0 @@ -271,23 +273,26 @@ def test_Image_basic(): assert im2_view.imag(x,y) == 0 assert im2_cview.imag(x,y) == 0 - value3 = 10*x + y + 111 + if is_jax_galsim(): + value3 = 10*x + y + 111 + else: + value3 = 10*x + y im1.addValue(x,y, np.int64(value3-value2)) im2_view[x,y] += np.int64(value3-value2) assert im1[galsim.PositionI(x,y)] == value3 assert im1.view()[x,y] == value3 assert im1.view(make_const=True)[galsim.PositionI(x,y)] == value3 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2[x,y] == value3 - else: assert im2[x,y] != value3 + else: + assert im2[x,y] == value3 assert im2_view[galsim.PositionI(x,y)] == value3 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # no real views in jax - assert im2_cview[x,y] == value3 - else: assert im2_cview[x,y] != value3 + else: + assert im2_cview[x,y] == value3 # Setting or getting the value outside the bounds should throw an exception. assert_raises(galsim.GalSimBoundsError,im1.setValue,0,0,1) @@ -398,15 +403,19 @@ def test_Image_basic(): assert im2.bounds == bounds for y in range(1,nrow+1): for x in range(1,ncol+1): - value3 = 10*x+y + 111 + if is_jax_galsim(): + value3 = 10*x+y + 111 + else: + value3 = 10*x+y assert im1(x+dx,y+dy) == value3 assert im1_view(x,y) == value3 - if hasattr(galsim, "_galsim"): - assert im2(x,y) == value3 - else: + if is_jax_galsim(): assert im2(x,y) != value3 + else: + assert im2(x,y) == value3 assert im2_view(x+dx,y+dy) == value3 - value3 = 10*x+y + if is_jax_galsim(): + value3 = 10*x+y assert im3_view(x+dx,y+dy) == value3 assert_raises(TypeError, im1.shift, dx) @@ -2461,11 +2470,11 @@ def test_Image_view(): assert imv.bounds == im.bounds imv.setValue(11,19, 20) assert imv(11,19) == 20 - if hasattr(galsim, "_galsim"): - assert im(11,19) == 20 - else: + if is_jax_galsim(): # jax-galsim does not support views assert im(11,19) != 20 + else: + assert im(11,19) == 20 check_pickle(im) check_pickle(imv) @@ -2477,11 +2486,11 @@ def test_Image_view(): assert imv.bounds == galsim.BoundsI(0,24,0,24) imv.setValue(10,18, 30) assert imv(10,18) == 30 - if hasattr(galsim, "_galsim"): - assert im(11,19) == 30 - else: + if is_jax_galsim(): # jax-galsim does not support views assert im(11,19) != 20 + else: + assert im(11,19) == 30 imv2 = im.view() imv2.setOrigin(0,0) assert imv.bounds == imv2.bounds @@ -2497,11 +2506,11 @@ def test_Image_view(): assert imv.bounds == galsim.BoundsI(-12,12,-12,12) imv.setValue(-2,6, 40) assert imv(-2,6) == 40 - if hasattr(galsim, "_galsim"): - assert im(11,19) == 40 - else: + if is_jax_galsim(): # jax-galsim does not support views assert im(11,19) != 40 + else: + assert im(11,19) == 40 imv2 = im.view() imv2.setCenter(0,0) assert imv.bounds == imv2.bounds @@ -2518,11 +2527,11 @@ def test_Image_view(): assert imv.bounds == im.bounds imv.setValue(11,19, 50) assert imv(11,19) == 50 - if hasattr(galsim, "_galsim"): - assert im(11,19) == 50 - else: + if is_jax_galsim(): # jax-galsim does not support views assert im(11,19) != 50 + else: + assert im(11,19) == 50 imv2 = im.view() with assert_raises(galsim.GalSimError): imv2.scale = 0.17 # Invalid if wcs is not PixelScale @@ -2540,11 +2549,11 @@ def test_Image_view(): assert imv.bounds == im.bounds imv.setValue(11,19, 60) assert imv(11,19) == 60 - if hasattr(galsim, "_galsim"): - assert im(11,19) == 60 - else: + if is_jax_galsim(): # jax-galsim does not support views assert im(11,19) != 60 + else: + assert im(11,19) == 60 imv2 = im.view() imv2.wcs = galsim.JacobianWCS(0.,0.23,-0.23,0.) assert imv.bounds == imv2.bounds @@ -2635,8 +2644,10 @@ def test_copy(): assert im(3,8) != 11. # If copy=False is specified, then it shares the same array - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # jax-galsim does not support references + pass + else: im3b = galsim.Image(im, copy=False) assert im3b.wcs == im.wcs assert im3b.bounds == im.bounds @@ -2694,8 +2705,10 @@ def test_copy(): assert im_slice(2,3) != 11. # Can also copy by giving the array and specify copy=True - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # jax-galsim does not support references + pass + else: im10 = galsim.Image(im.array, bounds=im.bounds, wcs=im.wcs, copy=False) assert im10.wcs == im.wcs assert im10.bounds == im.bounds @@ -2753,79 +2766,82 @@ def test_complex_image(): assert im1(x,y) == value assert im1.view()(x,y) == value assert im1.view(make_const=True)(x,y) == value - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2(x,y) == value - else: + if is_jax_galsim(): + # jax galsim does not support views assert im2(x,y) != value - assert im2_view(x,y) == value - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2_cview(x,y) == value else: + assert im2(x,y) == value + assert im2_view(x,y) == value + if is_jax_galsim(): + # jax galsim does not support views assert im2_cview(x,y) != value + else: + assert im2_cview(x,y) == value assert im1.conjugate(x,y) == np.conjugate(value) # complex conjugate is not a view into the original. assert im2_conj(x,y) == 23 - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2.conjugate(x,y) == np.conjugate(value) - else: + if is_jax_galsim(): + # jax galsim does not support views assert im2.conjugate(x,y) != np.conjugate(value) + else: + assert im2.conjugate(x,y) == np.conjugate(value) - value2 = 400000 + 10*x + y + 20j*x + 2j*y + if is_jax_galsim(): + value2 = 400000 + 10*x + y + 20j*x + 2j*y + else: + value2 = 10*x + y + 20j*x + 2j*y im1.setValue(x,y, value2) im2_view.setValue(x=x, y=y, value=value2) assert im1(x,y) == value2 assert im1.view()(x,y) == value2 assert im1.view(make_const=True)(x,y) == value2 - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2(x,y) == value2 - else: + if is_jax_galsim(): + # jax galsim does not support views assert im2(x,y) != value2 - assert im2_view(x,y) == value2 - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2_cview(x,y) == value2 else: + assert im2(x,y) == value2 + assert im2_view(x,y) == value2 + if is_jax_galsim(): + # jax galsim does not support views assert im2_cview(x,y) != value2 + else: + assert im2_cview(x,y) == value2 assert im1.real(x,y) == value2.real assert im1.view().real(x,y) == value2.real assert im1.view(make_const=True).real(x,y) == value2.real - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2.real(x,y) == value2.real - else: + if is_jax_galsim(): + # jax galsim does not support views assert im2.real(x,y) != value2.real - assert im2_view.real(x,y) == value2.real - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2_cview.real(x,y) == value2.real else: + assert im2.real(x,y) == value2.real + assert im2_view.real(x,y) == value2.real + if is_jax_galsim(): + # jax galsim does not support views assert im2_cview.real(x,y) != value2.real + else: + assert im2_cview.real(x,y) == value2.real assert im1.imag(x,y) == value2.imag assert im1.view().imag(x,y) == value2.imag assert im1.view(make_const=True).imag(x,y) == value2.imag - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2.imag(x,y) == value2.imag - else: + if is_jax_galsim(): + # jax galsim does not support views assert im2.imag(x,y) != value2.imag - assert im2_view.imag(x,y) == value2.imag - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2_cview.imag(x,y) == value2.imag else: + assert im2.imag(x,y) == value2.imag + assert im2_view.imag(x,y) == value2.imag + if is_jax_galsim(): + # jax galsim does not support views assert im2_cview.imag(x,y) != value2.imag - assert im1.conjugate(x,y) == np.conjugate(value2) - # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im2.conjugate(x,y) == np.conjugate(value2) else: + assert im2_cview.imag(x,y) == value2.imag + assert im1.conjugate(x,y) == np.conjugate(value2) + if is_jax_galsim(): + # jax galsim does not support views assert im2.conjugate(x,y) != np.conjugate(value2) + else: + assert im2.conjugate(x,y) == np.conjugate(value2) rvalue3 = 12*x + y ivalue3 = x + 21*y @@ -2835,16 +2851,7 @@ def test_complex_image(): im2_view.real.setValue(x,y, rvalue3) im2_view.imag.setValue(x,y, ivalue3) # jax galsim does not support views - if hasattr(galsim, "_galsim"): - assert im1(x,y) == value3 - assert im1.view()(x,y) == value3 - assert im1.view(make_const=True)(x,y) == value3 - assert im2(x,y) == value3 - assert im2_view(x,y) == value3 - assert im2_cview(x,y) == value3 - assert im1.conjugate(x,y) == np.conjugate(value3) - assert im2.conjugate(x,y) == np.conjugate(value3) - else: + if is_jax_galsim(): assert im1(x,y) != value3 assert im1.view()(x,y) != value3 assert im1.view(make_const=True)(x,y) != value3 @@ -2853,6 +2860,15 @@ def test_complex_image(): assert im2_cview(x,y) != value3 assert im1.conjugate(x,y) != np.conjugate(value3) assert im2.conjugate(x,y) != np.conjugate(value3) + else: + assert im1(x,y) == value3 + assert im1.view()(x,y) == value3 + assert im1.view(make_const=True)(x,y) == value3 + assert im2(x,y) == value3 + assert im2_view(x,y) == value3 + assert im2_cview(x,y) == value3 + assert im1.conjugate(x,y) == np.conjugate(value3) + assert im2.conjugate(x,y) == np.conjugate(value3) # Check view of given data im3_view = galsim.Image((1+2j)*ref_array.astype(complex)) From 3cd63b673e2258569e02ab15d39299d635b99bc9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 23 Aug 2024 15:16:28 -0500 Subject: [PATCH 336/351] test: clean up tests for utils --- tests/test_utilities.py | 109 +++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index b766c656e4..41bec8252c 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -35,7 +35,9 @@ def test_pos(): assert pi1.y == 23 assert isinstance(pi1.x, int) assert isinstance(pi1.y, int) - if hasattr(galsim, '_galsim'): + if is_jax_galsim(): + pass + else: assert isinstance(pi1._p, galsim._galsim.PositionI) pi2 = galsim.PositionI((11,23)) @@ -44,10 +46,10 @@ def test_pos(): pi5 = galsim.PositionI(galsim.PositionD(11.0,23.0)) pi6 = galsim.PositionD(11.3,23.4).round() pi7 = pi2.round() - if hasattr(galsim, '_galsim'): - pi8 = galsim._PositionI(11,23) - else: + if is_jax_galsim(): pi8 = galsim.PositionI(11,23) + else: + pi8 = galsim._PositionI(11,23) assert pi2 == pi1 assert pi3 == pi1 assert pi4 == pi1 @@ -65,7 +67,9 @@ def test_pos(): assert pd1.y == 23. assert isinstance(pd1.x, float) assert isinstance(pd1.y, float) - if hasattr(galsim, '_galsim'): + if is_jax_galsim(): + pass + else: assert isinstance(pd1._p, galsim._galsim.PositionD) pd2 = galsim.PositionD((11,23)) @@ -73,10 +77,10 @@ def test_pos(): pd4 = galsim.PositionD(pd1) pd5 = galsim.PositionD(pi1) pd6 = galsim.PositionD(galsim.PositionD(11.3,23.4).round()) - if hasattr(galsim, '_galsim'): - pd7 = galsim._PositionD(11.0,23.0) - else: + if is_jax_galsim(): pd7 = galsim.PositionD(11.0,23.0) + else: + pd7 = galsim._PositionD(11.0,23.0) assert pd2 == pd1 assert pd3 == pd1 assert pd4 == pd1 @@ -94,7 +98,9 @@ def test_pos(): assert_raises(TypeError, galsim.PositionI, x=11) assert_raises(TypeError, galsim.PositionD, x=11, y=23, z=17) assert_raises(TypeError, galsim.PositionI, 11, 23, x=13, z=21) - if hasattr(galsim, '_galsim'): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, galsim.PositionI, 11, 23.5) assert_raises(TypeError, galsim.PositionD, 11) @@ -103,10 +109,7 @@ def test_pos(): assert_raises(TypeError, galsim.PositionD, x=11) assert_raises(TypeError, galsim.PositionD, x=11, y=23, z=17) assert_raises(TypeError, galsim.PositionD, 11, 23, x=13, z=21) - try: - assert_raises(ValueError, galsim.PositionD, 11, "blue") - except Exception: - assert_raises(TypeError, galsim.PositionD, 11, "blue") + assert_raises((ValueError, TypeError), galsim.PositionD, 11, "blue") # Can't use base class directly. assert_raises(TypeError, galsim.Position, 11, 23) @@ -182,7 +185,9 @@ def test_bounds(): assert isinstance(bi1.xmax, int) assert isinstance(bi1.ymin, int) assert isinstance(bi1.ymax, int) - if hasattr(galsim, '_galsim'): + if is_jax_galsim(): + pass + else: assert isinstance(bi1._b, galsim._galsim.BoundsI) bi2 = galsim.BoundsI(galsim.PositionI(11,17), galsim.PositionI(23,50)) @@ -196,10 +201,10 @@ def test_bounds(): bi10 = galsim.BoundsI() + galsim.PositionI(11,17) + galsim.PositionI(23,50) bi11 = galsim.BoundsI(galsim.BoundsD(11.,23.,17.,50.)) bi12 = galsim.BoundsI(xmin=11,ymin=17,xmax=23,ymax=50) - if hasattr(galsim, '_galsim'): - bi13 = galsim._BoundsI(11,23,17,50) - else: + if is_jax_galsim(): bi13 = galsim.BoundsI(11,23,17,50) + else: + bi13 = galsim._BoundsI(11,23,17,50) bi14 = galsim.BoundsI() bi14 += galsim.PositionI(11,17) bi14 += galsim.PositionI(23,50) @@ -223,7 +228,9 @@ def test_bounds(): assert_floatlike(bd1.xmax) assert_floatlike(bd1.ymin) assert_floatlike(bd1.ymax) - if hasattr(galsim, '_galsim'): + if is_jax_galsim(): + pass + else: assert isinstance(bd1._b, galsim._galsim.BoundsD) bd2 = galsim.BoundsD(galsim.PositionI(11,17), galsim.PositionI(23,50)) @@ -237,10 +244,10 @@ def test_bounds(): bd10 = galsim.BoundsD() + galsim.PositionD(11,17) + galsim.PositionD(23,50) bd11 = galsim.BoundsD(galsim.BoundsI(11,23,17,50)) bd12 = galsim.BoundsD(xmin=11.0,ymin=17.0,xmax=23.0,ymax=50.0) - if hasattr(galsim, '_galsim'): - bd13 = galsim._BoundsD(11,23,17,50) - else: + if is_jax_galsim(): bd13 = galsim.BoundsD(11,23,17,50) + else: + bd13 = galsim._BoundsD(11,23,17,50) bd14 = galsim.BoundsD() bd14 += galsim.PositionD(11.,17.) bd14 += galsim.PositionD(23,50) @@ -261,7 +268,9 @@ def test_bounds(): assert_raises(TypeError, galsim.BoundsI, 11, 23, 9, 12, 59) assert_raises(TypeError, galsim.BoundsI, xmin=11, xmax=23, ymin=17, ymax=50, z=23) assert_raises(TypeError, galsim.BoundsI, xmin=11, xmax=50) - if hasattr(galsim, '_galsim'): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, galsim.BoundsI, 11, 23.5, 17, 50.9) assert_raises(TypeError, galsim.BoundsI, 11, 23, 9, 12, xmin=19, xmax=2) with assert_raises(TypeError): @@ -273,8 +282,10 @@ def test_bounds(): assert_raises(TypeError, galsim.BoundsD, 11, 23, 9, 12, 59) assert_raises(TypeError, galsim.BoundsD, xmin=11, xmax=23, ymin=17, ymax=50, z=23) assert_raises(TypeError, galsim.BoundsD, xmin=11, xmax=50) - if hasattr(galsim, '_galsim'): + if is_jax_galsim(): # jax doesn't raise for this + pass + else: assert_raises(ValueError, galsim.BoundsD, 11, 23, 17, "blue") assert_raises(TypeError, galsim.BoundsD, 11, 23, 9, 12, xmin=19, xmax=2) with assert_raises(TypeError): @@ -396,14 +407,18 @@ def test_bounds(): assert galsim.BoundsD() == galsim.BoundsD() + galsim.BoundsD() assert galsim.BoundsD().area() == 0 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert galsim.BoundsI(23, 11, 17, 50) == galsim.BoundsI() assert galsim.BoundsI(11, 23, 50, 17) == galsim.BoundsI() assert galsim.BoundsD(23, 11, 17, 50) == galsim.BoundsD() assert galsim.BoundsD(11, 23, 50, 17) == galsim.BoundsD() - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # jax doesn't raise for these things + pass + else: assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsI(), 'center') assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsD(), 'center') assert_raises(galsim.GalSimUndefinedBoundsError, getattr, galsim.BoundsI(), 'true_center') @@ -1135,10 +1150,10 @@ def test_horner(): # Make a random list of values to test x = np.empty(20) rng = galsim.UniformDeviate(1234) - if hasattr(galsim, "_galsim"): - rng.generate(x) - else: + if is_jax_galsim(): x = rng.generate(x) + else: + rng.generate(x) # Check against the direct calculation truth = coef[0] + coef[1]*x + coef[2]*x**2 + coef[3]*x**3 + coef[4]*x**4 @@ -1192,10 +1207,10 @@ def test_horner(): # Check length > 64 xx = np.empty(2000) - if hasattr(galsim, "_galsim"): - rng.generate(xx) - else: + if is_jax_galsim(): xx = rng.generate(xx) + else: + rng.generate(xx) result = galsim.utilities.horner(xx, coef) np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval(xx,coef)) @@ -1219,12 +1234,12 @@ def test_horner2d(): x = np.empty(20) y = np.empty(20) rng = galsim.UniformDeviate(1234) - if hasattr(galsim, "_galsim"): - rng.generate(x) - rng.generate(y) - else: + if is_jax_galsim(): x = rng.generate(x) y = rng.generate(y) + else: + rng.generate(x) + rng.generate(y) # Check against the direct calculation truth = coef[0,0] + coef[0,1]*y + coef[0,2]*y**2 + coef[0,3]*y**3 + coef[0,4]*y**4 @@ -1287,12 +1302,12 @@ def test_horner2d(): # Check length > 64 xx = np.empty(2000) yy = np.empty(2000) - if hasattr(galsim, "_galsim"): - rng.generate(xx) - rng.generate(yy) - else: + if is_jax_galsim(): xx = rng.generate(xx) yy = rng.generate(yy) + else: + rng.generate(xx) + rng.generate(yy) result = galsim.utilities.horner2d(xx, yy, coef) np.testing.assert_array_almost_equal(result, np.polynomial.polynomial.polyval2d(xx,yy,coef)) @@ -1347,22 +1362,22 @@ def test_horner_complex(): rx = np.empty(20) ry = np.empty(20) rng = galsim.UniformDeviate(1234) - if hasattr(galsim, "_galsim"): - rng.generate(rx) - rng.generate(ry) - else: + if is_jax_galsim(): rx = rng.generate(rx) ry = rng.generate(ry) + else: + rng.generate(rx) + rng.generate(ry) ix = np.empty(20) iy = np.empty(20) rng = galsim.UniformDeviate(1234) - if hasattr(galsim, "_galsim"): - rng.generate(ix) - rng.generate(iy) - else: + if is_jax_galsim(): ix = rng.generate(ix) iy = rng.generate(iy) + else: + rng.generate(ix) + rng.generate(iy) x = rx + 1j*ix y = ry + 1j*iy From 9a5ab87d8045c4268f26f6d6adab410b7049710f Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 26 Aug 2024 14:38:29 -0500 Subject: [PATCH 337/351] test: clean up random tests --- tests/test_random.py | 400 +++++++++++++++++++++++-------------------- 1 file changed, 210 insertions(+), 190 deletions(-) diff --git a/tests/test_random.py b/tests/test_random.py index d0e78fe319..5fbd90b43f 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -47,7 +47,7 @@ testseed = 1000 # seed used for UniformDeviate for all tests # Warning! If you change testseed, then all of the *Result variables below must change as well. -if os.environ.get("JAX_GALSIM_TESTING", "0") == "1": +if is_jax_galsim(): # the right answer for the first three uniform deviates produced from testseed uResult = (0.0160653916, 0.228817832, 0.1609966951) @@ -252,20 +252,20 @@ def test_uniform(): # Test generate u.seed(testseed) test_array = np.empty(3) - if hasattr(galsim, "_galsim"): - u.generate(test_array) - else: + if is_jax_galsim(): test_array = u.generate(test_array) + else: + u.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(uResult), precision, err_msg='Wrong uniform random number sequence from generate.') # Test add_generate u.seed(testseed) - if hasattr(galsim, "_galsim"): - u.add_generate(test_array) - else: + if is_jax_galsim(): test_array = u.add_generate(test_array) + else: + u.add_generate(test_array) np.testing.assert_array_almost_equal( test_array, 2.*np.array(uResult), precision, err_msg='Wrong uniform random number sequence from generate.') @@ -273,20 +273,20 @@ def test_uniform(): # Test generate with a float32 array u.seed(testseed) test_array = np.empty(3, dtype=np.float32) - if hasattr(galsim, "_galsim"): - u.generate(test_array) - else: + if is_jax_galsim(): test_array = u.generate(test_array) + else: + u.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(uResult), precisionF, err_msg='Wrong uniform random number sequence from generate.') # Test add_generate u.seed(testseed) - if hasattr(galsim, "_galsim"): - u.add_generate(test_array) - else: + if is_jax_galsim(): test_array = u.add_generate(test_array) + else: + u.add_generate(test_array) np.testing.assert_array_almost_equal( test_array, 2.*np.array(uResult), precisionF, err_msg='Wrong uniform random number sequence from generate.') @@ -297,26 +297,26 @@ def test_uniform(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - if hasattr(galsim, "_galsim"): - u1.generate(v1) - else: + if is_jax_galsim(): v1 = u1.generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - u2.generate(v2) else: + u1.generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = u2.generate(v2) + else: + u2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - if hasattr(galsim, "_galsim"): - u1.add_generate(v1) - else: + if is_jax_galsim(): v1 = u1.add_generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - u2.add_generate(v2) else: + u1.add_generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = u2.add_generate(v2) + else: + u2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability @@ -337,8 +337,10 @@ def test_uniform(): assert u1 != u2, "Consecutive UniformDeviate(None) compared equal!" # We shouldn't be able to construct a UniformDeviate from anything but a BaseDeviate, int, str, # or None. - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): # jax galsim doesn't test this + pass + else: assert_raises(TypeError, galsim.UniformDeviate, dict()) assert_raises(TypeError, galsim.UniformDeviate, list()) assert_raises(TypeError, galsim.UniformDeviate, set()) @@ -387,7 +389,11 @@ def test_gaussian(): v1,v2 = g(),g2() print('after %d vals, next one is %s, %s'%(nvals,v1,v2)) assert v1 == v2 - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + # jax doesn't have this issue + assert g.has_reliable_discard + assert not g.generates_in_pairs + else: # Note: For Gaussian, this only works if nvals is even. g2 = galsim.GaussianDeviate(testseed, mean=gMean, sigma=gSigma) g2.discard(nvals+1, suppress_warnings=True) @@ -396,14 +402,12 @@ def test_gaussian(): assert v1 != v2 assert g.has_reliable_discard assert g.generates_in_pairs - else: - # jax doesn't have this issue - assert g.has_reliable_discard - assert not g.generates_in_pairs # If don't explicitly suppress the warning, then a warning is emitted when n is odd. g2 = galsim.GaussianDeviate(testseed, mean=gMean, sigma=gSigma) - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: # jax doesn't do this with assert_warns(galsim.GalSimWarning): g2.discard(nvals+1) @@ -476,10 +480,10 @@ def test_gaussian(): # Test generate g.seed(testseed) test_array = np.empty(3) - if hasattr(galsim, "_galsim"): - g.generate(test_array) - else: + if is_jax_galsim(): test_array = g.generate(test_array) + else: + g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult), precision, err_msg='Wrong Gaussian random number sequence from generate.') @@ -489,29 +493,29 @@ def test_gaussian(): g3 = galsim.GaussianDeviate(testseed, mean=5, sigma=0.3) test_array = np.empty(3) test_array.fill(gSigma**2) - if hasattr(galsim, "_galsim"): - g2.generate_from_variance(test_array) - else: + if is_jax_galsim(): test_array = g2.generate_from_variance(test_array) + else: + g2.generate_from_variance(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult)-gMean, precision, err_msg='Wrong Gaussian random number sequence from generate_from_variance.') # After running generate_from_variance, it should be back to using the specified mean, sigma. # Note: need to round up to even number for discard, since gd generates 2 at a time. - if hasattr(galsim, "_galsim"): - g3.discard((len(test_array)+1)//2 * 2) - else: + if is_jax_galsim(): g3.discard(len(test_array)) + else: + g3.discard((len(test_array)+1)//2 * 2) print('g2,g3 = ',g2(),g3()) assert g2() == g3() # Test generate with a float32 array. g.seed(testseed) test_array = np.empty(3, dtype=np.float32) - if hasattr(galsim, "_galsim"): - g.generate(test_array) - else: + if is_jax_galsim(): test_array = g.generate(test_array) + else: + g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult), precisionF, err_msg='Wrong Gaussian random number sequence from generate.') @@ -520,10 +524,10 @@ def test_gaussian(): g2.seed(testseed) test_array = np.empty(3, dtype=np.float32) test_array.fill(gSigma**2) - if hasattr(galsim, "_galsim"): - g2.generate_from_variance(test_array) - else: + if is_jax_galsim(): test_array = g2.generate_from_variance(test_array) + else: + g2.generate_from_variance(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gResult)-gMean, precisionF, err_msg='Wrong Gaussian random number sequence from generate_from_variance.') @@ -534,45 +538,45 @@ def test_gaussian(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - if hasattr(galsim, "_galsim"): - g1.generate(v1) - else: + if is_jax_galsim(): v1 = g1.generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - g2.generate(v2) else: + g1.generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = g2.generate(v2) + else: + g2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - if hasattr(galsim, "_galsim"): - g1.add_generate(v1) - else: + if is_jax_galsim(): v1 = g1.add_generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - g2.add_generate(v2) else: + g1.add_generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = g2.add_generate(v2) + else: + g2.add_generate(v2) np.testing.assert_array_equal(v1, v2) ud = galsim.UniformDeviate(testseed + 3) ud.generate(v1) v1 += 6.7 - if hasattr(galsim, "_galsim"): - v2[:] = v1 - else: + if is_jax_galsim(): # jax galsim makes a copy v2 = v1.copy() + else: + v2[:] = v1 with single_threaded(): - if hasattr(galsim, "_galsim"): - g1.generate_from_variance(v1) - else: + if is_jax_galsim(): v1 = g1.generate_from_variance(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - g2.generate_from_variance(v2) else: + g1.generate_from_variance(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = g2.generate_from_variance(v2) + else: + g2.generate_from_variance(v2) np.testing.assert_array_equal(v1, v2) # Check picklability @@ -590,7 +594,9 @@ def test_gaussian(): assert g1 != g2, "Consecutive GaussianDeviate(None) compared equal!" # We shouldn't be able to construct a GaussianDeviate from anything but a BaseDeviate, int, str, # or None. - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: # jax-galsim doesn't test for these things assert_raises(TypeError, galsim.GaussianDeviate, dict()) assert_raises(TypeError, galsim.GaussianDeviate, list()) @@ -709,10 +715,10 @@ def test_binomial(): # Test generate b.seed(testseed) test_array = np.empty(3) - if hasattr(galsim, "_galsim"): - b.generate(test_array) - else: + if is_jax_galsim(): test_array = b.generate(test_array) + else: + b.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(bResult), precision, err_msg='Wrong binomial random number sequence from generate.') @@ -720,10 +726,10 @@ def test_binomial(): # Test generate with an int array b.seed(testseed) test_array = np.empty(3, dtype=int) - if hasattr(galsim, "_galsim"): - b.generate(test_array) - else: + if is_jax_galsim(): test_array = b.generate(test_array) + else: + b.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(bResult), precisionI, err_msg='Wrong binomial random number sequence from generate.') @@ -734,26 +740,26 @@ def test_binomial(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - if hasattr(galsim, "_galsim"): - b1.generate(v1) - else: + if is_jax_galsim(): v1 = b1.generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - b2.generate(v2) else: + b1.generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = b2.generate(v2) + else: + b2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - if hasattr(galsim, "_galsim"): - b1.add_generate(v1) - else: + if is_jax_galsim(): v1 = b1.add_generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - b2.add_generate(v2) else: + b1.add_generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = b2.add_generate(v2) + else: + b2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability @@ -771,7 +777,9 @@ def test_binomial(): assert b1 != b2, "Consecutive BinomialDeviate(None) compared equal!" # We shouldn't be able to construct a BinomialDeviate from anything but a BaseDeviate, int, str, # or None. - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: # jax does not raise for this assert_raises(TypeError, galsim.BinomialDeviate, dict()) assert_raises(TypeError, galsim.BinomialDeviate, list()) @@ -829,23 +837,23 @@ def test_poisson(): p2.discard(nvals, suppress_warnings=True) v1,v2 = p(),p2() print('With mean = %d, after %d vals, next one is %s, %s'%(high_mean,nvals,v1,v2)) - if hasattr(galsim, "_galsim"): - assert v1 != v2 - assert not p.has_reliable_discard - else: + if is_jax_galsim(): # jax always discards reliably assert v1 == v2 assert p.has_reliable_discard + else: + assert v1 != v2 + assert not p.has_reliable_discard assert not p.generates_in_pairs # Discard normally emits a warning for Poisson p2 = galsim.PoissonDeviate(testseed, mean=pMean) - if hasattr(galsim, "_galsim"): - with assert_warns(galsim.GalSimWarning): - p2.discard(nvals) - else: + if is_jax_galsim(): # jax always discards reliably p2.discard(nvals) + else: + with assert_warns(galsim.GalSimWarning): + p2.discard(nvals) # Check seed, reset p = galsim.PoissonDeviate(testseed, mean=pMean) @@ -915,10 +923,10 @@ def test_poisson(): # Test generate p.seed(testseed) test_array = np.empty(3) - if hasattr(galsim, "_galsim"): - p.generate(test_array) - else: + if is_jax_galsim(): test_array = p.generate(test_array) + else: + p.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(pResult), precision, err_msg='Wrong poisson random number sequence from generate.') @@ -926,10 +934,10 @@ def test_poisson(): # Test generate with an int array p.seed(testseed) test_array = np.empty(3, dtype=int) - if hasattr(galsim, "_galsim"): - p.generate(test_array) - else: + if is_jax_galsim(): test_array = p.generate(test_array) + else: + p.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(pResult), precisionI, err_msg='Wrong poisson random number sequence from generate.') @@ -937,10 +945,10 @@ def test_poisson(): # Test generate_from_expectation p2 = galsim.PoissonDeviate(testseed, mean=77) test_array = np.array([pMean]*3, dtype=int) - if hasattr(galsim, "_galsim"): - p2.generate_from_expectation(test_array) - else: + if is_jax_galsim(): test_array = p2.generate_from_expectation(test_array) + else: + p2.generate_from_expectation(test_array) np.testing.assert_array_almost_equal( test_array, np.array(pResult), precisionI, err_msg='Wrong poisson random number sequence from generate_from_expectation.') @@ -957,26 +965,26 @@ def test_poisson(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - if hasattr(galsim, "_galsim"): - p1.generate(v1) - else: + if is_jax_galsim(): v1 = p1.generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - p2.generate(v2) else: + p1.generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = p2.generate(v2) + else: + p2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - if hasattr(galsim, "_galsim"): - p1.add_generate(v1) - else: + if is_jax_galsim(): v1 = p1.add_generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - p2.add_generate(v2) else: + p1.add_generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = p2.add_generate(v2) + else: + p2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability @@ -994,7 +1002,9 @@ def test_poisson(): assert p1 != p2, "Consecutive PoissonDeviate(None) compared equal!" # We shouldn't be able to construct a PoissonDeviate from anything but a BaseDeviate, int, str, # or None. - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, galsim.PoissonDeviate, dict()) assert_raises(TypeError, galsim.PoissonDeviate, list()) assert_raises(TypeError, galsim.PoissonDeviate, set()) @@ -1129,20 +1139,20 @@ def test_poisson_zeromean(): # Test generate test_array = np.empty(3, dtype=int) - if hasattr(galsim, "_galsim"): - p.generate(test_array) - else: + if is_jax_galsim(): test_array = p.generate(test_array) - np.testing.assert_array_equal(test_array, 0) - if hasattr(galsim, "_galsim"): - p2.generate(test_array) else: - test_array = p2.generate(test_array) + p.generate(test_array) np.testing.assert_array_equal(test_array, 0) - if hasattr(galsim, "_galsim"): - p3.generate(test_array) + if is_jax_galsim(): + test_array = p2.generate(test_array) else: + p2.generate(test_array) + np.testing.assert_array_equal(test_array, 0) + if is_jax_galsim(): test_array = p3.generate(test_array) + else: + p3.generate(test_array) np.testing.assert_array_equal(test_array, 0) # Test generate_from_expectation @@ -1155,7 +1165,9 @@ def test_poisson_zeromean(): # Error raised if mean<0 # jax doesn't raise here - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: with assert_raises(ValueError): p = galsim.PoissonDeviate(testseed, mean=-0.1) with assert_raises(ValueError): @@ -1277,10 +1289,10 @@ def test_weibull(): # Test generate w.seed(testseed) test_array = np.empty(3) - if hasattr(galsim, "_galsim"): - w.generate(test_array) - else: + if is_jax_galsim(): test_array = w.generate(test_array) + else: + w.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(wResult), precision, err_msg='Wrong weibull random number sequence from generate.') @@ -1288,10 +1300,10 @@ def test_weibull(): # Test generate with a float32 array w.seed(testseed) test_array = np.empty(3, dtype=np.float32) - if hasattr(galsim, "_galsim"): - w.generate(test_array) - else: + if is_jax_galsim(): test_array = w.generate(test_array) + else: + w.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(wResult), precisionF, err_msg='Wrong weibull random number sequence from generate.') @@ -1302,26 +1314,26 @@ def test_weibull(): v1 = np.empty(555) v2 = np.empty(555) with single_threaded(): - if hasattr(galsim, "_galsim"): - w1.generate(v1) - else: + if is_jax_galsim(): v1 = w1.generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - w2.generate(v2) else: + w1.generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = w2.generate(v2) + else: + w2.generate(v2) np.testing.assert_array_equal(v1, v2) with single_threaded(): - if hasattr(galsim, "_galsim"): - w1.add_generate(v1) - else: + if is_jax_galsim(): v1 = w1.add_generate(v1) - with single_threaded(num_threads=10): - if hasattr(galsim, "_galsim"): - w2.add_generate(v2) else: + w1.add_generate(v1) + with single_threaded(num_threads=10): + if is_jax_galsim(): v2 = w2.add_generate(v2) + else: + w2.add_generate(v2) np.testing.assert_array_equal(v1, v2) # Check picklability @@ -1339,7 +1351,9 @@ def test_weibull(): assert w1 != w2, "Consecutive WeibullDeviate(None) compared equal!" # We shouldn't be able to construct a WeibullDeviate from anything but a BaseDeviate, int, str, # or None. - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, galsim.WeibullDeviate, dict()) assert_raises(TypeError, galsim.WeibullDeviate, list()) assert_raises(TypeError, galsim.WeibullDeviate, set()) @@ -1385,22 +1399,22 @@ def test_gamma(): v1,v2 = g(),g2() print('after %d vals, next one is %s, %s'%(nvals,v1,v2)) # Gamma uses at least 2 rngs per value, but can use arbitrarily more than this. - if hasattr(galsim, "_galsim"): - assert v1 != v2 - assert not g.has_reliable_discard - else: + if is_jax_galsim(): assert v1 == v2 assert g.has_reliable_discard + else: + assert v1 != v2 + assert not g.has_reliable_discard assert not g.generates_in_pairs # Discard normally emits a warning for Gamma g2 = galsim.GammaDeviate(testseed, k=gammaK, theta=gammaTheta) - if hasattr(galsim, "_galsim"): - with assert_warns(galsim.GalSimWarning): - g2.discard(nvals) - else: + if is_jax_galsim(): # jax always discards reliably g2.discard(nvals) + else: + with assert_warns(galsim.GalSimWarning): + g2.discard(nvals) # Check seed, reset g.seed(testseed) @@ -1467,10 +1481,10 @@ def test_gamma(): # Test generate g.seed(testseed) test_array = np.empty(3) - if hasattr(galsim, "_galsim"): - g.generate(test_array) - else: + if is_jax_galsim(): test_array = g.generate(test_array) + else: + g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gammaResult), precision, err_msg='Wrong gamma random number sequence from generate.') @@ -1478,10 +1492,10 @@ def test_gamma(): # Test generate with a float32 array g.seed(testseed) test_array = np.empty(3, dtype=np.float32) - if hasattr(galsim, "_galsim"): - g.generate(test_array) - else: + if is_jax_galsim(): test_array = g.generate(test_array) + else: + g.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(gammaResult), precisionF, err_msg='Wrong gamma random number sequence from generate.') @@ -1501,7 +1515,9 @@ def test_gamma(): assert g1 != g2, "Consecutive GammaDeviate(None) compared equal!" # We shouldn't be able to construct a GammaDeviate from anything but a BaseDeviate, int, str, # or None. - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, galsim.GammaDeviate, dict()) assert_raises(TypeError, galsim.GammaDeviate, list()) assert_raises(TypeError, galsim.GammaDeviate, set()) @@ -1547,22 +1563,22 @@ def test_chi2(): v1,v2 = c(),c2() print('after %d vals, next one is %s, %s'%(nvals,v1,v2)) # Chi2 uses at least 2 rngs per value, but can use arbitrarily more than this. - if hasattr(galsim, "_galsim"): - assert v1 != v2 - assert not c.has_reliable_discard - else: + if is_jax_galsim(): assert v1 == v2 assert c.has_reliable_discard + else: + assert v1 != v2 + assert not c.has_reliable_discard assert not c.generates_in_pairs # Discard normally emits a warning for Chi2 c2 = galsim.Chi2Deviate(testseed, n=chi2N) - if hasattr(galsim, "_galsim"): - with assert_warns(galsim.GalSimWarning): - c2.discard(nvals) - else: + if is_jax_galsim(): # jax always discards reliably c2.discard(nvals) + else: + with assert_warns(galsim.GalSimWarning): + c2.discard(nvals) # Check seed, reset c.seed(testseed) @@ -1629,10 +1645,10 @@ def test_chi2(): # Test generate c.seed(testseed) test_array = np.empty(3) - if hasattr(galsim, "_galsim"): - c.generate(test_array) - else: + if is_jax_galsim(): test_array = c.generate(test_array) + else: + c.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(chi2Result), precision, err_msg='Wrong Chi^2 random number sequence from generate.') @@ -1640,10 +1656,10 @@ def test_chi2(): # Test generate with a float32 array c.seed(testseed) test_array = np.empty(3, dtype=np.float32) - if hasattr(galsim, "_galsim"): - c.generate(test_array) - else: + if is_jax_galsim(): test_array = c.generate(test_array) + else: + c.generate(test_array) np.testing.assert_array_almost_equal( test_array, np.array(chi2Result), precisionF, err_msg='Wrong Chi^2 random number sequence from generate.') @@ -1663,7 +1679,9 @@ def test_chi2(): assert c1 != c2, "Consecutive Chi2Deviate(None) compared equal!" # We shouldn't be able to construct a Chi2Deviate from anything but a BaseDeviate, int, str, # or None. - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: assert_raises(TypeError, galsim.Chi2Deviate, dict()) assert_raises(TypeError, galsim.Chi2Deviate, list()) assert_raises(TypeError, galsim.Chi2Deviate, set()) @@ -2150,11 +2168,11 @@ def test_permute(): ind_list = list(range(n_list)) # Permute both at the same time. - if hasattr(galsim, "_galsim"): - galsim.random.permute(312, my_list, ind_list) - else: + if is_jax_galsim(): # jax requires arrays galsim.random.permute(312, np.array(my_list), np.array(ind_list)) + else: + galsim.random.permute(312, my_list, ind_list) # Make sure that everything is sensible for ind in range(n_list): @@ -2162,16 +2180,18 @@ def test_permute(): # Repeat with same seed, should do same permutation. my_list = copy.deepcopy(my_list_copy) - if hasattr(galsim, "_galsim"): - galsim.random.permute(312, my_list) - else: + if is_jax_galsim(): galsim.random.permute(312, np.array(my_list)) + else: + galsim.random.permute(312, my_list) for ind in range(n_list): assert my_list_copy[ind_list[ind]] == my_list[ind] # permute with no lists should raise TypeError # jax galsim does not raise - if hasattr(galsim, "_galsim"): + if is_jax_galsim(): + pass + else: with assert_raises(TypeError): galsim.random.permute(312) @@ -2181,16 +2201,16 @@ def test_ne(): """ Check that inequality works as expected for corner cases where the reprs of two unequal BaseDeviates may be the same due to truncation. """ - if hasattr(galsim, "_galsim"): - a = galsim.BaseDeviate(seed='1 2 3 4 5 6 7 8 9 10') - b = galsim.BaseDeviate(seed='1 2 3 7 6 5 4 8 9 10') - assert repr(a) == repr(b) - assert a != b - else: + if is_jax_galsim(): a = galsim.BaseDeviate(seed="(0, 10)") b = galsim.BaseDeviate(seed="(0, 11)") assert repr(a) != repr(b) assert a != b + else: + a = galsim.BaseDeviate(seed='1 2 3 4 5 6 7 8 9 10') + b = galsim.BaseDeviate(seed='1 2 3 7 6 5 4 8 9 10') + assert repr(a) == repr(b) + assert a != b # Check DistDeviate separately, since it overrides __repr__ and __eq__ d1 = galsim.DistDeviate(seed=a, function=galsim.LookupTable([1, 2, 3], [4, 5, 6])) From b1632e9831fe37cc2bc5269c7fe13daa9c7f1eae Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:05:36 -0500 Subject: [PATCH 338/351] fix: jax_galsim does not raise --- tests/test_integ.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_integ.py b/tests/test_integ.py index 537b5c72b1..0379e9da9a 100644 --- a/tests/test_integ.py +++ b/tests/test_integ.py @@ -183,8 +183,11 @@ def test_func(x): return x**-2 test_integral, true_result, decimal=test_decimal, verbose=True, err_msg="x^(-2) integral failed across interval [1, inf].") - with assert_raises(galsim.GalSimError): - galsim.integ.int1d(test_func, 0., 1., test_rel_err, test_abs_err) + if is_jax_galsim(): + with assert_raises(galsim.GalSimError): + galsim.integ.int1d(test_func, 0., 1., test_rel_err, test_abs_err) + else: + assert np.isnan(galsim.integ.int1d(test_func, 0., 1., test_rel_err, test_abs_err)) @timer From 108e1197196d971983d2535ac426d0a50c04a796 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:07:41 -0500 Subject: [PATCH 339/351] fix: wrong order of if statement --- tests/test_integ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_integ.py b/tests/test_integ.py index 0379e9da9a..c89785c20f 100644 --- a/tests/test_integ.py +++ b/tests/test_integ.py @@ -184,10 +184,10 @@ def test_func(x): return x**-2 err_msg="x^(-2) integral failed across interval [1, inf].") if is_jax_galsim(): + assert np.isnan(galsim.integ.int1d(test_func, 0., 1., test_rel_err, test_abs_err)) + else: with assert_raises(galsim.GalSimError): galsim.integ.int1d(test_func, 0., 1., test_rel_err, test_abs_err) - else: - assert np.isnan(galsim.integ.int1d(test_func, 0., 1., test_rel_err, test_abs_err)) @timer From 4f93a4e3900ed8d0c14d3a3ca2439059beddaae2 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:23:40 -0500 Subject: [PATCH 340/351] debug: figure out what is taking so long --- tests/test_interpolatedimage.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 45b7e90c31..dc603bf27d 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -410,7 +410,9 @@ def test_unit_integrals(): direct_integrals[0] = 1 else: for k in range(n): + print(k) direct_integrals[k] = galsim.integ.int1d(interp.xval, k-0.5, k+0.5) + print('direct: ',direct_integrals[k]) print('direct: ',direct_integrals) # Get from unit_integrals method (sometimes using analytic formulas) From b163e6f807f35688c690a30892306c2f5f5e0207 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:30:21 -0500 Subject: [PATCH 341/351] debug: how many --- tests/test_interpolatedimage.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index dc603bf27d..b8c0a17cf9 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -404,15 +404,14 @@ def test_unit_integrals(): print(str(interp)) # Compute directly with int1d n = interp.ixrange//2 + 1 + print("number of intervas: ",n) direct_integrals = np.zeros(n) if isinstance(interp, galsim.Delta): # int1d doesn't handle this well. direct_integrals[0] = 1 else: for k in range(n): - print(k) direct_integrals[k] = galsim.integ.int1d(interp.xval, k-0.5, k+0.5) - print('direct: ',direct_integrals[k]) print('direct: ',direct_integrals) # Get from unit_integrals method (sometimes using analytic formulas) From 61ae3d6b3cb2e8bf4d05184fdddc97b15a3e0452 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:45:10 -0500 Subject: [PATCH 342/351] debug: how fast --- tests/test_interpolatedimage.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index b8c0a17cf9..b953012fa7 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -411,6 +411,7 @@ def test_unit_integrals(): direct_integrals[0] = 1 else: for k in range(n): + print(k, n) direct_integrals[k] = galsim.integ.int1d(interp.xval, k-0.5, k+0.5) print('direct: ',direct_integrals) From 501c0fd751e9a7067f9554d94857ec1df0020971 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:51:11 -0500 Subject: [PATCH 343/351] test: just do less for jax --- tests/test_interpolatedimage.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index b953012fa7..57503e09a0 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -404,14 +404,18 @@ def test_unit_integrals(): print(str(interp)) # Compute directly with int1d n = interp.ixrange//2 + 1 - print("number of intervas: ",n) + if is_jax_galsim(): + # jax galsim is slow when doing direct integration + _n_do = min(n, 100) + else: + _n_do = n + direct_integrals = np.zeros(n) if isinstance(interp, galsim.Delta): # int1d doesn't handle this well. direct_integrals[0] = 1 else: - for k in range(n): - print(k, n) + for k in range(_n_do): direct_integrals[k] = galsim.integ.int1d(interp.xval, k-0.5, k+0.5) print('direct: ',direct_integrals) @@ -420,7 +424,7 @@ def test_unit_integrals(): print('integrals: ',len(integrals),integrals) assert len(integrals) == n - np.testing.assert_allclose(integrals, direct_integrals, atol=1.e-12) + np.testing.assert_allclose(integrals[_n_do], direct_integrals[_n_do], atol=1.e-12) if n > 10: print('n>10 for ',repr(interp)) From fb890ba437120461e56f8c769d98f3bdde71d161 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:52:03 -0500 Subject: [PATCH 344/351] test: just do less for jax --- tests/test_interpolatedimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_interpolatedimage.py b/tests/test_interpolatedimage.py index 57503e09a0..f3e97891e6 100644 --- a/tests/test_interpolatedimage.py +++ b/tests/test_interpolatedimage.py @@ -424,7 +424,7 @@ def test_unit_integrals(): print('integrals: ',len(integrals),integrals) assert len(integrals) == n - np.testing.assert_allclose(integrals[_n_do], direct_integrals[_n_do], atol=1.e-12) + np.testing.assert_allclose(integrals[:_n_do], direct_integrals[:_n_do], atol=1.e-12) if n > 10: print('n>10 for ',repr(interp)) From 3fc5a9032802cc3ddb16144e4d5b6b96c680773b Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 16:58:30 -0500 Subject: [PATCH 345/351] test: it is an array in jax --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 8709a5fa3c..1817b99ac7 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -227,7 +227,7 @@ def test_moffat_radii(): np.testing.assert_almost_equal( hlr_sum, 0.5, decimal=4, err_msg="Error in Moffat constructor with half-light radius") - np.testing.assert_equal( + np.testing.assert_array_equal( test_gal.half_light_radius, test_hlr, err_msg="Moffat half_light_radius returned wrong value") From 5e088ec1396784bc3b30e5b442069271f5902678 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 17:00:24 -0500 Subject: [PATCH 346/351] test: it is an array in jax --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 1817b99ac7..90f380f2d3 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -292,7 +292,7 @@ def test_moffat_radii(): np.testing.assert_almost_equal( ratio, 0.5, decimal=4, err_msg="Error in Moffat constructor with fwhm") - np.testing.assert_equal( + np.testing.assert_array_equal( test_gal.fwhm, test_fwhm, err_msg="Moffat fwhm returned wrong value") From b7ef1e22f265366b709e0f8ca0419a3f9fc1d270 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 17:01:07 -0500 Subject: [PATCH 347/351] test: it is an array in jax --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 90f380f2d3..7807c29780 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -322,7 +322,7 @@ def test_moffat_radii(): np.testing.assert_almost_equal( hlr_sum, 0.5, decimal=4, err_msg="Error in Moffat constructor with half-light radius") - np.testing.assert_equal( + np.testing.assert_array_equal( test_gal.half_light_radius, test_hlr, err_msg="Moffat hlr incorrect") From d8a549e581a0d4bf32f82e1df3f8c5c17600aa9a Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 13 Sep 2024 20:43:31 -0500 Subject: [PATCH 348/351] test: it is an array in jax --- tests/test_moffat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moffat.py b/tests/test_moffat.py index 7807c29780..f19b5c352f 100644 --- a/tests/test_moffat.py +++ b/tests/test_moffat.py @@ -322,7 +322,7 @@ def test_moffat_radii(): np.testing.assert_almost_equal( hlr_sum, 0.5, decimal=4, err_msg="Error in Moffat constructor with half-light radius") - np.testing.assert_array_equal( + np.testing.assert_allclose( test_gal.half_light_radius, test_hlr, err_msg="Moffat hlr incorrect") From ea74f8c3422d5235f186afab54adaba0f246fd40 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 10 Dec 2024 12:45:55 -0600 Subject: [PATCH 349/351] fix: make sure to export the pytest import --- tests/galsim_test_helpers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 9708944d90..169dfb90ed 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -49,6 +49,7 @@ "Profile", "galsim_backend", "is_jax_galsim", + "pytest", ] # This file has some helper functions that are used by tests from multiple files to help From 178f1b6f79f85d9214925651d138e251b4a4e22f Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 10 Dec 2024 12:51:55 -0600 Subject: [PATCH 350/351] fix: make sure to export the new fixtures and functions --- tests/galsim_test_helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/galsim_test_helpers.py b/tests/galsim_test_helpers.py index 169dfb90ed..309308262a 100644 --- a/tests/galsim_test_helpers.py +++ b/tests/galsim_test_helpers.py @@ -50,6 +50,8 @@ "galsim_backend", "is_jax_galsim", "pytest", + "run_slow", + "runtests", ] # This file has some helper functions that are used by tests from multiple files to help From 92049283e39a45348e6dfc133df0edbf4821d3b3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 10 Dec 2024 16:53:11 -0600 Subject: [PATCH 351/351] fix: make sure path to input test data is correct --- tests/test_wcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 7b3d206950..b01ed978c2 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2940,7 +2940,7 @@ def test_fittedsipwcs_singular(): # This test is in response to a case in imsim where the FittedSIPWCS could hit a # singular matrix error in the solver. - data = np.load('input/singular.npz') + data = np.load(os.path.join(os.path.dirname(__file__), 'input/singular.npz')) x = data['x'] y = data['y'] ra = data['ra']