lsst.afw  14.0-40-g0271be365
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 
81  PointKey(SubSchema const& s) : _x(s["x"]), _y(s["y"]) {}
82 
84  virtual geom::Point<T, 2> get(BaseRecord const& record) const;
85 
87  virtual void set(BaseRecord& record, geom::Point<T, 2> const& value) const;
88 
90  bool operator==(PointKey<T> const& other) const { return _x == other._x && _y == other._y; }
92  bool operator!=(PointKey<T> const& other) const { return !(*this == other); }
94 
96  bool isValid() const { return _x.isValid() && _y.isValid(); }
97 
99  Key<T> getX() const { return _x; }
100 
102  Key<T> getY() const { return _y; }
103 
104 private:
105  Key<T> _x;
106  Key<T> _y;
107 };
108 
111 
112 
118 template <typename Box>
119 class BoxKey : public FunctorKey<Box> {
120 public:
121 
123  using Element = typename Box::Element;
124 
138  static BoxKey addFields(Schema& schema, std::string const& name, std::string const& doc,
139  std::string const& unit);
140 
142  BoxKey() = default;
143 
145  BoxKey(PointKey<Element> const& min, PointKey<Element> const& max) : _min(min), _max(max) {}
146 
155  BoxKey(SubSchema const& s) : _min(s["min"]), _max(s["max"]) {}
156 
157  BoxKey(BoxKey const &) = default;
158  BoxKey(BoxKey &&) = default;
159  BoxKey & operator=(BoxKey const &) = default;
160  BoxKey & operator=(BoxKey &&) = default;
161  virtual ~BoxKey() = default;
162 
164  virtual Box get(BaseRecord const& record) const;
165 
167  virtual void set(BaseRecord& record, Box const& value) const;
168 
170  bool operator==(BoxKey const& other) const { return _min == other._min && _max == other._max; }
172  bool operator!=(BoxKey const& other) const { return !(*this == other); }
174 
176  bool isValid() const { return _min.isValid() && _max.isValid(); }
177 
179  PointKey<Element> getMin() const { return _min; }
180 
182  PointKey<Element> getMax() const { return _max; }
183 
184 private:
185  PointKey<Element> _min;
186  PointKey<Element> _max;
187 };
188 
191 
192 
199 class CoordKey : public FunctorKey<coord::IcrsCoord> {
200 public:
209  static CoordKey addFields(afw::table::Schema& schema, std::string const& name, std::string const& doc);
210 
212  CoordKey() : _ra(), _dec() {}
213 
215  CoordKey(Key<geom::Angle> const& ra, Key<geom::Angle> const& dec) : _ra(ra), _dec(dec) {}
216 
225  CoordKey(SubSchema const& s) : _ra(s["ra"]), _dec(s["dec"]) {}
226 
228  virtual coord::IcrsCoord get(BaseRecord const& record) const;
229 
231  virtual void set(BaseRecord& record, coord::IcrsCoord const& value) const;
232 
234  virtual void set(BaseRecord& record, coord::Coord const& value) const;
235 
237  bool operator==(CoordKey const& other) const { return _ra == other._ra && _dec == other._dec; }
239  bool operator!=(CoordKey const& other) const { return !(*this == other); }
241 
242  bool isValid() const { return _ra.isValid() && _dec.isValid(); }
243 
245  Key<geom::Angle> getRa() const { return _ra; }
247  Key<geom::Angle> getDec() const { return _dec; }
249 
250 private:
251  Key<geom::Angle> _ra;
252  Key<geom::Angle> _dec;
253 };
254 
256 bool operator==(CoordKey const& lhs, CoordKey const& rhs);
258 bool operator!=(CoordKey const& lhs, CoordKey const& rhs);
260 
263 
267 class QuadrupoleKey : public FunctorKey<lsst::afw::geom::ellipses::Quadrupole> {
268 public:
280  static QuadrupoleKey addFields(Schema& schema, std::string const& name, std::string const& doc,
281  CoordinateType coordType = CoordinateType::PIXEL);
282 
284  QuadrupoleKey() : _ixx(), _iyy(), _ixy() {}
285 
287  QuadrupoleKey(Key<double> const& ixx, Key<double> const& iyy, Key<double> const& ixy)
288  : _ixx(ixx), _iyy(iyy), _ixy(ixy) {}
289 
298  QuadrupoleKey(SubSchema const& s) : _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
299 
301  virtual geom::ellipses::Quadrupole get(BaseRecord const& record) const;
302 
304  virtual void set(BaseRecord& record, geom::ellipses::Quadrupole const& value) const;
305 
307  bool operator==(QuadrupoleKey const& other) const {
309  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
310  }
311  bool operator!=(QuadrupoleKey const& other) const { return !(*this == other); }
313 
315  bool isValid() const { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
316 
318  Key<double> getIxx() const { return _ixx; }
320  Key<double> getIyy() const { return _iyy; }
321  Key<double> getIxy() const { return _ixy; }
323 
324 private:
325  Key<double> _ixx;
326  Key<double> _iyy;
327  Key<double> _ixy;
328 };
329 
333 class EllipseKey : public FunctorKey<lsst::afw::geom::ellipses::Ellipse> {
334 public:
345  static EllipseKey addFields(Schema& schema, std::string const& name, std::string const& doc,
346  std::string const& unit);
347 
349  EllipseKey() : _qKey(), _pKey() {}
350 
352  EllipseKey(QuadrupoleKey const& qKey, PointKey<double> const& pKey) : _qKey(qKey), _pKey(pKey) {}
353 
362  EllipseKey(SubSchema const& s) : _qKey(s), _pKey(s) {}
363 
365  virtual geom::ellipses::Ellipse get(BaseRecord const& record) const;
366 
368  virtual void set(BaseRecord& record, geom::ellipses::Ellipse const& value) const;
369 
371  bool operator==(EllipseKey const& other) const { return _qKey == other._qKey && _pKey == other._pKey; }
373  bool operator!=(EllipseKey const& other) const { return !(*this == other); }
375 
377  bool isValid() const { return _qKey.isValid() && _pKey.isValid(); }
378 
380  QuadrupoleKey getCore() const { return _qKey; }
382  PointKey<double> getCenter() const { return _pKey; }
384 
385 private:
386  QuadrupoleKey _qKey;
387  PointKey<double> _pKey;
388 };
389 
390 template <typename T, int N>
391 class CovarianceMatrixKey : public FunctorKey<Eigen::Matrix<T, N, N> > {
392 public:
396 
410  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
411  std::string const& unit, bool diagonalOnly = false);
412 
427  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
428  NameArray const& units, bool diagonalOnly = false);
429 
432 
451  explicit CovarianceMatrixKey(SigmaKeyArray const& sigma,
452  CovarianceKeyArray const& cov = CovarianceKeyArray());
453 
465  CovarianceMatrixKey(SubSchema const& s, NameArray const& names);
466 
468  virtual Eigen::Matrix<T, N, N> get(BaseRecord const& record) const;
469 
471  virtual void set(BaseRecord& record, Eigen::Matrix<T, N, N> const& value) const;
472 
474  T getElement(BaseRecord const& record, int i, int j) const;
475 
477  void setElement(BaseRecord& record, int i, int j, T value) const;
478 
485  bool isValid() const;
486 
488  bool operator==(CovarianceMatrixKey const& other) const;
490  bool operator!=(CovarianceMatrixKey const& other) const { return !(*this == other); }
492 
493 private:
494  SigmaKeyArray _sigma;
495  CovarianceKeyArray _cov;
496 };
497 }
498 }
499 } // namespace lsst::afw::table
500 
501 #endif // !AFW_TABLE_aggregates_h_INCLUDED
CoordKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:212
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:185
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey)
Construct from individual Keys.
Definition: aggregates.h:352
A proxy type for name lookups in a Schema.
Definition: Schema.h:349
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:298
std::vector< std::string > NameArray
Definition: aggregates.h:395
table::Key< std::string > name
Definition: ApCorrMap.cc:71
EllipseKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:349
afw::table::Schema schema
Definition: GaussianPsf.cc:43
QuadrupoleKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:284
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:394
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:362
PointKey< int > Point2IKey
Definition: aggregates.h:109
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:110
Key< T > getX() const
Return the underlying x Key.
Definition: aggregates.h:99
bool operator!=(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:311
Key< double > getIyy() const
Return a constituent Key.
Definition: aggregates.h:320
A FunctorKey used to get or set a geom::Box2I or Box2D from a (min, max) pair of PointKeys.
Definition: aggregates.h:119
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:145
PointKey< Element > getMin() const
Return the underlying min PointKey.
Definition: aggregates.h:179
typename geom::Box2I ::Element Element
Type of coordinate elements (i.e. int or double).
Definition: aggregates.h:123
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:215
bool isValid() const
Return True if both the x and y Keys are valid.
Definition: aggregates.h:96
BoxKey(SubSchema const &s)
Construct from a subschema, assuming _min_x, _max_x, _min_y, _max_y subfields.
Definition: aggregates.h:155
bool isValid() const
Return True if both the min and max PointKeys are valid.
Definition: aggregates.h:176
bool operator!=(BoxKey const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:172
double x
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:247
PointKey< double > getCenter() const
Return constituent FunctorKeys.
Definition: aggregates.h:382
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:262
bool operator!=(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
Definition: aggregates.h:490
Key< double > getIxy() const
Return a constituent Key.
Definition: aggregates.h:321
STL class.
Base class for all records.
Definition: BaseRecord.h:29
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:393
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:81
bool operator!=(EllipseKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:373
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:225
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:333
PointKey< Element > getMax() const
Return the underlying max PointKey.
Definition: aggregates.h:182
Convenience base class that combines the OutputFunctorKey and InputFunctorKey.
Definition: FunctorKey.h:68
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:239
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy)
Construct from individual Keys.
Definition: aggregates.h:287
Key< T > getY() const
Return the underlying y Key.
Definition: aggregates.h:102
A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys...
Definition: aggregates.h:267
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:288
bool operator!=(PointKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:92
A FunctorKey used to get or set celestial coordinates from a pair of Angle keys.
Definition: aggregates.h:199
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:377
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:315