LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
DeltaFunctionKernel.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 #include <sstream>
25 #include <vector>
26 
27 #include "lsst/pex/exceptions.h"
28 #include "lsst/afw/math/Kernel.h"
31 
33 
34 namespace lsst {
35 namespace afw {
36 
37 template std::shared_ptr<math::DeltaFunctionKernel> table::io::PersistableFacade<
38  math::DeltaFunctionKernel>::dynamicCast(std::shared_ptr<table::io::Persistable> const&);
39 
40 namespace math {
41 
43  : Kernel(width, height, 0), _pixel(point) {
44  if (point.getX() < 0 || point.getX() >= width || point.getY() < 0 || point.getY() >= height) {
46  os << "point (" << point.getX() << ", " << point.getY() << ") lies outside " << width << "x" << height
47  << " sized kernel";
49  }
50 }
51 
54  new DeltaFunctionKernel(this->getWidth(), this->getHeight(), this->_pixel));
55  retPtr->setCtr(this->getCtr());
56  return retPtr;
57 }
58 
60  int padX = width - getWidth();
61  int padY = height - getHeight();
62  if ((padX % 2) || (padY % 2)) {
64  os << "Cannot resize DeltaFunctionKernel from (" << getWidth() << ", " << getHeight() << ") to ("
65  << width << ", " << height << "), because at least one dimension would change by an odd value.";
67  }
68  int newPixelX = getPixel().getX() + padX / 2;
69  int newPixelY = getPixel().getY() + padY / 2;
71  std::make_shared<DeltaFunctionKernel>(width, height, lsst::geom::Point2I(newPixelX, newPixelY));
72  return retPtr;
73 }
74 
76  const int pixelX = getPixel().getX(); // active pixel in Kernel
77  const int pixelY = getPixel().getY();
78 
80  os << prefix << "DeltaFunctionKernel:" << std::endl;
81  os << prefix << "Pixel (c,r) " << pixelX << "," << pixelY << ")" << std::endl;
82  os << Kernel::toString(prefix + "\t");
83  return os.str();
84 }
85 
87  const int pixelX = getPixel().getX(); // active pixel in Kernel
88  const int pixelY = getPixel().getY();
89 
90  image = 0;
91  *image.xy_at(pixelX, pixelY) = 1;
92 
93  return 1;
94 }
95 
96 // ------ Persistence ---------------------------------------------------------------------------------------
97 
98 namespace {
99 
100 struct DeltaFunctionKernelPersistenceHelper : public Kernel::PersistenceHelper {
101  table::PointKey<int> pixel;
102 
103  static DeltaFunctionKernelPersistenceHelper const& get() {
104  static DeltaFunctionKernelPersistenceHelper const instance;
105  return instance;
106  }
107 
108  // No copying
109  DeltaFunctionKernelPersistenceHelper(const DeltaFunctionKernelPersistenceHelper&) = delete;
110  DeltaFunctionKernelPersistenceHelper& operator=(const DeltaFunctionKernelPersistenceHelper&) = delete;
111 
112  // No moving
113  DeltaFunctionKernelPersistenceHelper(DeltaFunctionKernelPersistenceHelper&&) = delete;
114  DeltaFunctionKernelPersistenceHelper& operator=(DeltaFunctionKernelPersistenceHelper&&) = delete;
115 
116 private:
117  explicit DeltaFunctionKernelPersistenceHelper()
118  : Kernel::PersistenceHelper(0),
119  pixel(table::PointKey<int>::addFields(schema, "pixel", "position of nonzero pixel", "pixel")) {}
120 };
121 
122 } // namespace
123 
125 public:
127  CatalogVector const& catalogs) const override {
128  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
129  LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u);
130  DeltaFunctionKernelPersistenceHelper const& keys = DeltaFunctionKernelPersistenceHelper::get();
131  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
132  afw::table::BaseRecord const& record = catalogs.front().front();
134  new DeltaFunctionKernel(record.get(keys.dimensions.getX()),
135  record.get(keys.dimensions.getY()), record.get(keys.pixel)));
136  result->setCtr(record.get(keys.center));
137  return result;
138  }
139 
140  explicit Factory(std::string const& name) : afw::table::io::PersistableFactory(name) {}
141 };
142 
143 namespace {
144 
145 std::string getDeltaFunctionKernelPersistenceName() { return "DeltaFunctionKernel"; }
146 
147 DeltaFunctionKernel::Factory registration(getDeltaFunctionKernelPersistenceName());
148 
149 } // namespace
150 
152  return getDeltaFunctionKernelPersistenceName();
153 }
154 
156  DeltaFunctionKernelPersistenceHelper const& keys = DeltaFunctionKernelPersistenceHelper::get();
157  std::shared_ptr<afw::table::BaseRecord> record = keys.write(handle, *this);
158  record->set(keys.pixel, _pixel);
159 }
160 } // namespace math
161 } // namespace afw
162 } // namespace lsst
schema
table::Schema schema
Definition: Amplifier.cc:115
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::table::BaseRecord::get
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:151
lsst::afw::math::DeltaFunctionKernel::Factory::Factory
Factory(std::string const &name)
Definition: DeltaFunctionKernel.cc:140
lsst::afw::math::Kernel::getHeight
int getHeight() const
Return the Kernel's height.
Definition: Kernel.h:230
lsst::afw::table::io::OutputArchiveHandle
An object passed to Persistable::write to allow it to persist itself.
Definition: OutputArchive.h:118
lsst::afw::math::DeltaFunctionKernel::toString
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
Definition: DeltaFunctionKernel.cc:75
lsst::afw::math::DeltaFunctionKernel::doComputeImage
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
Definition: DeltaFunctionKernel.cc:86
std::vector::size
T size(T... args)
lsst::afw::math::DeltaFunctionKernel::getPixel
lsst::geom::Point2I getPixel() const
Definition: Kernel.h:671
lsst::afw::math::DeltaFunctionKernel::clone
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: DeltaFunctionKernel.cc:52
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::table::io::InputArchive
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
astshim.keyMap.keyMapContinued.keys
def keys(self)
Definition: keyMapContinued.py:6
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
std::vector::front
T front(T... args)
lsst::afw::math::Kernel::getCtr
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
Definition: Kernel.h:235
lsst::afw::table::io::PersistableFactory::PersistableFactory
PersistableFactory(std::string const &name)
Constructor for the factory.
Definition: Persistable.cc:74
lsst::afw::math::Kernel::toString
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:195
lsst::afw::math::DeltaFunctionKernel::resized
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
Definition: DeltaFunctionKernel.cc:59
lsst::afw::table::BaseRecord
Base class for all records.
Definition: BaseRecord.h:31
lsst::afw::math::DeltaFunctionKernel::Factory::read
std::shared_ptr< afw::table::io::Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const override
Construct a new object from the given InputArchive and vector of catalogs.
Definition: DeltaFunctionKernel.cc:126
lsst::afw::table::io::CatalogVector
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:29
lsst::afw::table::io::PersistableFactory
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:228
lsst::afw::math::DeltaFunctionKernel::DeltaFunctionKernel
DeltaFunctionKernel(int width, int height, lsst::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
Definition: DeltaFunctionKernel.cc:42
pixel
table::PointKey< int > pixel
Definition: DeltaFunctionKernel.cc:101
result
py::object result
Definition: _schema.cc:429
lsst::afw::math::Kernel::getWidth
int getWidth() const
Return the Kernel's width.
Definition: Kernel.h:225
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
std::ostringstream
STL class.
os
std::ostream * os
Definition: Schema.cc:746
lsst::afw::math::DeltaFunctionKernel::getPersistenceName
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: DeltaFunctionKernel.cc:151
std::endl
T endl(T... args)
lsst.pex::exceptions::InvalidParameterError
Reports invalid arguments.
Definition: Runtime.h:66
KernelPersistenceHelper.h
lsst::afw::image.slicing.Factory
Factory
Definition: slicing.py:252
lsst::afw::math::DeltaFunctionKernel::Factory
Definition: DeltaFunctionKernel.cc:124
LSST_ARCHIVE_ASSERT
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
lsst::afw::math::DeltaFunctionKernel::write
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: DeltaFunctionKernel.cc:155
Kernel.h
lsst::geom::Point< int, 2 >
Persistable.cc
lsst.pex::exceptions
Definition: Exception.h:37
lsst::afw::math::Kernel::PersistenceHelper
Definition: KernelPersistenceHelper.h:39
lsst::afw::math::Kernel
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:111
lsst::afw::image::Image< Pixel >
prefix
std::string prefix
Definition: SchemaMapper.cc:79
exceptions.h