36template std::shared_ptr<math::PixelAreaBoundedField>
38 std::shared_ptr<table::io::Persistable>
const&
55 if (_skyWcs ==
nullptr) {
58 "SkyWcs passed to PixelAreaBoundedField is null."
61 _scaling /=
std::pow((1.0*unit).asRadians(), 2);
65 return std::pow(_skyWcs->getPixelScale(position).asRadians(), 2) * _scaling;
69 ndarray::Array<double const, 1>
const & x,
70 ndarray::Array<double const, 1>
const & y
72 if (x.getShape() != y.getShape()) {
75 (boost::format(
"Inconsistent shapes in evaluate; %s != %s.") % x.getShape() % y.getShape()).str()
80 double constexpr side = 1.0;
89 auto skyPoints = _skyWcs->pixelToSky(pixPoints);
91 ndarray::Array<double, 1, 1> z = ndarray::allocate(x.getShape());
94 auto skyLL = skyPoints[j].getVector();
95 auto skyDx = skyPoints[j + 1].getVector() - skyLL;
96 auto skyDy = skyPoints[j + 2].getVector() - skyLL;
97 double skyAreaSq = skyDx.cross(skyDy).getSquaredNorm();
98 z[i] = _scaling *
std::sqrt(skyAreaSq) / (side*side);
104 return _skyWcs->isPersistable();
113 if (!rhsCasted)
return false;
115 return getBBox() == rhsCasted->getBBox() && *_skyWcs == *rhsCasted->_skyWcs &&
116 _scaling == rhsCasted->_scaling;
121 os <<
"PixelAreaBoundedField(" << (*_skyWcs) <<
", scaling=" << _scaling <<
")";
128struct PersistenceHelper {
134 static PersistenceHelper
const & get() {
135 static PersistenceHelper
const instance;
140 PersistenceHelper() :
142 bbox(
table::Box2IKey::addFields(schema,
"bbox",
"Bounding box for field.",
"pixel")),
143 wcs(schema.addField<int>(
"wcs",
"Archive ID for SkyWcs instance.")),
144 scaling(schema.addField<double>(
"scaling",
145 "Scaling factor (including any transformation from rad^2."))
147 PersistenceHelper(PersistenceHelper
const &) =
delete;
148 PersistenceHelper(PersistenceHelper &&) =
delete;
149 PersistenceHelper & operator=(PersistenceHelper
const &) =
delete;
150 PersistenceHelper & operator=(PersistenceHelper &&) =
delete;
151 ~PersistenceHelper() noexcept = default;
154class PixelAreaBoundedFieldFactory : public table::io::PersistableFactory {
156 explicit PixelAreaBoundedFieldFactory(
std::string const& name)
157 :
afw::table::io::PersistableFactory(name) {}
160 CatalogVector
const& catalogs)
const override {
163 table::BaseRecord
const& record = catalogs.front().front();
164 auto const & keys = PersistenceHelper::get();
167 auto wcs = archive.get<afw::geom::SkyWcs>(record.get(keys.wcs));
168 double scaling = record.get(keys.scaling);
173std::string getPixelAreaBoundedFieldPersistenceName() {
return "PixelAreaBoundedField"; }
175PixelAreaBoundedFieldFactory registration(getPixelAreaBoundedFieldPersistenceName());
180 return getPixelAreaBoundedFieldPersistenceName();
186 auto const & keys = PersistenceHelper::get();
189 record->set(keys.bbox,
getBBox());
190 record->set(keys.wcs, handle.
put(_skyWcs));
191 record->set(keys.scaling, _scaling);
#define LSST_EXCEPT(type,...)
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
A BoundedField that gives the amount a pixel is distorted at each point.
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
BoundedField(BoundedField const &)=default
double evaluate(lsst::geom::Point2D const &position) const override
Evaluate the field at the given point.
std::shared_ptr< BoundedField > operator*(double const scale) const override
Return a scaled BoundedField.
bool isPersistable() const noexcept override
PixelAreaBoundedField is persistable if and only if the nested SkyWcs is.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
PixelAreaBoundedField(lsst::geom::Box2I const &bbox, std::shared_ptr< geom::SkyWcs const > skyWcs, lsst::geom::AngleUnit const &unit=lsst::geom::radians, double scaling=1.0)
Create a PixelAreaBoundedField from a SkyWcs.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
std::string toString() 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::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
A class used as a handle to a particular field in a table.
Defines the fields and offsets for a table.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
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...
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
io::OutputArchiveHandle OutputArchiveHandle
T emplace_back(T... args)
CatalogT< BaseRecord > BaseCatalog
BoxKey< lsst::geom::Box2I > Box2IKey
AngleUnit constexpr radians
Point< double, 2 > Point2D
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override