LSSTApplications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
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 
26 namespace lsst {
27 namespace meas {
28 namespace 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 
41 Shape const ShapeResult::getShape() const { return Shape(xx, yy, xy); }
42 
43 void 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 
56 void ShapeResult::setShapeErr(ShapeCov const &matrix) {
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,
76  afw::table::CoordinateType coordType) {
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 
107 namespace {
108 
109 std::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 {
123  } catch (pex::exceptions::NotFoundError &) {
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 
136 void 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
lsst::afw::geom::ellipses::Quadrupole::getIxx
double const getIxx() const
Definition: Quadrupole.h:54
lsst::meas::base::FULL_COVARIANCE
@ FULL_COVARIANCE
The full covariance matrix is provided.
Definition: constants.h:46
lsst::meas::base::ShapeResult::xy
ShapeElement xy
image or model second moment for xy^2
Definition: ShapeUtilities.h:46
std::string
STL class.
lsst::meas::base::UncertaintyEnum
UncertaintyEnum
An enum used to specify how much uncertainty information measurement algorithms provide.
Definition: constants.h:43
lsst::meas::base::ShapeCov
Eigen::Matrix< ErrElement, 3, 3, Eigen::DontAlign > ShapeCov
Definition: constants.h:61
lsst::meas::base::ShapeResult::xxErr
ErrElement xxErr
standard deviation of xx
Definition: ShapeUtilities.h:47
lsst::afw::table::BaseRecord::get
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:151
lsst::meas::base::NO_UNCERTAINTY
@ NO_UNCERTAINTY
Algorithm provides no uncertainy information at all.
Definition: constants.h:44
lsst::meas::base::ShapeResult::xyErr
ErrElement xyErr
standard deviation of xy
Definition: ShapeUtilities.h:49
lsst::meas::base::ShapeResult::yy_xy_Cov
ErrElement yy_xy_Cov
yy,xy term in the uncertainty convariance matrix
Definition: ShapeUtilities.h:52
std::vector
STL class.
lsst.pex::exceptions::NotFoundError
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
lsst::geom::LinearTransform
A 2D linear coordinate transformation.
Definition: LinearTransform.h:69
sigma
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:50
lsst::meas::base::ShapeResult::ShapeResult
ShapeResult()
Constructor; initializes everything to NaN.
Definition: ShapeUtilities.cc:30
lsst::afw::geom::ellipses::Quadrupole::getIxy
double const getIxy() const
Definition: Quadrupole.h:60
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::meas::base::ShapeResultKey
A FunctorKey for ShapeResult.
Definition: ShapeUtilities.h:113
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::meas::base::ShapeResult::yyErr
ErrElement yyErr
standard deviation of yy
Definition: ShapeUtilities.h:48
lsst::afw::table::CovarianceMatrixKey< ErrElement, 3 >
std::sqrt
T sqrt(T... args)
std::vector::push_back
T push_back(T... args)
lsst::meas::base::ShapeTrMatrix
Eigen::Matrix< ShapeElement, 3, 3, Eigen::DontAlign > ShapeTrMatrix
Definition: constants.h:62
BaseRecord.h
lsst::afw::table::CovarianceMatrixKey::isValid
bool isValid() const noexcept
Return True if all the constituent error Keys are valid.
Definition: aggregates.cc:294
schema
table::Schema schema
Definition: python.h:134
lsst::afw::table::CoordinateType
CoordinateType
Enum used to set units for geometric FunctorKeys.
Definition: aggregates.h:277
lsst::afw::table::QuadrupoleKey::addFields
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
lsst::meas::base::ShapeResultKey::addFields
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.
Definition: ShapeUtilities.cc:74
lsst::afw::geom::ellipses::Quadrupole::getIyy
double const getIyy() const
Definition: Quadrupole.h:57
lsst::afw::table::BaseRecord
Base class for all records.
Definition: BaseRecord.h:31
lsst::meas::base::ShapeResult::setShapeErr
void setShapeErr(ShapeCov const &matrix)
Set the struct standard deviation elements from the given matrix, with rows and columns ordered (xx,...
Definition: ShapeUtilities.cc:56
lsst::meas::base::ShapeResult::yy
ShapeElement yy
image or model second moment for y^2
Definition: ShapeUtilities.h:45
lsst::meas::base::ShapeResult::xx_xy_Cov
ErrElement xx_xy_Cov
xx,xy term in the uncertainty convariance matrix
Definition: ShapeUtilities.h:51
lsst::meas::base::ShapeResultKey::get
virtual ShapeResult get(afw::table::BaseRecord const &record) const
Get a ShapeResult from the given record.
Definition: ShapeUtilities.cc:127
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::meas::base::ShapeResult::xx_yy_Cov
ErrElement xx_yy_Cov
xx,yy term in the uncertainty convariance matrix
Definition: ShapeUtilities.h:50
lsst::afw::geom::ellipses::Quadrupole
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
ShapeUtilities.h
lsst::meas::base::ShapeResultKey::ShapeResultKey
ShapeResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
Definition: ShapeUtilities.h:131
lsst::meas::base::makeShapeTransformMatrix
ShapeTrMatrix makeShapeTransformMatrix(geom::LinearTransform const &xform)
Construct a matrix suitable for transforming second moments.
Definition: ShapeUtilities.cc:143
lsst::meas::base::ErrElement
float ErrElement
Definition: constants.h:55
lsst::afw::table::SubSchema
A proxy type for name lookups in a Schema.
Definition: Schema.h:357
std
STL namespace.
lsst::meas::base::ShapeResult::getShape
Shape const getShape() const
Return an afw::geom::ellipses object corresponding to xx, yy, xy.
Definition: ShapeUtilities.cc:41
lsst::meas::base::ShapeResult::getShapeErr
ShapeCov const getShapeErr() const
Return the 3x3 symmetric covariance matrix, with rows and columns ordered (xx, yy,...
Definition: ShapeUtilities.cc:49
lsst::meas::base::ShapeResult::setShape
void setShape(Shape const &shape)
Set struct elements from the given Quadrupole object.
Definition: ShapeUtilities.cc:43
lsst::meas::base::ShapeResult
A reusable struct for moments-based shape measurements.
Definition: ShapeUtilities.h:43
lsst::afw::table::BaseRecord::set
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:164
lsst::meas::base::ShapeResultKey::set
virtual void set(afw::table::BaseRecord &record, ShapeResult const &value) const
Set a ShapeResult in the given record.
Definition: ShapeUtilities.cc:136
lsst::meas::base::ShapeResult::xx
ShapeElement xx
image or model second moment for x^2
Definition: ShapeUtilities.h:44
lsst::meas::base::ShapeElement
double ShapeElement
Definition: constants.h:57
lsst::meas::base::Shape
afw::geom::ellipses::Quadrupole Shape
Definition: constants.h:60
m
int m
Definition: SpanSet.cc:49