47 PixelAreaBoundedField::PixelAreaBoundedField(
56 if (_skyWcs ==
nullptr) {
59 "SkyWcs passed to PixelAreaBoundedField is null."
62 _scaling /=
std::pow((1.0*unit).asRadians(), 2);
66 return std::pow(_skyWcs->getPixelScale(position).asRadians(), 2) * _scaling;
70 ndarray::Array<double const, 1>
const &
x,
71 ndarray::Array<double const, 1>
const &
y
73 if (
x.getShape() !=
y.getShape()) {
76 (
boost::format(
"Inconsistent shapes in evaluate; %s != %s.") %
x.getShape() %
y.getShape()).str()
81 double constexpr side = 1.0;
90 auto skyPoints = _skyWcs->pixelToSky(pixPoints);
92 ndarray::Array<double, 1, 1>
z = ndarray::allocate(
x.getShape());
95 auto skyLL = skyPoints[j].getVector();
96 auto skyDx = skyPoints[j + 1].getVector() - skyLL;
97 auto skyDy = skyPoints[j + 2].getVector() - skyLL;
98 double skyAreaSq = skyDx.cross(skyDy).getSquaredNorm();
99 z[i] = _scaling *
std::sqrt(skyAreaSq) / (side*side);
105 return _skyWcs->isPersistable();
114 if (!rhsCasted)
return false;
116 return getBBox() == rhsCasted->getBBox() && *_skyWcs == *rhsCasted->_skyWcs &&
117 _scaling == rhsCasted->_scaling;
120 std::string PixelAreaBoundedField::toString()
const {
122 os <<
"PixelAreaBoundedField(" << (*_skyWcs) <<
", scaling=" << _scaling <<
")";
129 struct PersistenceHelper {
135 static PersistenceHelper
const & get() {
136 static PersistenceHelper
const instance;
141 PersistenceHelper() :
144 wcs(
schema.addField<int>(
"wcs",
"Archive ID for SkyWcs instance.")),
146 "Scaling factor (including any transformation from rad^2."))
148 PersistenceHelper(PersistenceHelper
const &) =
delete;
149 PersistenceHelper(PersistenceHelper &&) =
delete;
150 PersistenceHelper &
operator=(PersistenceHelper
const &) =
delete;
151 PersistenceHelper &
operator=(PersistenceHelper &&) =
delete;
152 ~PersistenceHelper() noexcept = default;
155 class PixelAreaBoundedFieldFactory : public table::io::PersistableFactory {
158 :
afw::table::io::PersistableFactory(
name) {}
161 CatalogVector
const& catalogs)
const override {
164 table::BaseRecord
const& record = catalogs.front().front();
165 auto const &
keys = PersistenceHelper::get();
168 auto wcs = archive.get<afw::geom::SkyWcs>(record.get(
keys.wcs));
174 std::string getPixelAreaBoundedFieldPersistenceName() {
return "PixelAreaBoundedField"; }
176 PixelAreaBoundedFieldFactory registration(getPixelAreaBoundedFieldPersistenceName());
181 return getPixelAreaBoundedFieldPersistenceName();
187 auto const &
keys = PersistenceHelper::get();
191 record->set(
keys.wcs, handle.
put(_skyWcs));
192 record->set(
keys.scaling, _scaling);
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
A BoundedField that gives the amount a pixel is distorted at each point.
#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.
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
A BoundedField that evaluate the pixel area of a SkyWcs in angular units.
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.
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...
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.
An object passed to Persistable::write to allow it to persist itself.
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.
A class used to convert scalar POD types such as double to Angle.
An integer coordinate rectangle.
Reports invalid arguments.
T emplace_back(T... args)
def scale(algorithm, min, max=None, frame=None)
FilterProperty & operator=(FilterProperty const &)=default
BoxKey< lsst::geom::Box2I > Box2IKey
constexpr AngleUnit radians
constant with units of radians
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.
table::Key< double > scaling