LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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"
30 #include "lsst/afw/table/io/Persistable.cc"
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  schema.getCitizen().markPersistent();
121  }
122 };
123 
124 } // namespace
125 
127 public:
129  CatalogVector const& catalogs) const override {
130  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
131  LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u);
132  DeltaFunctionKernelPersistenceHelper const& keys = DeltaFunctionKernelPersistenceHelper::get();
133  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
134  afw::table::BaseRecord const& record = catalogs.front().front();
136  new DeltaFunctionKernel(record.get(keys.dimensions.getX()),
137  record.get(keys.dimensions.getY()), record.get(keys.pixel)));
138  result->setCtr(record.get(keys.center));
139  return result;
140  }
141 
142  explicit Factory(std::string const& name) : afw::table::io::PersistableFactory(name) {}
143 };
144 
145 namespace {
146 
147 std::string getDeltaFunctionKernelPersistenceName() { return "DeltaFunctionKernel"; }
148 
149 DeltaFunctionKernel::Factory registration(getDeltaFunctionKernelPersistenceName());
150 
151 } // namespace
152 
154  return getDeltaFunctionKernelPersistenceName();
155 }
156 
158  DeltaFunctionKernelPersistenceHelper const& keys = DeltaFunctionKernelPersistenceHelper::get();
159  std::shared_ptr<afw::table::BaseRecord> record = keys.write(handle, *this);
160  record->set(keys.pixel, _pixel);
161 }
162 } // namespace math
163 } // namespace afw
164 } // namespace lsst
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:233
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
An object passed to Persistable::write to allow it to persist itself.
T front(T... args)
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:228
T endl(T... args)
py::object result
Definition: schema.cc:418
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
Definition: aggregates.cc:36
std::string prefix
Definition: SchemaMapper.cc:79
STL class.
STL class.
A base class for image defects.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
T str(T... args)
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
table::Schema schema
Definition: Camera.cc:161
lsst::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:238
Point< int, 2 > Point2I
Definition: Point.h:321
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:228
T size(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:29
Base class for all records.
Definition: BaseRecord.h:31
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
Reports invalid arguments.
Definition: Runtime.h:66
table::PointKey< int > pixel
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.
lsst::geom::Point2I getPixel() const
Definition: Kernel.h:708
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
DeltaFunctionKernel(int width, int height, lsst::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
DeltaFunctionKernel & operator=(const DeltaFunctionKernel &)=delete
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:112
xy_locator xy_at(int x, int y) const
Return an xy_locator at the point (x, y) in the image.
Definition: ImageBase.h:443
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:204
std::ostream * os
Definition: Schema.cc:746