45 namespace algorithms {
55 bool ptrEquals(T a, T
b) {
75 : afw::math::BoundedField(
bbox),
76 _throwOnMissing(true),
79 _elements(elements) {}
83 : afw::math::BoundedField(
bbox),
84 _throwOnMissing(false),
87 _elements(elements) {}
90 auto coord = _coaddWcs->pixelToSky(position);
93 for (ElementVector::const_iterator i = _elements.
begin(); i != _elements.
end(); ++i) {
94 geom::Point2D transformedPosition = i->wcs->skyToPixel(coord);
95 bool inValidArea = i->validPolygon ? i->validPolygon->contains(transformedPosition) :
true;
97 sum += i->weight * i->field->evaluate(transformedPosition);
102 if (_throwOnMissing) {
104 (boost::format(
"No constituent fields to evaluate at point %f, %f") %
105 position.getX() % position.getY())
123 class CoaddBoundedFieldPersistenceKeys1 {
132 static CoaddBoundedFieldPersistenceKeys1
const& get() {
133 static CoaddBoundedFieldPersistenceKeys1
const instance;
138 CoaddBoundedFieldPersistenceKeys1(
const CoaddBoundedFieldPersistenceKeys1&) =
delete;
139 CoaddBoundedFieldPersistenceKeys1&
operator=(
const CoaddBoundedFieldPersistenceKeys1&) =
delete;
142 CoaddBoundedFieldPersistenceKeys1(CoaddBoundedFieldPersistenceKeys1&&) =
delete;
143 CoaddBoundedFieldPersistenceKeys1&
operator=(CoaddBoundedFieldPersistenceKeys1&&) =
delete;
146 CoaddBoundedFieldPersistenceKeys1()
148 bboxMin(afw::table::PointKey<int>::addFields(
schema,
"bbox_min",
149 "lower-left corner of bounding box",
"pixel")),
150 bboxMax(afw::table::PointKey<int>::addFields(
schema,
"bbox_max",
151 "upper-right corner of bounding box",
"pixel")),
152 coaddWcs(
schema.addField<int>(
"coaddWcs",
"archive ID of the coadd's WCS")),
154 "throwOnMissing",
"whether to throw an exception on missing data")),
156 "default value to use when throwOnMissing is False")) {}
160 class CoaddBoundedFieldPersistenceKeys2 {
162 afw::table::Schema
schema;
168 static CoaddBoundedFieldPersistenceKeys2
const& get() {
169 static CoaddBoundedFieldPersistenceKeys2
const instance;
174 CoaddBoundedFieldPersistenceKeys2(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
175 CoaddBoundedFieldPersistenceKeys2&
operator=(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
178 CoaddBoundedFieldPersistenceKeys2(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
179 CoaddBoundedFieldPersistenceKeys2&
operator=(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
182 CoaddBoundedFieldPersistenceKeys2()
184 field(
schema.addField<int>(
"field",
"archive ID of the BoundedField to be coadded")),
185 wcs(
schema.addField<int>(
"wcs",
"archive ID of the Wcs associated with this element")),
187 "archive ID of the Polygon associated with this element")),
188 weight(
schema.addField<double>(
"weight",
"weight value for this element")) {}
197 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
198 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
204 elements.
reserve(catalogs.back().size());
210 i->get(keys2.weight)));
212 return std::make_shared<CoaddBoundedField>(
215 record1.
get(keys1.default_));
223 std::string getCoaddBoundedFieldPersistenceName() {
return "CoaddBoundedField"; }
225 CoaddBoundedField::Factory registration(getCoaddBoundedFieldPersistenceName());
234 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
235 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
238 record1->set(keys1.bboxMin,
getBBox().getMin());
239 record1->set(keys1.bboxMax,
getBBox().getMax());
240 record1->set(keys1.coaddWcs, handle.put(_coaddWcs));
241 record1->set(keys1.default_, _default);
242 handle.saveCatalog(cat1);
244 for (ElementVector::const_iterator i = _elements.
begin(); i != _elements.
end(); ++i) {
246 record2->set(keys2.field, handle.put(i->field));
247 record2->set(keys2.wcs, handle.put(i->wcs));
248 record2->set(keys2.validPolygon, handle.put(i->validPolygon));
249 record2->set(keys2.weight, i->weight);
251 handle.saveCatalog(cat2);
260 if (!rhsCasted)
return false;
262 return (
getBBox() == rhsCasted->getBBox()) && (_default == rhsCasted->_default) &&
263 ptrEquals(_coaddWcs, rhsCasted->_coaddWcs) && (_elements == rhsCasted->_elements);
afw::table::Key< double > weight
afw::table::PointKey< int > bboxMax
afw::table::Key< afw::table::Flag > throwOnMissing
afw::table::Key< int > coaddWcs
afw::table::Key< int > field
afw::table::Key< double > default_
afw::table::Key< int > validPolygon
afw::table::Schema schema
afw::table::PointKey< int > bboxMin
afw::table::Key< int > wcs
afw::table::Key< double > b
#define LSST_EXCEPT(type,...)
#define LSST_ARCHIVE_ASSERT(EXPR)
lsst::geom::Box2I getBBox() const
Field< T >::Value get(Key< T > const &key) const
std::shared_ptr< BaseRecord > addNew()
CatalogIterator< typename Internal::const_iterator > const_iterator
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
io::OutputArchiveHandle OutputArchiveHandle
bool contains(Point2D const &point) const noexcept
Factory(std::string const &name)
void write(OutputArchiveHandle &handle) const override
CoaddBoundedField(geom::Box2I const &bbox, boost::shared_ptr< afw::geom::SkyWcs const > coaddWcs, ElementVector const &elements)
std::string getPythonModule() const override
double evaluate(geom::Point2D const &position) const override
boost::shared_ptr< afw::math::BoundedField > operator*(double const scale) const override
bool operator==(BoundedField const &rhs) const override
BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal.
std::string getPersistenceName() const override
FilterProperty & operator=(FilterProperty const &)=default
Struct used to hold one Exposure's data in a CoaddBoundedField.
boost::shared_ptr< afw::geom::SkyWcs const > wcs
boost::shared_ptr< afw::geom::polygon::Polygon const > validPolygon
boost::shared_ptr< afw::math::BoundedField > field