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

Spergel stepk has two powers of the scale radius #1324

Closed
beckermr opened this issue Dec 19, 2024 · 4 comments
Closed

Spergel stepk has two powers of the scale radius #1324

beckermr opened this issue Dec 19, 2024 · 4 comments
Labels
bug report Bug report

Comments

@beckermr
Copy link
Contributor

It appears that galsim has two factors of r0 being applied when computing the stepk for the Spergel profile.

The first power is here:

GalSim/src/SBSpergel.cpp

Lines 101 to 102 in 120eab3

double SBSpergel::SBSpergelImpl::calculateFluxRadius(double f) const
{ return _info->calculateFluxRadius(f) * _r0; }

but then the scale radius is applied again here:

GalSim/galsim/spergel.py

Lines 206 to 211 in 120eab3

@property
def _stepk(self):
R = self.calculateFluxRadius(1.0 - self.gsparams.folding_threshold) * self._r0
# Go to at least 5*hlr
R = max(R, self.gsparams.stepk_minimum_hlr * self.half_light_radius)
return math.pi / R

I compared to the implementation in jax-galsim, and I can only get them to agree if I use a second factor of r0 within jax-galsim like this

    @property
    def _stepk(self):
        R = calculateFluxRadius(1.0 - self.gsparams.folding_threshold, self.nu)
        R *= self._r0**2
        # Go to at least 5*hlr
        R = jnp.maximum(R, self.gsparams.stepk_minimum_hlr * self.half_light_radius)
        return jnp.pi / R

Note that the jax-galsim calculateFluxRadius function is in normalized units, and so should have only one factor of r0.

@beckermr
Copy link
Contributor Author

cc @rmjarvis @jmeyers314

@rmjarvis
Copy link
Member

I concur. Looks like this error was introduced when trying to move more of the implementation up to python. The pure C++ code looks right, but the python code has a spurious extra r0. And we apparently didn't have a test that would catch the change.

@jmeyers314
Copy link
Member

Yep. Tests pass either way. Maybe we should check stepk /propto scale_radius.

@rmjarvis
Copy link
Member

propto 1/scale_radius. But yeah, we should add a test about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Bug report
Projects
None yet
Development

No branches or pull requests

3 participants