Skip to content

Commit

Permalink
Remove CcdImageList std::list subclass
Browse files Browse the repository at this point in the history
CcdImageList is now just a typedef, and the "valid size" method got lifted
into Associations, where it fits nicely.
  • Loading branch information
parejkoj committed Mar 17, 2017
1 parent 8da60c6 commit 04e3e5d
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 69 deletions.
13 changes: 11 additions & 2 deletions include/lsst/jointcal/Associations.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

#include <string>
#include <iostream>

//#include "stringlist.h"
#include <list>

#include "lsst/afw/table/Source.h"
#include "lsst/afw/image/TanWcs.h"
Expand Down Expand Up @@ -117,6 +116,16 @@ class Associations {
const lsst::afw::geom::Box2D getRaDecBBox();


/**
* @brief return the number of CcdImages with non-empty catalogs to-be-fit.
*/
int nCcdImagesValidForFit() const
{
return std::count_if(ccdImageList.begin(), ccdImageList.end(),
[](std::shared_ptr<CcdImage> const &item)
{return item->getCatalogForFit().size() > 0;});
}

private:
void associateRefStars(double matchCutInArcsec, const Gtransfo* gtransfo);

Expand Down
43 changes: 4 additions & 39 deletions include/lsst/jointcal/CcdImage.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef CCDIMAGE__H
#define CCDIMAGE__H

#include <string>
#include <list>
#include <vector>
#include <string>

#include "lsst/afw/table/Source.h"
#include "lsst/afw/image/TanWcs.h"
Expand All @@ -19,6 +18,8 @@
namespace lsst {
namespace jointcal {

typedef std::list<std::shared_ptr<CcdImage> > CcdImageList;

typedef int VisitIdType;
typedef int CcdIdType;

Expand Down Expand Up @@ -188,42 +189,6 @@ class CcdImage : public RefCount
CcdImage(const CcdImage &); // forbid copies
};


/********* CcdImageList *************/


/**
* A list of CcdImage. Usually produced by Associations.
*/
//class CcdImageList : public std::list<CountedRef<CcdImage> >
class CcdImageList : public std::list<std::shared_ptr<CcdImage> >
{
public:

template<class Accept> CcdImageList SubList(const Accept &OP) const
{
CcdImageList out;
for (auto const &i: *this)
if (OP(*i)) out.push_back(i);
return out;
}

/**
* @brief Return the number of ccdImages with a populated catalogForFit list.
*/
int sizeValidForFit() const
{
return std::count_if(this->begin(), this->end(),
[](std::shared_ptr<CcdImage> const &item)
{return item->getCatalogForFit().size() > 0;});
}
};


typedef CcdImageList::iterator CcdImageIterator;
typedef CcdImageList::const_iterator CcdImageCIterator;

}
} // end of namespaces
}} // end of namespaces

#endif /* CCDIMAGE__H */
4 changes: 1 addition & 3 deletions include/lsst/jointcal/ConstrainedPolyModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CcdImage;
#include "lsst/jointcal/SimplePolyMapping.h"
#include "lsst/jointcal/ProjectionHandler.h"
#include "lsst/jointcal/TwoTransfoMapping.h"
#include "lsst/jointcal/CcdImage.h" // for VisitIdType;
#include "lsst/jointcal/CcdImage.h"


#include <map>
Expand All @@ -22,8 +22,6 @@ class CcdImage;
namespace lsst {
namespace jointcal {

class CcdImageList;

/**
* This is the model used to fit mappings as the combination of a
* transformation depending on the chip number (instrument model) and a
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/jointcal/ProjectionHandler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PROJECTIONHANDLER__H
#define PROJECTIONHANDLER__H

#include "lsst/jointcal/CcdImage.h"
#include "lsst/jointcal/Gtransfo.h"
#include "map"

Expand All @@ -9,7 +10,6 @@ namespace jointcal {

class Mapping;
class CcdImage;
class CcdImageList;

/**
* This is a virtual class that allows a lot of freedom in the choice of the
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/jointcal/SimplePhotometryModel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SIMPLEPHOTOMMODEL__H
#define SIMPLEPHOTOMMODEL__H

#include "lsst/jointcal/CcdImage.h"
#include "lsst/jointcal/Eigenstuff.h"
#include "lsst/jointcal/PhotometryModel.h"
#include "lsst/jointcal/Point.h"
Expand All @@ -9,7 +10,6 @@
namespace lsst {
namespace jointcal {

class CcdImageList;
class CcdImage;
class Point;

Expand Down
1 change: 0 additions & 1 deletion include/lsst/jointcal/SimplePolyModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace lsst {
namespace jointcal {

class CcdImage;
class CcdImageList;

/* We deal here with coordinate transforms which are fitted
and/or necessary to AstrometryFit. The classes SimplePolyModel
Expand Down
2 changes: 2 additions & 0 deletions python/lsst/jointcal/associations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "lsst/jointcal/Associations.h"
#include "lsst/jointcal/CcdImage.h"
Expand All @@ -43,6 +44,7 @@ void declareAssociations(py::module &mod) {
"matchCutInArcsec"_a=0, "useFittedList"_a=false, "enlargeFittedList"_a=true);
cls.def("collectRefStars", &Associations::collectRefStars);
cls.def("deprojectFittedStars", &Associations::deprojectFittedStars);
cls.def("nCcdImagesValidForFit", &Associations::nCcdImagesValidForFit);

cls.def("addImage", &Associations::addImage);
cls.def("selectFittedStars", &Associations::selectFittedStars);
Expand Down
1 change: 1 addition & 0 deletions python/lsst/jointcal/astrometryModels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "lsst/jointcal/CcdImage.h"
#include "lsst/jointcal/AstrometryModel.h"
Expand Down
15 changes: 0 additions & 15 deletions python/lsst/jointcal/ccdImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include <list>

#include "lsst/jointcal/CcdImage.h"

namespace py = pybind11;
Expand Down Expand Up @@ -60,23 +58,10 @@ void declareCcdImage(py::module &mod) {

}

void declareCcdImageList(py::module &mod) {
py::class_<CcdImageList, std::shared_ptr<CcdImageList>> cls(mod, "CcdImageList");

cls.def("sizeValidForFit", &CcdImageList::sizeValidForFit);

// Make this behave like a std::list (which it is but we can't wrap std::list subclasses trivially)
cls.def("__len__", &CcdImageList::size);
cls.def("__iter__", [](const CcdImageList &self) {
return py::make_iterator(self.begin(), self.end());
}, py::keep_alive<0, 1>()); /* Essential: keep object alive while iterator exists */
}

PYBIND11_PLUGIN(ccdImage) {
py::module mod("ccdImage");

declareCcdImage(mod);
declareCcdImageList(mod);

return mod.ptr();
}
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/jointcal/jointcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _do_load_refcat_and_fit(self, associations, defaultFilter, center, radius,
self._check_star_lists(associations, name)
self.metrics['selected%sRefStars' % name] = associations.refStarListSize()
self.metrics['selected%sFittedStars' % name] = associations.fittedStarListSize()
self.metrics['selected%sCcdImageList' % name] = associations.ccdImageList.sizeValidForFit()
self.metrics['selected%sCcdImageList' % name] = associations.nCcdImagesValidForFit()

load_cat_prof_file = 'jointcal_fit_%s.prof'%name if profile_jointcal else ''
with pipeBase.cmdLineTask.profile(load_cat_prof_file):
Expand All @@ -374,7 +374,7 @@ def _do_load_refcat_and_fit(self, associations, defaultFilter, center, radius,

def _check_star_lists(self, associations, name):
# TODO: these should be len(blah), but we need this properly wrapped first.
if associations.ccdImageList.sizeValidForFit() == 0:
if associations.nCcdImagesValidForFit() == 0:
raise RuntimeError('No images in the ccdImageList!')
if associations.fittedStarListSize() == 0:
raise RuntimeError('No stars in the {} fittedStarList!'.format(name))
Expand Down
1 change: 1 addition & 0 deletions python/lsst/jointcal/photometryModels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "lsst/jointcal/CcdImage.h"
#include "lsst/jointcal/PhotometryModel.h"
Expand Down
1 change: 1 addition & 0 deletions python/lsst/jointcal/projectionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "lsst/jointcal/ProjectionHandler.h"
#include "lsst/jointcal/CcdImage.h"
Expand Down
9 changes: 4 additions & 5 deletions src/ConstrainedPolyModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ ConstrainedPolyModel::ConstrainedPolyModel(const CcdImageList &ccdImageList,
{
// from datacards (or default)
unsigned degree = DistortionDegree;
unsigned count = 0;
VisitIdType refVisit;
// first loop to initialize all visit and chip transfos.
for (auto i=ccdImageList.cbegin(); i!= ccdImageList.cend(); ++i, ++count)
for (auto &ccdImage: ccdImageList)
{
const CcdImage &im = **i;
const CcdImage &im = *ccdImage;
unsigned visit = im.getVisit();
unsigned chip = im.getCcdId();
auto visitp = _visitMap.find(visit);
Expand Down Expand Up @@ -88,9 +87,9 @@ ConstrainedPolyModel::ConstrainedPolyModel(const CcdImageList &ccdImageList,
}
}
// now, second loop to set the mappings of the CCdImages
for (auto i=ccdImageList.cbegin(); i!= ccdImageList.cend(); ++i, ++count)
for (auto &ccdImage: ccdImageList)
{
const CcdImage &im = **i;
const CcdImage &im = *ccdImage;
unsigned visit = im.getVisit();
unsigned chip = im.getCcdId();
// check that the chip_indexed part was indeed assigned
Expand Down

0 comments on commit 04e3e5d

Please sign in to comment.