LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 
82  PointKey(SubSchema const & s) : _x(s["x"]), _y(s["y"]) {}
83 
85  virtual geom::Point<T,2> get(BaseRecord const & record) const;
86 
88  virtual void set(BaseRecord & record, geom::Point<T,2> const & value) const;
89 
91  bool operator==(PointKey<T> const & other) const { return _x == other._x && _y == other._y; }
93  bool operator!=(PointKey<T> const & other) const { return !(*this == other); }
95 
97  bool isValid() const { return _x.isValid() && _y.isValid(); }
98 
100  Key<T> getX() const { return _x; }
101 
103  Key<T> getY() const { return _y; }
104 
105 private:
108 };
109 
112 
119 class CoordKey : public FunctorKey < coord::IcrsCoord > {
120 public:
129  static CoordKey addFields(
131  std::string const & name,
132  std::string const & doc
133  );
134 
136  CoordKey() : _ra(), _dec() {}
137 
140  Key<geom::Angle> const & ra,
141  Key<geom::Angle> const & dec
142  ) :
143  _ra(ra), _dec(dec)
144  {}
145 
155  CoordKey(SubSchema const & s) : _ra(s["ra"]), _dec(s["dec"]) {}
156 
158  virtual coord::IcrsCoord get(BaseRecord const & record) const;
159 
161  virtual void set(BaseRecord & record, coord::IcrsCoord const & value) const;
162 
164  virtual void set(BaseRecord & record, coord::Coord const & value) const;
165 
166  bool isValid() const { return _ra.isValid() && _dec.isValid(); }
167 
169  Key<geom::Angle> getRa() const { return _ra; }
171  Key<geom::Angle> getDec() const { return _dec; }
173 
174 private:
177 };
178 
180 bool operator==(CoordKey const & lhs, CoordKey const & rhs);
182 bool operator!=(CoordKey const & lhs, CoordKey const & rhs);
184 
188 class QuadrupoleKey : public FunctorKey< lsst::afw::geom::ellipses::Quadrupole > {
189 public:
190 
202  static QuadrupoleKey addFields(
203  Schema & schema,
204  std::string const & name,
205  std::string const & doc,
207  );
208 
210  QuadrupoleKey() : _ixx(), _iyy(), _ixy() {}
211 
213  QuadrupoleKey(Key<double> const & ixx, Key<double> const & iyy, Key<double> const & ixy) :
214  _ixx(ixx), _iyy(iyy), _ixy(ixy)
215  {}
216 
227  QuadrupoleKey(SubSchema const & s): _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
228 
230  virtual geom::ellipses::Quadrupole get(BaseRecord const & record) const;
231 
233  virtual void set(BaseRecord & record, geom::ellipses::Quadrupole const & value) const;
234 
236  bool operator==(QuadrupoleKey const & other) const {
238  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
239  }
240  bool operator!=(QuadrupoleKey const & other) const { return !(*this == other); }
242 
244  bool isValid() const { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
245 
247  Key<double> getIxx() const { return _ixx; }
249  Key<double> getIyy() const { return _iyy; }
250  Key<double> getIxy() const { return _ixy; }
252 
253 private:
257 };
258 
259 
263 class EllipseKey : public FunctorKey< lsst::afw::geom::ellipses::Ellipse > {
264 public:
265 
276  static EllipseKey addFields(
277  Schema & schema,
278  std::string const & name,
279  std::string const & doc,
280  std::string const & unit
281  );
282 
284  EllipseKey() : _qKey(), _pKey() {}
285 
287  EllipseKey(QuadrupoleKey const & qKey, PointKey<double> const & pKey) :
288  _qKey(qKey), _pKey(pKey)
289  {}
290 
300  EllipseKey(SubSchema const & s) : _qKey(s), _pKey(s) {}
301 
303  virtual geom::ellipses::Ellipse get(BaseRecord const & record) const;
304 
306  virtual void set(BaseRecord & record, geom::ellipses::Ellipse const & value) const;
307 
309  bool operator==(EllipseKey const & other) const {
311  return _qKey == other._qKey && _pKey == other._pKey;
312  }
313  bool operator!=(EllipseKey const & other) const { return !(*this == other); }
315 
317  bool isValid() const { return _qKey.isValid() && _pKey.isValid(); }
318 
320  QuadrupoleKey getCore() const { return _qKey; }
322  PointKey<double> getCenter() const { return _pKey; }
324 
325 private:
328 };
329 
330 
331 template <typename T, int N>
332 class CovarianceMatrixKey : public FunctorKey< Eigen::Matrix<T,N,N> > {
333 public:
334 
335  typedef std::vector< Key<T> > SigmaKeyArray;
336  typedef std::vector< Key<T> > CovarianceKeyArray;
337  typedef std::vector<std::string> NameArray;
338 
353  Schema & schema,
354  std::string const & prefix,
355  NameArray const & names,
356  std::string const & unit,
357  bool diagonalOnly=false
358  );
359 
375  Schema & schema,
376  std::string const & prefix,
377  NameArray const & names,
378  NameArray const & units,
379  bool diagonalOnly=false
380  );
381 
384 
404  explicit CovarianceMatrixKey(
405  SigmaKeyArray const & sigma,
407  );
408 
420  CovarianceMatrixKey(SubSchema const & s, NameArray const & names);
421 
423  virtual Eigen::Matrix<T,N,N> get(BaseRecord const & record) const;
424 
426  virtual void set(BaseRecord & record, Eigen::Matrix<T,N,N> const & value) const;
427 
429  T getElement(BaseRecord const & record, int i, int j) const;
430 
432  void setElement(BaseRecord & record, int i, int j, T value) const;
433 
440  bool isValid() const;
441 
443  bool operator==(CovarianceMatrixKey const & other) const;
445  bool operator!=(CovarianceMatrixKey const & other) const { return !(*this == other); }
447 
448 private:
451 };
452 
453 }}} // namespace lsst::afw::table
454 
455 #endif // !AFW_TABLE_aggregates_h_INCLUDED
int y
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Key.h:83
Key< double > getIxy() const
Return a constituent Key.
Definition: aggregates.h:250
CoordKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:136
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
Defines the fields and offsets for a table.
Definition: Schema.h:46
PointKey< double > getCenter() const
Return constituent FunctorKeys.
Definition: aggregates.h:322
A coordinate class intended to represent absolute positions (2-d specialization). ...
Definition: Point.h:183
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey)
Construct from individual Keys.
Definition: aggregates.h:287
A proxy type for name lookups in a Schema.
Definition: Schema.h:330
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:227
Key< T > getY() const
Return the underlying y Key.
Definition: aggregates.h:103
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
std::vector< std::string > NameArray
Definition: aggregates.h:337
table::Key< std::string > name
Definition: ApCorrMap.cc:71
QuadrupoleKey getCore() const
Return constituent FunctorKeys.
Definition: aggregates.h:321
EllipseKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:284
Key< geom::Angle > _dec
Definition: aggregates.h:176
Key< double > getIyy() const
Return a constituent Key.
Definition: aggregates.h:249
static CovarianceMatrixKey addFields(Schema &schema, std::string const &prefix, NameArray const &names, std::string const &unit, bool diagonalOnly=false)
afw::table::Schema schema
Definition: GaussianPsf.cc:41
QuadrupoleKey()
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:210
virtual void set(BaseRecord &record, geom::Point< T, 2 > const &value) const
Set a Point in the given record.
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:300
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:244
Key< double > getIxx() const
Return a constituent Key.
Definition: aggregates.h:248
PointKey< int > Point2IKey
Definition: aggregates.h:110
bool operator!=(PointKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:93
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:111
PointKey< double > _pKey
Definition: aggregates.h:327
static CoordKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
Key< T > getX() const
Return the underlying x Key.
Definition: aggregates.h:100
bool isValid() const
Return True if both the x and y Keys are valid.
Definition: aggregates.h:97
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:43
A FunctorKey used to get or set a geom::Point from an (x,y) pair of int or double Keys...
Definition: aggregates.h:48
static QuadrupoleKey addFields(Schema &schema, std::string const &name, std::string const &doc, CoordinateType coordType=CoordinateType::PIXEL)
std::vector< Key< T > > SigmaKeyArray
Definition: aggregates.h:335
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
bool isValid() const
Return True if all the constituent Keys are valid.
Definition: aggregates.h:317
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:50
bool operator!=(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:240
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:171
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:336
virtual void set(BaseRecord &record, coord::IcrsCoord const &value) const
Set an IcrsCoord in the given record.
bool operator==(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
CoordKey(Key< geom::Angle > const &ra, Key< geom::Angle > const &dec)
Construct from a pair of Keys.
Definition: aggregates.h:139
double x
T getElement(BaseRecord const &record, int i, int j) const
Return the element in row i and column j.
virtual void set(BaseRecord &record, geom::ellipses::Quadrupole const &value) const
Set a Quadrupole 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:313
Key< geom::Angle > _ra
Definition: aggregates.h:175
Base class for all records.
Definition: BaseRecord.h:27
bool operator!=(CovarianceMatrixKey const &other) const
Compare the FunctorKey for equality with another, using its constituent Keys.
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
bool operator==(EllipseKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:310
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) ...
PointKey(SubSchema const &s)
Construct from a subschema, assuming x and y subfields.
Definition: aggregates.h:82
PointKey(Key< T > const &x, Key< T > const &y)
Construct from a pair of Keys.
Definition: aggregates.h:71
virtual void set(BaseRecord &record, geom::ellipses::Ellipse const &value) const
Set an Ellipse in the given record.
bool isValid() const
Return True if all the constituent sigma Keys are valid.
CoordKey(SubSchema const &s)
Construct from a subschema, assuming ra and dec subfields.
Definition: aggregates.h:155
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:263
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy)
Construct from individual Keys.
Definition: aggregates.h:213
A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys...
Definition: aggregates.h:188
dictionary Point
Definition: __init__.py:39
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:157
static EllipseKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Key< geom::Angle > getRa() const
Return a constituent Key.
Definition: aggregates.h:170
bool operator==(QuadrupoleKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:237
CovarianceMatrixKey()
Construct an invalid instance; must assign before subsequent use.
void setElement(BaseRecord &record, int i, int j, T value) const
Set the element in row i and column j.
A FunctorKey used to get or set celestial coordiantes from a pair of Angle keys.
Definition: aggregates.h:119