LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
ShapeUtilities.cc
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 * Copyright 2008-2015 AURA/LSST.
4 *
5 * This product includes software developed by the
6 * LSST Project (http://www.lsst.org/).
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the LSST License Statement and
19 * the GNU General Public License along with this program. If not,
20 * see <http://www.lsstcorp.org/LegalNotices/>.
21 */
22
25
26namespace lsst {
27namespace meas {
28namespace base {
29
31 : xx(std::numeric_limits<ShapeElement>::quiet_NaN()),
32 yy(std::numeric_limits<ShapeElement>::quiet_NaN()),
33 xy(std::numeric_limits<ShapeElement>::quiet_NaN()),
34 xxErr(std::numeric_limits<ErrElement>::quiet_NaN()),
35 yyErr(std::numeric_limits<ErrElement>::quiet_NaN()),
36 xyErr(std::numeric_limits<ErrElement>::quiet_NaN()),
37 xx_yy_Cov(std::numeric_limits<ErrElement>::quiet_NaN()),
38 xx_xy_Cov(std::numeric_limits<ErrElement>::quiet_NaN()),
39 yy_xy_Cov(std::numeric_limits<ErrElement>::quiet_NaN()) {}
40
41Shape const ShapeResult::getShape() const { return Shape(xx, yy, xy); }
42
43void ShapeResult::setShape(Shape const &shape) {
44 xx = shape.getIxx();
45 yy = shape.getIyy();
46 xy = shape.getIxy();
47}
48
50 ShapeCov m;
53 return m;
54}
55
57 xxErr = std::sqrt(matrix(0, 0));
58 yyErr = std::sqrt(matrix(1, 1));
59 xyErr = std::sqrt(matrix(2, 2));
60 xx_yy_Cov = matrix(0, 1);
61 xx_xy_Cov = matrix(0, 2);
62 yy_xy_Cov = matrix(1, 2);
63}
64
66 xxErr = _xxErr;
67 yyErr = _yyErr;
68 xyErr = _xyErr;
69 xx_yy_Cov = 0.0;
70 xx_xy_Cov = 0.0;
71 yy_xy_Cov = 0.0;
72}
73
75 std::string const &doc, UncertaintyEnum uncertainty,
78 r._shape = afw::table::QuadrupoleKey::addFields(schema, name, doc, coordType);
79 if (uncertainty != NO_UNCERTAINTY) {
82 sigma[0] = schema.addField<ErrElement>(
83 schema.join(name, "xxErr"), "Standard deviation of xx moment",
84 coordType == afw::table::CoordinateType::PIXEL ? "pixel^2" : "rad^2");
85 sigma[1] = schema.addField<ErrElement>(
86 schema.join(name, "yyErr"), "Standard deviation of yy moment",
87 coordType == afw::table::CoordinateType::PIXEL ? "pixel^2" : "rad^2");
88 sigma[2] = schema.addField<ErrElement>(
89 schema.join(name, "xyErr"), "Standard deviation of xy moment",
90 coordType == afw::table::CoordinateType::PIXEL ? "pixel^2" : "rad^2");
91 if (uncertainty == FULL_COVARIANCE) {
92 cov.push_back(schema.addField<ErrElement>(
93 schema.join(name, "xx_yy_Cov"), "uncertainty covariance in xx and yy",
94 coordType == afw::table::CoordinateType::PIXEL ? "pixel^4" : "rad^4"));
95 cov.push_back(schema.addField<ErrElement>(
96 schema.join(name, "xx_xy_Cov"), "uncertainty covariance in xx and xy",
97 coordType == afw::table::CoordinateType::PIXEL ? "pixel^4" : "rad^4"));
98 cov.push_back(schema.addField<ErrElement>(
99 schema.join(name, "yy_xy_Cov"), "uncertainty covariance in yy and xy",
100 coordType == afw::table::CoordinateType::PIXEL ? "pixel^4" : "rad^4"));
101 }
103 }
104 return r;
105}
106
107namespace {
108
109std::vector<std::string> getNameVector() {
111 v.push_back("xx");
112 v.push_back("yy");
113 v.push_back("xy");
114 return v;
115}
116
117} // namespace
118
120 static std::vector<std::string> names = getNameVector(); // C++11 TODO: just use initializer list
121 try {
124 }
125}
126
128 ShapeResult r;
129 r.setShape(record.get(_shape));
130 if (_shapeErr.isValid()) {
131 r.setShapeErr(record.get(_shapeErr));
132 }
133 return r;
134}
135
136void ShapeResultKey::set(afw::table::BaseRecord &record, ShapeResult const &value) const {
137 record.set(_shape, value.getShape());
138 if (_shapeErr.isValid()) {
139 record.set(_shapeErr, value.getShapeErr());
140 }
141}
142
144 typedef geom::LinearTransform LT;
145 Eigen::Matrix<ShapeElement, 3, 3, Eigen::DontAlign> m;
146 m << xform[LT::XX] * xform[LT::XX], xform[LT::XY] * xform[LT::XY], 2 * xform[LT::XX] * xform[LT::XY],
147 xform[LT::YX] * xform[LT::YX], xform[LT::YY] * xform[LT::YY], 2 * xform[LT::YX] * xform[LT::YY],
148 xform[LT::XX] * xform[LT::YX], xform[LT::XY] * xform[LT::YY],
149 xform[LT::XX] * xform[LT::YY] + xform[LT::XY] * xform[LT::YX];
150 return m;
151}
152
153} // namespace base
154} // namespace meas
155} // namespace lsst
table::Key< std::string > name
Definition: Amplifier.cc:116
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:49
int m
Definition: SpanSet.cc:48
table::Schema schema
Definition: python.h:134
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Base class for all records.
Definition: BaseRecord.h:31
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:151
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:164
static QuadrupoleKey addFields(Schema &schema, std::string const &name, std::string const &doc, CoordinateType coordType=CoordinateType::PIXEL)
Add a set of quadrupole subfields to a schema and return a QuadrupoleKey that points to them.
Definition: aggregates.cc:100
Defines the fields and offsets for a table.
Definition: Schema.h:51
A proxy type for name lookups in a Schema.
Definition: Schema.h:367
A 2D linear coordinate transformation.
A FunctorKey for ShapeResult.
static ShapeResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc, UncertaintyEnum uncertainty, afw::table::CoordinateType coordType=afw::table::CoordinateType::PIXEL)
Add the appropriate fields to a Schema, and return a ShapeResultKey that manages them.
virtual ShapeResult get(afw::table::BaseRecord const &record) const
Get a ShapeResult from the given record.
ShapeResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
virtual void set(afw::table::BaseRecord &record, ShapeResult const &value) const
Set a ShapeResult in the given record.
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:277
UncertaintyEnum
An enum used to specify how much uncertainty information measurement algorithms provide.
Definition: constants.h:43
@ FULL_COVARIANCE
The full covariance matrix is provided.
Definition: constants.h:46
@ NO_UNCERTAINTY
Algorithm provides no uncertainy information at all.
Definition: constants.h:44
Eigen::Matrix< ErrElement, 3, 3, Eigen::DontAlign > ShapeCov
Definition: constants.h:61
Eigen::Matrix< ShapeElement, 3, 3, Eigen::DontAlign > ShapeTrMatrix
Definition: constants.h:62
afw::geom::ellipses::Quadrupole Shape
Definition: constants.h:60
float ErrElement
Definition: constants.h:55
double ShapeElement
Definition: constants.h:57
ShapeTrMatrix makeShapeTransformMatrix(geom::LinearTransform const &xform)
Construct a matrix suitable for transforming second moments.
A base class for image defects.
STL namespace.
T push_back(T... args)
T sqrt(T... args)
A reusable struct for moments-based shape measurements.
ErrElement yy_xy_Cov
yy,xy term in the uncertainty convariance matrix
Shape const getShape() const
Return an afw::geom::ellipses object corresponding to xx, yy, xy.
ShapeCov const getShapeErr() const
Return the 3x3 symmetric covariance matrix, with rows and columns ordered (xx, yy,...
ErrElement xyErr
standard deviation of xy
void setShape(Shape const &shape)
Set struct elements from the given Quadrupole object.
ErrElement xx_xy_Cov
xx,xy term in the uncertainty convariance matrix
ShapeResult()
Constructor; initializes everything to NaN.
ShapeElement xy
image or model second moment for xy^2
ErrElement xxErr
standard deviation of xx
ShapeElement xx
image or model second moment for x^2
void setShapeErr(ShapeCov const &matrix)
Set the struct standard deviation elements from the given matrix, with rows and columns ordered (xx,...
ErrElement xx_yy_Cov
xx,yy term in the uncertainty convariance matrix
ErrElement yyErr
standard deviation of yy
ShapeElement yy
image or model second moment for y^2