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

Implement ChromaticSum._shoot #1259

Merged
merged 11 commits into from
Nov 1, 2023
Merged

Conversation

rmjarvis
Copy link
Member

In PR #1100, I implemented the applyTo method for chromatic objects, so they can be used as photon_ops. This is now the canonical way to do photon shooting with chromatic objects, since it can use each photon's specific wavelength to do wavelength-dependent things.

One that I skipped in that PR was ChromaticSum. I suspect I thought that class would only be used for things like bulge + disk, where each object has a spectral SED. These can't be used as photon_ops, so I didn't implement that functionality for them.

However, @matroxel wants to use ChromaticSum for the RomanPSF to smoothly interpolate across a sensor using a weighted sum of 4 PSFs, corresponding to the 4 corners of the sensor. So this PR rectifies my oversight, and implements ChromaticSum._shoot, which is the back end function for all PSF applyTo calls.

Note: when implementing this, I added PhotonArray._copyFrom, which can copy portions of the data from one PhotonArray to another. It copies all the allocated arrays, using an arbitrary mask in both the original and target PhotonArray. Similar to assignAt but more flexible. (And assignAt now uses _copyFrom for its implementation.)

I now use this all the places where we were doing this. I think this is safer than what we were doing, since some PSFs may need things like the pupil positions or time and when generating the positions/fluxes, they may have generated such things. So it's a little bit less efficient in most cases (but not much) in the interest of avoiding potentially subtle bugs that may turn up in various edge cases. (We don't currently have any unit tests that care about such things.)

@rmjarvis rmjarvis added this to the v2.5 milestone Oct 31, 2023
@rmjarvis rmjarvis added roman Relevant to Roman Space Telescope specifically, especially including the galsim.roman module. chromatic Related to the Chromatic classes, SEDs, bandpasses, etc. labels Oct 31, 2023
@rmjarvis rmjarvis requested a review from jmeyers314 October 31, 2023 16:42
Copy link
Member

@jmeyers314 jmeyers314 left a comment

Choose a reason for hiding this comment

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

Looks good to me. I have one question and one additional testing suggestion.

ret._is_corr = False
if is_corr:
from .deprecated import depr
depr('is_corr=True', 2.5, '',
Copy link
Member

Choose a reason for hiding this comment

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

What was the former use case and why is it no longer necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was for the Sum._shoot implementation. That had done all the photons in one component first, then all the ones in the other component. I switched that to do the same algorithm I used for ChromaticSum. This is potentially important if the PSF is time dependent for instance (e.g. includes a PhasePSF), so the order in the PhotonArray matters. It seems like there are subtle implications to letting them be correlated like that, and it was very easy to switch it to not ever be correlated in the first place.

assert_raises(ValueError, pa2.copyFrom, pa1, 100, 0)
assert_raises(ValueError, pa2.copyFrom, pa1, 0, slice(None))
assert_raises(ValueError, pa2.copyFrom, pa1)

Copy link
Member

Choose a reason for hiding this comment

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

Should probably add some tests for numpy fancy indexing too.
I.e., pa1.copyFrom(pa2, pa2.flux>10) and pa1.copyFrom(pa2, np.where(pa2.flux>10))

Copy link
Member

Choose a reason for hiding this comment

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

And maybe even discontiguous slices. pa1.copyFrom(pa2, slice(0, 100, 2))

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. Good ideas. Will do.

@rmjarvis
Copy link
Member Author

rmjarvis commented Nov 1, 2023

Question for you. Do you think we should deprecate assignAt as well in favor of the new copyFrom?
I think the new name is clearer (and matches a similar method in Image). The only place we had used assignAt was in the old Sum._shoot method, so that's now gone with the new algorithm. And I doubt any users probably use assignAt for anything.

@jmeyers314
Copy link
Member

Do you think we should deprecate assignAt as well in favor of the new copyFrom?

Yep, this sounds good to me.

@rmjarvis rmjarvis merged commit f75b7ae into releases/2.5 Nov 1, 2023
10 checks passed
@rmjarvis rmjarvis deleted the chromatic_sum_photon_op branch November 1, 2023 18:00
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. roman Relevant to Roman Space Telescope specifically, especially including the galsim.roman module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants