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
port jointcal to pybind11 tickets/DM-9187 #31
Conversation
a17e8e7
to
1e75587
Compare
Remove swig from sconscript
Cleanup DistortionMap API: produceSipWcs should be in base class.
1e75587
to
c942994
Compare
@@ -52,6 +52,12 @@ class MeasuredStar : public BaseStar | |||
{ if (F) F->MeasurementCount()++; fittedStar = F; | |||
} | |||
|
|||
void dump(std::ostream & stream = std::cout) const | |||
{ | |||
BaseStar::dump(stream); |
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'll refrain from commenting on the uglyness of the C++ (i.e. why does dump
exist in the first place).
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, since I've already cleaned up the interface some as part of this work, please feel free to suggest some improvements like that. What would you prefer instead of "dump"?
python/lsst/jointcal/star.cc
Outdated
cls.def(py::init<>()); | ||
cls.def(py::init<double, double, double>(), "x"_a, "y"_a, "flux"_a); | ||
|
||
// these three are actually declared in FatPoint, but we don't need that in Python |
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.
Please add DM-9814 to comment.
py::class_<MeasuredStar, std::shared_ptr<MeasuredStar>, BaseStar> cls(mod, "MeasuredStar"); | ||
|
||
cls.def(py::init<const BaseStar&>(), "baseStar"_a); | ||
} |
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.
Usually we close anonymous here. But there is some confusion on it. See upcoming slack discussion.
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 I change anything, or just leave it pending that discussion?
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.
After further discussion with @pschella , I'm leaving this until we've settled on a standard way to handle these.
src/SimplePolyModel.cc
Outdated
{ | ||
const GtransfoPoly &pix2Tp=dynamic_cast<const GtransfoPoly&>(GetTransfo(Ccd)); | ||
const TanRaDec2Pix *proj=dynamic_cast<const TanRaDec2Pix*>(sky2TP(Ccd)); | ||
const GtransfoPoly &pix2Tp=dynamic_cast<const GtransfoPoly&>(GetTransfo(ccdImage)); |
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.
Be careful, may throw.
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.
In this case, throwing is fine: if that's unable to be dereferenced, something has gone terribly wrong.
@@ -21,17 +21,17 @@ public : | |||
virtual const Mapping* getMapping(const CcdImage &) const = 0; | |||
|
|||
//! Assign indices to parameters involved in mappings, starting at FirstIndex. Returns the highest assigned index. | |||
virtual unsigned assignIndices(unsigned FirstIndex, std::string &WhatToFit) = 0; | |||
virtual unsigned assignIndices(unsigned firstIndex, std::string &whatToFit) = 0; |
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.
const
for arguments? Here and in other functions below.
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 only see the one const
that needs adding in this class and its subclases.
cls.def("addImage", &Associations::addImage); | ||
cls.def("selectFittedStars", &Associations::selectFittedStars); | ||
|
||
cls.def("getCcdImageList", &Associations::getCcdImageList); |
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 is not an stl
container and does not return by reference I assume.
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 is now an stl::list
, and does return by const&
.
python/lsst/jointcal/ccdImage.cc
Outdated
|
||
cls.def("sizeValidForFit", &CcdImageList::sizeValidForFit); | ||
|
||
// Make this behave like a std::list, which it is, but we can't wrap children of it easily. |
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.
Hmm, are we really really sure we can't just return this as a Python list?
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 would be the first list-like object in the stack. And unless we absolutely cannot use STL containers or ndarray here it shouldn't exist.
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.
CcdImageList is now just a typedef of std::list<shared_ptr<CcdImage>>
.
python/lsst/jointcal/jointcal.py
Outdated
@@ -197,14 +197,13 @@ def _build_ccdImage(self, dataRef, associations, jointcalControl): | |||
this calexp's filter | |||
""" | |||
visit = dataRef.dataId["visit"] | |||
src = dataRef.get("src", flags=lsst.afw.table.SOURCE_IO_NO_FOOTPRINTS, immediate=True) | |||
src = dataRef.get("src", flags=int(lsst.afw.table.SOURCE_IO_NO_FOOTPRINTS), immediate=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.
Should this be wrapped as integer instead of enum?
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.
Was waiting on DM-9764. That's fixed now, so I removed the cast.
@@ -0,0 +1,54 @@ | |||
/* | |||
* LSST Data Management System |
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 is not the copyright statement from the template :)
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.
Also see all other files.
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.
Assuming you mean (the template package)[https://github.com/lsst/templates]: it wasn't clear to me that that was up-to-date with our current copyright standard (per RFC-45, or even earlier discussion). Given that RFC-45 is adopted, I think I'll wait on its implementation before changing all the copyright headers.
|
||
// The following routines are the interface to AstromFit | ||
//! | ||
const Mapping* GetMapping(const CcdImage &) const; | ||
const Mapping* getMapping(const CcdImage &) const; |
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.
Is this wrapped? If so please be careful with the return value policy. Should this copy or reference_internal? Should this perhaps be smart pointer? Etc. If not wrapped then outside of scope.
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.
Same for all other functions that return raw pointers.
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.
getMapping
is not wrapped.
Thanks for the suggestion though: I went and checked, and none of the wrapped methods return pointers (raw or otherwise), so there are no problems with copy vs. reference.
python/lsst/jointcal/ccdImage.cc
Outdated
@@ -66,13 +65,11 @@ void declareCcdImageList(py::module &mod) { | |||
|
|||
cls.def("sizeValidForFit", &CcdImageList::sizeValidForFit); | |||
|
|||
// Make this behave like a std::list, which it is, but we can't wrap children of it easily. | |||
// Make this behave like a std::list (which it is but we can't wrap std::list subclasses trivially) |
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.
Can't we make jointcal use a regular STL container (probably preferably vector
) somehow?
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 we want to try to sort out some of DM-4043 now (what it would take to decide that question), or should we just try to do that in the next sprint?
ccdImageList
can probably be turned into a List without too much trouble, but the *StarList
are all built on CountedRefs
, which are boost::intrusive_ptr
, so I fear more complication there.
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, I don't think we should remove custom containers just on principle. Sometimes having a custom container that can really add value if the container has some special functionality, and it can be a nice solution to the case where we can't convert directly to a built-in Python container in the wrapper layer for one reason or another.
Of course, any custom containers should delegate most of their work to an STL container (and do so via composition, not inheritance). I have no idea if these particular containers add value over their STL counterparts, but I do suspect Pierre had a good reason to choose std::list
over std::vector
.
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.
One constraint is that MeasuredStar's contain some reference to their mother CcdImage.
For sake of efficiency, this is implemented as some sort of pointer, and so CcdImage's should not move in memory. The no-copy policy of CcdImages is enforced by making the copy constructor private (the comment there does not tell why. My fault). I am guessing this was the original constraint, but maybe at some point, I switched to a container of pointers for the CcdImageList, which voids the argument. So, it might just work as well with std::vector as a container. But unless a new scheme is devised to represent the MeasuredStar->CcdImage relation, copying CcdImage's should remain forbidden, which excludes a std::vector.
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 unraveled CcdImageList
into typedef std::list<std::shared_ptr<CcdImage> > CcdImageList;
, with no obvious ill effects. I'm going to punt on the question of how to manage the various StarList
s as out of scope for this ticket and deal with it in DM-4043 (which I plan to schedule for next cycle).
I suspect we'll stick with list
instead of vector
here, since than the algorithm has a cleanup step that removes items from the middle of the list. But lets table that until DM-4043.
4d9a201
to
2c2d186
Compare
Add sconscript and __init__ support Change jointcal.py to remove jointcalLib and use lsst.jointcal.blah directly. Moved *astromModel stuff into astrometryModels, similarly for *photomModel. NOTE: this suggests I should clarify the names of `simplePolyModel` and `constrainedPolyModel`, since they're really astrometry-specific models. NOTE: Several of the wrapped classes are only minimally wrapped: they will be opaque from python, but had to be wrapped as they are either returned by other methods or are default values of methods. NOTE: Remaining question is how much extra "sugar" to add (e.g. str/repr, attribute access, list-member access, etc.)
Rename distortionModel -> astrometryModel Rename photomModel -> photometryModel Rename photomFit -> photometryFit Rename astromFit -> astrometryFit
Move `point` definition into `star.cc`, since it's the base class (which should eventually disappear once DM-4044 is done) *Star have at least partially useful __str__, but still cannot be accessed when they're inside a *StarList (still waiting on DM-4043). I don't know what all the #ifndef SWIG's were for, but they seem potentially useful, and we'll never have SWIG defined, if we ever did in the first place.
CcdImageList is now just a typedef, and the "valid size" method got lifted into Associations, where it fits nicely.
7916b95
to
04e3e5d
Compare
No description provided.