-
Notifications
You must be signed in to change notification settings - Fork 2
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
Test against DM implementation of CTInterpolator #84
Conversation
59bb716
to
93d047d
Compare
@@ -78,7 +78,7 @@ def test_coadd_image_correct(crazy_wcs, crazy_obj): | |||
world_origin = galsim.CelestialCoord(0 * galsim.degrees, 0 * galsim.degrees) | |||
|
|||
aff = galsim.PixelScale(scale).affine() | |||
aff = aff.withOrigin( | |||
aff = aff.shiftOrigin( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is shiftOrigin
more appropriate than withOrigin
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been deprecated since GalSim v2.3. I just noticed it when looking at the GitHub Actions logs when I had a failure in the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withOrigin
is basically a call to shiftOrigin
with a deprecation warning:
descwl_coadd/tests/test_coadd.py
Outdated
assert (coadd_data['coadd_exp'].image.array == | ||
dm_coadd_data['coadd_exp'].image.array).all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This level of agreement is surprising in that you'd need the set of good pixels around the bad ones to match exactly.
Let's add an assert that some data was actually interpolated in the test. Otherwise things would appear to agree but it'd be because we didn't do any interpolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic of selecting the bad pixels is exactly the same and involves only integer tuples. The floating point operations are all done by the scipy
function, so I am not surprised that the agreement is exact. But I'll add a test to see that some pixels are actually interpolated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned in the pr description that the dm version was more efficient since it used some sort of spanset data structure / algorithm. I assumed this might not give the same results in all cases. Is that not true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I said that we have a different implementation of this function in the DM codebase: https://github.com/LSSTDESC/descwl_coadd/blob/master/descwl_coadd/interp.py#L13-L14
Once we get the location of good pixels and bad pixels, we call the scipy.CloughTocher2DInterpolator
the same way as done here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, here's the C++ implementation of the function that behaves identical to the function I posted above: https://github.com/lsst/meas_algorithms/blob/main/src/CloughTocher2DInterpolatorUtils.cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch with the pixels not being interpolated in the first place, Matt. I'm going to do some more local testing and raise it again later. Marking it as a draft for now.
10b2217
to
b6a6c0f
Compare
cfa08c7
to
a513517
Compare
It turns out that the Delaunay triangulation happening under the hood is not invariant under x-y flip (not too surprising). The DM implementation uses (x, y) notation which is flipped relative to the [row, col] notation used with the numpy arrays here. This results in slightly different values in the output of |
568ee55
to
c029a46
Compare
Since this uses LSST DM code, which has GPL v3 LICENSE, this repo will have to have the same license.
a28ea7b
to
65f1e41
Compare
w37 appeared on |
descwl_coadd/tests/test_coadd.py
Outdated
actual=dm_coadd_data['coadd_exp'].image.array, | ||
desired=coadd_data['coadd_exp'].image.array, | ||
atol=0.0, | ||
rtol=1653.16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we allow such a large rtol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these values are empirically set based on observed differences and are intended to act as benchmarking rather than tests. For small pixel values close to zero, this shouldn't be surprising but this is just how sensitive CTInterpolator is to the choice of coordinate frames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is better specified in atol anyways - the values cross zero
descwl_coadd/tests/test_coadd.py
Outdated
actual=dm_coadd_data['coadd_exp'].image.array, | ||
desired=coadd_data['coadd_exp'].image.array, | ||
atol=0.0, | ||
rtol=1653.16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is better specified in atol anyways - the values cross zero
Why does values crossing zero matter? |
Here is the formula from the numpy docs:
If In this case, the image values are of order -1 to 1 and sometimes quite small. Thus we hit the math above near zero quite a bit, causing the need for a large |
That's all consistent with what I told Erin. There's a test with |
Yes, I suspect the test based on atol will be more robust. |
LGTM |
I'll merge this despite the stale 'Changes requested' from @beckermr since i) the comments have been addressed and ii) this is largely an addition to unit tests and not a change to the behavior of the code |
Thanks and sorry for missing the formal lgtm! |
Well, we do need your help now. GHA is failing with
that was not the case about a week ago. |
Yep - will get fixed by conda-forge/admin-requests#1094 Just merged - will be maybe 30 mins |
Since the
interpolator
objects can now be specified, I have added a test in this PR to compare that the CT interpolation implemented in DM behaves identical to the implementation here. The implementation differs in that i) the computationally expensive search function under the hood that finds good pixels around bad pixels is implemented in C++ instead of numba for policy reasons and ii) it uses theSpanSet
data structure to find the bad pixels more efficiently than the multipass brute-force search implemented here. The test here ensures that the end results are the same and will highlight any regressions in the future.