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
DM-9895 FrameSet frames not preserved by Transform(frameSet) constructor #198
Conversation
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.
I spotted a few inconsistencies and I'm a bit concerned by the code duplication in test_transform
, but no major issues.
src/geom/Endpoint.cc
Outdated
if (!skyFramePtr) { | ||
std::ostringstream os; | ||
os << "frame is a \"" << framePtr->getClass() << "\", not a SkyFrame"; | ||
os << "frame is a " << getFrame(framePtr)->getClass() << ", not a SkyFrame"; |
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.
Are you sure you want PointEndpoint::normalizeFrame
to report the original class and SpherePointEndpoint::normalizeFrame
to report FrameSets
as Frames
? I don't see the reason for the inconsistency.
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.
Thanks for catching this. I'll fix PointEndpoint<N>::normalizeFrame
to show the frame class (not FrameSet
)
tests/test_transform.py
Outdated
@@ -37,6 +38,122 @@ def makeRawArrayData(nPoints, nAxes, delta=0.123): | |||
def makeRawPointData(nAxes, delta=0.123): | |||
return [i*delta for i in range(nAxes)] | |||
|
|||
|
|||
def makeEndpoint(name, nAxes): |
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.
Handy, thanks!
tests/test_transform.py
Outdated
|
||
|
||
def makeGoodFrame(name, nAxes): | ||
"""Return the appropriate frame for the given name and nAzes |
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.
nAzes
-> nAxes
tests/test_transform.py
Outdated
@param[in] nAxes number of input axes | ||
""" | ||
if name == "Generic": | ||
return () |
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.
Should this be the empty list rather than the empty tuple?
tests/test_transform.py
Outdated
|
||
|
||
def makeBadFrames(name, nAxes): | ||
"""Return a list of 0 or more frames that are not a valid match for name and nAxes |
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.
nAxes
is unused. By "not a valid match for nAxes", do you mean, e.g., returning a 3D frame of the correct type when nAxes == 2?
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.
Thank you for realizing nAxes
was irrelevant. The point of this subroutine is to construct a collection of 0 or more astshim frames that are not compatible with the named endpoint. Since all frames are compatible with GenericEndpoint
and the number of axes is known for all other endpoints, nAxes is indeed irrelevant.
tests/test_transform.py
Outdated
inPoint = fromEndpoint.pointFromData(rawInPoint) | ||
outPoint = transform.tranForward(inPoint) | ||
rawOutPoint = toEndpoint.dataFromPoint(outPoint) | ||
# TODO replace all use of np.allclose with assertFloatsAlmostEqual once DM-9707 is fixed |
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.
Copy-and-pasted comment.
Can you factor out the common code here and in checkTransformFromMapping
into a method that takes a Transform
?
tests/test_transform.py
Outdated
|
||
# If frameSet has a SkyFrame as base or current, try permuting that (in place); | ||
# the Transform constructor should undo the permutation. | ||
# Warning: you must permute the axes of the SkYFrame once it is in the frameSet, |
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.
Capitalization error in SkYFrame
tests/test_transform.py
Outdated
# rather than before adding it to the FrameSet, else the behavior is wrong | ||
for permFrameSet, isBasePermuted, isCurrPermuted in permFrameSetIter(frameSet): | ||
if isBasePermuted: | ||
self.assertEqual(permFrameSet.getFrame(astshim.FrameSet.BASE).getLonAxis(), 2) |
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.
Do you need an else
case for these setup assertions?
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.
I think the code is right. If isBasePermuted
then the code permutes the base frame (which is a bit messy because of the need to temporarily set it to be the current frame). If isCurrPermuted
then the code permutes the current frame (which is trivial). There is no interaction between these flags, though at least one of them will be true.
Am I missing something? Can you say more about what you had in mind?
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.
I assume the purpose of this block is to double-check the output of permFrameSetIter
before using it to actually test FrameSet
or Transform
.
I was thinking that if you want to check getLonAxis() == 2
when isBasePermuted
, then you would also want to check that getLonAxis() == 1
when !isBasePermuted
.
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.
It's a bit of a nuisance, since if isXPermuted
is false then the axis may not be a SkyFrame
, but I see your point. I'll do it.
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.
Actually, I completely missed the part about getLonAxis()
not being defined for all frames... that does make my suggestion rather pointless.
tests/test_transform.py
Outdated
if isCurrPermuted: | ||
self.assertEqual(permFrameSet.getFrame(astshim.FrameSet.CURRENT).getLonAxis(), 2) | ||
transformBasePerm = transformClass(permFrameSet) | ||
# the base frame set in the transform should NOT be permuted |
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.
I don't understand this comment. It looks below like you're requiring that neither the base nor the current frame be permuted.
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.
What I am testing is that SpherePoint.normalizeFrame
correctly unpermutes the axes into the standard order. I changed the comment as follows in hopes of clarifying this:
# Verify that the base and current frames in the frame set in the *transform*
# are *not* permuted (i.e. that SpherePointEndpoint.normalizeFrame correctly
# set the axes to the standard order long, lat)
tests/test_transform.py
Outdated
fromEndpoint = transform.getFromEndpoint() | ||
|
||
# the transform should work identically to `transform` | ||
nPoints = 7 # arbitrary |
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.
Again, can this duplicate code be factored out?
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. Done as part of the earlier refactoring. I'm really glad you suggested that. It was a huge help.
c977d3c
to
4e9cc51
Compare
Transform(FrameSet) was never called in Python, because Transform(Mapping) was listed first in the pybind11 wrapper, and so was always called. Fixing this turned up several bugs in normalizing frames: - naive tests in PointEndpoint and SpherePointEndpoint were fooled when a FrameSet was passed in as a Frame. - SpherePointEndpoint needed a tweak so that permAxes was called on the frame argument, rather than a copy when the frame was a FrameSet. I addded tests for all these issues to tests/test_transform.py
Replace `self.assertTrue(numpy.allclose(...))` with `numpy.testing.assert_allclose(...)` in the two tests where I found it.
No description provided.