lsst.afw  16.0-12-gf08c31002
aggregates.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2014 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef AFW_TABLE_aggregates_h_INCLUDED
24 #define AFW_TABLE_aggregates_h_INCLUDED
25 
27 #include "lsst/afw/table/Schema.h"
28 #include "lsst/geom.h"
29 
30 namespace lsst {
31 namespace afw {
32 namespace geom {
33 
34 namespace ellipses {
35 
36 class Quadrupole;
37 
38 } // namespace ellipses
39 } // namespace geom
40 
41 namespace table {
42 
46 template <typename T>
47 class PointKey : public FunctorKey<lsst::geom::Point<T, 2> > {
48 public:
58  static PointKey addFields(Schema& schema, std::string const& name, std::string const& doc,
59  std::string const& unit);
60 
62  PointKey() noexcept : _x(), _y() {}
63 
65  PointKey(Key<T> const& x, Key<T> const& y) noexcept : _x(x), _y(y) {}
66 
67  PointKey(PointKey const&) noexcept = default;
68  PointKey(PointKey&&) noexcept = default;
69  PointKey& operator=(PointKey const&) noexcept = default;
70  PointKey& operator=(PointKey&&) noexcept = default;
71  virtual ~PointKey() noexcept = default;
72 
81  PointKey(SubSchema const& s) : _x(s["x"]), _y(s["y"]) {}
82 
84  virtual lsst::geom::Point<T, 2> get(BaseRecord const& record) const;
85 
87  virtual void set(BaseRecord& record, lsst::geom::Point<T, 2> const& value) const;
88 
90  bool operator==(PointKey<T> const& other) const noexcept { return _x == other._x && _y == other._y; }
92  bool operator!=(PointKey<T> const& other) const noexcept { return !(*this == other); }
94 
96  bool isValid() const noexcept { return _x.isValid() && _y.isValid(); }
97 
99  Key<T> getX() const noexcept { return _x; }
100 
102  Key<T> getY() const noexcept { return _y; }
103 
104 private:
105  Key<T> _x;
106  Key<T> _y;
107 };
108 
111 
117 template <typename Box>
118 class BoxKey : public FunctorKey<Box> {
119 public:
121  using Element = typename Box::Element;
122 
136  static BoxKey addFields(Schema& schema, std::string const& name, std::string const& doc,
137  std::string const& unit);
138 
140  BoxKey() noexcept = default;
141 
143  BoxKey(PointKey<Element> const& min, PointKey<Element> const& max) noexcept : _min(min), _max(max) {}
144 
153  BoxKey(SubSchema const& s) : _min(s["min"]), _max(s["max"]) {}
154 
155  BoxKey(BoxKey const&) noexcept = default;
156  BoxKey(BoxKey&&) noexcept = default;
157  BoxKey& operator=(BoxKey const&) noexcept = default;
158  BoxKey& operator=(BoxKey&&) noexcept = default;
159  virtual ~BoxKey() noexcept = default;
160 
162  virtual Box get(BaseRecord const& record) const;
163 
165  virtual void set(BaseRecord& record, Box const& value) const;
166 
168  bool operator==(BoxKey const& other) const noexcept { return _min == other._min && _max == other._max; }
170  bool operator!=(BoxKey const& other) const noexcept { return !(*this == other); }
172 
174  bool isValid() const noexcept { return _min.isValid() && _max.isValid(); }
175 
177  PointKey<Element> getMin() const noexcept { return _min; }
178 
180  PointKey<Element> getMax() const noexcept { return _max; }
181 
182 private:
183  PointKey<Element> _min;
184  PointKey<Element> _max;
185 };
186 
189 
196 class CoordKey : public FunctorKey<lsst::geom::SpherePoint> {
197 public:
206  static CoordKey addFields(afw::table::Schema& schema, std::string const& name, std::string const& doc);
207 
209  CoordKey() noexcept : _ra(), _dec() {}
210 
213  : _ra(ra), _dec(dec) {}
214 
223  CoordKey(SubSchema const& s) : _ra(s["ra"]), _dec(s["dec"]) {}
224 
225  CoordKey(CoordKey const&) noexcept = default;
226  CoordKey(CoordKey&&) noexcept = default;
227  CoordKey& operator=(CoordKey const&) noexcept = default;
228  CoordKey& operator=(CoordKey&&) noexcept = default;
229  virtual ~CoordKey() noexcept = default;
230 
232  virtual lsst::geom::SpherePoint get(BaseRecord const& record) const;
233 
235  virtual void set(BaseRecord& record, lsst::geom::SpherePoint const& value) const;
236 
238  bool operator==(CoordKey const& other) const noexcept { return _ra == other._ra && _dec == other._dec; }
240  bool operator!=(CoordKey const& other) const noexcept { return !(*this == other); }
242 
243  bool isValid() const noexcept { return _ra.isValid() && _dec.isValid(); }
244 
246  Key<lsst::geom::Angle> getRa() const noexcept { return _ra; }
248  Key<lsst::geom::Angle> getDec() const noexcept { return _dec; }
250 
251 private:
254 };
255 
257 bool operator==(CoordKey const& lhs, CoordKey const& rhs);
259 bool operator!=(CoordKey const& lhs, CoordKey const& rhs);
261 
264 
268 class QuadrupoleKey : public FunctorKey<lsst::afw::geom::ellipses::Quadrupole> {
269 public:
281  static QuadrupoleKey addFields(Schema& schema, std::string const& name, std::string const& doc,
282  CoordinateType coordType = CoordinateType::PIXEL);
283 
285  QuadrupoleKey() noexcept : _ixx(), _iyy(), _ixy() {}
286 
288  QuadrupoleKey(Key<double> const& ixx, Key<double> const& iyy, Key<double> const& ixy) noexcept
289  : _ixx(ixx), _iyy(iyy), _ixy(ixy) {}
290 
299  QuadrupoleKey(SubSchema const& s) : _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
300 
301  QuadrupoleKey(QuadrupoleKey const&) noexcept = default;
302  QuadrupoleKey(QuadrupoleKey&&) noexcept = default;
303  QuadrupoleKey& operator=(QuadrupoleKey const&) noexcept = default;
304  QuadrupoleKey& operator=(QuadrupoleKey&&) noexcept = default;
305  virtual ~QuadrupoleKey() noexcept = default;
306 
308  virtual geom::ellipses::Quadrupole get(BaseRecord const& record) const;
309 
311  virtual void set(BaseRecord& record, geom::ellipses::Quadrupole const& value) const;
312 
314  bool operator==(QuadrupoleKey const& other) const noexcept {
316  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
317  }
318  bool operator!=(QuadrupoleKey const& other) const noexcept { return !(*this == other); }
320 
322  bool isValid() const noexcept { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
323 
325  Key<double> getIxx() const noexcept { return _ixx; }
327  Key<double> getIyy() const noexcept { return _iyy; }
328  Key<double> getIxy() const noexcept { return _ixy; }
330 
331 private:
332  Key<double> _ixx;
333  Key<double> _iyy;
334  Key<double> _ixy;
335 };
336 
340 class EllipseKey : public FunctorKey<lsst::afw::geom::ellipses::Ellipse> {
341 public:
352  static EllipseKey addFields(Schema& schema, std::string const& name, std::string const& doc,
353  std::string const& unit);
354 
356  EllipseKey() noexcept : _qKey(), _pKey() {}
357 
359  EllipseKey(QuadrupoleKey const& qKey, PointKey<double> const& pKey) noexcept : _qKey(qKey), _pKey(pKey) {}
360 
369  EllipseKey(SubSchema const& s) : _qKey(s), _pKey(s) {}
370 
371  EllipseKey(EllipseKey const&) noexcept = default;
372  EllipseKey(EllipseKey&&) noexcept = default;
373  EllipseKey& operator=(EllipseKey const&) noexcept = default;
374  EllipseKey& operator=(EllipseKey&&) noexcept = default;
375  virtual ~EllipseKey() noexcept = default;
376 
378  virtual geom::ellipses::Ellipse get(BaseRecord const& record) const;
379 
381  virtual void set(BaseRecord& record, geom::ellipses::Ellipse const& value) const;
382 
384  bool operator==(EllipseKey const& other) const noexcept {
386  return _qKey == other._qKey && _pKey == other._pKey;
387  }
388  bool operator!=(EllipseKey const& other) const noexcept { return !(*this == other); }
390 
392  bool isValid() const noexcept { return _qKey.isValid() && _pKey.isValid(); }
393 
395  QuadrupoleKey getCore() const noexcept { return _qKey; }
397  PointKey<double> getCenter() const noexcept { return _pKey; }
399 
400 private:
401  QuadrupoleKey _qKey;
402  PointKey<double> _pKey;
403 };
404 
405 template <typename T, int N>
406 class CovarianceMatrixKey : public FunctorKey<Eigen::Matrix<T, N, N> > {
407 public:
411 
425  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
426  std::string const& unit, bool diagonalOnly = false);
427 
442  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
443  NameArray const& units, bool diagonalOnly = false);
444 
447 
466  explicit CovarianceMatrixKey(SigmaKeyArray const& sigma,
467  CovarianceKeyArray const& cov = CovarianceKeyArray());
468 
480  CovarianceMatrixKey(SubSchema const& s, NameArray const& names);
481 
484  CovarianceMatrixKey& operator=(CovarianceMatrixKey const&);
486  virtual ~CovarianceMatrixKey() noexcept;
487 
489  virtual Eigen::Matrix<T, N, N> get(BaseRecord const& record) const;
490 
492  virtual void set(BaseRecord& record, Eigen::Matrix<T, N, N> const& value) const;
493 
495  T getElement(BaseRecord const& record, int i, int j) const;
496 
498  void setElement(BaseRecord& record, int i, int j, T value) const;
499 
506  bool isValid() const noexcept;
507 
509  bool operator==(CovarianceMatrixKey const& other) const noexcept;
511  bool operator!=(CovarianceMatrixKey const& other) const noexcept { return !(*this == other); }
513 
514 private:
515  SigmaKeyArray _sigma;
516  CovarianceKeyArray _cov;
517 };
518 } // namespace table
519 } // namespace afw
520 } // namespace lsst
521 
522 #endif // !AFW_TABLE_aggregates_h_INCLUDED
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Defines the fields and offsets for a table.
Definition: Schema.h:50
double dec
Definition: Match.cc:41
A proxy type for name lookups in a Schema.
Definition: Schema.h:357
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:299
std::vector< std::string > NameArray
Definition: aggregates.h:410
Key< T > getX() const noexcept
Return the underlying x Key.
Definition: aggregates.h:99
bool isValid() const noexcept
Return True if both the min and max PointKeys are valid.
Definition: aggregates.h:174
CoordKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:209
bool isValid() const noexcept
Return True if all the constituent Keys are valid.
Definition: aggregates.h:392
afw::table::Schema schema
Definition: GaussianPsf.cc:43
PointKey< Element > getMin() const noexcept
Return the underlying min PointKey.
Definition: aggregates.h:177
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:409
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:369
bool operator!=(PointKey< T > const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:92
PointKey< Element > getMax() const noexcept
Return the underlying max PointKey.
Definition: aggregates.h:180
bool operator!=(QuadrupoleKey const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:318
PointKey< int > Point2IKey
Definition: aggregates.h:109
int min
Definition: Coord.cc:82
bool operator!=(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
Key< lsst::geom::Angle > getDec() const noexcept
Return a constituent Key.
Definition: aggregates.h:248
PointKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:62
bool operator!=(BoxKey const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:170
PointKey< double > Point2DKey
Definition: aggregates.h:110
ItemVariant const * other
Definition: Schema.cc:55
A FunctorKey used to get or set a lsst::geom::Box2I or Box2D from a (min, max) pair of PointKeys...
Definition: aggregates.h:118
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:45
STL class.
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey) noexcept
Construct from individual Keys.
Definition: aggregates.h:359
typename lsst::geom::Box2I ::Element Element
Type of coordinate elements (i.e. int or double).
Definition: aggregates.h:121
A base class for image defects.
A FunctorKey used to get or set a lsst::geom::Point from an (x,y) pair of int or double Keys...
Definition: aggregates.h:47
PointKey(Key< T > const &x, Key< T > const &y) noexcept
Construct from a pair of Keys.
Definition: aggregates.h:65
bool isValid() const noexcept
Definition: aggregates.h:243
bool isValid() const noexcept
Return True if both the x and y Keys are valid.
Definition: aggregates.h:96
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
int max
Definition: BoundedField.cc:98
CoordKey(Key< lsst::geom::Angle > const &ra, Key< lsst::geom::Angle > const &dec) noexcept
Construct from a pair of Keys.
Definition: aggregates.h:212
PointKey< double > getCenter() const noexcept
Return constituent FunctorKeys.
Definition: aggregates.h:397
Key< double > getIxy() const noexcept
Return a constituent Key.
Definition: aggregates.h:328
bool operator!=(EllipseKey const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:388
BoxKey(SubSchema const &s)
Construct from a subschema, assuming _min_x, _max_x, _min_y, _max_y subfields.
Definition: aggregates.h:153
double x
Key< double > getIyy() const noexcept
Return a constituent Key.
Definition: aggregates.h:327
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:263
QuadrupoleKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:285
STL class.
Base class for all records.
Definition: BaseRecord.h:31
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:408
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
bool operator!=(CoordKey const &other) const noexcept
Compare CoordKeys for equality using the constituent ra and dec Keys.
Definition: aggregates.h:240
PointKey(SubSchema const &s)
Construct from a subschema, assuming x and y subfields.
Definition: aggregates.h:81
EllipseKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:356
std::string prefix
Definition: SchemaMapper.cc:79
CoordKey(SubSchema const &s)
Construct from a subschema, assuming ra and dec subfields.
Definition: aggregates.h:223
bool isValid() const noexcept
Return True if all the constituent Keys are valid.
Definition: aggregates.h:322
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:340
Convenience base class that combines the OutputFunctorKey and InputFunctorKey.
Definition: FunctorKey.h:74
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy) noexcept
Construct from individual Keys.
Definition: aggregates.h:288
bool isValid
Definition: fits.cc:364
A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys...
Definition: aggregates.h:268
Key< T > getY() const noexcept
Return the underlying y Key.
Definition: aggregates.h:102
int y
Definition: SpanSet.cc:44
A FunctorKey used to get or set celestial coordinates from a pair of lsst::geom::Angle keys...
Definition: aggregates.h:196
daf::base::PropertySet * set
Definition: fits.cc:818