Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for new FlagHandler #12

Merged
merged 1 commit into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/lsst/meas/extensions/simpleShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ class SimpleShapeResultKey : public afw::table::FunctorKey<SimpleShapeResult> {


class SimpleShape : public lsst::meas::base::SimpleAlgorithm {
public:
public:

typedef SimpleShapeControl Control;
// Structures and routines to manage flaghandler
static base::FlagDefinitionList const & getFlagDefinitions();
static unsigned int const N_FLAGS = 1;
static base::FlagDefinition const FAILURE;

enum {
FAILURE=lsst::meas::base::FlagHandler::FAILURE,
N_FLAGS
};
typedef SimpleShapeControl Control;

SimpleShape(Control const & ctrl, std::string const & name, afw::table::Schema & schema);

Expand Down
27 changes: 17 additions & 10 deletions src/simpleShape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
#include "lsst/afw/math.h"

namespace lsst { namespace meas { namespace extensions { namespace simpleShape {
namespace {
base::FlagDefinitionList flagDefinitions;
} // end anonymous

base::FlagDefinition const SimpleShape::FAILURE = flagDefinitions.addFailureFlag();

base::FlagDefinitionList const & SimpleShape::getFlagDefinitions() {
return flagDefinitions;
}


/* ---- Machinery for iterating over elliptical regions ----------------------------------------------------
*
Expand Down Expand Up @@ -233,14 +243,14 @@ MatrixM SimpleShape::correctWeightedMoments(
throw LSST_EXCEPT(
base::MeasurementError,
"Weight moments matrix is singular",
FAILURE
FAILURE.number
);
}
if (mMat.determinant() <= 0.0) {
throw LSST_EXCEPT(
base::MeasurementError,
"Measured moments matrix is singular",
FAILURE
FAILURE.number
);
}
Eigen::Matrix2d mInv = mMat.inverse();
Expand All @@ -249,7 +259,7 @@ MatrixM SimpleShape::correctWeightedMoments(
throw LSST_EXCEPT(
base::MeasurementError,
"Corrected moments matrix is singular",
FAILURE
FAILURE.number
);
}
Eigen::Matrix2d cMat = cInv.inverse();
Expand Down Expand Up @@ -305,9 +315,6 @@ SimpleShapeResult::SimpleShapeResult() : ellipse(std::numeric_limits<lsst::meas:
covariance(Eigen::Matrix<double,5,5>::Constant(std::numeric_limits<lsst::meas::base::ErrElement>::quiet_NaN()))
{}

static std::array<lsst::meas::base::FlagDefinition, SimpleShape::N_FLAGS> const flagDefs = {{
{"flag", "general failure flag, set if anything went wrong"}
}};

SimpleShapeResultKey SimpleShapeResultKey::addFields(
afw::table::Schema & schema,
Expand All @@ -322,23 +329,23 @@ SimpleShapeResultKey SimpleShapeResultKey::addFields(
std::vector<std::string> ({"Ixx", "Iyy", "Ixy",
"Ix", "Iy"}), "pixel");
r._flagHandler = lsst::meas::base::FlagHandler::addFields(schema,
name, flagDefs.begin(), flagDefs.end());
name, SimpleShape::getFlagDefinitions());
return r;
}

SimpleShapeResultKey::SimpleShapeResultKey(lsst::afw::table::SubSchema const & s) :
_shapeResult(s),
_centroidResult(s),
_uncertantyResult(s, std::vector<std::string> ({"Ixx", "Iyy", "Ixy", "Ix", "Iy"})),
_flagHandler(s, flagDefs.begin(), flagDefs.end())
_flagHandler(s, SimpleShape::getFlagDefinitions())
{}

SimpleShapeResult SimpleShapeResultKey::get(lsst::afw::table::BaseRecord const & record) const {
SimpleShapeResult result;
result.ellipse = record.get(_shapeResult);
result.center = record.get(_centroidResult);
result.covariance = record.get(_uncertantyResult);
for (int n = 0; n < SimpleShape::N_FLAGS; ++n) {
for (std::size_t n = 0; n < SimpleShape::N_FLAGS; ++n) {
result.flags[n] = _flagHandler.getValue(record, n);
}
return result;
Expand All @@ -348,7 +355,7 @@ void SimpleShapeResultKey::set(afw::table::BaseRecord & record, SimpleShapeResul
record.set(_shapeResult, value.ellipse);
record.set(_centroidResult, value.center);
record.set(_uncertantyResult, value.covariance);
for (int n = 0; n < SimpleShape::N_FLAGS; ++n) {
for (std::size_t n = 0; n < SimpleShape::N_FLAGS; ++n) {
_flagHandler.setValue(record, n, value.flags[n]);
}
}
Expand Down