Skip to content

Multiple SED in ChromaticTransformation by absolute value of determinant#1349

Merged
rmjarvis merged 4 commits into
mainfrom
1346-negative-flux-chromatictransformation
Feb 22, 2026
Merged

Multiple SED in ChromaticTransformation by absolute value of determinant#1349
rmjarvis merged 4 commits into
mainfrom
1346-negative-flux-chromatictransformation

Conversation

@FedericoBerlfein

Copy link
Copy Markdown
Contributor

As described in #1346 1346, the sed() function in the ChromaticTransformation class should multiply the SED by the absolute value of the determinant of the jacobian. It currently multiplies by the determinant, allowing for negative fluxes if the determinant is negative. The change here simply adds the absolute value when multiplying the SED.

@arunkannawadi

Copy link
Copy Markdown
Member

Looks good to me. This appears to be the only use of the determinant from np.linalg

@arunkannawadi

Copy link
Copy Markdown
Member

May be we should make it detjac.abs() (preferably) or move the np.abs within detjac (noting that this is absolute value)

@arunkannawadi

Copy link
Copy Markdown
Member

If you could also simplify your how-to-reproduce code to mock up a JacobianWCS with negative determinant and include a unit test, that'd be great.

Comment thread galsim/chromatic.py Outdated
def detjac(w):
return np.linalg.det(np.asarray(self._jac(w)).reshape(2,2))
sed *= detjac
sed *= np.abs(detjac)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not correct. abs needs to be inside the function. Note that detjac here is a function, not a number.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I didn't notice this at first. Moved inside the function.

@sidneymau sidneymau Feb 20, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we wanted to keep detjac as returning a signed number and to only apply the absolute value when doing the SED transformation, then the following should work

sed *= lambda w: np.abs(detjac(w))

Python could really do with better support for functional composition...

@rmjarvis rmjarvis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix, Federico.

@rmjarvis rmjarvis merged commit 05b977e into main Feb 22, 2026
10 checks passed
@rmjarvis rmjarvis deleted the 1346-negative-flux-chromatictransformation branch February 22, 2026 17:47
@rmjarvis rmjarvis added this to the v2.8 milestone Feb 22, 2026
@arunkannawadi

Copy link
Copy Markdown
Member

Credits go to Cole Meldorf (Penn) for identifying the existence of this issue.

@wmwv

wmwv commented Feb 22, 2026

Copy link
Copy Markdown

If we want to reproduce results from OU24 would one want to use the old behavior? Specifically, if one were modeling the PSF of an object in an image, is it necessary to reproduce the old behavior to recover the truth values for OU24?

@rmjarvis

Copy link
Copy Markdown
Member

@wmwv I would hope not. If the Open Universe sims did anything that involved this bug, I think there would be huge problems in the images. Whatever code paths it used seem to have avoided this bug.

@wmwv

wmwv commented Feb 23, 2026

Copy link
Copy Markdown

Great, thank you for that reassurance.

@rmjarvis rmjarvis added numerics Involving details of the numerical algorithms for performing some calculation(s) chromatic Related to the Chromatic classes, SEDs, bandpasses, etc. labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chromatic Related to the Chromatic classes, SEDs, bandpasses, etc. numerics Involving details of the numerical algorithms for performing some calculation(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants