lsst.afw  14.0-27-gbdf48f848+1
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 namespace ellipses {
38 
39 class Quadrupole;
40 
41 } // namespace ellipses
42 } // namespace geom
43 
44 namespace table {
45 
49 template <typename T>
50 class PointKey : public FunctorKey<lsst::afw::geom::Point<T, 2> > {
51 public:
61  static PointKey addFields(Schema& schema, std::string const& name, std::string const& doc,
62  std::string const& unit);
63 
65  PointKey() : _x(), _y() {}
66 
68  PointKey(Key<T> const& x, Key<T> const& y) : _x(x), _y(y) {}
69 
78  PointKey(SubSchema const& s) : _x(s["x"]), _y(s["y"]) {}
79 
81  virtual geom::Point<T, 2> get(BaseRecord const& record) const;
82 
84  virtual void set(BaseRecord& record, geom::Point<T, 2> const& value) const;
85 
87  bool operator==(PointKey<T> const& other) const { return _x == other._x && _y == other._y; }
89  bool operator!=(PointKey<T> const& other) const { return !(*this == other); }
91 
93  bool isValid() const { return _x.isValid() && _y.isValid(); }
94 
96  Key<T> getX() const { return _x; }
97 
99  Key<T> getY() const { return _y; }
100 
101 private:
102  Key<T> _x;
103  Key<T> _y;
104 };
105 
108 
115 class CoordKey : public FunctorKey<coord::IcrsCoord> {
116 public:
125  static CoordKey addFields(afw::table::Schema& schema, std::string const& name, std::string const& doc);
126 
128  CoordKey() : _ra(), _dec() {}
129 
131  CoordKey(Key<geom::Angle> const& ra, Key<geom::Angle> const& dec) : _ra(ra), _dec(dec) {}
132 
141  CoordKey(SubSchema const& s) : _ra(s["ra"]), _dec(s["dec"]) {}
142 
144  virtual coord::IcrsCoord get(BaseRecord const& record) const;
145 
147  virtual void set(BaseRecord& record, coord::IcrsCoord const& value) const;
148 
150  virtual void set(BaseRecord& record, coord::Coord const& value) const;
151 
153  bool operator==(CoordKey const& other) const { return _ra == other._ra && _dec == other._dec; }
155  bool operator!=(CoordKey const& other) const { return !(*this == other); }
157 
158  bool isValid() const { return _ra.isValid() && _dec.isValid(); }
159 
161  Key<geom::Angle> getRa() const { return _ra; }
163  Key<geom::Angle> getDec() const { return _dec; }
165 
166 private:
167  Key<geom::Angle> _ra;
168  Key<geom::Angle> _dec;
169 };
170 
172 bool operator==(CoordKey const& lhs, CoordKey const& rhs);
174 bool operator!=(CoordKey const& lhs, CoordKey const& rhs);
176 
179 
183 class QuadrupoleKey : public FunctorKey<lsst::afw::geom::ellipses::Quadrupole> {
184 public:
196  static QuadrupoleKey addFields(Schema& schema, std::string const& name, std::string const& doc,
197  CoordinateType coordType = CoordinateType::PIXEL);
198 
200  QuadrupoleKey() : _ixx(), _iyy(), _ixy() {}
201 
203  QuadrupoleKey(Key<double> const& ixx, Key<double> const& iyy, Key<double> const& ixy)
204  : _ixx(ixx), _iyy(iyy), _ixy(ixy) {}
205 
214  QuadrupoleKey(SubSchema const& s) : _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
215 
217  virtual geom::ellipses::Quadrupole get(BaseRecord const& record) const;
218 
220  virtual void set(BaseRecord& record, geom::ellipses::Quadrupole const& value) const;
221 
223  bool operator==(QuadrupoleKey const& other) const {
225  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
226  }
227  bool operator!=(QuadrupoleKey const& other) const { return !(*this == other); }
229 
231  bool isValid() const { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
232 
234  Key<double> getIxx() const { return _ixx; }
236  Key<double> getIyy() const { return _iyy; }
237  Key<double> getIxy() const { return _ixy; }
239 
240 private:
241  Key<double> _ixx;
242  Key<double> _iyy;
243  Key<double> _ixy;
244 };
245 
249 class EllipseKey : public FunctorKey<lsst::afw::geom::ellipses::Ellipse> {
250 public:
261  static EllipseKey addFields(Schema& schema, std::string const& name, std::string const& doc,
262  std::string const& unit);
263 
265  EllipseKey() : _qKey(), _pKey() {}
266 
268  EllipseKey(QuadrupoleKey const& qKey, PointKey<double> const& pKey) : _qKey(qKey), _pKey(pKey) {}
269 
278  EllipseKey(SubSchema const& s) : _qKey(s), _pKey(s) {}
279 
281  virtual geom::ellipses::Ellipse get(BaseRecord const& record) const;
282 
284  virtual void set(BaseRecord& record, geom::ellipses::Ellipse const& value) const;
285 
287  bool operator==(EllipseKey const& other) const { return _qKey == other._qKey && _pKey == other._pKey; }
289  bool operator!=(EllipseKey const& other) const { return !(*this == other); }
291 
293  bool isValid() const { return _qKey.isValid() && _pKey.isValid(); }
294 
296  QuadrupoleKey getCore() const { return _qKey; }
298  PointKey<double> getCenter() const { return _pKey; }
300 
301 private:
302  QuadrupoleKey _qKey;
303  PointKey<double> _pKey;
304 };
305 
306 template <typename T, int N>
307 class CovarianceMatrixKey : public FunctorKey<Eigen::Matrix<T, N, N> > {
308 public:
312 
326  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
327  std::string const& unit, bool diagonalOnly = false);
328 
343  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
344  NameArray const& units, bool diagonalOnly = false);
345 
348 
367  explicit CovarianceMatrixKey(SigmaKeyArray const& sigma,
368  CovarianceKeyArray const& cov = CovarianceKeyArray());
369 
381  CovarianceMatrixKey(SubSchema const& s, NameArray const& names);
382 
384  virtual Eigen::Matrix<T, N, N> get(BaseRecord const& record) const;
385 
387  virtual void set(BaseRecord& record, Eigen::Matrix<T, N, N> const& value) const;
388 
390  T getElement(BaseRecord const& record, int i, int j) const;
391 
393  void setElement(BaseRecord& record, int i, int j, T value) const;
394 
401  bool isValid() const;
402 
404  bool operator==(CovarianceMatrixKey const& other) const;
406  bool operator!=(CovarianceMatrixKey const& other) const { return !(*this == other); }
408 
409 private:
410  SigmaKeyArray _sigma;
411  CovarianceKeyArray _cov;
412 };
413 }
414 }
415 } // namespace lsst::afw::table
416 
417 #endif // !AFW_TABLE_aggregates_h_INCLUDED
CoordKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:128
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Defines the fields and offsets for a table.
Definition: Schema.h:46
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:268
A proxy type for name lookups in a Schema.
Definition: Schema.h:348
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:214
std::vector< std::string > NameArray
Definition: aggregates.h:311
table::Key< std::string > name
Definition: ApCorrMap.cc:71
EllipseKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:265
afw::table::Schema schema
Definition: GaussianPsf.cc:43
QuadrupoleKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:200
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:310
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:278
PointKey< int > Point2IKey
Definition: aggregates.h:106
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:107
Key< T > getX() const
Return the underlying x Key.
Definition: aggregates.h:96
bool operator!=(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:227
Key< double > getIyy() const
Return a constituent Key.
Definition: aggregates.h:236
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:45
STL class.
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:50
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
CoordKey(Key< geom::Angle > const &ra, Key< geom::Angle > const &dec)
Construct from a pair of Keys.
Definition: aggregates.h:131
bool isValid() const
Return True if both the x and y Keys are valid.
Definition: aggregates.h:93
double x
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:163
PointKey< double > getCenter() const
Return constituent FunctorKeys.
Definition: aggregates.h:298
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:178
bool operator!=(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
Definition: aggregates.h:406
Key< double > getIxy() const
Return a constituent Key.
Definition: aggregates.h:237
STL class.
Base class for all records.
Definition: BaseRecord.h:29
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:309
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:65
PointKey(SubSchema const &s)
Construct from a subschema, assuming x and y subfields.
Definition: aggregates.h:78
bool operator!=(EllipseKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:289
PointKey(Key< T > const &x, Key< T > const &y)
Construct from a pair of Keys.
Definition: aggregates.h:68
CoordKey(SubSchema const &s)
Construct from a subschema, assuming ra and dec subfields.
Definition: aggregates.h:141
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:249
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:155
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy)
Construct from individual Keys.
Definition: aggregates.h:203
Key< T > getY() const
Return the underlying y Key.
Definition: aggregates.h:99
A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys...
Definition: aggregates.h:183
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:89
A FunctorKey used to get or set celestial coordinates from a pair of Angle keys.
Definition: aggregates.h:115
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:293
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:231