49 namespace algorithms {
53 inline double min4(
double a,
double b,
double c,
double d) {
57 inline double max4(
double a,
double b,
double c,
double d) {
65 int nx = im.getWidth();
66 int ny = im.getHeight();
68 auto out = std::make_shared<afw::detection::Psf::Image>(nx + 2 * xPad, ny + 2 * yPad);
69 out->setXY0(im.getX0() - xPad, im.getY0() - yPad);
78 static const int dst_padding = 0;
84 static const double maxTransformCoeff = 200.0;
87 throw LSST_EXCEPT(pex::exceptions::RangeError,
"Unexpectedly large transform passed to WarpedPsf");
91 int in_xlo =
bbox.getMinX();
92 int in_xhi =
bbox.getMinX() +
bbox.getWidth() - 1;
93 int in_ylo =
bbox.getMinY();
94 int in_yhi =
bbox.getMinY() +
bbox.getHeight() - 1;
105 int out_xlo =
floor(min4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) - dst_padding;
106 int out_ylo =
floor(min4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) - dst_padding;
107 int out_xhi =
ceil(max4(c00.getX(), c01.getX(), c10.getX(), c11.getX())) + dst_padding;
108 int out_yhi =
ceil(max4(c00.getY(), c01.getY(), c10.getY(), c11.getY())) + dst_padding;
130 afw::math::WarpingControl
const &wc) {
134 afw::math::SeparableKernel
const &kernel = *wc.getWarpingKernel();
136 int const xPad =
std::max(center.getX(), kernel.getWidth() - center.getX());
137 int const yPad =
std::max(center.getY(), kernel.getHeight() - center.getY());
141 auto ret = std::make_shared<afw::detection::Psf::Image>(
bbox);
157 _undistortedPsf(undistortedPsf),
158 _distortion(distortion),
159 _warpingControl(control) {
167 _undistortedPsf(undistortedPsf),
168 _distortion(distortion),
169 _warpingControl(new
afw::math::WarpingControl(kernelName,
"", cache)) {
173 void WarpedPsf::_init() {
176 "Undistorted Psf passed to WarpedPsf must not be None/NULL");
181 if (!_warpingControl) {
183 "WarpingControl passed to WarpedPsf must not be None/NULL");
213 double normFactor = 1.0;
219 for (
int y = 0;
y != ret->getHeight(); ++
y) {
222 normFactor += *imPtr;
225 if (normFactor == 0.0) {
243 struct PersistenceHelper {
249 static PersistenceHelper
const &get() {
250 static PersistenceHelper
const instance;
257 psfIndex(
schema.addField<int>(
"psfIndex",
"archive ID of nested Psf object")),
258 transformIndex(
schema.addField<int>(
"transformIndex",
"archive ID of nested Transform object")),
260 schema.addField<int>(
"controlIndex",
"archive ID of nested WarpingControl object")) {}
263 std::string _getPersistenceName() {
return "WarpedPsf"; }
265 class :
public afw::table::io::PersistableFactory {
268 afw::table::io::InputArchive
const &archive,
269 afw::table::io::CatalogVector
const &catalogs)
const {
270 static PersistenceHelper
const &
keys = PersistenceHelper::get();
273 afw::table::BaseRecord
const &record = catalogs.front().front();
275 return std::make_shared<WarpedPsf>(
276 archive.get<afw::detection::Psf>(record.get(
keys.psfIndex)),
278 archive.get<afw::math::WarpingControl>(record.get(
keys.controlIndex)));
282 } warpedPsfFactory(_getPersistenceName());
290 static PersistenceHelper
const &
keys = PersistenceHelper::get();
296 record->set(
keys.controlIndex, handle.
put(_warpingControl));
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
image::Image< Pixel > Image
Image type returned by computeImage.
Describe the colour of a source.
typename _view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
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.
PersistableFactory(std::string const &name)
Constructor for the factory.
An integer coordinate rectangle.
An intermediate base class for Psfs that use an image representation.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< afw::detection::Psf > resized(int width, int height) const override
Return a clone with specified kernel dimensions.
geom::Point2D getAveragePosition() const override
Return the average of the positions of the stars that went into this Psf.
std::shared_ptr< afw::detection::Psf::Image > doComputeKernelImage(geom::Point2D const &position, afw::image::Color const &color) const override
These virtual member functions are private, not protected, because we only want derived classes to im...
std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > _distortion
std::shared_ptr< afw::detection::Psf const > _undistortedPsf
WarpedPsf(std::shared_ptr< afw::detection::Psf const > undistortedPsf, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > distortion, std::shared_ptr< afw::math::WarpingControl const > control)
Construct WarpedPsf from unwarped psf and distortion.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::shared_ptr< afw::detection::Psf > clone() const override
Polymorphic deep copy. Usually unnecessary, as Psfs are immutable.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Reports invalid arguments.
Reports errors in the logical structure of the program.
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
lsst::geom::AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, lsst::geom::Point2D const &inPoint)
Approximate a Transform by its local linearization.
int warpImage(DestImageT &destImage, geom::SkyWcs const &destWcs, SrcImageT const &srcImage, geom::SkyWcs const &srcWcs, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
Warp an Image or MaskedImage to a new Wcs.
Extent< int, N > floor(Extent< double, N > const &input) noexcept
Return the component-wise floor (round towards more negative).
Extent< int, N > ceil(Extent< double, N > const &input) noexcept
Return the component-wise ceil (round towards more positive).
A base class for image defects.
afw::table::Key< int > controlIndex
afw::table::Key< int > transformIndex
afw::table::Key< int > psfIndex
afw::table::Schema schema
virtual std::shared_ptr< afw::table::io::Persistable > read(afw::table::io::InputArchive const &archive, afw::table::io::CatalogVector const &catalogs) const