29 #include "lsst/afw/table/io/Persistable.cc" 45 namespace algorithms {
55 bool ptrEquals(T
a, T
b) {
75 :
afw::math::BoundedField(bbox),
76 _throwOnMissing(true),
79 _elements(elements) {}
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()
149 "lower-left corner of bounding box",
"pixel")),
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")),
155 default_(schema.addField<
double>(
"default",
156 "default value to use when throwOnMissing is False")) {
157 schema.getCitizen().markPersistent();
162 class CoaddBoundedFieldPersistenceKeys2 {
164 afw::table::Schema
schema;
170 static CoaddBoundedFieldPersistenceKeys2
const&
get() {
171 static CoaddBoundedFieldPersistenceKeys2
const instance;
176 CoaddBoundedFieldPersistenceKeys2(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
177 CoaddBoundedFieldPersistenceKeys2&
operator=(
const CoaddBoundedFieldPersistenceKeys2&) =
delete;
180 CoaddBoundedFieldPersistenceKeys2(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
181 CoaddBoundedFieldPersistenceKeys2&
operator=(CoaddBoundedFieldPersistenceKeys2&&) =
delete;
184 CoaddBoundedFieldPersistenceKeys2()
186 field(schema.addField<
int>(
"field",
"archive ID of the BoundedField to be coadded")),
187 wcs(schema.addField<
int>(
"wcs",
"archive ID of the Wcs associated with this element")),
189 "archive ID of the Polygon associated with this element")),
190 weight(schema.addField<
double>(
"weight",
"weight value for this element")) {
191 schema.getCitizen().markPersistent();
201 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
202 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
208 elements.
reserve(catalogs.back().size());
214 i->get(keys2.weight)));
216 return std::make_shared<CoaddBoundedField>(
217 geom::Box2I(record1.get(keys1.bboxMin), record1.get(keys1.bboxMax)),
219 record1.get(keys1.default_));
227 std::string getCoaddBoundedFieldPersistenceName() {
return "CoaddBoundedField"; }
238 CoaddBoundedFieldPersistenceKeys1
const& keys1 = CoaddBoundedFieldPersistenceKeys1::get();
239 CoaddBoundedFieldPersistenceKeys2
const& keys2 = CoaddBoundedFieldPersistenceKeys2::get();
242 record1->set(keys1.bboxMin,
getBBox().getMin());
243 record1->set(keys1.bboxMax,
getBBox().getMax());
244 record1->set(keys1.coaddWcs, handle.
put(_coaddWcs));
245 record1->set(keys1.default_, _default);
248 for (ElementVector::const_iterator i = _elements.
begin(); i != _elements.
end(); ++i) {
250 record2->set(keys2.field, handle.
put(i->field));
251 record2->set(keys2.wcs, handle.
put(i->wcs));
252 record2->set(keys2.validPolygon, handle.
put(i->validPolygon));
253 record2->set(keys2.weight, i->weight);
264 if (!rhsCasted)
return false;
266 return (
getBBox() == rhsCasted->getBBox()) && (_default == rhsCasted->_default) &&
267 ptrEquals(_coaddWcs, rhsCasted->_coaddWcs) && (_elements == rhsCasted->_elements);
Struct used to hold one Exposure's data in a CoaddBoundedField.
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
boost::shared_ptr< afw::geom::SkyWcs const > wcs
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
afw::table::Key< double > default_
A floating-point coordinate rectangle geometry.
An object passed to Persistable::write to allow it to persist itself.
CoaddBoundedFieldElement Element
A base class for factory classes used to reconstruct objects from records.
def scale(algorithm, min, max=None, frame=None)
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
Reports arguments outside the domain of an operation.
double evaluate(geom::Point2D const &position) const override
Evaluate the field at the given point.
afw::table::Schema schema
afw::table::PointKey< int > bboxMax
A base class for objects that can be persisted via afw::table::io Archive classes.
BoundedField & operator=(BoundedField const &)=delete
afw::table::PointKey< int > bboxMin
Reports attempts to access elements using an invalid key.
afw::table::Key< int > field
bool operator==(BoundedField const &rhs) const override
BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal...
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
BoundedField(BoundedField const &)=default
A base class for image defects.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Iterator class for CatalogT.
afw::table::Key< int > coaddWcs
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
boost::shared_ptr< afw::math::BoundedField > operator*(double const scale) const override
Return a scaled BoundedField.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
Factory(std::string const &name)
afw::table::Key< double > weight
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
A vector of catalogs used by Persistable.
Base class for all records.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
An abstract base class for 2-d functions defined on an integer bounding boxes.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
afw::table::Key< int > validPolygon
CoaddBoundedField(geom::Box2I const &bbox, boost::shared_ptr< afw::geom::SkyWcs const > coaddWcs, ElementVector const &elements)
afw::table::Key< int > wcs
An integer coordinate rectangle.
afw::table::Key< afw::table::Flag > throwOnMissing
boost::shared_ptr< afw::math::BoundedField > field
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
boost::shared_ptr< afw::geom::polygon::Polygon const > validPolygon