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

DM-8440: Create new Wcs class #9

Merged
merged 6 commits into from May 2, 2017
Merged

DM-8440: Create new Wcs class #9

merged 6 commits into from May 2, 2017

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented Apr 27, 2017

No description provided.

Copy link
Contributor

@PaulPrice PaulPrice left a comment

Choose a reason for hiding this comment

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

Some minor comments.

This is my first time looking through astshim, and I found the few breakages of our naming rules (e.g., FitsChan and getNcard) rather annoying. I thought the whole idea of a shim would mean that our naming rules would apply.

@@ -24,6 +24,7 @@

#include <pybind11/pybind11.h>
#include <pybind11/complex.h>
#include <pybind11/stl.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks unrelated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is needed because getCardNames returns a vector. pybind11/stl.h wraps C++ vectors so they are usable in Python.

Not "const" because the code changes the index of the current card while operating
(but restores the original index when done).
*/
std::vector<std::string> getCardNames();
Copy link
Contributor

Choose a reason for hiding this comment

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

This method differs only by a single character from the one before. Might people get confused? The previous one might be better named getCurrentCardName.
Could you make the card index volatile and make this method const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The names are based on AST. astshim is a 3rd party package intended to be a thin shim around AST. As such I felt minimum friction was to follow AST where possible, so the extensive AST documentation would still apply.

Copy link
Contributor

Choose a reason for hiding this comment

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

But astshim isn't a third-party package: it's hosted here in LSST's GitHub, and I'm reviewing code changes for it. But maybe I'm just unaware of the context.

Copy link
Member

Choose a reason for hiding this comment

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

I'm hoping we'll integrate it with AST upstream to make it part of the normal C++ interface for AST.

Copy link
Member

Choose a reason for hiding this comment

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

I was treating astshim as a temporary package name rather than a permanent package name for LSST.

Copy link
Contributor

Choose a reason for hiding this comment

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

If astshim is going into AST, then shouldn't we have our own wrappers that insulate us from changes in that? All of this seems to be in this strange no man's land, not quite LSST, but not quite AST. We're exposing far more of AST than we do with any other package, including Eigen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can easily switch {{astshim}} names to use LSST capitalization, e.g. {{getNAxes}} instead of {{getNaxes}}. That will remove some of the pain but certainly not all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting back to your first comment...I agree that {{getCardNames}} could be confused with {{getCardName}} though I was hoping we could live with it. Is it worth changing to {{getAllCardNames}} or do you have a better suggestion?

{{FitsChan}} makes heavy use of its index and the concept of the current card, so I think it will take more work than it's worth to make this method const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And...I should have said: {{getCardName}} is from AST so I don't want to change it. A method to return all card names in order does not exist in AST so I can easily rename that.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this package is indeed bound for integration into AST and afw isn't exposing any of this, then I won't object to your naming choices. However, I do think it's worth considering getAllCardNames or something else that will distinguish it from getCardName.

self.assertEqual(fc.getNcard(), 1)
self.assertEqual(fc.getCardNames(), ["FRED1"])
fc.setFitsCF("FRED1", complex(99.9, 99.8), "Hello there", True)
fv = fc.getFitsCF("FRED1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt the test didn't need all those extra cards. The first new card was informative (e.g. FRED1 and FRED2), but the rest (FRED3 and FRED4) did not enhance the test, and reusing a name is also a useful test.

fc.setFitsS("FRED4", "-12", "Hello there", True)
fv = fc.getFitsI("FRED4")
fc.setFitsS("FRED1", "-12", "Hello there", True)
fv = fc.getFitsI("FRED1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

(as a Mapping) to transform coordinate values in either direction.
If conversion is possible, it returns a shared pointer to a @ref FrameSet which describes
the conversion and which may be used (as a Mapping) to transform coordinate values in either direction.
Otherwise it returns an empty shared pointer.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are cases where you want the exception and not an empty pointer. Ideally, one wants both modes. Can you put in an overload that will throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I'll add a flag or a new method. It should be a custom exception so it's easy to differentiate "not found" from other errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought I want to hold off on this. I think users will often want to control the exception being raised and the message string when a search fails. Furthermore it is not idiomatic C++ to raise an exception when a search fails.

@@ -769,7 +767,7 @@ class Frame : public Mapping {
using a "domainlist" string which does not include the template's domain
(or a blank field). If you do so, no coordinate system will be found.
*/
FrameSet findFrame(Frame const &tmplt, std::string const &domainlist = "");
std::shared_ptr<FrameSet> findFrame(Frame const &tmplt, std::string const &domainlist = "");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why spaces around the = here but not above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clang-format. Apparently I didn't run it on the whole file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will run clang-format on all C++ code.

src/Frame.cc Outdated
}
return FrameSet(rawFrameSet);
return Object::fromAstObject<FrameSet>(reinterpret_cast<AstObject *>(rawFrameSet), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Trailing whitespace.
And line 47 too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll run clang-format on both Frame.cc and Frame.h

r-owen added 6 commits May 2, 2017 11:45
and test the new method.
I took the opportunity to slightly simplify one of the test cases:
a card was being replaced without testing that it was truly being
replaced, and the card name changed more often than necessary
to show that replacement works.
Change `Frame.convert` and `Frame.findFrame` to return
`std::shared_ptr<FrameSet>` instead of `FrameSet`
and return an empty pointer if the search is unsuccessful
instead of throwing notfound_error. This is more useful for
the user and closer to how AST does it. It also eliminates
the need for notfound_error and avoids raising a C++ exception
for a normal situation.
Document the effect that `FrameSet.removeFrame` and `FrameSet.addFrame`
have on the indices of the various frames.
@r-owen r-owen merged commit b752128 into master May 2, 2017
@ktlim ktlim deleted the tickets/DM-8440 branch August 25, 2018 04:31
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.

None yet

3 participants