34 namespace algorithms {
44 bool ptrEquals(T a, T
b) {
64 : afw::math::BoundedField(bbox),
65 _throwOnMissing(true),
68 _elements(elements) {}
73 _throwOnMissing(false),
76 _elements(elements) {}
79 auto coord = _coaddWcs->pixelToSky(position);
82 for (ElementVector::const_iterator i = _elements.
begin(); i != _elements.
end(); ++i) {
83 geom::Point2D transformedPosition = i->wcs->skyToPixel(coord);
84 bool inValidArea = i->validPolygon ? i->validPolygon->contains(transformedPosition) :
true;
85 if (
geom::Box2D(i->field->getBBox()).contains(transformedPosition) && inValidArea) {
86 sum += i->weight * i->field->evaluate(transformedPosition);
91 if (_throwOnMissing) {
93 (boost::format(
"No constituent fields to evaluate at point %f, %f") %
94 position.getX() % position.getY())
112 class CoaddBoundedFieldPersistenceKeys1 {
121 static CoaddBoundedFieldPersistenceKeys1
const&
get() {
122 static CoaddBoundedFieldPersistenceKeys1
const instance;
127 CoaddBoundedFieldPersistenceKeys1(
const CoaddBoundedFieldPersistenceKeys1&) =
delete;
128 CoaddBoundedFieldPersistenceKeys1&
operator=(
const CoaddBoundedFieldPersistenceKeys1&) =
delete;
131 CoaddBoundedFieldPersistenceKeys1(CoaddBoundedFieldPersistenceKeys1&&) =
delete;
132 CoaddBoundedFieldPersistenceKeys1&
operator=(CoaddBoundedFieldPersistenceKeys1&&) =
delete;
135 CoaddBoundedFieldPersistenceKeys1()
138 "lower-left corner of bounding box",
"pixel")),
140 "upper-right corner of bounding box",
"pixel")),
141 coaddWcs(schema.addField<
int>(
"coaddWcs",
"archive ID of the coadd's WCS")),
143 "throwOnMissing",
"whether to throw an exception on missing data")),
144 default_(schema.addField<
double>(
"default",
145 "default value to use when throwOnMissing is False")) {
146 schema.getCitizen().markPersistent();
151 class CoaddBoundedFieldPersistenceKeys2 {
153 afw::table::Schema
schema;
159 static CoaddBoundedFieldPersistenceKeys2
const&
get() {
160 static CoaddBoundedFieldPersistenceKeys2
const instance;
165 CoaddBoundedFieldPersistenceKeys2(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
166 CoaddBoundedFieldPersistenceKeys2&
operator=(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
169 CoaddBoundedFieldPersistenceKeys2(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
170 CoaddBoundedFieldPersistenceKeys2&
operator=(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
173 CoaddBoundedFieldPersistenceKeys2()
175 field(schema.addField<
int>(
"field",
"archive ID of the BoundedField to be coadded")),
176 wcs(schema.addField<
int>(
"wcs",
"archive ID of the Wcs associated with this element")),
178 "archive ID of the Polygon associated with this element")),
179 weight(schema.addField<
double>(
"weight",
"weight value for this element")) {
180 schema.getCitizen().markPersistent();
190 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
191 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
197 elements.
reserve(catalogs.back().size());
203 i->get(keys2.weight)));
205 return std::make_shared<CoaddBoundedField>(
206 geom::Box2I(record1.get(keys1.bboxMin), record1.get(keys1.bboxMax)),
208 record1.get(keys1.default_));
216 std::string getCoaddBoundedFieldPersistenceName() {
return "CoaddBoundedField"; }
227 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
228 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
231 record1->set(keys1.bboxMin,
getBBox().getMin());
232 record1->set(keys1.bboxMax,
getBBox().getMax());
233 record1->set(keys1.coaddWcs, handle.put(_coaddWcs));
234 record1->set(keys1.default_, _default);
235 handle.saveCatalog(cat1);
237 for (ElementVector::const_iterator i = _elements.begin(); i != _elements.end(); ++i) {
239 record2->set(keys2.field, handle.put(i->field));
240 record2->set(keys2.wcs, handle.put(i->wcs));
241 record2->set(keys2.validPolygon, handle.put(i->validPolygon));
242 record2->set(keys2.weight, i->weight);
244 handle.saveCatalog(cat2);
253 if (!rhsCasted)
return false;
255 return (
getBBox() == rhsCasted->getBBox()) && (_default == rhsCasted->_default) &&
256 ptrEquals(_coaddWcs, rhsCasted->_coaddWcs) && (_elements == rhsCasted->_elements);
virtual std::string getPersistenceName() const
Struct used to hold one Exposure's data in a CoaddBoundedField.
virtual std::string getPythonModule() const
boost::shared_ptr< afw::geom::SkyWcs const > wcs
#define LSST_ARCHIVE_ASSERT(EXPR)
CoaddBoundedFieldElement Element
afw::table::Key< int > wcs
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
afw::table::PointKey< int > bboxMax
afw::table::Key< int > validPolygon
afw::table::PointKey< int > bboxMin
afw::table::Key< double > default_
virtual void write(OutputArchiveHandle &handle) const
bool operator==(CoaddBoundedFieldElement const &rhs) const
Elements are equal if all their components are equal.
BoundedField & operator=(BoundedField const &)=delete
BoundedField(BoundedField const &)=default
afw::table::Key< afw::table::Flag > throwOnMissing
afw::table::Key< int > field
virtual bool operator==(BoundedField const &rhs) const
BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal...
afw::table::Schema schema
lsst::geom::Box2I getBBox() const
afw::table::Key< int > coaddWcs
virtual double evaluate(geom::Point2D const &position) const
CatalogIterator< typename Internal::const_iterator > const_iterator
Factory(std::string const &name)
#define LSST_EXCEPT(type,...)
virtual boost::shared_ptr< afw::math::BoundedField > operator*(double const scale) const
io::OutputArchiveHandle OutputArchiveHandle
afw::table::Key< double > b
afw::table::Key< double > weight
CoaddBoundedField(geom::Box2I const &bbox, boost::shared_ptr< afw::geom::SkyWcs const > coaddWcs, ElementVector const &elements)
boost::shared_ptr< afw::math::BoundedField > field
std::shared_ptr< BaseRecord > addNew()
boost::shared_ptr< afw::geom::polygon::Polygon const > validPolygon