26 #include "ndarray/eigen.h" 47 if (factors.size() < 1u) {
49 pex::exceptions::LengthError,
50 "ProductBoundedField requires at least one BoundedField factor." 53 auto iter = factors.begin();
54 auto bbox = (**iter).getBBox();
56 for (;
iter != factors.end(); ++
iter) {
57 if ((**iter).getBBox() !=
bbox) {
59 pex::exceptions::InvalidParameterError,
60 (boost::format(
"Inconsistency in ProductBoundedField bboxes: %s != %s") %
61 bbox % (**iter).getBBox()).str()
71 BoundedField(checkAndExtractBBox(factors)), _factors(factors)
80 for (
auto const &
field : _factors) {
81 product *=
field->evaluate(position);
87 ndarray::Array<double const, 1>
const&
x,
88 ndarray::Array<double const, 1>
const&
y 90 if (x.getShape() != y.getShape()) {
93 (boost::format(
"Inconsistent shapes: %s != %s") % x.getShape() % y.getShape()).str()
96 ndarray::Array<double, 1, 1>
z = ndarray::allocate(x.getShape());
98 for (
auto const &
field : _factors) {
99 ndarray::asEigenArray(z) *= ndarray::asEigenArray(
field->evaluate(x, y));
108 struct PersistenceHelper {
112 static PersistenceHelper
const &
get() {
113 static PersistenceHelper
const instance;
119 PersistenceHelper() :
121 id(schema.addField<
int>(
"id",
"Archive ID of a BoundedField factor."))
124 PersistenceHelper(PersistenceHelper
const &) =
delete;
125 PersistenceHelper(PersistenceHelper &&) =
delete;
126 PersistenceHelper &
operator=(PersistenceHelper
const &) =
delete;
127 PersistenceHelper &
operator=(PersistenceHelper &&) =
delete;
129 ~PersistenceHelper() noexcept =
default;
133 class ProductBoundedFieldFactory :
public table::io::PersistableFactory {
136 : afw::table::io::PersistableFactory(name) {}
139 CatalogVector
const& catalogs)
const override {
141 auto const &
keys = PersistenceHelper::get();
142 auto const & cat = catalogs.front();
145 for (
auto const & record : cat) {
148 return std::make_shared<ProductBoundedField>(factors);
152 std::string getProductBoundedFieldPersistenceName() {
return "ProductBoundedField"; }
154 ProductBoundedFieldFactory registration(getProductBoundedFieldPersistenceName());
159 return std::all_of(_factors.begin(), _factors.end(),
160 [](
auto const &
field) {
return field->isPersistable(); });
164 return getProductBoundedFieldPersistenceName();
170 auto const &
keys = PersistenceHelper::get();
172 catalog.
reserve(_factors.size());
173 for (
auto const &
field : _factors) {
183 bool multiplied =
false;
184 for (
auto &
field : factors) {
192 ndarray::Array<double, 2, 2>
coefficients = ndarray::allocate(1, 1);
193 coefficients[0][0] =
scale;
194 factors.push_back(std::make_shared<ChebyshevBoundedField>(
getBBox(), coefficients));
196 return std::make_shared<ProductBoundedField>(factors);
201 if (!rhsCasted)
return false;
203 return (
getBBox() == rhsCasted->getBBox()) &&
205 rhsCasted->_factors.begin(), rhsCasted->_factors.end(),
206 [](
auto const &
a,
auto const &
b) {
return *
a == *
b; });
209 std::string ProductBoundedField::toString()
const {
211 os <<
"ProductBoundedField([";
212 for (
auto const &
field : _factors) {
213 os << (*field) <<
", ";
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...
ProductBoundedField & operator=(ProductBoundedField const &)=delete
An object passed to Persistable::write to allow it to persist itself.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
ProductBoundedField(std::vector< std::shared_ptr< BoundedField const >> const &factors)
Construct from a sequence of BoundedField factors.
def scale(algorithm, min, max=None, frame=None)
A BoundedField that lazily multiplies a sequence of other BoundedFields.
ndarray::Array< double const, 2, 2 > coefficients
BoundedField(BoundedField const &)=default
A base class for image defects.
bool isPersistable() const noexcept override
ProductBoundedField is persistable if and only if all of its factors are.
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
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...
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
#define LSST_EXCEPT(type,...)
double evaluate(lsst::geom::Point2D const &position) const override
Evaluate the field at the given point.
An abstract base class for 2-d functions defined on an integer bounding boxes.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
~ProductBoundedField() override
std::shared_ptr< BoundedField > operator*(double const scale) const override
Return a scaled BoundedField.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.