Skip to content

Commit

Permalink
all_obj_diff -> check_all_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Aug 22, 2023
1 parent 7b2e988 commit 7faaf33
Show file tree
Hide file tree
Showing 29 changed files with 59 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Test Suite Helper Functions and Contexts

.. autofunction:: galsim.utilities.check_pickle

.. autofunction:: galsim.utilities.all_obj_diff
.. autofunction:: galsim.utilities.check_all_diff

.. autoclass:: galsim.utilities.CaptureLog

Expand Down
9 changes: 4 additions & 5 deletions galsim/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2026,14 +2026,13 @@ def check_pickle(obj, func = lambda x : x, irreprable=False, random=None):

# Historical note:
# We used to have a test here where we perturbed the construction arguments to make sure
# that objects that should be different really are different.
# However, that used `__getinitargs__`, which we've moved away from using for pickle, so
# none of our classes get checked this way anymore. So we removed this section.
# This means that this inequality test has to be done manually via all_obj_diff.
# that objects that should be different really are different. However, that used
# `__getinitargs__`, which we don't use anymore, so we removed this section.
# This means that this inequality test has to be done manually via check_all_diff.
# See releases v2.3 or earlier for the old way we did this.


def all_obj_diff(objs, check_hash=True):
def check_all_diff(objs, check_hash=True):
"""Test that all objects test as being unequal.
It checks all pairs of objects in the list and asserts that obj1 != obj2.
Expand Down
2 changes: 1 addition & 1 deletion tests/galsim_test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import copy
import galsim

from galsim.utilities import check_pickle, all_obj_diff, timer, CaptureLog, Profile
from galsim.utilities import check_pickle, check_all_diff, timer, CaptureLog, Profile

# We used to roll our own versions of these, but numpy.testing has good ones now.
from numpy.testing import assert_raises
Expand Down
2 changes: 1 addition & 1 deletion tests/test_airy.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_ne():
galsim.Airy(lam=1.0, diam=1.0, obscuration=0.1),
galsim.Airy(lam_over_diam=1.0, flux=1.1),
galsim.Airy(lam_over_diam=1.0, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def test_ne():
galsim.Bandpass(throughput=lt, wave_type='nm').withZeropoint('Vega'),
galsim.Bandpass(throughput=lt, wave_type='nm').withZeropoint(100.0),
galsim.Bandpass(throughput=lt, wave_type='nm').withZeropoint(sed)]
all_obj_diff(bps)
check_all_diff(bps)

with assert_raises(galsim.GalSimValueError):
galsim.Bandpass(throughput=lt, wave_type='nm').withZeropoint('invalid')
Expand Down
6 changes: 3 additions & 3 deletions tests/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_ne():
galsim.Pixel(scale=1.1),
galsim.Pixel(scale=1.0, flux=1.1),
galsim.Pixel(scale=1.0, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# Box. Params include width, height, flux, gsparams.
# gsparams.
Expand All @@ -307,7 +307,7 @@ def test_ne():
galsim.Box(width=1.0, height=1.1),
galsim.Box(width=1.0, height=1.0, flux=1.1),
galsim.Box(width=1.0, height=1.0, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# TopHat. Params include radius, flux, gsparams.
# gsparams.
Expand All @@ -316,7 +316,7 @@ def test_ne():
galsim.TopHat(radius=1.1),
galsim.TopHat(radius=1.0, flux=1.1),
galsim.TopHat(radius=1.0, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)

if __name__ == "__main__":
testfns = [v for k, v in vars().items() if k[:5] == 'test_' and callable(v)]
Expand Down
28 changes: 14 additions & 14 deletions tests/test_chromatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,7 @@ def test_ne():
# ChromaticObject. Only param is the GSObject to chromaticize.
# The following should test unequal:
gals = [cgal1, cgal2]
all_obj_diff(gals)
check_all_diff(gals)

# # Check that setifying doesn't remove any duplicate items.
# assert len(gals) == len(set(gals))
Expand All @@ -2695,7 +2695,7 @@ def test_ne():
galsim.InterpolatedChromaticObject(cgal1, np.arange(500, 700, 50), oversample_fac=1.1),
cgal1.interpolate(np.arange(500, 700, 10)),
cgal1.interpolate(np.arange(500, 700, 10), oversample_fac=1.2)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticAtmosphere. Params include base_obj, base_wavelength, scale_unit, alpha,
# zenith_angle, parallactic_angle, obj_coord, zenith_coord, HA, latitude, pressure, temperature,
Expand Down Expand Up @@ -2727,7 +2727,7 @@ def test_ne():
H2O_pressure=2.0),
galsim.ChromaticAtmosphere(gal1, 500.0, obj_coord=m101, HA=HA, latitude=latitude),
galsim.ChromaticAtmosphere(gal1, 500.0, obj_coord=m101, zenith_coord=zenith_coord)]
all_obj_diff(gals)
check_all_diff(gals)

# Chromatic. Params are a gsobject and an SED.
sed1 = galsim.SED(lambda w: w, 'nm', 'flambda')
Expand All @@ -2737,7 +2737,7 @@ def test_ne():
gal1 * sed2,
gal2 * sed1,
gal2 * sed2]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticTransformation. Params are an object (possibly chromatic), a jacobian jac, an
# offset, a flux_ratio, and gsparams. For coverage, test jac, offset, and flux_ratio as
Expand Down Expand Up @@ -2772,7 +2772,7 @@ def test_ne():
galsim.ChromaticTransformation(cgal1, gsparams=gsp, propagate_gsparams=False),
galsim.ChromaticTransformation(cgal3).withGSParams(gsp),
galsim.ChromaticTransformation(cgal3, propagate_gsparams=False).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticSum. Params are objs to add and potentially gsparams.
# The following should test unequal.
Expand All @@ -2786,7 +2786,7 @@ def test_ne():
galsim.ChromaticSum(cgal1, gsparams=gsp, propagate_gsparams=False),
galsim.ChromaticSum(cgal3).withGSParams(gsp),
galsim.ChromaticSum(cgal3, propagate_gsparams=False).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticConvolution. Params are objs to convolve and potentially gsparams.
# The following should test unequal
Expand All @@ -2803,7 +2803,7 @@ def test_ne():
galsim.ChromaticConvolution(cgal1, gsparams=gsp, propagate_gsparams=False),
galsim.ChromaticConvolution(cgal3).withGSParams(gsp),
galsim.ChromaticConvolution(cgal3, propagate_gsparams=False).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticDeconvolution. Only params here are obj to deconvolve and gsparams.
gals = [galsim.ChromaticDeconvolution(cgal1),
Expand All @@ -2813,7 +2813,7 @@ def test_ne():
galsim.ChromaticDeconvolution(cgal1, gsparams=gsp, propagate_gsparams=False),
galsim.ChromaticDeconvolution(cgal3).withGSParams(gsp),
galsim.ChromaticDeconvolution(cgal3, propagate_gsparams=False).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticAutoConvolution.
gals = [galsim.ChromaticAutoConvolution(cgal1),
Expand All @@ -2823,7 +2823,7 @@ def test_ne():
galsim.ChromaticAutoConvolution(cgal1, gsparams=gsp, propagate_gsparams=False),
galsim.ChromaticAutoConvolution(cgal3).withGSParams(gsp),
galsim.ChromaticAutoConvolution(cgal3, propagate_gsparams=False).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticAutoCorrelation.
gals = [galsim.ChromaticAutoCorrelation(cgal1),
Expand All @@ -2833,7 +2833,7 @@ def test_ne():
galsim.ChromaticAutoCorrelation(cgal1, gsparams=gsp, propagate_gsparams=False),
galsim.ChromaticAutoCorrelation(cgal3).withGSParams(gsp),
galsim.ChromaticAutoCorrelation(cgal3, propagate_gsparams=False).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticFourierSqrt.
gals = [galsim.ChromaticFourierSqrtProfile(cgal1),
Expand All @@ -2843,7 +2843,7 @@ def test_ne():
galsim.ChromaticFourierSqrtProfile(cgal1, gsparams=gsp, propagate_gsparams=False),
galsim.ChromaticFourierSqrtProfile(cgal3).withGSParams(gsp),
galsim.ChromaticFourierSqrtProfile(cgal3, propagate_gsparams=False).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticOpticalPSF. Params include: lam, (diam or lam_over_diam), aberrations, nstruts,
# strut_thick, strut_angle, obscuration, oversampling, pad_factor, flux, gsparams, ...
Expand All @@ -2860,7 +2860,7 @@ def test_ne():
galsim.ChromaticOpticalPSF(lam=1.0, lam_over_diam=1.0, flux=0.2),
galsim.ChromaticOpticalPSF(lam=1.0, lam_over_diam=1.0, gsparams=gsp),
galsim.ChromaticOpticalPSF(lam=1.0, lam_over_diam=1.0, flux=0.2).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# ChromaticAiry. Params include: lam, diam, lam_over_diam, scale_unit, flux, obscuration,
# gsparams.
Expand All @@ -2872,7 +2872,7 @@ def test_ne():
galsim.ChromaticAiry(lam=1.0, lam_over_diam=1.0, flux=1.1),
galsim.ChromaticAiry(lam=1.0, lam_over_diam=1.0, gsparams=gsp),
galsim.ChromaticAiry(lam=1.0, lam_over_diam=1.0, flux=1.1).withGSParams(gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# Check that all the various combinations are properly unequal
gals = [cgal1,
Expand All @@ -2888,7 +2888,7 @@ def test_ne():
galsim.ChromaticAutoCorrelation(cgal1),
galsim.ChromaticOpticalPSF(lam=1.0, lam_over_diam=1.0),
galsim.ChromaticAiry(lam=1.0, lam_over_diam=1.0)]
all_obj_diff(gals)
check_all_diff(gals)

@timer
def test_atredshift():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,28 +739,28 @@ def test_ne():
galsim.Convolution(gal1, galsim.Convolution(gal2, gal2)), # Not! associative.
galsim.Convolution(gal1, gsparams=gsp),
galsim.Convolution(gal1, gsparams=gsp, propagate_gsparams=False)]
all_obj_diff(gals)
check_all_diff(gals)

# Deconvolution. Only params here are obj to deconvolve and gsparams.
gals = [galsim.Deconvolution(gal1),
galsim.Deconvolution(gal2),
galsim.Deconvolution(gal1, gsparams=gsp),
galsim.Deconvolution(gal1, gsparams=gsp, propagate_gsparams=False)]
all_obj_diff(gals)
check_all_diff(gals)

# AutoConvolution. Only params here are obj to deconvolve and gsparams.
gals = [galsim.AutoConvolution(gal1),
galsim.AutoConvolution(gal2),
galsim.AutoConvolution(gal1, gsparams=gsp),
galsim.AutoConvolution(gal1, gsparams=gsp, propagate_gsparams=False)]
all_obj_diff(gals)
check_all_diff(gals)

# AutoCorrelation. Only params here are obj to deconvolve and gsparams.
gals = [galsim.AutoCorrelation(gal1),
galsim.AutoCorrelation(gal2),
galsim.AutoCorrelation(gal1, gsparams=gsp),
galsim.AutoCorrelation(gal1, gsparams=gsp, propagate_gsparams=False)]
all_obj_diff(gals)
check_all_diff(gals)


@timer
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exponential.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_ne():
galsim.Exponential(scale_radius=1.0),
galsim.Exponential(half_light_radius=1.0, flux=1.1),
galsim.Exponential(half_light_radius=1.0, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def test_ne():
galsim.Gaussian(sigma=1.2, flux=1.1),
galsim.Gaussian(sigma=1.2, gsparams=gsp)]
# Check that setifying doesn't remove any duplicate items.
all_obj_diff(gals)
check_all_diff(gals)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2521,7 +2521,7 @@ def test_ne():
galsim.ImageD(array2, make_const=True),
galsim.ImageD(array1, wcs=galsim.PixelScale(0.2)),
galsim.ImageD(array1, xmin=2)]
all_obj_diff(objs)
check_all_diff(objs)


@timer
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inclined.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def test_eq_ne():
galsim.InclinedSersic(n=1.0, inclination=0.1 * galsim.radians, scale_radius=3.0,
scale_h_over_r=0.3)]

all_obj_diff(diff_gals)
check_all_diff(diff_gals)

@timer
def test_pickle():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_interpolatedimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,14 +1684,14 @@ def test_ne():
galsim.InterpolatedImage(ref_image, scale=0.2),
galsim.InterpolatedImage(ref_image, use_true_center=False),
galsim.InterpolatedImage(ref_image, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)

# And repeat for InterpolatedKImage
gals = [galsim.InterpolatedKImage(kim),
galsim.InterpolatedKImage(kim, k_interpolant='Linear'),
galsim.InterpolatedKImage(kim, stepk=1.1),
galsim.InterpolatedKImage(kim, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)

def test_quintic_glagn():
"""This is code that was giving a seg fault. cf. Issue 1079.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_kolmogorov.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def test_ne():
galsim.Kolmogorov(lam=1.0, r0_500=1.0),
galsim.Kolmogorov(lam=1.0, r0=1.0, flux=1.1),
galsim.Kolmogorov(lam=1.0, r0=1.0, flux=1.1, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)

@timer
def test_low_folding_threshold():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def test_shear_units():
galsim.PowerSpectrum('k', 'k', False, 'arcsec'),
galsim.PowerSpectrum('k', 'k**2', True, 'arcsec'),
galsim.PowerSpectrum('k', 'k**2', False, 'arcmin')]
all_obj_diff(diff_ps_list)
check_all_diff(diff_ps_list)

@timer
def test_tabulated():
Expand Down Expand Up @@ -1368,7 +1368,7 @@ def test_psr():
galsim.lensing_ps.PowerSpectrumRealizer(100, 0.005, pe, None),
galsim.lensing_ps.PowerSpectrumRealizer(100, 0.005, None, pb),
galsim.lensing_ps.PowerSpectrumRealizer(100, 0.005, pb, pe)]
all_obj_diff(diff_psr_list)
check_all_diff(diff_psr_list)

with assert_raises(TypeError):
psr(gd=galsim.BaseDeviate(1234))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_moffat.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def test_ne():
galsim.Moffat(beta=3.0, scale_radius=1.1, trunc=2.0),
galsim.Moffat(beta=3.0, scale_radius=1.0, flux=1.1),
galsim.Moffat(beta=3.0, scale_radius=1.0, gsparams=gsp)]
all_obj_diff(gals)
check_all_diff(gals)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ def test_ne():
suppress_warning=True),
galsim.OpticalPSF(lam_over_diam=1.0, pupil_plane_im=pupil_plane_im, gsparams=gsp1,
pupil_angle=10*galsim.degrees, suppress_warning=True)]
all_obj_diff(objs)
check_all_diff(objs)


@timer
Expand Down
14 changes: 7 additions & 7 deletions tests/test_phase_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def test_ne():
galsim.Aperture(diam=1.0, pupil_plane_im=pupil_plane_im),
galsim.Aperture(diam=1.0, pupil_plane_im=pupil_plane_im,
pupil_angle=10.0*galsim.degrees)]
all_obj_diff(objs)
check_all_diff(objs)

# Test AtmosphericScreen __ne__
rng = galsim.BaseDeviate(1)
Expand All @@ -640,12 +640,12 @@ def test_ne():
galsim.AtmosphericScreen(10.0, rng=rng, L0=10.0),
galsim.AtmosphericScreen(10.0, rng=rng, vx=10.0),
]
all_obj_diff(objs)
check_all_diff(objs)
objs.append(galsim.AtmosphericScreen(10.0, rng=rng))
objs[-1].instantiate()
# Should still all be __ne__, but first and last will have the same hash this time.
assert hash(objs[0]) == hash(objs[-1])
all_obj_diff(objs, check_hash=False)
check_all_diff(objs, check_hash=False)

# Test OpticalScreen __ne__
objs = [galsim.OpticalScreen(diam=1.0),
Expand All @@ -662,14 +662,14 @@ def test_ne():
galsim.OpticalScreen(diam=1.0, spher=1.0, lam_0=100.0),
galsim.OpticalScreen(diam=1.0, aberrations=[0,0,1.1]), # tip=1.1
]
all_obj_diff(objs)
check_all_diff(objs)

# Test PhaseScreenList __ne__
atm = galsim.Atmosphere(10.0, vx=1.0)
objs = [galsim.PhaseScreenList(atm),
galsim.PhaseScreenList(objs), # Reuse list of OpticalScreens above
galsim.PhaseScreenList(objs[0:2])]
all_obj_diff(objs)
check_all_diff(objs)

# Test PhaseScreenPSF __ne__
psl = galsim.PhaseScreenList(atm)
Expand All @@ -683,7 +683,7 @@ def test_ne():
maxk = objs[0].maxk
objs += [galsim.PhaseScreenPSF(psl, 700.0, exptime=0.03, diam=1.0, _force_stepk=stepk/1.5)]
objs += [galsim.PhaseScreenPSF(psl, 700.0, exptime=0.03, diam=1.0, _force_maxk=maxk*2.0)]
all_obj_diff(objs)
check_all_diff(objs)


@timer
Expand Down Expand Up @@ -1482,7 +1482,7 @@ def test_user_screen():
uscreen3 = galsim.UserScreen(table, diam=2, obscuration=0.5)
check_pickle(uscreen2)
check_pickle(uscreen3)
all_obj_diff([uscreen, uscreen2, uscreen3])
check_all_diff([uscreen, uscreen2, uscreen3])


@timer
Expand Down
Loading

0 comments on commit 7faaf33

Please sign in to comment.