34 namespace algorithms {
38 : afw::math::BoundedField(bbox),
39 _throwOnMissing(true),
42 _elements(elements) {}
47 _throwOnMissing(false),
50 _elements(elements) {}
53 auto coord = _coaddWcs->pixelToSky(position);
56 for (ElementVector::const_iterator i = _elements.
begin(); i != _elements.
end(); ++i) {
57 geom::Point2D transformedPosition = i->wcs->skyToPixel(coord);
58 bool inValidArea = i->validPolygon ? i->validPolygon->contains(transformedPosition) :
true;
59 if (
geom::Box2D(i->field->getBBox()).contains(transformedPosition) && inValidArea) {
60 sum += i->weight * i->field->evaluate(transformedPosition);
65 if (_throwOnMissing) {
67 (boost::format(
"No constituent fields to evaluate at point %f, %f") %
68 position.getX() % position.getY())
86 class CoaddBoundedFieldPersistenceKeys1 {
95 static CoaddBoundedFieldPersistenceKeys1
const&
get() {
96 static CoaddBoundedFieldPersistenceKeys1
const instance;
101 CoaddBoundedFieldPersistenceKeys1(
const CoaddBoundedFieldPersistenceKeys1&) =
delete;
102 CoaddBoundedFieldPersistenceKeys1&
operator=(
const CoaddBoundedFieldPersistenceKeys1&) =
delete;
105 CoaddBoundedFieldPersistenceKeys1(CoaddBoundedFieldPersistenceKeys1&&) =
delete;
106 CoaddBoundedFieldPersistenceKeys1&
operator=(CoaddBoundedFieldPersistenceKeys1&&) =
delete;
109 CoaddBoundedFieldPersistenceKeys1()
112 "lower-left corner of bounding box",
"pixel")),
114 "upper-right corner of bounding box",
"pixel")),
115 coaddWcs(schema.addField<
int>(
"coaddWcs",
"archive ID of the coadd's WCS")),
117 "throwOnMissing",
"whether to throw an exception on missing data")),
118 default_(schema.addField<
double>(
"default",
119 "default value to use when throwOnMissing is False")) {
120 schema.getCitizen().markPersistent();
125 class CoaddBoundedFieldPersistenceKeys2 {
127 afw::table::Schema
schema;
133 static CoaddBoundedFieldPersistenceKeys2
const&
get() {
134 static CoaddBoundedFieldPersistenceKeys2
const instance;
139 CoaddBoundedFieldPersistenceKeys2(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
140 CoaddBoundedFieldPersistenceKeys2&
operator=(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
143 CoaddBoundedFieldPersistenceKeys2(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
144 CoaddBoundedFieldPersistenceKeys2&
operator=(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
147 CoaddBoundedFieldPersistenceKeys2()
149 field(schema.addField<
int>(
"field",
"archive ID of the BoundedField to be coadded")),
150 wcs(schema.addField<
int>(
"wcs",
"archive ID of the Wcs associated with this element")),
152 "archive ID of the Polygon associated with this element")),
153 weight(schema.addField<
double>(
"weight",
"weight value for this element")) {
154 schema.getCitizen().markPersistent();
164 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
165 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
171 elements.
reserve(catalogs.back().size());
177 i->get(keys2.weight)));
179 return std::make_shared<CoaddBoundedField>(
180 geom::Box2I(record1.get(keys1.bboxMin), record1.get(keys1.bboxMax)),
182 record1.get(keys1.default_));
190 std::string getCoaddBoundedFieldPersistenceName() {
return "CoaddBoundedField"; }
201 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
202 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
205 record1->set(keys1.bboxMin,
getBBox().getMin());
206 record1->set(keys1.bboxMax,
getBBox().getMax());
207 record1->set(keys1.coaddWcs, handle.put(_coaddWcs));
208 record1->set(keys1.default_, _default);
209 handle.saveCatalog(cat1);
211 for (ElementVector::const_iterator i = _elements.begin(); i != _elements.end(); ++i) {
213 record2->set(keys2.field, handle.put(i->field));
214 record2->set(keys2.wcs, handle.put(i->wcs));
215 record2->set(keys2.validPolygon, handle.put(i->validPolygon));
216 record2->set(keys2.weight, i->weight);
218 handle.saveCatalog(cat2);
227 if (!rhsCasted)
return false;
229 return (
getBBox() == rhsCasted->getBBox()) && (_default == rhsCasted->_default) &&
230 ((*_coaddWcs) == (*rhsCasted->_coaddWcs)) && (_elements == rhsCasted->_elements);
virtual std::string getPersistenceName() const
virtual std::string getPythonModule() const
#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
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 > weight
CoaddBoundedField(geom::Box2I const &bbox, boost::shared_ptr< afw::geom::SkyWcs const > coaddWcs, ElementVector const &elements)
std::shared_ptr< BaseRecord > addNew()