Skip to content

Commit

Permalink
Extend QuadrupoleKey to celestial coords.
Browse files Browse the repository at this point in the history
We can thereby use the same underlying mechanism to describe quadrupoles in
pixel and celestial coordinates. Internally, we continue to refer to "x" and
"y", but use appropriate names and units when writing to a table.
  • Loading branch information
jdswinbank committed Apr 11, 2015
1 parent fbfdce8 commit dce194d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
29 changes: 16 additions & 13 deletions include/lsst/afw/table/aggregates.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,27 @@ bool operator!=(CoordKey const & lhs, CoordKey const & rhs);
//@}

/**
* @brief A FunctorKey used to get or set a geom::ellipses::Quadrupole from an (xx,yy,xy) tuple of Keys.
* @brief A FunctorKey used to get or set a geom::ellipses::Quadrupole from a tuple of constituent Keys.
*/
class QuadrupoleKey : public FunctorKey< lsst::afw::geom::ellipses::Quadrupole > {
public:

/**
* Add a set of _xx, _yy, _xy fields to a Schema, and return a QuadrupoleKey that points to them.
*
* @param[in,out] schema Schema to add fields to.
* @param[in] name Name prefix for all fields; "_xx", "_yy", "_xy", will be appended to this
* to form the full field names.
* @param[in] doc String used as the documentation for the fields.
* @param[in] unit String used as the unit for all fields.
* Add a set of quadrupole subfields to a schema and return a QuadrupoleKey that points to them.
*
* @param[in,out] schema Schema to add fields to.
* @param[in] name Name prefix for all fields; ("_xx", "_yy", "_xy") will be appended to
* this to form the full field names. In celestial coordinates, we use "x"
* as a synonym for "RA" and "y" for "dec".
* @param[in] doc String used as the documentation for the fields.
* @param[in] coordType Type of coordinates in use (PIXEL or CELESTIAL).
*/
static QuadrupoleKey addFields(
Schema & schema,
std::string const & name,
std::string const & doc,
std::string const & unit
CoordinateType coordType=CoordinateType::PIXEL
);

/// Default constructor; instance will not be usable unless subsequently assigned to.
Expand All @@ -231,15 +233,16 @@ class QuadrupoleKey : public FunctorKey< lsst::afw::geom::ellipses::Quadrupole >
{}

/**
* @brief Construct from a subschema, assuming xx, yy, and xy subfields
* @brief Construct from a subschema with appropriate subfields
*
* If the schema has "a_xx", "a_yy" and "a_xy" fields this constructor enables you to
* construct a QuadrupoleKey via:
*
* If a schema has "a_xx", "a_yy", and "a_xy" fields, this constructor allows you to construct
* a QuadrupoleKey via:
* @code
* QuadrupoleKey k(schema["a"]);
* QuadrupoleKey k(schema["a"], coordType);
* @endcode
*/
QuadrupoleKey(SubSchema const & s) : _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}
QuadrupoleKey(SubSchema const & s): _ixx(s["xx"]), _iyy(s["yy"]), _ixy(s["xy"]) {}

/// Get a Quadrupole from the given record
virtual geom::ellipses::Quadrupole get(BaseRecord const & record) const;
Expand Down
5 changes: 5 additions & 0 deletions include/lsst/afw/table/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace lsst { namespace afw { namespace table {
*/
typedef boost::int64_t RecordId;

enum class CoordinateType {
PIXEL,
CELESTIAL
};

//@{
/**
* @brief Tag types used to declare specialized field types.
Expand Down
6 changes: 4 additions & 2 deletions src/table/aggregates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ QuadrupoleKey QuadrupoleKey::addFields(
Schema & schema,
std::string const & name,
std::string const & doc,
std::string const & unit
CoordinateType coordType
) {
std::string unit = coordType == CoordinateType::PIXEL ? "pixels^2" : "radians^2";

Key<double> xxKey = schema.addField<double>(schema.join(name, "xx"), doc, unit);
Key<double> yyKey = schema.addField<double>(schema.join(name, "yy"), doc, unit);
Key<double> xyKey = schema.addField<double>(schema.join(name, "xy"), doc, unit);
Expand All @@ -120,7 +122,7 @@ EllipseKey EllipseKey::addFields(
std::string const & doc,
std::string const & unit
) {
QuadrupoleKey qKey = QuadrupoleKey::addFields(schema, name, doc, unit + "^2");
QuadrupoleKey qKey = QuadrupoleKey::addFields(schema, name, doc, CoordinateType::PIXEL);
PointKey<double> pKey = PointKey<double>::addFields(schema, name, doc, unit);
return EllipseKey(qKey, pKey);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testFunctorKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def testCoordKey(self):

def testQuadrupoleKey(self):
schema = lsst.afw.table.Schema();
fKey0 = lsst.afw.table.QuadrupoleKey.addFields(schema, "a", "moments", "pixels^2")
fKey0 = lsst.afw.table.QuadrupoleKey.addFields(schema, "a", "moments", lsst.afw.table.PIXEL)
xxKey = schema.find("a_xx").key
yyKey = schema.find("a_yy").key
xyKey = schema.find("a_xy").key
Expand Down
2 changes: 1 addition & 1 deletion tests/testSourceTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setUp(self):
self.centroidFlagKey = self.schema.addField("b_flag", type="Flag")

self.shapeKey = lsst.afw.table.QuadrupoleKey.addFields(self.schema,
"c", "", "pixels^2")
"c", "", lsst.afw.table.PIXEL)
self.xxErrKey = self.schema.addField("c_xxSigma", type = "F")
self.xyErrKey = self.schema.addField("c_xySigma", type = "F")
self.yyErrKey = self.schema.addField("c_yySigma", type = "F")
Expand Down

0 comments on commit dce194d

Please sign in to comment.