lsst.afw  15.0-33-g5c41f601f+4
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() : _x(), _y() {}
63 
65  PointKey(Key<T> const& x, Key<T> const& y) : _x(x), _y(y) {}
66 
67  PointKey(PointKey const&) = default;
68  PointKey(PointKey&&) = default;
69  PointKey& operator=(PointKey const&) = default;
70  PointKey& operator=(PointKey&&) = default;
71  virtual ~PointKey() = 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 { 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 
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() = default;
141 
143  BoxKey(PointKey<Element> const& min, PointKey<Element> const& max) : _min(min), _max(max) {}
144 
153  BoxKey(SubSchema const& s) : _min(s["min"]), _max(s["max"]) {}
154 
155  BoxKey(BoxKey const&) = default;
156  BoxKey(BoxKey&&) = default;
157  BoxKey& operator=(BoxKey const&) = default;
158  BoxKey& operator=(BoxKey&&) = default;
159  virtual ~BoxKey() = 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 { return _min == other._min && _max == other._max; }
170  bool operator!=(BoxKey const& other) const { return !(*this == other); }
172 
174  bool isValid() const { return _min.isValid() && _max.isValid(); }
175 
177  PointKey<Element> getMin() const { return _min; }
178 
180  PointKey<Element> getMax() const { 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() : _ra(), _dec() {}
210 
212  CoordKey(Key<lsst::geom::Angle> const& ra, Key<lsst::geom::Angle> const& dec) : _ra(ra), _dec(dec) {}
213 
222  CoordKey(SubSchema const& s) : _ra(s["ra"]), _dec(s["dec"]) {}
223 
224  CoordKey(CoordKey const&) = default;
225  CoordKey(CoordKey&&) = default;
226  CoordKey& operator=(CoordKey const&) = default;
227  CoordKey& operator=(CoordKey&&) = default;
228  virtual ~CoordKey() = default;
229 
231  virtual lsst::geom::SpherePoint get(BaseRecord const& record) const;
232 
234  virtual void set(BaseRecord& record, lsst::geom::SpherePoint 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<lsst::geom::Angle> getRa() const { return _ra; }
247  Key<lsst::geom::Angle> getDec() const { return _dec; }
249 
250 private:
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 
300  QuadrupoleKey(QuadrupoleKey const&) = default;
301  QuadrupoleKey(QuadrupoleKey&&) = default;
302  QuadrupoleKey& operator=(QuadrupoleKey const&) = default;
303  QuadrupoleKey& operator=(QuadrupoleKey&&) = default;
304  virtual ~QuadrupoleKey() = default;
305 
307  virtual geom::ellipses::Quadrupole get(BaseRecord const& record) const;
308 
310  virtual void set(BaseRecord& record, geom::ellipses::Quadrupole const& value) const;
311 
313  bool operator==(QuadrupoleKey const& other) const {
315  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
316  }
317  bool operator!=(QuadrupoleKey const& other) const { return !(*this == other); }
319 
321  bool isValid() const { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
322 
324  Key<double> getIxx() const { return _ixx; }
326  Key<double> getIyy() const { return _iyy; }
327  Key<double> getIxy() const { return _ixy; }
329 
330 private:
331  Key<double> _ixx;
332  Key<double> _iyy;
333  Key<double> _ixy;
334 };
335 
339 class EllipseKey : public FunctorKey<lsst::afw::geom::ellipses::Ellipse> {
340 public:
351  static EllipseKey addFields(Schema& schema, std::string const& name, std::string const& doc,
352  std::string const& unit);
353 
355  EllipseKey() : _qKey(), _pKey() {}
356 
358  EllipseKey(QuadrupoleKey const& qKey, PointKey<double> const& pKey) : _qKey(qKey), _pKey(pKey) {}
359 
368  EllipseKey(SubSchema const& s) : _qKey(s), _pKey(s) {}
369 
370  EllipseKey(EllipseKey const&) = default;
371  EllipseKey(EllipseKey&&) = default;
372  EllipseKey& operator=(EllipseKey const&) = default;
373  EllipseKey& operator=(EllipseKey&&) = default;
374  virtual ~EllipseKey() = default;
375 
377  virtual geom::ellipses::Ellipse get(BaseRecord const& record) const;
378 
380  virtual void set(BaseRecord& record, geom::ellipses::Ellipse const& value) const;
381 
383  bool operator==(EllipseKey const& other) const { return _qKey == other._qKey && _pKey == other._pKey; }
385  bool operator!=(EllipseKey const& other) const { return !(*this == other); }
387 
389  bool isValid() const { return _qKey.isValid() && _pKey.isValid(); }
390 
392  QuadrupoleKey getCore() const { return _qKey; }
394  PointKey<double> getCenter() const { return _pKey; }
396 
397 private:
398  QuadrupoleKey _qKey;
399  PointKey<double> _pKey;
400 };
401 
402 template <typename T, int N>
403 class CovarianceMatrixKey : public FunctorKey<Eigen::Matrix<T, N, N> > {
404 public:
408 
422  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
423  std::string const& unit, bool diagonalOnly = false);
424 
439  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
440  NameArray const& units, bool diagonalOnly = false);
441 
444 
463  explicit CovarianceMatrixKey(SigmaKeyArray const& sigma,
464  CovarianceKeyArray const& cov = CovarianceKeyArray());
465 
477  CovarianceMatrixKey(SubSchema const& s, NameArray const& names);
478 
481  CovarianceMatrixKey& operator=(CovarianceMatrixKey const&);
483  virtual ~CovarianceMatrixKey();
484 
486  virtual Eigen::Matrix<T, N, N> get(BaseRecord const& record) const;
487 
489  virtual void set(BaseRecord& record, Eigen::Matrix<T, N, N> const& value) const;
490 
492  T getElement(BaseRecord const& record, int i, int j) const;
493 
495  void setElement(BaseRecord& record, int i, int j, T value) const;
496 
503  bool isValid() const;
504 
506  bool operator==(CovarianceMatrixKey const& other) const;
508  bool operator!=(CovarianceMatrixKey const& other) const { return !(*this == other); }
510 
511 private:
512  SigmaKeyArray _sigma;
513  CovarianceKeyArray _cov;
514 };
515 } // namespace table
516 } // namespace afw
517 } // namespace lsst
518 
519 #endif // !AFW_TABLE_aggregates_h_INCLUDED
CoordKey(Key< lsst::geom::Angle > const &ra, Key< lsst::geom::Angle > const &dec)
Construct from a pair of Keys.
Definition: aggregates.h:212
CoordKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:209
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Defines the fields and offsets for a table.
Definition: Schema.h:48
double dec
Definition: Match.cc:41
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey)
Construct from individual Keys.
Definition: aggregates.h:358
A proxy type for name lookups in a Schema.
Definition: Schema.h:355
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:298
std::vector< std::string > NameArray
Definition: aggregates.h:407
EllipseKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:355
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:406
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:368
PointKey< int > Point2IKey
Definition: aggregates.h:109
int min
Definition: Coord.cc:82
Key< lsst::geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:247
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
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:317
Key< double > getIyy() const
Return a constituent Key.
Definition: aggregates.h:326
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.
BoxKey(PointKey< Element > const &min, PointKey< Element > const &max)
Construct from a pair of PointKeys.
Definition: aggregates.h:143
PointKey< Element > getMin() const
Return the underlying min PointKey.
Definition: aggregates.h:177
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
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
int max
Definition: BoundedField.cc:98
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:153
bool isValid() const
Return True if both the min and max PointKeys are valid.
Definition: aggregates.h:174
bool operator!=(BoxKey const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:170
double x
PointKey< double > getCenter() const
Return constituent FunctorKeys.
Definition: aggregates.h:394
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:508
Key< double > getIxy() const
Return a constituent Key.
Definition: aggregates.h:327
STL class.
Base class for all records.
Definition: BaseRecord.h:31
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:405
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:62
PointKey(SubSchema const &s)
Construct from a subschema, assuming x and y subfields.
Definition: aggregates.h:81
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:385
PointKey(Key< T > const &x, Key< T > const &y)
Construct from a pair of Keys.
Definition: aggregates.h:65
CoordKey(SubSchema const &s)
Construct from a subschema, assuming ra and dec subfields.
Definition: aggregates.h:222
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:339
PointKey< Element > getMax() const
Return the underlying max PointKey.
Definition: aggregates.h:180
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:239
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy)
Construct from individual Keys.
Definition: aggregates.h:287
bool isValid
Definition: fits.cc:364
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
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:92
A FunctorKey used to get or set celestial coordinates from a pair of lsst::geom::Angle keys...
Definition: aggregates.h:196
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:389
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:321