lsst.afw  14.0-52-g19103d347
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 
29 namespace lsst {
30 namespace afw {
31 
32 namespace geom {
33 
34 template <typename T, int N>
35 class Point;
36 
37 class Box2I;
38 class Box2D;
39 
40 namespace ellipses {
41 
42 class Quadrupole;
43 
44 } // namespace ellipses
45 } // namespace geom
46 
47 namespace table {
48 
52 template <typename T>
53 class PointKey : public FunctorKey<lsst::afw::geom::Point<T, 2> > {
54 public:
64  static PointKey addFields(Schema& schema, std::string const& name, std::string const& doc,
65  std::string const& unit);
66 
68  PointKey() : _x(), _y() {}
69 
71  PointKey(Key<T> const& x, Key<T> const& y) : _x(x), _y(y) {}
72 
73  PointKey(PointKey const &) = default;
74  PointKey(PointKey &&) = default;
75  PointKey & operator=(PointKey const &) = default;
76  PointKey & operator=(PointKey &&) = default;
77  virtual ~PointKey() = default;
78 
87  PointKey(SubSchema const& s) : _x(s["x"]), _y(s["y"]) {}
88 
90  virtual geom::Point<T, 2> get(BaseRecord const& record) const;
91 
93  virtual void set(BaseRecord& record, geom::Point<T, 2> const& value) const;
94 
96  bool operator==(PointKey<T> const& other) const { return _x == other._x && _y == other._y; }
98  bool operator!=(PointKey<T> const& other) const { return !(*this == other); }
100 
102  bool isValid() const { return _x.isValid() && _y.isValid(); }
103 
105  Key<T> getX() const { return _x; }
106 
108  Key<T> getY() const { return _y; }
109 
110 private:
111  Key<T> _x;
112  Key<T> _y;
113 };
114 
117 
118 
124 template <typename Box>
125 class BoxKey : public FunctorKey<Box> {
126 public:
127 
129  using Element = typename Box::Element;
130 
144  static BoxKey addFields(Schema& schema, std::string const& name, std::string const& doc,
145  std::string const& unit);
146 
148  BoxKey() = default;
149 
151  BoxKey(PointKey<Element> const& min, PointKey<Element> const& max) : _min(min), _max(max) {}
152 
161  BoxKey(SubSchema const& s) : _min(s["min"]), _max(s["max"]) {}
162 
163  BoxKey(BoxKey const &) = default;
164  BoxKey(BoxKey &&) = default;
165  BoxKey & operator=(BoxKey const &) = default;
166  BoxKey & operator=(BoxKey &&) = default;
167  virtual ~BoxKey() = default;
168 
170  virtual Box get(BaseRecord const& record) const;
171 
173  virtual void set(BaseRecord& record, Box const& value) const;
174 
176  bool operator==(BoxKey const& other) const { return _min == other._min && _max == other._max; }
178  bool operator!=(BoxKey const& other) const { return !(*this == other); }
180 
182  bool isValid() const { return _min.isValid() && _max.isValid(); }
183 
185  PointKey<Element> getMin() const { return _min; }
186 
188  PointKey<Element> getMax() const { return _max; }
189 
190 private:
191  PointKey<Element> _min;
192  PointKey<Element> _max;
193 };
194 
197 
198 
205 class CoordKey : public FunctorKey<coord::IcrsCoord> {
206 public:
215  static CoordKey addFields(afw::table::Schema& schema, std::string const& name, std::string const& doc);
216 
218  CoordKey() : _ra(), _dec() {}
219 
221  CoordKey(Key<geom::Angle> const& ra, Key<geom::Angle> const& dec) : _ra(ra), _dec(dec) {}
222 
231  CoordKey(SubSchema const& s) : _ra(s["ra"]), _dec(s["dec"]) {}
232 
233  CoordKey(CoordKey const &) = default;
234  CoordKey(CoordKey &&) = default;
235  CoordKey & operator=(CoordKey const &) = default;
236  CoordKey & operator=(CoordKey &&) = default;
237  virtual ~CoordKey() = default;
238 
240  virtual coord::IcrsCoord get(BaseRecord const& record) const;
241 
243  virtual void set(BaseRecord& record, coord::IcrsCoord const& value) const;
244 
246  virtual void set(BaseRecord& record, coord::Coord const& value) const;
247 
249  bool operator==(CoordKey const& other) const { return _ra == other._ra && _dec == other._dec; }
251  bool operator!=(CoordKey const& other) const { return !(*this == other); }
253 
254  bool isValid() const { return _ra.isValid() && _dec.isValid(); }
255 
257  Key<geom::Angle> getRa() const { return _ra; }
259  Key<geom::Angle> getDec() const { return _dec; }
261 
262 private:
263  Key<geom::Angle> _ra;
264  Key<geom::Angle> _dec;
265 };
266 
268 bool operator==(CoordKey const& lhs, CoordKey const& rhs);
270 bool operator!=(CoordKey const& lhs, CoordKey const& rhs);
272 
275 
279 class QuadrupoleKey : public FunctorKey<lsst::afw::geom::ellipses::Quadrupole> {
280 public:
292  static QuadrupoleKey addFields(Schema& schema, std::string const& name, std::string const& doc,
293  CoordinateType coordType = CoordinateType::PIXEL);
294 
296  QuadrupoleKey() : _ixx(), _iyy(), _ixy() {}
297 
299  QuadrupoleKey(Key<double> const& ixx, Key<double> const& iyy, Key<double> const& ixy)
300  : _ixx(ixx), _iyy(iyy), _ixy(ixy) {}
301 
310  QuadrupoleKey(SubSchema const& s) : _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
311 
312  QuadrupoleKey(QuadrupoleKey const &) = default;
313  QuadrupoleKey(QuadrupoleKey &&) = default;
314  QuadrupoleKey & operator=(QuadrupoleKey const &) = default;
315  QuadrupoleKey & operator=(QuadrupoleKey &&) = default;
316  virtual ~QuadrupoleKey() = default;
317 
319  virtual geom::ellipses::Quadrupole get(BaseRecord const& record) const;
320 
322  virtual void set(BaseRecord& record, geom::ellipses::Quadrupole const& value) const;
323 
325  bool operator==(QuadrupoleKey const& other) const {
327  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
328  }
329  bool operator!=(QuadrupoleKey const& other) const { return !(*this == other); }
331 
333  bool isValid() const { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
334 
336  Key<double> getIxx() const { return _ixx; }
338  Key<double> getIyy() const { return _iyy; }
339  Key<double> getIxy() const { return _ixy; }
341 
342 private:
343  Key<double> _ixx;
344  Key<double> _iyy;
345  Key<double> _ixy;
346 };
347 
351 class EllipseKey : public FunctorKey<lsst::afw::geom::ellipses::Ellipse> {
352 public:
363  static EllipseKey addFields(Schema& schema, std::string const& name, std::string const& doc,
364  std::string const& unit);
365 
367  EllipseKey() : _qKey(), _pKey() {}
368 
370  EllipseKey(QuadrupoleKey const& qKey, PointKey<double> const& pKey) : _qKey(qKey), _pKey(pKey) {}
371 
380  EllipseKey(SubSchema const& s) : _qKey(s), _pKey(s) {}
381 
382  EllipseKey(EllipseKey const &) = default;
383  EllipseKey(EllipseKey &&) = default;
384  EllipseKey & operator=(EllipseKey const &) = default;
385  EllipseKey & operator=(EllipseKey &&) = default;
386  virtual ~EllipseKey() = default;
387 
389  virtual geom::ellipses::Ellipse get(BaseRecord const& record) const;
390 
392  virtual void set(BaseRecord& record, geom::ellipses::Ellipse const& value) const;
393 
395  bool operator==(EllipseKey const& other) const { return _qKey == other._qKey && _pKey == other._pKey; }
397  bool operator!=(EllipseKey const& other) const { return !(*this == other); }
399 
401  bool isValid() const { return _qKey.isValid() && _pKey.isValid(); }
402 
404  QuadrupoleKey getCore() const { return _qKey; }
406  PointKey<double> getCenter() const { return _pKey; }
408 
409 private:
410  QuadrupoleKey _qKey;
411  PointKey<double> _pKey;
412 };
413 
414 template <typename T, int N>
415 class CovarianceMatrixKey : public FunctorKey<Eigen::Matrix<T, N, N> > {
416 public:
420 
434  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
435  std::string const& unit, bool diagonalOnly = false);
436 
451  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
452  NameArray const& units, bool diagonalOnly = false);
453 
456 
475  explicit CovarianceMatrixKey(SigmaKeyArray const& sigma,
476  CovarianceKeyArray const& cov = CovarianceKeyArray());
477 
489  CovarianceMatrixKey(SubSchema const& s, NameArray const& names);
490 
493  CovarianceMatrixKey & operator=(CovarianceMatrixKey const &);
495  virtual ~CovarianceMatrixKey();
496 
498  virtual Eigen::Matrix<T, N, N> get(BaseRecord const& record) const;
499 
501  virtual void set(BaseRecord& record, Eigen::Matrix<T, N, N> const& value) const;
502 
504  T getElement(BaseRecord const& record, int i, int j) const;
505 
507  void setElement(BaseRecord& record, int i, int j, T value) const;
508 
515  bool isValid() const;
516 
518  bool operator==(CovarianceMatrixKey const& other) const;
520  bool operator!=(CovarianceMatrixKey const& other) const { return !(*this == other); }
522 
523 private:
524  SigmaKeyArray _sigma;
525  CovarianceKeyArray _cov;
526 };
527 }
528 }
529 } // namespace lsst::afw::table
530 
531 #endif // !AFW_TABLE_aggregates_h_INCLUDED
CoordKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:218
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Defines the fields and offsets for a table.
Definition: Schema.h:47
A coordinate class intended to represent absolute positions (2-d specialization). ...
Definition: Point.h:198
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey)
Construct from individual Keys.
Definition: aggregates.h:370
A proxy type for name lookups in a Schema.
Definition: Schema.h:354
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:310
std::vector< std::string > NameArray
Definition: aggregates.h:419
table::Key< std::string > name
Definition: ApCorrMap.cc:71
EllipseKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:367
afw::table::Schema schema
Definition: GaussianPsf.cc:43
QuadrupoleKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:296
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:418
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:380
PointKey< int > Point2IKey
Definition: aggregates.h:115
int min
Definition: Coord.cc:160
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.
PointKey< double > Point2DKey
Definition: aggregates.h:116
Key< T > getX() const
Return the underlying x Key.
Definition: aggregates.h:105
bool operator!=(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:329
Key< double > getIyy() const
Return a constituent Key.
Definition: aggregates.h:338
A FunctorKey used to get or set a geom::Box2I or Box2D from a (min, max) pair of PointKeys.
Definition: aggregates.h:125
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:45
STL class.
BoxKey(PointKey< Element > const &min, PointKey< Element > const &max)
Construct from a pair of PointKeys.
Definition: aggregates.h:151
PointKey< Element > getMin() const
Return the underlying min PointKey.
Definition: aggregates.h:185
typename geom::Box2I ::Element Element
Type of coordinate elements (i.e. int or double).
Definition: aggregates.h:129
A base class for image defects.
A FunctorKey used to get or set a geom::Point from an (x,y) pair of int or double Keys...
Definition: aggregates.h:53
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
int max
Definition: BoundedField.cc:99
CoordKey(Key< geom::Angle > const &ra, Key< geom::Angle > const &dec)
Construct from a pair of Keys.
Definition: aggregates.h:221
bool isValid() const
Return True if both the x and y Keys are valid.
Definition: aggregates.h:102
BoxKey(SubSchema const &s)
Construct from a subschema, assuming _min_x, _max_x, _min_y, _max_y subfields.
Definition: aggregates.h:161
bool isValid() const
Return True if both the min and max PointKeys are valid.
Definition: aggregates.h:182
bool operator!=(BoxKey const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:178
double x
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:259
PointKey< double > getCenter() const
Return constituent FunctorKeys.
Definition: aggregates.h:406
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:274
bool operator!=(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
Definition: aggregates.h:520
Key< double > getIxy() const
Return a constituent Key.
Definition: aggregates.h:339
STL class.
Base class for all records.
Definition: BaseRecord.h:29
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:417
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
PointKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:68
PointKey(SubSchema const &s)
Construct from a subschema, assuming x and y subfields.
Definition: aggregates.h:87
bool operator!=(EllipseKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:397
PointKey(Key< T > const &x, Key< T > const &y)
Construct from a pair of Keys.
Definition: aggregates.h:71
CoordKey(SubSchema const &s)
Construct from a subschema, assuming ra and dec subfields.
Definition: aggregates.h:231
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:351
PointKey< Element > getMax() const
Return the underlying max PointKey.
Definition: aggregates.h:188
Convenience base class that combines the OutputFunctorKey and InputFunctorKey.
Definition: FunctorKey.h:74
This is the base class for spherical coordinates.
Definition: Coord.h:63
bool operator!=(CoordKey const &other) const
Compare CoordKeys for equality using the constituent ra and dec Keys.
Definition: aggregates.h:251
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy)
Construct from individual Keys.
Definition: aggregates.h:299
Key< T > getY() const
Return the underlying y Key.
Definition: aggregates.h:108
A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys...
Definition: aggregates.h:279
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:291
bool operator!=(PointKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:98
A FunctorKey used to get or set celestial coordinates from a pair of Angle keys.
Definition: aggregates.h:205
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:401
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:333