LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
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 
26 #include "lsst/utils/hashCombine.h"
27 
29 #include "lsst/afw/table/Schema.h"
30 #include "lsst/geom.h"
31 
32 namespace lsst {
33 namespace afw {
34 namespace geom {
35 
36 namespace ellipses {
37 
38 class Quadrupole;
39 
40 } // namespace ellipses
41 } // namespace geom
42 
43 namespace table {
44 
48 template <typename T>
49 class PointKey : public FunctorKey<lsst::geom::Point<T, 2> > {
50 public:
60  static PointKey addFields(Schema& schema, std::string const& name, std::string const& doc,
61  std::string const& unit);
62 
64  PointKey() noexcept : _x(), _y() {}
65 
67  PointKey(Key<T> const& x, Key<T> const& y) noexcept : _x(x), _y(y) {}
68 
69  PointKey(PointKey const&) noexcept = default;
70  PointKey(PointKey&&) noexcept = default;
71  PointKey& operator=(PointKey const&) noexcept = default;
72  PointKey& operator=(PointKey&&) noexcept = default;
73  ~PointKey() noexcept override = default;
74 
83  PointKey(SubSchema const& s) : _x(s["x"]), _y(s["y"]) {}
84 
86  lsst::geom::Point<T, 2> get(BaseRecord const& record) const override;
87 
89  void set(BaseRecord& record, lsst::geom::Point<T, 2> const& value) const override;
90 
92  bool operator==(PointKey<T> const& other) const noexcept { return _x == other._x && _y == other._y; }
94  bool operator!=(PointKey<T> const& other) const noexcept { return !(*this == other); }
96 
98  std::size_t hash_value() const noexcept {
99  // Completely arbitrary seed
100  return utils::hashCombine(17, _x, _y);
101  }
102 
104  bool isValid() const noexcept { return _x.isValid() && _y.isValid(); }
105 
107  Key<T> getX() const noexcept { return _x; }
108 
110  Key<T> getY() const noexcept { return _y; }
111 
112 private:
113  Key<T> _x;
114  Key<T> _y;
115 };
116 
119 
125 template <typename Box>
126 class BoxKey : public FunctorKey<Box> {
127 public:
129  using Element = typename Box::Element;
130 
144  static BoxKey addFields(Schema& schema, std::string const& name, std::string const& doc,
145  std::string const& unit);
146 
148  BoxKey() noexcept = default;
149 
151  BoxKey(PointKey<Element> const& min, PointKey<Element> const& max) noexcept : _min(min), _max(max) {}
152 
161  BoxKey(SubSchema const& s) : _min(s["min"]), _max(s["max"]) {}
162 
163  BoxKey(BoxKey const&) noexcept = default;
164  BoxKey(BoxKey&&) noexcept = default;
165  BoxKey& operator=(BoxKey const&) noexcept = default;
166  BoxKey& operator=(BoxKey&&) noexcept = default;
167  ~BoxKey() noexcept override = default;
168 
170  std::size_t hash_value() const noexcept {
171  // Completely arbitrary seed
172  return utils::hashCombine(17, _min, _max);
173  }
174 
176  Box get(BaseRecord const& record) const override;
177 
179  void set(BaseRecord& record, Box const& value) const override;
180 
182  bool operator==(BoxKey const& other) const noexcept { return _min == other._min && _max == other._max; }
184  bool operator!=(BoxKey const& other) const noexcept { return !(*this == other); }
186 
188  bool isValid() const noexcept { return _min.isValid() && _max.isValid(); }
189 
191  PointKey<Element> getMin() const noexcept { return _min; }
192 
194  PointKey<Element> getMax() const noexcept { return _max; }
195 
196 private:
197  PointKey<Element> _min;
198  PointKey<Element> _max;
199 };
200 
203 
210 class CoordKey : public FunctorKey<lsst::geom::SpherePoint> {
211 public:
220  static CoordKey addFields(afw::table::Schema& schema, std::string const& name, std::string const& doc);
221 
223  CoordKey() noexcept : _ra(), _dec() {}
224 
227  : _ra(ra), _dec(dec) {}
228 
237  CoordKey(SubSchema const& s) : _ra(s["ra"]), _dec(s["dec"]) {}
238 
239  CoordKey(CoordKey const&) noexcept = default;
240  CoordKey(CoordKey&&) noexcept = default;
241  CoordKey& operator=(CoordKey const&) noexcept = default;
242  CoordKey& operator=(CoordKey&&) noexcept = default;
243  ~CoordKey() noexcept override = default;
244 
246  lsst::geom::SpherePoint get(BaseRecord const& record) const override;
247 
249  void set(BaseRecord& record, lsst::geom::SpherePoint const& value) const override;
250 
252  bool operator==(CoordKey const& other) const noexcept { return _ra == other._ra && _dec == other._dec; }
254  bool operator!=(CoordKey const& other) const noexcept { return !(*this == other); }
256 
258  std::size_t hash_value() const noexcept {
259  // Completely arbitrary seed
260  return utils::hashCombine(17, _ra, _dec);
261  }
262 
263  bool isValid() const noexcept { return _ra.isValid() && _dec.isValid(); }
264 
266  Key<lsst::geom::Angle> getRa() const noexcept { return _ra; }
268  Key<lsst::geom::Angle> getDec() const noexcept { return _dec; }
270 
271 private:
274 };
275 
278 
282 class QuadrupoleKey : public FunctorKey<lsst::afw::geom::ellipses::Quadrupole> {
283 public:
295  static QuadrupoleKey addFields(Schema& schema, std::string const& name, std::string const& doc,
296  CoordinateType coordType = CoordinateType::PIXEL);
297 
299  QuadrupoleKey() noexcept : _ixx(), _iyy(), _ixy() {}
300 
302  QuadrupoleKey(Key<double> const& ixx, Key<double> const& iyy, Key<double> const& ixy) noexcept
303  : _ixx(ixx), _iyy(iyy), _ixy(ixy) {}
304 
313  QuadrupoleKey(SubSchema const& s) : _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
314 
315  QuadrupoleKey(QuadrupoleKey const&) noexcept = default;
316  QuadrupoleKey(QuadrupoleKey&&) noexcept = default;
317  QuadrupoleKey& operator=(QuadrupoleKey const&) noexcept = default;
318  QuadrupoleKey& operator=(QuadrupoleKey&&) noexcept = default;
319  ~QuadrupoleKey() noexcept override = default;
320 
322  geom::ellipses::Quadrupole get(BaseRecord const& record) const override;
323 
325  void set(BaseRecord& record, geom::ellipses::Quadrupole const& value) const override;
326 
328  bool operator==(QuadrupoleKey const& other) const noexcept {
330  return _ixx == other._ixx && _iyy == other._iyy && _ixy == other._ixy;
331  }
332  bool operator!=(QuadrupoleKey const& other) const noexcept { return !(*this == other); }
334 
336  std::size_t hash_value() const noexcept {
337  // Completely arbitrary seed
338  return utils::hashCombine(17, _ixx, _iyy, _ixy);
339  }
340 
342  bool isValid() const noexcept { return _ixx.isValid() && _iyy.isValid() && _ixy.isValid(); }
343 
345  Key<double> getIxx() const noexcept { return _ixx; }
347  Key<double> getIyy() const noexcept { return _iyy; }
348  Key<double> getIxy() const noexcept { return _ixy; }
350 
351 private:
352  Key<double> _ixx;
353  Key<double> _iyy;
354  Key<double> _ixy;
355 };
356 
360 class EllipseKey : public FunctorKey<lsst::afw::geom::ellipses::Ellipse> {
361 public:
372  static EllipseKey addFields(Schema& schema, std::string const& name, std::string const& doc,
373  std::string const& unit);
374 
376  EllipseKey() noexcept : _qKey(), _pKey() {}
377 
379  EllipseKey(QuadrupoleKey const& qKey, PointKey<double> const& pKey) noexcept : _qKey(qKey), _pKey(pKey) {}
380 
389  EllipseKey(SubSchema const& s) : _qKey(s), _pKey(s) {}
390 
391  EllipseKey(EllipseKey const&) noexcept = default;
392  EllipseKey(EllipseKey&&) noexcept = default;
393  EllipseKey& operator=(EllipseKey const&) noexcept = default;
394  EllipseKey& operator=(EllipseKey&&) noexcept = default;
395  ~EllipseKey() noexcept override = default;
396 
398  geom::ellipses::Ellipse get(BaseRecord const& record) const override;
399 
401  void set(BaseRecord& record, geom::ellipses::Ellipse const& value) const override;
402 
404  bool operator==(EllipseKey const& other) const noexcept {
406  return _qKey == other._qKey && _pKey == other._pKey;
407  }
408  bool operator!=(EllipseKey const& other) const noexcept { return !(*this == other); }
410 
412  std::size_t hash_value() const noexcept {
413  // Completely arbitrary seed
414  return utils::hashCombine(17, _qKey, _pKey);
415  }
416 
418  bool isValid() const noexcept { return _qKey.isValid() && _pKey.isValid(); }
419 
421  QuadrupoleKey getCore() const noexcept { return _qKey; }
423  PointKey<double> getCenter() const noexcept { return _pKey; }
425 
426 private:
427  QuadrupoleKey _qKey;
428  PointKey<double> _pKey;
429 };
430 
431 template <typename T, int N>
432 class CovarianceMatrixKey : public FunctorKey<Eigen::Matrix<T, N, N> > {
433 public:
437 
451  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
452  std::string const& unit, bool diagonalOnly = false);
453 
468  static CovarianceMatrixKey addFields(Schema& schema, std::string const& prefix, NameArray const& names,
469  NameArray const& units, bool diagonalOnly = false);
470 
473 
492  explicit CovarianceMatrixKey(ErrKeyArray const& err,
493  CovarianceKeyArray const& cov = CovarianceKeyArray());
494 
506  CovarianceMatrixKey(SubSchema const& s, NameArray const& names);
507 
510  CovarianceMatrixKey& operator=(CovarianceMatrixKey const&);
512  ~CovarianceMatrixKey() noexcept override;
513 
515  Eigen::Matrix<T, N, N> get(BaseRecord const& record) const override;
516 
518  void set(BaseRecord& record, Eigen::Matrix<T, N, N> const& value) const override;
519 
521  T getElement(BaseRecord const& record, int i, int j) const;
522 
524  void setElement(BaseRecord& record, int i, int j, T value) const;
525 
532  bool isValid() const noexcept;
533 
535  bool operator==(CovarianceMatrixKey const& other) const noexcept;
537  bool operator!=(CovarianceMatrixKey const& other) const noexcept { return !(*this == other); }
539 
541  std::size_t hash_value() const noexcept;
542 
543 private:
544  ErrKeyArray _err;
545  CovarianceKeyArray _cov;
546 };
547 } // namespace table
548 } // namespace afw
549 } // namespace lsst
550 
551 namespace std {
552 template <typename T>
553 struct hash<lsst::afw::table::PointKey<T>> {
556  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
557 };
558 
559 template <typename T>
560 struct hash<lsst::afw::table::BoxKey<T>> {
563  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
564 };
565 
566 template <>
567 struct hash<lsst::afw::table::CoordKey> {
570  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
571 };
572 
573 template <>
574 struct hash<lsst::afw::table::QuadrupoleKey> {
577  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
578 };
579 
580 template <>
581 struct hash<lsst::afw::table::EllipseKey> {
584  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
585 };
586 
587 template <typename T, int N>
588 struct hash<lsst::afw::table::CovarianceMatrixKey<T, N>> {
591  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
592 };
593 } // namespace std
594 
595 #endif // !AFW_TABLE_aggregates_h_INCLUDED
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Defines the fields and offsets for a table.
Definition: Schema.h:50
size_t operator()(argument_type const &obj) const noexcept
Definition: aggregates.h:563
double dec
Definition: Match.cc:41
A proxy type for name lookups in a Schema.
Definition: Schema.h:357
QuadrupoleKey(SubSchema const &s)
Construct from a subschema with appropriate subfields.
Definition: aggregates.h:313
size_t operator()(argument_type const &obj) const noexcept
Definition: aggregates.h:591
std::vector< std::string > NameArray
Definition: aggregates.h:436
A coordinate class intended to represent absolute positions (2-d specialization). ...
Definition: Point.h:211
Key< T > getX() const noexcept
Return the underlying x Key.
Definition: aggregates.h:107
size_t operator()(argument_type const &obj) const noexcept
Definition: aggregates.h:570
bool isValid() const noexcept
Return True if both the min and max PointKeys are valid.
Definition: aggregates.h:188
CoordKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:223
bool isValid() const noexcept
Return True if all the constituent Keys are valid.
Definition: aggregates.h:418
PointKey< Element > getMin() const noexcept
Return the underlying min PointKey.
Definition: aggregates.h:191
std::vector< Key< T > > CovarianceKeyArray
Definition: aggregates.h:435
EllipseKey(SubSchema const &s)
Construct from a subschema, assuming (xx, yy, xy, x, y) subfields.
Definition: aggregates.h:389
bool operator!=(PointKey< T > const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:94
PointKey< Element > getMax() const noexcept
Return the underlying max PointKey.
Definition: aggregates.h:194
bool operator!=(QuadrupoleKey const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:332
PointKey< int > Point2IKey
Definition: aggregates.h:117
int y
Definition: SpanSet.cc:49
size_t operator()(argument_type const &obj) const noexcept
Definition: aggregates.h:577
STL namespace.
Key< lsst::geom::Angle > getDec() const noexcept
Return a constituent Key.
Definition: aggregates.h:268
PointKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:64
bool operator!=(BoxKey const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying x and y Keys.
Definition: aggregates.h:184
PointKey< double > Point2DKey
Definition: aggregates.h:118
ItemVariant const * other
Definition: Schema.cc:56
daf::base::PropertySet * set
Definition: fits.cc:902
std::size_t hash_value(Extent< T, N > const &extent) noexcept
Definition: Extent.cc:127
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: aggregates.h:98
int min
A FunctorKey used to get or set a lsst::geom::Box2I or Box2D from a (min, max) pair of PointKeys...
Definition: aggregates.h:126
std::vector< Key< T > > ErrKeyArray
Definition: aggregates.h:434
STL class.
EllipseKey(QuadrupoleKey const &qKey, PointKey< double > const &pKey) noexcept
Construct from individual Keys.
Definition: aggregates.h:379
size_t operator()(argument_type const &obj) const noexcept
Definition: aggregates.h:584
typename lsst::geom::Box2I ::Element Element
Type of coordinate elements (i.e. int or double).
Definition: aggregates.h:129
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:49
PointKey(Key< T > const &x, Key< T > const &y) noexcept
Construct from a pair of Keys.
Definition: aggregates.h:67
bool isValid() const noexcept
Definition: aggregates.h:263
bool isValid() const noexcept
Return True if both the x and y Keys are valid.
Definition: aggregates.h:104
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
bool isValid
Definition: fits.cc:398
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Typedefs to be used for probability and parameter values.
Definition: common.h:45
table::Schema schema
Definition: Amplifier.cc:115
CoordKey(Key< lsst::geom::Angle > const &ra, Key< lsst::geom::Angle > const &dec) noexcept
Construct from a pair of Keys.
Definition: aggregates.h:226
PointKey< double > getCenter() const noexcept
Return constituent FunctorKeys.
Definition: aggregates.h:423
Key< double > getIxy() const noexcept
Return a constituent Key.
Definition: aggregates.h:348
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: aggregates.h:412
bool operator!=(EllipseKey const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying Ixx, Iyy, Ixy Keys...
Definition: aggregates.h:408
int max
BoxKey(SubSchema const &s)
Construct from a subschema, assuming _min_x, _max_x, _min_y, _max_y subfields.
Definition: aggregates.h:161
double x
Key< double > getIyy() const noexcept
Return a constituent Key.
Definition: aggregates.h:347
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:277
QuadrupoleKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:299
STL class.
size_t operator()(argument_type const &obj) const noexcept
Definition: aggregates.h:556
Base class for all records.
Definition: BaseRecord.h:31
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: aggregates.h:336
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: aggregates.h:170
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
bool operator!=(CoordKey const &other) const noexcept
Compare CoordKeys for equality using the constituent ra and dec Keys.
Definition: aggregates.h:254
PointKey(SubSchema const &s)
Construct from a subschema, assuming x and y subfields.
Definition: aggregates.h:83
EllipseKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to. ...
Definition: aggregates.h:376
std::string prefix
Definition: SchemaMapper.cc:79
CoordKey(SubSchema const &s)
Construct from a subschema, assuming ra and dec subfields.
Definition: aggregates.h:237
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: aggregates.h:258
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
bool isValid() const noexcept
Return True if all the constituent Keys are valid.
Definition: aggregates.h:342
A FunctorKey used to get or set a geom::ellipses::Ellipse from an (xx,yy,xy,x,y) tuple of Keys...
Definition: aggregates.h:360
Convenience base class that combines the OutputFunctorKey and InputFunctorKey.
Definition: FunctorKey.h:74
QuadrupoleKey(Key< double > const &ixx, Key< double > const &iyy, Key< double > const &ixy) noexcept
Construct from individual Keys.
Definition: aggregates.h:302
A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys...
Definition: aggregates.h:282
Key< T > getY() const noexcept
Return the underlying y Key.
Definition: aggregates.h:110
A FunctorKey used to get or set celestial coordinates from a pair of lsst::geom::Angle keys...
Definition: aggregates.h:210