Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST fix tests for JAX-Galsim #1252

Open
wants to merge 358 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
358 commits
Select commit Hold shift + click to select a range
a01cc05
file paths
beckermr Nov 21, 2023
41482af
draw exceptions
beckermr Nov 21, 2023
1561a15
array tests
beckermr Nov 21, 2023
1bf8ca9
array tests
beckermr Nov 21, 2023
4bb3fd9
array tests
beckermr Nov 21, 2023
e7778a0
array tests
beckermr Nov 21, 2023
caa88d9
jax no warn
beckermr Nov 21, 2023
a4cb713
jax no warn
beckermr Nov 21, 2023
60424b8
jax no warn
beckermr Nov 21, 2023
efd15fc
jax no warn
beckermr Nov 21, 2023
011944c
jax no warn
beckermr Nov 21, 2023
a7503db
jax no fwd fft complex
beckermr Nov 21, 2023
7131c51
jax no fwd fft complex
beckermr Nov 21, 2023
da8ae43
jax no fwd fft complex
beckermr Nov 21, 2023
3d32477
array compare
beckermr Nov 21, 2023
8b25443
array compare
beckermr Nov 21, 2023
0515ad8
jax rounds a bit different
beckermr Nov 21, 2023
19471ac
jax rounds a bit different
beckermr Nov 21, 2023
6bcd68f
jax rounds a bit different
beckermr Nov 21, 2023
e3c5280
make_const not supported
beckermr Nov 21, 2023
5f55582
paths
beckermr Nov 21, 2023
0d3ca1a
paths
beckermr Nov 21, 2023
c1aa753
paths
beckermr Nov 21, 2023
ac7d4d9
paths
beckermr Nov 21, 2023
51151af
paths
beckermr Nov 21, 2023
b7cad5b
paths
beckermr Nov 21, 2023
030bda0
paths
beckermr Nov 21, 2023
c07af19
support make const
beckermr Nov 21, 2023
3940467
support make const
beckermr Nov 21, 2023
0a92bc4
support make const
beckermr Nov 21, 2023
86682d2
support make const
beckermr Nov 21, 2023
163687f
support make const
beckermr Nov 21, 2023
4cd1536
support make const
beckermr Nov 21, 2023
0952f29
no references
beckermr Nov 21, 2023
f3a65d3
no references
beckermr Nov 21, 2023
7786e37
no references
beckermr Nov 21, 2023
be2e75f
no references
beckermr Nov 21, 2023
2169160
no references
beckermr Nov 21, 2023
bcee242
no references
beckermr Nov 21, 2023
cb75725
no references
beckermr Nov 21, 2023
6214b62
no references
beckermr Nov 21, 2023
5e5b57d
no references
beckermr Nov 21, 2023
1d988d1
no references
beckermr Nov 21, 2023
7191fa0
no references
beckermr Nov 21, 2023
90791a6
weird failure
beckermr Nov 21, 2023
0505fc7
weird failure
beckermr Nov 21, 2023
6b5fa52
weird failure
beckermr Nov 21, 2023
5c838bb
weird failure
beckermr Nov 21, 2023
b2700bb
weird failure
beckermr Nov 21, 2023
ff23b6d
weird failure
beckermr Nov 21, 2023
6539ce1
weird failure
beckermr Nov 21, 2023
46a0e10
weird failure
beckermr Nov 21, 2023
56dc788
weird failure
beckermr Nov 21, 2023
0035409
weird failure
beckermr Nov 21, 2023
b2c451f
paths
beckermr Nov 21, 2023
ed7dae2
paths
beckermr Nov 21, 2023
27bfe2b
paths
beckermr Nov 21, 2023
cc94ba8
paths
beckermr Nov 21, 2023
ad4395d
norefs
beckermr Nov 21, 2023
f3aefd2
norefs
beckermr Nov 21, 2023
5158546
norefs
beckermr Nov 21, 2023
54cffec
norefs
beckermr Nov 21, 2023
ebf552c
norefs
beckermr Nov 21, 2023
da90aac
norefs
beckermr Nov 21, 2023
51a8583
norefs
beckermr Nov 21, 2023
3fbe8d4
norefs
beckermr Nov 21, 2023
e2cfddd
norefs
beckermr Nov 21, 2023
93632df
norefs
beckermr Nov 21, 2023
4ba61f6
paths
beckermr Nov 21, 2023
f6cfcd6
paths
beckermr Nov 21, 2023
53cd860
paths
beckermr Nov 21, 2023
f50323f
norefs
beckermr Nov 21, 2023
2100ade
norefs
beckermr Nov 21, 2023
9e69cc1
norefs
beckermr Nov 21, 2023
b2bcdc9
norefs
beckermr Nov 21, 2023
2ef3457
norefs
beckermr Nov 21, 2023
0994337
norefs
beckermr Nov 21, 2023
458cabb
norefs
beckermr Nov 21, 2023
d2f41ff
norefs
beckermr Nov 21, 2023
52b9910
norefs
beckermr Nov 21, 2023
8427e0b
norefs
beckermr Nov 21, 2023
5e4036a
norefs
beckermr Nov 21, 2023
b2a33fb
norefs
beckermr Nov 21, 2023
a534b6f
norefs
beckermr Nov 21, 2023
eb01912
norefs
beckermr Nov 21, 2023
88d7404
norefs
beckermr Nov 21, 2023
a6c0b3d
norefs
beckermr Nov 21, 2023
913aa52
norefs
beckermr Nov 21, 2023
213823c
norefs
beckermr Nov 21, 2023
cbcf0ec
norefs
beckermr Nov 21, 2023
e222d5e
norefs
beckermr Nov 21, 2023
5dd48a0
norefs
beckermr Nov 21, 2023
2cbb070
norefs
beckermr Nov 21, 2023
0d1dad3
norefs
beckermr Nov 21, 2023
ffe9e8a
norefs
beckermr Nov 21, 2023
caecb71
norefs
beckermr Nov 21, 2023
92a0f0c
norefs
beckermr Nov 21, 2023
7e24347
norefs
beckermr Nov 21, 2023
ac7876a
norefs
beckermr Nov 21, 2023
ad828a4
norefs
beckermr Nov 21, 2023
98346bf
norefs
beckermr Nov 21, 2023
bdeeb71
norefs
beckermr Nov 21, 2023
b4ad42e
norefs
beckermr Nov 21, 2023
13b55be
norefs
beckermr Nov 21, 2023
856169c
norefs
beckermr Nov 21, 2023
3524b8c
norefs
beckermr Nov 21, 2023
6c497dc
norefs
beckermr Nov 21, 2023
3d402a9
norefs
beckermr Nov 21, 2023
db25fdb
norefs
beckermr Nov 21, 2023
0c97449
norefs
beckermr Nov 21, 2023
d6982b9
norefs
beckermr Nov 21, 2023
322b3db
norefs
beckermr Nov 21, 2023
b030c3b
norefs
beckermr Nov 21, 2023
16402d3
norefs
beckermr Nov 21, 2023
34b37d1
norefs
beckermr Nov 21, 2023
53d54ee
norefs
beckermr Nov 21, 2023
f598233
norefs
beckermr Nov 21, 2023
944505b
norefs
beckermr Nov 21, 2023
7641057
norefs
beckermr Nov 21, 2023
f2cab46
norefs
beckermr Nov 21, 2023
dbe4829
norefs
beckermr Nov 21, 2023
e675f72
norefs
beckermr Nov 21, 2023
a4a183b
norefs
beckermr Nov 21, 2023
a68288d
norefs
beckermr Nov 21, 2023
6c2bac1
no raise
beckermr Nov 23, 2023
d293d88
no raise
beckermr Nov 23, 2023
618a33b
no raise
beckermr Nov 23, 2023
5591ded
no raise
beckermr Nov 25, 2023
a093624
no raise
beckermr Nov 25, 2023
8a3440d
no raise
beckermr Nov 26, 2023
7d6923e
Merge branch 'main' into fix_tests
beckermr Nov 26, 2023
6fac1a7
no raise
beckermr Nov 26, 2023
552aef8
paths
beckermr Nov 26, 2023
ba43346
Merge branch 'fix_tests' of https://github.com/GalSim-developers/GalS…
beckermr Nov 26, 2023
3a225bd
paths
beckermr Nov 26, 2023
b67d4db
no refs
beckermr Nov 26, 2023
38d06d5
no refs
beckermr Nov 26, 2023
58b7f77
array asserts
beckermr Nov 26, 2023
633d0f5
Update test_random.py
beckermr Nov 27, 2023
d5b6d76
no views
beckermr Nov 27, 2023
8cc107a
Merge branch 'fix_tests' of https://github.com/GalSim-developers/GalS…
beckermr Nov 27, 2023
ed0df69
no views
beckermr Nov 27, 2023
a320a40
no views
beckermr Nov 27, 2023
49c4416
no views
beckermr Nov 27, 2023
fdfda0c
no views
beckermr Nov 27, 2023
9c660b5
no views
beckermr Nov 27, 2023
746ee19
no views
beckermr Nov 27, 2023
481cdbb
no views
beckermr Nov 27, 2023
728a18f
no views
beckermr Nov 27, 2023
3ff8c02
no views
beckermr Nov 27, 2023
5263be7
no views
beckermr Nov 27, 2023
aacd9c8
no views
beckermr Nov 27, 2023
46cbdfc
no views
beckermr Nov 27, 2023
9a2d102
no views
beckermr Nov 27, 2023
dfe3d11
no views
beckermr Nov 27, 2023
7192fa6
no views
beckermr Nov 27, 2023
8592754
no index errors
beckermr Nov 27, 2023
71400ad
bool env
beckermr Nov 27, 2023
eecef97
bool env
beckermr Nov 27, 2023
fc4e74f
zernike import
beckermr Nov 27, 2023
75dfbcb
bug in test of randoms
beckermr Nov 27, 2023
e003b5a
remove deprecation warnings
beckermr Nov 27, 2023
ef5d07a
Apply suggestions from code review
beckermr Nov 27, 2023
f1dd4d2
Apply suggestions from code review
beckermr Nov 27, 2023
73851f4
Apply suggestions from code review
beckermr Nov 27, 2023
7f4fd66
Apply suggestions from code review
beckermr Nov 27, 2023
73b4e75
Apply suggestions from code review
beckermr Nov 27, 2023
01d0ab6
Update tests/test_deprecated.py
beckermr Nov 27, 2023
e01492d
Apply suggestions from code review
beckermr Nov 27, 2023
5775587
Apply suggestions from code review
beckermr Nov 27, 2023
a5c6415
Apply suggestions from code review
beckermr Nov 27, 2023
185bb5a
Apply suggestions from code review
beckermr Nov 27, 2023
4ae8a78
Apply suggestions from code review
beckermr Nov 27, 2023
544cc29
Update tests/test_deprecated.py
beckermr Nov 27, 2023
1f1699e
Update tests/test_deprecated.py
beckermr Nov 27, 2023
496ce4d
Apply suggestions from code review
beckermr Nov 27, 2023
af11c61
Apply suggestions from code review
beckermr Nov 27, 2023
bcfc251
Apply suggestions from code review
beckermr Nov 27, 2023
3b5c1ca
Apply suggestions from code review
beckermr Nov 27, 2023
70a875f
Apply suggestions from code review
beckermr Nov 27, 2023
48edcbb
Apply suggestions from code review
beckermr Nov 27, 2023
dff8cba
Apply suggestions from code review
beckermr Nov 27, 2023
36064f5
Apply suggestions from code review
beckermr Nov 27, 2023
e4c6a49
Apply suggestions from code review
beckermr Nov 27, 2023
f9a318d
Apply suggestions from code review
beckermr Nov 27, 2023
81d788f
Apply suggestions from code review
beckermr Nov 27, 2023
e2a9c7e
Apply suggestions from code review
beckermr Nov 27, 2023
5c716c8
Apply suggestions from code review
beckermr Nov 27, 2023
88103b5
these are not supported at all in jax-galsim
beckermr Nov 27, 2023
bb64924
WIP update test for jax-galsim memory use
beckermr Jun 4, 2024
783f757
TST remove extra B
beckermr Jun 4, 2024
ab72b99
TST less memory
beckermr Jun 4, 2024
80db992
TST less memory
beckermr Jun 4, 2024
b1c10d4
TST less memory
beckermr Jun 4, 2024
0f0feeb
TST less memory
beckermr Jun 4, 2024
e61fc38
TST less memory
beckermr Jun 4, 2024
7e3cded
TST less memory
beckermr Jun 4, 2024
011fde6
TST cancel concurrent tests
beckermr Jun 4, 2024
68e4b7a
TST cancel concurrent tests
beckermr Jun 5, 2024
d6886c9
TST fix fft tests
beckermr Jun 5, 2024
1b44daa
test: update tests for jax galsim
beckermr Jun 20, 2024
ff175e1
test: lower precision for some interp image tests
beckermr Jul 12, 2024
62634db
Revert "test: lower precision for some interp image tests"
beckermr Jul 12, 2024
4161bad
Merge branch 'main' into fix_tests
beckermr Aug 21, 2024
0e379d2
fix: missing import
beckermr Aug 21, 2024
9696fbb
test: more missing imports and tests
beckermr Aug 21, 2024
6a326a7
test: rename the imports
beckermr Aug 21, 2024
0d55c54
feat: add function to extract the galsim backend
beckermr Aug 22, 2024
13a3042
fix: start to use a proper helper function
beckermr Aug 22, 2024
d80d1d8
test: convert more to use the helper functions
beckermr Aug 22, 2024
cc57eca
test: fix test helpers file for new functions
beckermr Aug 22, 2024
36da37b
test: clean up celestial tests
beckermr Aug 22, 2024
414c8ab
fix: need to test Angle
beckermr Aug 22, 2024
9cd8ab2
fix: bug in parens
beckermr Aug 22, 2024
aae4649
test: clean up test_optics
beckermr Aug 22, 2024
1b627dc
tests: always default to running tests for other backends
beckermr Aug 22, 2024
396084f
test: clean up tests for exp w/ phots
beckermr Aug 22, 2024
ae74cc7
test: clean up tests for moffat
beckermr Aug 22, 2024
ea082f5
fix: testing functions do not have atol/rtol
beckermr Aug 22, 2024
1a3b3cb
test: fix first part of deprecation test file
beckermr Aug 22, 2024
4173070
test: better test here
beckermr Aug 22, 2024
04c247a
test: check allocated
beckermr Aug 22, 2024
79536e1
test: clean up more test stuff
beckermr Aug 22, 2024
a2f674a
test: clean up more test stuff
beckermr Aug 22, 2024
ce25e31
test: get rest of test cases
beckermr Aug 22, 2024
3c4841c
test: clean up tests for photon arrays
beckermr Aug 23, 2024
c987110
test: clean up for interpolated images
beckermr Aug 23, 2024
5337334
test: clean up for noise tests
beckermr Aug 23, 2024
8454028
test: try using the olde value
beckermr Aug 23, 2024
101a36e
test: clean up tests for draw
beckermr Aug 23, 2024
682f592
test: clean up tests for draw
beckermr Aug 23, 2024
63855f9
test: clean up tests for draw
beckermr Aug 23, 2024
15943e2
test: clean up tests for image
beckermr Aug 23, 2024
3cd63b6
test: clean up tests for utils
beckermr Aug 23, 2024
9a5ab87
test: clean up random tests
beckermr Aug 26, 2024
b1632e9
fix: jax_galsim does not raise
beckermr Sep 13, 2024
108e119
fix: wrong order of if statement
beckermr Sep 13, 2024
4f93a4e
debug: figure out what is taking so long
beckermr Sep 13, 2024
b163e6f
debug: how many
beckermr Sep 13, 2024
61ae3d6
debug: how fast
beckermr Sep 13, 2024
501c0fd
test: just do less for jax
beckermr Sep 13, 2024
fb890ba
test: just do less for jax
beckermr Sep 13, 2024
3fc5a90
test: it is an array in jax
beckermr Sep 13, 2024
5e088ec
test: it is an array in jax
beckermr Sep 13, 2024
b7ef1e2
test: it is an array in jax
beckermr Sep 13, 2024
d8a549e
test: it is an array in jax
beckermr Sep 14, 2024
1513366
Merge branch 'main' into fix_tests
beckermr Dec 10, 2024
ea74f8c
fix: make sure to export the pytest import
beckermr Dec 10, 2024
178f1b6
fix: make sure to export the new fixtures and functions
beckermr Dec 10, 2024
9204928
fix: make sure path to input test data is correct
beckermr Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 72 additions & 13 deletions tests/galsim_test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"assert_intlike",
"check_basic",
"do_shoot",
"do_kvalue",
"radial_integrate",
"drawNoise",
"check_pickle",
"check_all_diff",
"timer",
"CaptureLog",
"assert_raises",
"assert_warns",
"profile",
beckermr marked this conversation as resolved.
Show resolved Hide resolved
]

# This file has some helper functions that are used by tests from multiple files to help
# avoid code duplication.

Expand Down Expand Up @@ -138,20 +161,32 @@ 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() 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() and "LAX" not in line:
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)
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? I thought they were equivalent. I'd rather not use the more verbose one if we can avoid it.


# 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)
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:
Expand Down Expand Up @@ -199,7 +234,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.
Expand All @@ -211,6 +246,30 @@ 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 (
(not hasattr(galsim, "_galsim"))
beckermr marked this conversation as resolved.
Show resolved Hide resolved
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"))
beckermr marked this conversation as resolved.
Show resolved Hide resolved
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.
"""
Expand All @@ -225,12 +284,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)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_fitsheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
73 changes: 40 additions & 33 deletions tests/test_interpolatedimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -954,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
Expand Down Expand Up @@ -1697,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)
Expand Down Expand Up @@ -1844,33 +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 = '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)



Expand Down
20 changes: 11 additions & 9 deletions tests/test_shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,17 +178,19 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does JaxGalSim do with these inputs? They don't define valid Shear values.

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)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_shear_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__":
Expand Down
12 changes: 6 additions & 6 deletions tests/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading