Update calculateFWHM to be insensitive to np.argsort algorithmic details #1337
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@welucas2 reported on #1336 that our
calculateFWHM
calculation could return different values for different numpy versions. Specifically with different argsort algorithmic details.The problem occurs when the profile is centered directly on a pixel center (or corner or some other special locations) such that there are repeated rsq values. Argsort will report one of these to be the "first" one to be farther than the half max value, but different numpy versions could report different pixels to be this location.
If the profile is symmetric and drawn directly or with fft, then this still wasn't a problem, since all data at that rsq would have the same value, so it didn't matter which one was the "first" one. But with photon shooting or asymmetric profiles, that's not the case.
This PR updates our FWHM algorithm to compute the mean data value of all pixels with the desired rsq if there are more than one. This should be insensitive to the details of how argsort does its thing, and also probably produce a slightly more robust answer for photon shooting, since it will average over the noise somewhat. When the profile is slightly off-center, this will produce the same result as GalSIm has calculated in the past.