LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
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 { namespace afw {
30 
31 namespace geom {
32 
33 template <typename T, int N> class Point;
34 
35 namespace ellipses {
36 
37 class Quadrupole;
38 
39 } // namespace ellipses
40 } // namespace geom
41 
42 namespace table {
43 
47 template <typename T>
48 class PointKey : public FunctorKey< lsst::afw::geom::Point<T,2> > {
49 public:
50 
60  static PointKey addFields(
61  Schema & schema,
62  std::string const & name,
63  std::string const & doc,
64  std::string const & unit
65  );
66 
68  PointKey() : _x(), _y() {}
69 
71  PointKey(Key<T> const & x, Key<T> const & y) : _x(x), _y(y) {}
72 
79  explicit PointKey(Key< Point<T> > const & other) : _x(other.getX()), _y(other.getY()) {}
80 
90  PointKey(SubSchema const & s) : _x(s["x"]), _y(s["y"]) {}
91 
93  virtual geom::Point<T,2> get(BaseRecord const & record) const;
94 
96  virtual void set(BaseRecord & record, geom::Point<T,2> const & value) const;
97 
99  bool operator==(PointKey<T> const & other) const { return _x == other._x && _y == other._y; }
101  bool operator!=(PointKey<T> const & other) const { return !(*this == other); }
103 
105  bool isValid() const { return _x.isValid() && _y.isValid(); }
106 
108  Key<T> getX() const { return _x; }
109 
111  Key<T> getY() const { return _y; }
112 
113 private:
116 };
117 
120 
127 class CoordKey : public FunctorKey < coord::IcrsCoord > {
128 public:
137  static CoordKey addFields(
139  std::string const & name,
140  std::string const & doc
141  );
142 
144  CoordKey() : _ra(), _dec() {}
145 
148  Key<geom::Angle> const & ra,
149  Key<geom::Angle> const & dec
150  ) :
151  _ra(ra), _dec(dec)
152  {}
153 
163  CoordKey(SubSchema const & s) : _ra(s["ra"]), _dec(s["dec"]) {}
164 
166  virtual coord::IcrsCoord get(BaseRecord const & record) const;
167 
169  virtual void set(BaseRecord & record, coord::IcrsCoord const & value) const;
170 
172  virtual void set(BaseRecord & record, coord::Coord const & value) const;
173 
174  bool isValid() const { return _ra.isValid() && _dec.isValid(); }
175 
177  Key<geom::Angle> getRa() const { return _ra; }
179  Key<geom::Angle> getDec() const { return _dec; }
181 
182 private:
185 };
186 
188 bool operator==(CoordKey const & lhs, CoordKey const & rhs);
190 bool operator!=(CoordKey const & lhs, CoordKey const & rhs);
192 
196 class QuadrupoleKey : public FunctorKey< lsst::afw::geom::ellipses::Quadrupole > {
197 public:
198 
210  static QuadrupoleKey addFields(
211  Schema & schema,
212  std::string const & name,
213  std::string const & doc,
215  );
216 
218  QuadrupoleKey() : _ixx(), _iyy(), _ixy() {}
219 
221  QuadrupoleKey(Key<double> const & ixx, Key<double> const & iyy, Key<double> const & ixy) :
222  _ixx(ixx), _iyy(iyy), _ixy(ixy)
223  {}
224 
231  explicit QuadrupoleKey(Key< Moments<double> > const & other) :
232  _ixx(other.getIxx()), _iyy(other.getIyy()), _ixy(other.getIxy())
233  {}
234 
245  QuadrupoleKey(SubSchema const & s): _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
246 
248  virtual geom::ellipses::Quadrupole get(BaseRecord const & record) const;
249 
251  virtual void set(BaseRecord & record, geom::ellipses::Quadrupole const & value) const;
252 
254  bool operator==(QuadrupoleKey const & other) const {
256  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
257  }
258  bool operator!=(QuadrupoleKey const & other) const { return !(*this == other); }
260 
262  bool isValid() const { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
263 
265  Key<double> getIxx() const { return _ixx; }
267  Key<double> getIyy() const { return _iyy; }
268  Key<double> getIxy() const { return _ixy; }
270 
271 private:
275 };
276 
277 
281 class EllipseKey : public FunctorKey< lsst::afw::geom::ellipses::Ellipse > {
282 public:
283 
294  static EllipseKey addFields(
295  Schema & schema,
296  std::string const & name,
297  std::string const & doc,
298  std::string const & unit
299  );
300 
302  EllipseKey() : _qKey(), _pKey() {}
303 
305  EllipseKey(QuadrupoleKey const & qKey, PointKey<double> const & pKey) :
306  _qKey(qKey), _pKey(pKey)
307  {}
308 
318  EllipseKey(SubSchema const & s) : _qKey(s), _pKey(s) {}
319 
321  virtual geom::ellipses::Ellipse get(BaseRecord const & record) const;
322 
324  virtual void set(BaseRecord & record, geom::ellipses::Ellipse const & value) const;
325 
327  bool operator==(EllipseKey const & other) const {
329  return _qKey == other._qKey && _pKey == other._pKey;
330  }
331  bool operator!=(EllipseKey const & other) const { return !(*this == other); }
333 
335  bool isValid() const { return _qKey.isValid() && _pKey.isValid(); }
336 
338  QuadrupoleKey getCore() const { return _qKey; }
340  PointKey<double> getCenter() const { return _pKey; }
342 
343 private:
346 };
347 
348 
349 template <typename T, int N>
350 class CovarianceMatrixKey : public FunctorKey< Eigen::Matrix<T,N,N> > {
351 public:
352 
353  typedef std::vector< Key<T> > SigmaKeyArray;
354  typedef std::vector< Key<T> > CovarianceKeyArray;
355  typedef std::vector<std::string> NameArray;
356 
359 
379  explicit CovarianceMatrixKey(
380  SigmaKeyArray const & sigma,
382  );
383 
396  template <typename U>
397  explicit CovarianceMatrixKey(Key< Covariance<U> > const & other);
398 
410  CovarianceMatrixKey(SubSchema const & s, NameArray const & names);
411 
413  virtual Eigen::Matrix<T,N,N> get(BaseRecord const & record) const;
414 
416  virtual void set(BaseRecord & record, Eigen::Matrix<T,N,N> const & value) const;
417 
419  T getElement(BaseRecord const & record, int i, int j) const;
420 
422  void setElement(BaseRecord & record, int i, int j, T value) const;
423 
430  bool isValid() const;
431 
433  bool operator==(CovarianceMatrixKey const & other) const;
435  bool operator!=(CovarianceMatrixKey const & other) const { return !(*this == other); }
437 
438 private:
442 };
443 
447 }
448 
449 inline CovarianceMatrixKey<float,2>
451  return CovarianceMatrixKey<float,2>(other);
452 }
453 
454 inline CovarianceMatrixKey<float,3>
456  return CovarianceMatrixKey<float,3>(other);
457 }
458 
459 }}} // namespace lsst::afw::table
460 
461 #endif // !AFW_TABLE_aggregates_h_INCLUDED
Key< T > getX() const
Return the underlying x Key.
Definition: aggregates.h:108
int y
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
Defines the fields and offsets for a table.
Definition: Schema.h:46
bool isValid() const
Definition: aggregates.h:174
PointKey(SubSchema const &s)
Construct from a subschema, assuming x and y subfields.
Definition: aggregates.h:90
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:262
PointKey(Key< Point< T > > const &other)
Definition: aggregates.h:79
A coordinate class intended to represent absolute positions (2-d specialization). ...
Definition: Point.h:183
Key< geom::Angle > getRa() const
Return a constituent Key.
Definition: aggregates.h:178
A proxy type for name lookups in a Schema.
Definition: Schema.h:372
bool operator!=(EllipseKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:331
virtual void set(BaseRecord &record, geom::ellipses::Quadrupole const &value) const
Set a Quadrupole in the given record.
virtual void set(BaseRecord &record, coord::IcrsCoord const &value) const
Set an IcrsCoord in the given record.
bool operator==(EllipseKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:328
PointKey< double > _pKey
Definition: aggregates.h:345
void setElement(BaseRecord &record, int i, int j, T value) const
Set the element in row i and column j.
Key< geom::Angle > _ra
Definition: aggregates.h:183
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:335
CoordKey(SubSchema const &s)
Construct from a subschema, assuming ra and dec subfields.
Definition: aggregates.h:163
PointKey< double > getCenter() const
Return constituent FunctorKeys.
Definition: aggregates.h:340
virtual void set(BaseRecord &record, geom::ellipses::Ellipse const &value) const
Set an Ellipse in the given record.
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Key.h:83
bool operator!=(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
Definition: aggregates.h:435
bool operator!=(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey)
Construct from individual Keys.
Definition: aggregates.h:305
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
std::vector< std::string > NameArray
Definition: aggregates.h:355
Key< geom::Angle > _dec
Definition: aggregates.h:184
static QuadrupoleKey addFields(Schema &schema, std::string const &name, std::string const &doc, CoordinateType coordType=CoordinateType::PIXEL)
Key< double > getIxy() const
Return a constituent Key.
Definition: aggregates.h:268
bool operator!=(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:258
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:354
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:42
CovarianceMatrixKey()
Construct an invalid instance; must assign before subsequent use.
virtual void set(BaseRecord &record, geom::Point< T, 2 > const &value) const
Set a Point in the given record.
CoordKey(Key< geom::Angle > const &ra, Key< geom::Angle > const &dec)
Construct from a pair of Keys.
Definition: aggregates.h:147
PointKey(Key< T > const &x, Key< T > const &y)
Construct from a pair of Keys.
Definition: aggregates.h:71
static CoordKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
A FunctorKey used to get or set a geom::Point from an (x,y) pair of int or double Keys...
Definition: aggregates.h:48
tbl::Schema schema
Definition: CoaddPsf.cc:324
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:318
bool isValid() const
Return True if all the constituent sigma Keys are valid.
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:245
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:50
QuadrupoleKey getCore() const
Return constituent FunctorKeys.
Definition: aggregates.h:339
bool operator==(PointKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:100
QuadrupoleKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:218
Key< T > getY() const
Return the underlying y Key.
Definition: aggregates.h:111
int x
CoordinateType
Definition: misc.h:23
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy)
Construct from individual Keys.
Definition: aggregates.h:221
Base class for all records.
Definition: BaseRecord.h:27
PointKey< double > Point2DKey
Definition: aggregates.h:119
QuadrupoleKey(Key< Moments< double > > const &other)
Definition: aggregates.h:231
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:179
CovarianceMatrixKey< float, Eigen::Dynamic > makeCovarianceMatrixKey(Key< Covariance< float > > const &other)
Definition: aggregates.h:445
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
PointKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:68
static EllipseKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
bool operator==(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:255
T getElement(BaseRecord const &record, int i, int j) const
Return the element in row i and column j.
virtual void set(BaseRecord &record, Eigen::Matrix< T, N, N > const &value) const
Set a covariance matrix in the given record (uses only the lower triangle of the given matrix) ...
bool operator==(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
bool operator!=(PointKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:101
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:281
Key< double > getIxx() const
Return a constituent Key.
Definition: aggregates.h:266
CoordKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:144
Tag types used to declare specialized field types.
Definition: misc.h:35
A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys...
Definition: aggregates.h:196
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:155
bool isValid() const
Return True if both the x and y Keys are valid.
Definition: aggregates.h:105
dictionary Point
Definition: __init__.py:38
EllipseKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:302
PointKey< int > Point2IKey
Definition: aggregates.h:118
A FunctorKey used to get or set celestial coordiantes from a pair of Angle keys.
Definition: aggregates.h:127
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:353
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Key< double > getIyy() const
Return a constituent Key.
Definition: aggregates.h:267