Skip to content

Multiple SED in ChromaticTransformation by absolute value of determinant#1349

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

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

Conversation

@FedericoBerlfein
Copy link
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
Member

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

@arunkannawadi
Copy link
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
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.

def detjac(w):
return np.linalg.det(np.asarray(self._jac(w)).reshape(2,2))
sed *= detjac
sed *= np.abs(detjac)
Copy link
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
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.

Copy link
Contributor

@sidneymau sidneymau Feb 20, 2026

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...

Copy link
Member

@rmjarvis rmjarvis left a comment

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
Member

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

@wmwv
Copy link

wmwv commented Feb 22, 2026

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
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
Copy link

wmwv commented Feb 23, 2026

Great, thank you for that reassurance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants