Skip to content

Commit 8e32318

Browse files
committed
API: Introduce check input arg to toggle checking
1 parent 6c5d815 commit 8e32318

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

galsim/hsm.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def _convertImage(image):
563563
def EstimateShear(gal_image, PSF_image, weight=None, badpix=None, sky_var=0.0,
564564
shear_est="REGAUSS", recompute_flux="FIT", guess_sig_gal=5.0,
565565
guess_sig_PSF=3.0, precision=1.0e-6, guess_centroid=None,
566-
strict=True, hsmparams=None):
566+
strict=True, check=True, hsmparams=None):
567567
"""Carry out moments-based PSF correction routines.
568568
569569
Carry out PSF correction using one of the methods of the HSM package (see references in
@@ -667,6 +667,9 @@ def EstimateShear(gal_image, PSF_image, weight=None, badpix=None, sky_var=0.0,
667667
``False``, then information about failures will be silently stored in
668668
the output ShapeData object. [default: True]
669669
670+
check: Check if the object_image, weight are in the correct format and valid.
671+
[default: True]
672+
670673
hsmparams: The hsmparams keyword can be used to change the settings used by
671674
`EstimateShear` when estimating shears; see `HSMParams` documentation
672675
for more information. [default: None]
@@ -677,11 +680,11 @@ def EstimateShear(gal_image, PSF_image, weight=None, badpix=None, sky_var=0.0,
677680
# prepare inputs to C++ routines: ImageF or ImageD for galaxy, PSF, and ImageI for weight map
678681
gal_image = _convertImage(gal_image)
679682
PSF_image = _convertImage(PSF_image)
680-
_checkWeightAndBadpix(gal_image, weight=weight, badpix=badpix)
681683
hsmparams = HSMParams.check(hsmparams)
684+
if check:
685+
_checkWeightAndBadpix(gal_image, weight=weight, badpix=badpix)
682686
weight = _convertMask(gal_image, weight=weight, badpix=badpix)
683687

684-
685688
if guess_centroid is None:
686689
guess_centroid = gal_image.true_center
687690
try:
@@ -699,7 +702,7 @@ def EstimateShear(gal_image, PSF_image, weight=None, badpix=None, sky_var=0.0,
699702
return ShapeData(error_message = str(err))
700703

701704
def FindAdaptiveMom(object_image, weight=None, badpix=None, guess_sig=5.0, precision=1.0e-6,
702-
guess_centroid=None, strict=True, round_moments=False, hsmparams=None,
705+
guess_centroid=None, strict=True, check=True, round_moments=False, hsmparams=None,
703706
use_sky_coords=False):
704707
"""Measure adaptive moments of an object.
705708
@@ -797,6 +800,8 @@ def FindAdaptiveMom(object_image, weight=None, badpix=None, guess_sig=5.0, preci
797800
``GalSimHSMError`` exception if shear estimation fails. If set to
798801
``False``, then information about failures will be silently stored in
799802
the output ShapeData object. [default: True]
803+
check: Check if the object_image, weight are in the correct format and valid.
804+
[default: True]
800805
round_moments: Use a circular weight function instead of elliptical.
801806
[default: False]
802807
hsmparams: The hsmparams keyword can be used to change the settings used by
@@ -812,9 +817,10 @@ def FindAdaptiveMom(object_image, weight=None, badpix=None, guess_sig=5.0, preci
812817
"""
813818
# prepare inputs to C++ routines: ImageF or ImageD for galaxy, PSF, and ImageI for weight map
814819
object_image = _convertImage(object_image)
815-
816-
_checkWeightAndBadpix(object_image, weight=weight, badpix=badpix)
817820
hsmparams = HSMParams.check(hsmparams)
821+
if check:
822+
_checkWeightAndBadpix(object_image, weight=weight, badpix=badpix)
823+
818824
weight = _convertMask(object_image, weight=weight, badpix=badpix)
819825

820826
if guess_centroid is None:

0 commit comments

Comments
 (0)