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-11095 add refcat support for jointcal photometry #44
Conversation
Add Constrained to PhotometryModel pybind11, and cleanup file
NOTE: doesn't work yet because PhotometryFit doesn't accept nOutliers. It probably should? But this is telling me something important about the difference between the as-implemented photometry and astrometry fitters. fix indentation in jointcal.py
Make astrometryFit.minimize() return int like photometry photometry code now compiles and python will run; doesn't fit (needs ref cat)
Start switching PhotometryFit to use Astrometry's Cholmod code
Load per-filter fluxes from refcat Add refCat flux loading to python Cleanup RefStar cruft
Move Chi2Entry/Chi2List out of *Fit and cleanup chi2 naming. Add computeAverageAndSigma() to Chi2List for *Fit to use.
Rename variables to better match document
Remove unnecessary line breaks Name and text cleanup
Correctly load refStar fluxErrs Improve chi2 and photometryTransfo output
Lift as many methods up into FitterBase as possible and refactor. Remove templating of chi2 accumulator and do it via inheritance. Lift getMapping into base PhotometryModel class. Add lots of missing documentation. Fix photomFactor use in jointcal.py
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've finished a zoomed-in, detail-oriented review of all of the code, with lots of small style requests. I'd like to take more of a big-picture look next week to better understand how all of the classes fit together, and would love to hear any thoughts you have on how to approach that.
algebra, the Cholmod and Eigen packages provide the required | ||
functionality. It turns out that for practical problems, the | ||
calculation of $J^TJ$ or the factorization are the most CPU intensive | ||
parts of the calculations, and |
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.
Interesting to note that in Bernstein (2017), the calculation of the matrix was more CPU intensive than the matrix factorization. The way we're fitting isn't exactly the same, but maybe this is a sign that with more complex models this statement may not hold.
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 it depends a lot on the models, but we'll have to see (e.g., our derivative approach saves us some work, I think). We'll definitely have to spend some time profiling jointcal in the future: I've reshuffled a lot of things, and haven't always been totally performance oriented (i.e., just make it work) in my thinking.
include/lsst/jointcal/Associations.h
Outdated
afw::geom::Angle matchCut, std::string const &fluxField); | ||
afw::geom::Angle matchCut, std::string const &fluxField, | ||
std::map<std::string, std::vector<double> > const &refFluxMap, | ||
std::map<std::string, std::vector<double> > const &refFluxErrMap); |
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.
C++11 means not having to add a space between those angle brackets at the end of a nested template type.
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 find it helps readability for me, otherwise I have trouble separating the brackets. We don't seem to have a documented standard on this.
include/lsst/jointcal/Associations.h
Outdated
@@ -43,7 +43,7 @@ class Associations { | |||
* Source selection is performed in python, so Associations' constructor | |||
* only initializes a couple of variables. | |||
*/ | |||
Associations(); | |||
Associations() : _commonTangentPoint(Point(0, 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.
I'm guessing this default is never supposed to be used, and if that's the case, NaN
might be a better choice to make it more apparent if it accidentally is.
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.
Thinking about it, you're probably right.
bool _fittingDistortions, _fittingPos, _fittingRefrac, _fittingPM; | ||
AstrometryModel *_astrometryModel; | ||
int _LastNTrip; // last triplet count, used to speed up allocation | ||
AstrometryModel &_astrometryModel; |
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 recommend against using references (const or otherwise) as data members. If you don't want any kind of ownership relationship between the two classes, I think raw pointer is a bit better because it makes it a bit more explicit what's going on (I'm guessing you have a reason why you can't use shared_ptr
or weak_ptr
instead here). I also think you need to delete
or redefine all of the compiler-generated copy/move constructors and assignment operators for either to be safe.
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 have any reason not to use a shared_ptr here: is there one? I think that'd be preferable to a raw pointer, but I'm not well versed enough to know better.
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've deleted the move/copy constructors/assignment for most things, with a comment as to why.
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 hard to know from just looking locally at the code whether shared_ptr
will work; it's mostly a question of whether there would be cycles (unlike Python, shared_ptr
doesn't do garbage collection).
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 some offline discussion, we decided that shared_ptr was appropriate for this case: the Associations
instance outlives any given fitter, and the Model
s must live at least as long as the fitter that works with them.
|
||
//! Produces both ntuples (cook up names from the provided string) | ||
void makeResTuple(const std::string &tupleName) const; | ||
void saveResultTuples(const std::string &tupleName) 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.
I'm sure this is preexisting, so don't feel obligated to fix it on this ticket, but DM convention would be std::string const & tupleName
.
Semi-unrelated doc request, just because I'm confused: what does this function do? Where does it save the things it claims to save?
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've gone and cleaned up a bunch of const T &
things, and added a better docstring for that method. It's mostly for debugging, by dumping the all the current internal values to text files. We probably want something better eventually.
src/FitterBase.cc
Outdated
causing the large chi2 we have in hand. */ | ||
bool drop_it = true; | ||
for (auto const &i : indices) | ||
if (affectedParams(i) != 0) drop_it = false; |
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.
Use braces after for
and if
.
src/FitterBase.cc
Outdated
// mark the parameters as directly changed when we discard this chi2 term. | ||
for (auto const &i : indices) affectedParams(i)++; | ||
nOutliers++; | ||
} |
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.
Fix/use more braces.
src/FitterBase.cc
Outdated
int nOutliers = findOutliers(nSigmaCut, msOutliers, fsOutliers); | ||
totalOutliers += nOutliers; | ||
if (nOutliers == 0) break; | ||
TripletList tripletList(1000); // initial allocation size. |
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.
Bothered by the magic number. Should at least be a product of the number of stars and/or CCD images, right?
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'm pretty sure it is exactly the number of outliers computed above. Fixed, thanks.
src/RefStar.cc
Outdated
// void RefStar::assignRefFluxes(std::vector<double> const &refFlux) { | ||
// _refFlux.clear(); | ||
// copy(refFlux.begin(), refFlux.end(), back_inserter(_refFlux)); | ||
// } |
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.
remove?
raise unittest.SkipTest("testdata_jointcal not setup") | ||
|
||
def setUp(self): | ||
do_plot = False |
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.
Lots of nonconforming variable names in this file.
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.
As above, I thought we were allowed to use pythonic _
names?
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.
Everywhere except for Science Pipelines code.
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.
So, wait, what does that leave? Where's the standard on this again?
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.
I'll hold off on converting for this ticket.
0ac89dc
to
991f8f7
Compare
I think I've responded/fixed to all of your comments with the latest commits. I'd love some suggestions regarding the data references as members questions (I'd be happy to chat on slack, so I can better understand why): I don't know if raw, shared, or other pointers are a better replacement. See also a few other questions above. |
Add Chi2.cc pulled from Chi2.h in review Fix many "const T &" -> "T const &" Make minimize() return an enum type Explicit delete or default copy/move for many classes Have Fitter constructors set _nPar* variables to 0, instead of calling overridden assignIndices(), which makes further sub-classes hard to create. cleanup doxygen
3e6a04c
to
447a761
Compare
This work developed out of the start of DM-9195, and I had to complete it before doing 9195, but it's worth its own review first.