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

tickets/DM-4606 #44

Merged
merged 5 commits into from
Dec 17, 2015
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
10 changes: 5 additions & 5 deletions examples/wcsTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int argc, char **argv) {
}
std::cout << "Opening exposure " << inImagePath << std::endl;

PropertySet::Ptr miMetadata(new PropertySet);
auto miMetadata(new PropertySet);
afwImage::Exposure<Pixel> exposure(inImagePath);
if (!exposure.hasWcs()) {
std::cerr << "Exposure does not have a WCS." << std::endl;
Expand All @@ -84,8 +84,8 @@ int main(int argc, char **argv) {
afwGeom::Point2D minCoord = afwGeom::Point2D(1.0, 1.0);
afwGeom::Point2D xy = afwGeom::Point2D(exposure.getWidth(), exposure.getHeight());

afwCoord::Coord::ConstPtr sky1 = wcs->pixelToSky(minCoord);
afwCoord::Coord::ConstPtr sky2 = wcs->pixelToSky(xy);
PTR(afwCoord::Coord const) sky1 = wcs->pixelToSky(minCoord);
PTR(afwCoord::Coord const) sky2 = wcs->pixelToSky(xy);

afwGeom::Angle miRa1 = sky1->getLongitude();
afwGeom::Angle miDecl1 = sky1->getLatitude();
Expand Down Expand Up @@ -114,8 +114,8 @@ int main(int argc, char **argv) {
std::cout << "col, row of " << inImagePath << " at ("<< miRa2.asDegrees() << " " << miDecl2.asDegrees() <<") = "
<< "col: " << pix2[0] << " row: " << pix2[1] << std::endl << std::endl;

afwCoord::Coord::ConstPtr raDecl1 = makeCoord(afwCoord::FK5, miRa1, miDecl1);
afwCoord::Coord::ConstPtr raDecl2 = makeCoord(afwCoord::FK5, miRa2, miDecl2);
PTR(afwCoord::Coord const) raDecl1 = makeCoord(afwCoord::FK5, miRa1, miDecl1);
PTR(afwCoord::Coord const) raDecl2 = makeCoord(afwCoord::FK5, miRa2, miDecl2);

afwGeom::Point2D pix3 = wcs->skyToPixel(*raDecl1);
afwGeom::Point2D pix4 = wcs->skyToPixel(*raDecl2);
Expand Down
59 changes: 30 additions & 29 deletions include/lsst/afw/coord/Coord.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "boost/shared_ptr.hpp"

#include "lsst/base.h"
#include "lsst/afw/geom/Point.h"
#include "lsst/afw/geom/Angle.h"
#include "lsst/afw/coord/Observatory.h"
Expand All @@ -51,7 +52,7 @@ namespace coord {
/*
* Information about the coordinate system we support
*/
enum CoordSystem { FK5, ICRS, GALACTIC, ECLIPTIC, TOPOCENTRIC };
enum CoordSystem { UNKNOWN=-1, FK5, ICRS, GALACTIC, ECLIPTIC, TOPOCENTRIC };
CoordSystem makeCoordEnum(std::string const system);

class IcrsCoord;
Expand All @@ -69,9 +70,6 @@ class TopocentricCoord;
class Coord {
public:

typedef boost::shared_ptr<Coord> Ptr;
typedef boost::shared_ptr<Coord const> ConstPtr;

Coord(lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit = lsst::afw::geom::degrees, double const epoch = 2000.0);
Coord(lsst::afw::geom::Point3D const &p3d, double const epoch = 2000.0,
bool normalize=true,
Expand All @@ -81,7 +79,7 @@ class Coord {
Coord();
virtual ~Coord() {}

virtual Coord::Ptr clone() const { return Coord::Ptr(new Coord(*this)); }
virtual PTR(Coord) clone() const { return PTR(Coord)(new Coord(*this)); }

virtual void reset(lsst::afw::geom::Angle const longitude, lsst::afw::geom::Angle const latitude) {
double const epoch = 2000.0;
Expand All @@ -100,6 +98,8 @@ class Coord {

virtual std::string getClassName() const { return "Coord"; }

virtual CoordSystem getCoordSystem() const { return UNKNOWN; }

// These are inline functions and are defined at the end of this header file
lsst::afw::geom::Angle operator[](int const index) const;
bool operator==(Coord const &rhs) const;
Expand Down Expand Up @@ -131,7 +131,7 @@ class Coord {
void rotate(Coord const &axis, lsst::afw::geom::Angle const theta);
lsst::afw::geom::Angle offset(lsst::afw::geom::Angle const phi, lsst::afw::geom::Angle const arcLen);

Coord::Ptr convert(CoordSystem system, double epoch=2000) const;
PTR(Coord) convert(CoordSystem system, double epoch=2000) const;

virtual Fk5Coord toFk5(double const epoch) const;
virtual Fk5Coord toFk5() const;
Expand All @@ -156,7 +156,6 @@ class Coord {
*/
class IcrsCoord : public Coord {
public:
typedef boost::shared_ptr<IcrsCoord> Ptr;

IcrsCoord(lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit = lsst::afw::geom::degrees) : Coord(p2d, unit, 2000.0) {}
IcrsCoord(lsst::afw::geom::Point3D const &p3d, bool normalize=true, lsst::afw::geom::Angle const defaultLongitude = lsst::afw::geom::Angle(0.)) :
Expand All @@ -165,9 +164,11 @@ class IcrsCoord : public Coord {
IcrsCoord(std::string const ra, std::string const dec) : Coord(ra, dec, 2000.0) {}
IcrsCoord() : Coord() {}

virtual Coord::Ptr clone() const { return IcrsCoord::Ptr(new IcrsCoord(*this)); }
virtual PTR(Coord) clone() const { return PTR(IcrsCoord)(new IcrsCoord(*this)); }

virtual std::string getClassName() const { return "IcrsCoord"; }

virtual CoordSystem getCoordSystem() const { return ICRS; }

virtual void reset(lsst::afw::geom::Angle const longitude, lsst::afw::geom::Angle const latitude);

Expand All @@ -191,8 +192,6 @@ class IcrsCoord : public Coord {
class Fk5Coord : public Coord {
public:

typedef boost::shared_ptr<Fk5Coord> Ptr;

Fk5Coord(lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit = lsst::afw::geom::degrees, double const epoch = 2000.0) :
Coord(p2d, unit, epoch) {}
Fk5Coord(lsst::afw::geom::Point3D const &p3d, double const epoch = 2000.0,
Expand All @@ -205,10 +204,12 @@ class Fk5Coord : public Coord {
Coord(ra, dec, epoch) {}
Fk5Coord() : Coord() {}

virtual Coord::Ptr clone() const { return Fk5Coord::Ptr(new Fk5Coord(*this)); }
virtual PTR(Coord) clone() const { return PTR(Fk5Coord)(new Fk5Coord(*this)); }

virtual std::string getClassName() const { return "Fk5Coord"; }

virtual CoordSystem getCoordSystem() const { return FK5; }

Fk5Coord precess(double const epochTo) const;

lsst::afw::geom::Angle getRa() const { return getLongitude(); }
Expand Down Expand Up @@ -237,8 +238,6 @@ class Fk5Coord : public Coord {
class GalacticCoord : public Coord {
public:

typedef boost::shared_ptr<GalacticCoord> Ptr;

GalacticCoord(lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit = lsst::afw::geom::degrees) : Coord(p2d, unit) {}
GalacticCoord(lsst::afw::geom::Point3D const &p3d,
bool normalize=true, lsst::afw::geom::Angle const defaultLongitude= lsst::afw::geom::Angle(0.)) :
Expand All @@ -247,10 +246,12 @@ class GalacticCoord : public Coord {
GalacticCoord(std::string const l, std::string const b) : Coord(l, b) {}
GalacticCoord() : Coord() {}

virtual Coord::Ptr clone() const { return GalacticCoord::Ptr(new GalacticCoord(*this)); }
virtual PTR(Coord) clone() const { return PTR(GalacticCoord)(new GalacticCoord(*this)); }

virtual std::string getClassName() const { return "GalacticCoord"; }

virtual CoordSystem getCoordSystem() const { return GALACTIC; }

virtual void reset(lsst::afw::geom::Angle const longitude, lsst::afw::geom::Angle const latitude);

virtual std::pair<std::string, std::string> getCoordNames() const {
Expand Down Expand Up @@ -278,8 +279,6 @@ class GalacticCoord : public Coord {
class EclipticCoord : public Coord {
public:

typedef boost::shared_ptr<EclipticCoord> Ptr;

EclipticCoord(lsst::afw::geom::Point2D const &p2d,
lsst::afw::geom::AngleUnit unit = lsst::afw::geom::degrees,
double const epoch = 2000.0) :
Expand All @@ -298,10 +297,12 @@ class EclipticCoord : public Coord {

EclipticCoord() : Coord() {}

virtual Coord::Ptr clone() const { return EclipticCoord::Ptr(new EclipticCoord(*this)); }
virtual PTR(Coord) clone() const { return PTR(EclipticCoord)(new EclipticCoord(*this)); }

virtual std::string getClassName() const { return "EclipticCoord"; }

virtual CoordSystem getCoordSystem() const { return ECLIPTIC; }

virtual std::pair<std::string, std::string> getCoordNames() const {
return std::pair<std::string, std::string>("Lambda", "Beta");
}
Expand Down Expand Up @@ -329,8 +330,6 @@ class EclipticCoord : public Coord {
class TopocentricCoord : public Coord {
public:

typedef boost::shared_ptr<TopocentricCoord> Ptr;

TopocentricCoord(lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit, double const epoch,
Observatory const &obs) : Coord(p2d, unit, epoch), _obs(obs) {}
TopocentricCoord(lsst::afw::geom::Point3D const &p3d, double const epoch,
Expand All @@ -342,10 +341,12 @@ class TopocentricCoord : public Coord {
TopocentricCoord(std::string const az, std::string const alt, double const epoch,
Observatory const &obs) : Coord(az, alt, epoch), _obs(obs) {}

virtual Coord::Ptr clone() const { return TopocentricCoord::Ptr(new TopocentricCoord(*this)); }
virtual PTR(Coord) clone() const { return PTR(TopocentricCoord)(new TopocentricCoord(*this)); }

virtual std::string getClassName() const { return "TopocentricCoord"; }

virtual CoordSystem getCoordSystem() const { return TOPOCENTRIC; }

Observatory getObservatory() const { return _obs; }

virtual std::pair<std::string, std::string> getCoordNames() const {
Expand All @@ -371,20 +372,20 @@ class TopocentricCoord : public Coord {
* Factory Functions
*
*/
Coord::Ptr makeCoord(CoordSystem const system, lsst::afw::geom::Angle const ra, lsst::afw::geom::Angle const dec, double const epoch);
Coord::Ptr makeCoord(CoordSystem const system, std::string const ra, std::string const dec,
PTR(Coord) makeCoord(CoordSystem const system, lsst::afw::geom::Angle const ra, lsst::afw::geom::Angle const dec, double const epoch);
PTR(Coord) makeCoord(CoordSystem const system, std::string const ra, std::string const dec,
double const epoch);
Coord::Ptr makeCoord(CoordSystem const system, lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit,
PTR(Coord) makeCoord(CoordSystem const system, lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit,
double const epoch);
Coord::Ptr makeCoord(CoordSystem const system, lsst::afw::geom::Point3D const &p3d, double const epoch,
PTR(Coord) makeCoord(CoordSystem const system, lsst::afw::geom::Point3D const &p3d, double const epoch,
bool normalize=true,
lsst::afw::geom::Angle const defaultLongitude=lsst::afw::geom::Angle(0.));
Coord::Ptr makeCoord(CoordSystem const system);
PTR(Coord) makeCoord(CoordSystem const system);

Coord::Ptr makeCoord(CoordSystem const system, lsst::afw::geom::Angle const ra, lsst::afw::geom::Angle const dec);
Coord::Ptr makeCoord(CoordSystem const system, std::string const ra, std::string const dec);
Coord::Ptr makeCoord(CoordSystem const system, lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit);
Coord::Ptr makeCoord(CoordSystem const system, lsst::afw::geom::Point3D const &p3d,
PTR(Coord) makeCoord(CoordSystem const system, lsst::afw::geom::Angle const ra, lsst::afw::geom::Angle const dec);
PTR(Coord) makeCoord(CoordSystem const system, std::string const ra, std::string const dec);
PTR(Coord) makeCoord(CoordSystem const system, lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit);
PTR(Coord) makeCoord(CoordSystem const system, lsst::afw::geom::Point3D const &p3d,
bool normalize=true,
lsst::afw::geom::Angle const defaultLongitude=lsst::afw::geom::Angle(0.));

Expand Down
12 changes: 6 additions & 6 deletions include/lsst/afw/image/Wcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Wcs : public lsst::daf::base::Persistable,
*
* Set stripMetadata=true to remove processed keywords from the PropertySet.
*/
friend Wcs::Ptr makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata,
friend PTR(Wcs) makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata,
bool stripMetadata);

Wcs(lsst::afw::geom::Point2D const & crval, lsst::afw::geom::Point2D const & crpix,
Expand All @@ -135,7 +135,7 @@ class Wcs : public lsst::daf::base::Persistable,
bool operator!=(Wcs const & other) const { return !(*this == other); }

/// Returns CRVAL. This need not be the centre of the image.
lsst::afw::coord::Coord::Ptr getSkyOrigin() const;
PTR(lsst::afw::coord::Coord) getSkyOrigin() const;

/// Returns CRPIX (corrected to LSST convention).
lsst::afw::geom::Point2D getPixelOrigin() const;
Expand Down Expand Up @@ -382,13 +382,13 @@ class Wcs : public lsst::daf::base::Persistable,
virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const;
virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const;

afw::coord::Coord::Ptr makeCorrectCoord(geom::Angle sky0, geom::Angle sky1) const;
PTR(afw::coord::Coord) makeCorrectCoord(geom::Angle sky0, geom::Angle sky1) const;

/**
* Given a Coord (as a shared pointer), return the sky position in the correct
* coordinate system for this Wcs.
*/
afw::coord::Coord::Ptr convertCoordToSky(coord::Coord const & coord) const;
PTR(afw::coord::Coord) convertCoordToSky(coord::Coord const & coord) const;

virtual geom::AffineTransform linearizePixelToSkyInternal(
geom::Point2D const & pix,
Expand Down Expand Up @@ -424,12 +424,12 @@ namespace detail {
geom::Point2I getImageXY0FromMetadata(std::string const& wcsName, lsst::daf::base::PropertySet *metadata);
}

Wcs::Ptr makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata, bool stripMetadata=false);
PTR(Wcs) makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata, bool stripMetadata=false);

/*
Note, CD matrix elements must be in degrees/pixel.
*/
Wcs::Ptr makeWcs(coord::Coord const & crval, geom::Point2D const & crpix,
PTR(Wcs) makeWcs(coord::Coord const & crval, geom::Point2D const & crpix,
double CD11, double CD12, double CD21, double CD22);

namespace detail {
Expand Down
15 changes: 9 additions & 6 deletions python/lsst/afw/coord/coord.i
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


%{
#include "lsst/base.h" // for PTR
#include "lsst/afw/image.h"
#include "lsst/afw/geom.h"
#include "lsst/daf/base.h"
Expand All @@ -46,16 +47,16 @@
// -----------------------------------------------------------------------
// THESE CASTS ARE NOW DEPRECATED; USE E.G. `Fk5Coord.cast()` INSTEAD
%inline %{
lsst::afw::coord::Fk5Coord::Ptr cast_Fk5(lsst::afw::coord::Coord::Ptr c) {
PTR(lsst::afw::coord::Fk5Coord) cast_Fk5(PTR(lsst::afw::coord::Coord) c) {
return boost::dynamic_pointer_cast<lsst::afw::coord::Fk5Coord>(c);
}
lsst::afw::coord::IcrsCoord::Ptr cast_Icrs(lsst::afw::coord::Coord::Ptr c) {
PTR(lsst::afw::coord::IcrsCoord) cast_Icrs(PTR(lsst::afw::coord::Coord) c) {
return boost::dynamic_pointer_cast<lsst::afw::coord::IcrsCoord>(c);
}
lsst::afw::coord::GalacticCoord::Ptr cast_Galactic(lsst::afw::coord::Coord::Ptr c) {
PTR(lsst::afw::coord::GalacticCoord) cast_Galactic(PTR(lsst::afw::coord::Coord) c) {
return boost::dynamic_pointer_cast<lsst::afw::coord::GalacticCoord>(c);
}
lsst::afw::coord::EclipticCoord::Ptr cast_Ecliptic(lsst::afw::coord::Coord::Ptr c) {
PTR(lsst::afw::coord::EclipticCoord) cast_Ecliptic(PTR(lsst::afw::coord::Coord) c) {
return boost::dynamic_pointer_cast<lsst::afw::coord::EclipticCoord>(c);
}
%}
Expand All @@ -69,6 +70,7 @@

%include "lsst/afw/coord/Coord.h"

// add __str__ and __repr__ methods to a specified Coord class (e.g. Fk5Coord)
%define strCoord(TYPE)
%extend lsst::afw::coord::TYPE {
std::string __str__() const {
Expand All @@ -79,14 +81,15 @@
%pythoncode %{
def __repr__(self):
className = self.getClassName()
coordSystem = self.getCoordSystem()
argList = ["%r * afwGeom.degrees" % (pos.asDegrees(),) for pos in self]
if className == "TopocentricCoord":
if coordSystem == TOPOCENTRIC:
topoCoord = TopocentricCoord.cast(self)
argList += [
repr(self.getEpoch()),
"(%r)" % (topoCoord.getObservatory(),),
]
elif className not in ("IcrsCoord", "GalacticCoord"):
elif coordSystem not in (ICRS, GALACTIC):
argList.append(repr(self.getEpoch()))
return "%s(%s)" % (self.getClassName(), ", ".join(argList))
%}
Expand Down