Skip to content

Commit 413c5dd

Browse files
cailmdaleyclaude
andcommitted
refactor: route size conversions through cs_util.size
The Gaussian size conversions are now sourced from cs_util.size, the single source of truth shared with sp_validation, instead of being re-derived locally: - ngmix.py get_noise window: np.sqrt(guess[4]/2) -> cs_size.T_to_sigma (guess[4] is the ngmix area parameter T = 2 sigma^2; bit-exact). - make_cat.py PSF_FWHM: galaxy.sigma_to_fwhm -> cs_size.sigma_to_fwhm (bare conversion, no pixel_scale). - utilities/galaxy.sigma_to_fwhm becomes a thin wrapper that keeps the pixel_scale rescaling and ShapePipe input validation but delegates the bare 2*sqrt(2 ln 2) factor to cs_util.size; this preserves its second caller (spread_model.py, which uses pixel_scale) and the test_utilities contract. Matches the old hard-coded 2.35482004503 constant to <1e-11 relative. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent dfac162 commit 413c5dd

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/shapepipe/modules/make_cat_package/make_cat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
from astropy import coordinates as coords
1414
from astropy import units as u
1515
from astropy.wcs import WCS
16+
from cs_util import size as cs_size
1617
from sqlitedict import SqliteDict
1718

1819
from shapepipe.pipeline import file_io
19-
from shapepipe.utilities import galaxy
2020

2121

2222
def get_output_name(output_dir, file_number_string):
@@ -725,7 +725,7 @@ def _save_psf_data(self, galaxy_psf_path):
725725
)
726726
self._add2dict(f"PSF_ELL_{epoch + 1}", e_psf, idx)
727727

728-
psf_fwhm = galaxy.sigma_to_fwhm(
728+
psf_fwhm = cs_size.sigma_to_fwhm(
729729
gpc_data["SHAPES"]["SIGMA_PSF_HSM"]
730730
)
731731
self._add2dict(f"PSF_FWHM_{epoch + 1}", psf_fwhm, idx)

src/shapepipe/modules/ngmix_package/ngmix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import galsim
1515
import numpy as np
1616
from astropy.io import fits
17+
from cs_util import size as cs_size
1718
from modopt.math.stats import sigma_mad
1819
from ngmix.observation import Observation, ObsList
1920
from sqlitedict import SqliteDict
@@ -970,7 +971,7 @@ def get_noise(gal, weight, guess, pixel_scale, thresh=1.2):
970971

971972
sig_tmp = sigma_mad(gal[m_weight])
972973

973-
gauss_win = galsim.Gaussian(sigma=np.sqrt(guess[4] / 2), flux=guess[5])
974+
gauss_win = galsim.Gaussian(sigma=cs_size.T_to_sigma(guess[4]), flux=guess[5])
974975
gauss_win = gauss_win.shear(g1=guess[2], g2=guess[3])
975976
gauss_win = gauss_win.drawImage(
976977
nx=img_shape[0], ny=img_shape[1], scale=pixel_scale

src/shapepipe/utilities/galaxy.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
import numpy as np
10+
from cs_util import size as cs_size
1011

1112

1213
def sigma_to_fwhm(sigma, pixel_scale=1.0):
@@ -15,6 +16,11 @@ def sigma_to_fwhm(sigma, pixel_scale=1.0):
1516
Transform standard deviation of a 1D Gaussian, sigma, to FWHM
1617
(Full Width Half Maximum).
1718
19+
Thin wrapper over :func:`cs_util.size.sigma_to_fwhm`, the single
20+
source of truth for the bare ``FWHM = 2 sqrt(2 ln 2) sigma``
21+
conversion; this layer adds the optional ``pixel_scale`` rescaling
22+
and ShapePipe's input validation.
23+
1824
Parameters
1925
----------
2026
sigma : numpy.ndarray
@@ -89,6 +95,4 @@ def sigma_to_fwhm(sigma, pixel_scale=1.0):
8995
f"Invalid pixel scale {pixel_scale}, needs to be greater than 0.0."
9096
)
9197

92-
cst = 2.35482004503
93-
94-
return sigma * cst * pixel_scale
98+
return cs_size.sigma_to_fwhm(sigma) * pixel_scale

0 commit comments

Comments
 (0)