lsst.afw  15.0-29-ga12a2b06e
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<SpherePoint> {
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 SpherePoint get(BaseRecord const& record) const;
241 
243  virtual void set(BaseRecord& record, SpherePoint const& value) const;
244 
246  bool operator==(CoordKey const& other) const { return _ra == other._ra && _dec == other._dec; }
248  bool operator!=(CoordKey const& other) const { return !(*this == other); }
250 
251  bool isValid() const { return _ra.isValid() && _dec.isValid(); }
252 
254  Key<geom::Angle> getRa() const { return _ra; }
256  Key<geom::Angle> getDec() const { return _dec; }
258 
259 private:
260  Key<geom::Angle> _ra;
261  Key<geom::Angle> _dec;
262 };
263 
265 bool operator==(CoordKey const& lhs, CoordKey const& rhs);
267 bool operator!=(CoordKey const& lhs, CoordKey const& rhs);
269 
272 
276 class QuadrupoleKey : public FunctorKey<lsst::afw::geom::ellipses::Quadrupole> {
277 public:
289  static QuadrupoleKey addFields(Schema& schema, std::string const& name, std::string const& doc,
290  CoordinateType coordType = CoordinateType::PIXEL);
291 
293  QuadrupoleKey() : _ixx(), _iyy(), _ixy() {}
294 
296  QuadrupoleKey(Key<double> const& ixx, Key<double> const& iyy, Key<double> const& ixy)
297  : _ixx(ixx), _iyy(iyy), _ixy(ixy) {}
298 
307  QuadrupoleKey(SubSchema const& s) : _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
308 
309  QuadrupoleKey(QuadrupoleKey const &) = default;
310  QuadrupoleKey(QuadrupoleKey &&) = default;
311  QuadrupoleKey & operator=(QuadrupoleKey const &) = default;
312  QuadrupoleKey & operator=(QuadrupoleKey &&) = default;
313  virtual ~QuadrupoleKey() = default;
314 
316  virtual geom::ellipses::Quadrupole get(BaseRecord const& record) const;
317 
319  virtual void set(BaseRecord& record, geom::ellipses::Quadrupole const& value) const;
320 
322  bool operator==(QuadrupoleKey const& other) const {
324  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
325  }
326  bool operator!=(QuadrupoleKey const& other) const { return !(*this == other); }
328 
330  bool isValid() const { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
331 
333  Key<double> getIxx() const { return _ixx; }
335  Key<double> getIyy() const { return _iyy; }
336  Key<double> getIxy() const { return _ixy; }
338 
339 private:
340  Key<double> _ixx;
341  Key<double> _iyy;
342  Key<double> _ixy;
343 };
344 
348 class EllipseKey : public FunctorKey<lsst::afw::geom::ellipses::Ellipse> {
349 public:
360  static EllipseKey addFields(Schema& schema, std::string const& name, std::string const& doc,
361  std::string const& unit);
362 
364  EllipseKey() : _qKey(), _pKey() {}
365 
367  EllipseKey(QuadrupoleKey const& qKey, PointKey<double> const& pKey) : _qKey(qKey), _pKey(pKey) {}
368 
377  EllipseKey(SubSchema const& s) : _qKey(s), _pKey(s) {}
378 
379  EllipseKey(EllipseKey const &) = default;
380  EllipseKey(EllipseKey &&) = default;
381  EllipseKey & operator=(EllipseKey const &) = default;
382  EllipseKey & operator=(EllipseKey &&) = default;
383  virtual ~EllipseKey() = default;
384 
386  virtual geom::ellipses::Ellipse get(BaseRecord const& record) const;
387 
389  virtual void set(BaseRecord& record, geom::ellipses::Ellipse const& value) const;
390 
392  bool operator==(EllipseKey const& other) const { return _qKey == other._qKey && _pKey == other._pKey; }
394  bool operator!=(EllipseKey const& other) const { return !(*this == other); }
396 
398  bool isValid() const { return _qKey.isValid() && _pKey.isValid(); }
399 
401  QuadrupoleKey getCore() const { return _qKey; }
403  PointKey<double> getCenter() const { return _pKey; }
405 
406 private:
407  QuadrupoleKey _qKey;
408  PointKey<double> _pKey;
409 };
410 
411 template <typename T, int N>
412 class CovarianceMatrixKey : public FunctorKey<Eigen::Matrix<T, N, N> > {
413 public:
417 
431  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
432  std::string const& unit, bool diagonalOnly = false);
433 
448  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
449  NameArray const& units, bool diagonalOnly = false);
450 
453 
472  explicit CovarianceMatrixKey(SigmaKeyArray const& sigma,
473  CovarianceKeyArray const& cov = CovarianceKeyArray());
474 
486  CovarianceMatrixKey(SubSchema const& s, NameArray const& names);
487 
490  CovarianceMatrixKey & operator=(CovarianceMatrixKey const &);
492  virtual ~CovarianceMatrixKey();
493 
495  virtual Eigen::Matrix<T, N, N> get(BaseRecord const& record) const;
496 
498  virtual void set(BaseRecord& record, Eigen::Matrix<T, N, N> const& value) const;
499 
501  T getElement(BaseRecord const& record, int i, int j) const;
502 
504  void setElement(BaseRecord& record, int i, int j, T value) const;
505 
512  bool isValid() const;
513 
515  bool operator==(CovarianceMatrixKey const& other) const;
517  bool operator!=(CovarianceMatrixKey const& other) const { return !(*this == other); }
519 
520 private:
521  SigmaKeyArray _sigma;
522  CovarianceKeyArray _cov;
523 };
524 }
525 }
526 } // namespace lsst::afw::table
527 
528 #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
double dec
Definition: Match.cc:41
A coordinate class intended to represent absolute positions (2-d specialization). ...
Definition: Point.h:198
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:61
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey)
Construct from individual Keys.
Definition: aggregates.h:367
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:307
std::vector< std::string > NameArray
Definition: aggregates.h:416
EllipseKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:364
afw::table::Schema schema
Definition: GaussianPsf.cc:43
QuadrupoleKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:293
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:415
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:377
PointKey< int > Point2IKey
Definition: aggregates.h:115
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.
PointKey< double > Point2DKey
Definition: aggregates.h:116
Key< T > getX() const
Return the underlying x Key.
Definition: aggregates.h:105
ItemVariant const * other
Definition: Schema.cc:55
bool operator!=(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:326
Key< double > getIyy() const
Return a constituent Key.
Definition: aggregates.h:335
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:256
PointKey< double > getCenter() const
Return constituent FunctorKeys.
Definition: aggregates.h:403
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:271
bool operator!=(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
Definition: aggregates.h:517
Key< double > getIxy() const
Return a constituent Key.
Definition: aggregates.h:336
STL class.
Base class for all records.
Definition: BaseRecord.h:31
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:414
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
std::string prefix
Definition: SchemaMapper.cc:79
bool operator!=(EllipseKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:394
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:348
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
bool operator!=(CoordKey const &other) const
Compare CoordKeys for equality using the constituent ra and dec Keys.
Definition: aggregates.h:248
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy)
Construct from individual Keys.
Definition: aggregates.h:296
bool isValid
Definition: fits.cc:363
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:276
int y
Definition: SpanSet.cc:44
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:398
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:330