LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
KernelPsf.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 #include "lsst/geom/Box.h"
7 
8 namespace lsst {
9 namespace afw {
10 namespace table {
11 namespace io {
12 
15 
16 } // namespace io
17 } // namespace table
18 } // namespace afw
19 namespace meas {
20 namespace algorithms {
21 
23 KernelPsf::doComputeKernelImage(geom::Point2D const& position, afw::image::Color const& color) const {
24  std::shared_ptr<Psf::Image> im = std::make_shared<Psf::Image>(_kernel->getDimensions());
25  _kernel->computeImage(*im, true, position.getX(), position.getY());
26  return im;
27 }
28 
29 geom::Box2I KernelPsf::doComputeBBox(geom::Point2D const& position, afw::image::Color const& color) const {
30  return _kernel->getBBox();
31 }
32 
33 KernelPsf::KernelPsf(afw::math::Kernel const& kernel, geom::Point2D const& averagePosition)
34  : ImagePsf(!kernel.isSpatiallyVarying()),
35  _kernel(kernel.clone()),
36  _averagePosition(averagePosition) {}
37 
39  : ImagePsf(!kernel->isSpatiallyVarying()), _kernel(kernel), _averagePosition(averagePosition) {}
40 
41 std::shared_ptr<afw::detection::Psf> KernelPsf::clone() const { return std::make_shared<KernelPsf>(*this); }
42 
44  return std::make_shared<KernelPsf>(*_kernel->resized(width, height), _averagePosition);
45 }
46 
47 geom::Point2D KernelPsf::getAveragePosition() const { return _averagePosition; }
48 
49 namespace {
50 
51 KernelPsfFactory<> registration("KernelPsf");
52 
53 } // namespace
54 
56  static KernelPsfPersistenceHelper instance;
57  return instance;
58 }
59 
60 KernelPsfPersistenceHelper::KernelPsfPersistenceHelper()
61  : schema(),
62  kernel(schema.addField<int>("kernel", "archive ID of nested kernel object")),
63  averagePosition(afw::table::PointKey<double>::addFields(
64  schema, "averagePosition", "average position of stars used to make the PSF", "pixel")) {}
65 
66 bool KernelPsf::isPersistable() const noexcept { return _kernel->isPersistable(); }
67 
68 std::string KernelPsf::getPersistenceName() const { return "KernelPsf"; }
69 
70 std::string KernelPsf::getPythonModule() const { return "lsst.meas.algorithms"; }
71 
74  afw::table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
76  record->set(keys.kernel, handle.put(_kernel));
77  record->set(keys.averagePosition, _averagePosition);
78  handle.saveCatalog(catalog);
79 }
80 
81 } // namespace algorithms
82 } // namespace meas
83 } // namespace lsst
Utilities for persisting KernelPsf and subclasses thereof.
table::Schema schema
Definition: python.h:134
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:110
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
Definition: Kernel.h:212
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
Definition: Kernel.cc:76
lsst::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:239
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:490
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.
Definition: Persistable.cc:18
An integer coordinate rectangle.
Definition: Box.h:55
An intermediate base class for Psfs that use an image representation.
Definition: ImagePsf.h:40
A PersistableFactory for KernelPsf and its subclasses.
KernelPsf(afw::math::Kernel const &kernel, geom::Point2D const &averagePosition=geom::Point2D())
Construct a KernelPsf with a clone of the given kernel.
Definition: KernelPsf.cc:33
bool isPersistable() const noexcept override
Whether this object is persistable; just delegates to the kernel.
Definition: KernelPsf.cc:66
std::shared_ptr< afw::detection::Psf > clone() const override
Polymorphic deep copy.
Definition: KernelPsf.cc:41
std::shared_ptr< afw::detection::Psf > resized(int width, int height) const override
Return a clone with specified kernel dimensions.
Definition: KernelPsf.cc:43
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: KernelPsf.cc:68
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: KernelPsf.cc:70
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: KernelPsf.cc:72
geom::Point2D getAveragePosition() const override
Return average position of stars; used as default position.
Definition: KernelPsf.cc:47
A base class for image defects.
afw::table::PointKey< double > averagePosition
Definition: CoaddPsf.cc:349
A read-only singleton struct containing the schema and key used in persistence for KernelPsf.
static KernelPsfPersistenceHelper const & get()
Definition: KernelPsf.cc:55