37 #include "Eigen/Geometry" 40 #include "boost/algorithm/string.hpp" 41 #include "boost/tuple/tuple.hpp" 42 #include "boost/format.hpp" 58 CoordSystemMap
const getCoordSystemMap() {
81 double const cosDelta2) {
84 double const havD = havDDelta + cosDelta1 * cosDelta2 * havDAlpha;
91 double const epochTolerance = 1.0e-12;
96 Fk5Coord fk51 = c1.toFk5();
97 Fk5Coord fk5tmp = c2.toFk5();
101 if (
fabs(fk51.getEpoch() - fk5tmp.getEpoch()) > epochTolerance) {
102 fk52 = fk5tmp.precess(fk51.getEpoch());
113 static CoordSystemMap idmap = getCoordSystemMap();
114 if (idmap.find(system) != idmap.end()) {
115 return idmap[system];
124 double const JD2000 = 2451544.50;
143 Dms(
int const d,
int const m,
double const s,
bool const isSouth =
false) {
144 sign = (d < 0 || isSouth) ? -1 : 1;
153 sign = (deg0 >= 0) ? 1 : -1;
156 sec = ((absVal -
deg) * 60.0 -
min) * 60.0;
169 Coord const &GalacticPoleInFk5() {
174 Coord const &Fk5PoleInGalactic() {
183 geom::Angle meanSiderealTimeGreenwich(
double const jd
185 double const T = (jd - 2451545.0) / 36525.0;
186 return (280.46061837 + 360.98564736629 * (jd - 2451545.0) + 0.000387933 * T * T -
187 (T * T * T / 38710000.0)) *
191 double const atPoleEpsilon = 0.0;
193 double const defaultLongitude = 0.0,
194 bool normalize =
true) {
198 double const inorm = 1.0 / p3d.asEigen().norm();
199 double const x = inorm * p3d.getX();
200 double const y = inorm * p3d.getY();
201 double const z = inorm * p3d.getZ();
202 if (fabs(x) <= atPoleEpsilon && fabs(y) <= atPoleEpsilon) {
210 if (fabs(p3d.getX()) <= atPoleEpsilon && fabs(p3d.getY()) <= atPoleEpsilon) {
214 lonLat.first = (atan2(p3d.getY(), p3d.getX()) *
geom::radians).wrap();
229 if ((60.00 - dms.sec) < 0.005) {
235 if (dms.deg == 360) {
242 std::string s = (boost::format(fmt) % dms.deg % dms.min % dms.sec).str();
261 if (dms.
find(
":") == std::string::npos) {
263 (boost::format(
"String is not in xx:mm:ss format: %s") % dms).str());
266 boost::split(elements, dms, boost::is_any_of(
":"));
267 if (elements.
size() != 3) {
269 (boost::format(
"Could not parse string as xx:mm:ss format: %s") % dms).str());
271 int const deg = abs(atoi(elements[0].c_str()));
272 int const min = atoi(elements[1].c_str());
273 double const sec = atof(elements[2].c_str());
275 geom::Angle ang = (deg + min / 60.0 + sec / 3600.0) * unit;
276 if ((elements[0].c_str())[0] ==
'-') {
287 double const T = (epoch - 2000.0) / 100.0;
288 return (23.0 + 26.0 / 60.0 + (21.448 - 46.82 * T - 0.0006 * T * T - 0.0018 * T * T * T) / 3600.0) *
299 : _longitude(NaN), _latitude(NaN), _epoch(epoch) {
306 : _longitude(0. * geom::
radians), _latitude(0. * geom::
radians), _epoch(epoch) {
308 _longitude = lonLat.first;
309 _latitude = lonLat.second;
314 : _longitude(ra.
wrap()), _latitude(dec), _epoch(epoch) {
331 void Coord::_verifyValues()
const {
335 (boost::format(
"Latitude coord must be: -PI/2 <= lat <= PI/2 (%f).") % _latitude).str());
340 _longitude = longitude.
wrap();
365 double const alphaGP = poleFrom[0];
366 double const deltaGP = poleFrom[1];
367 double const lCP = poleTo[0];
384 double const mc = 1.0 - c;
390 double const ux = u[0];
391 double const uy = u[1];
392 double const uz = u[2];
396 xprime[0] = (ux * ux + (1.0 - ux * ux) * c) * x[0] + (ux * uy * mc - uz * s) * x[1] +
397 (ux * uz * mc + uy * s) * x[2];
398 xprime[1] = (uy * uy + (1.0 - uy * uy) * c) * x[1] + (uy * uz * mc - ux * s) * x[2] +
399 (ux * uy * mc + uz * s) * x[0];
400 xprime[2] = (uz * uz + (1.0 - uz * uz) * c) * x[2] + (uz * ux * mc - uy * s) * x[0] +
401 (uy * uz * mc + ux * s) * x[1];
405 _longitude = lonLat.first;
406 _latitude = lonLat.second;
438 Eigen::Vector3d w = r.cross(u);
439 Eigen::Vector3d v = arcLen *
std::cos(phi) * u + arcLen *
std::sin(phi) * w;
442 Eigen::Vector3d axisVector = r.cross(v);
443 axisVector.normalize();
446 rotate(axisCoord, arcLen);
458 Eigen::Vector3d w2 = r2.cross(u2);
463 v2Coord.
rotate(axisCoord, arcLen);
493 "Cannot make Topocentric with convert() (must also specify Observatory).\n" 494 "Instantiate TopocentricCoord() directly.");
501 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC allowed.");
515 return haversine(alpha1 - alpha2, delta1 - delta2,
std::cos(delta1),
std::cos(delta2));
530 double const cosDelta1 =
std::cos(delta1);
531 double const cosDelta2 =
std::cos(delta2);
533 geom::Angle separation = haversine(dAlpha, dDelta, cosDelta1, cosDelta2);
536 double const y =
std::sin(dAlpha) * cosDelta2;
553 double const sinDelta1 =
std::sin(delta1);
554 double const cosDelta1 =
std::cos(delta1);
555 double const sinDelta2 =
std::sin(delta2);
556 double const cosDelta2 =
std::cos(delta2);
557 double const cosAlphaDiff =
std::cos(alpha2 - alpha1);
558 double const sinAlphaDiff =
std::sin(alpha2 - alpha1);
560 double const div = cosDelta1 * cosAlphaDiff * cosDelta2 + sinDelta1 * sinDelta2;
561 double const xi = cosDelta1 * sinAlphaDiff / div;
562 double const eta = (cosDelta1 * cosAlphaDiff * sinDelta2 - sinDelta1 * cosDelta2) / div;
597 if (fabs(
getEpoch() - 2000.0) > epochTolerance) {
608 if (fabs(
getEpoch() - 2000.0) > epochTolerance) {
650 double const tanAnumerator =
std::sin(H);
662 if (fabs(
getEpoch() - epochTo) < epochTolerance) {
671 double const T = (jd0 - JD2000) / 36525.0;
672 double const t = (jd - jd0) / 36525.0;
673 double const tt = t * t;
674 double const ttt = tt * t;
676 geom::Angle const xi = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (0.30188 - 0.000344 * T) * tt +
679 geom::Angle const z = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (1.09468 + 0.000066 * T) * tt +
682 geom::Angle const theta = ((2004.3109 - 0.85330 * T - 0.000217 * T * T) * t -
683 (0.42665 + 0.000217 * T) * tt - 0.041833 * ttt) *
699 return Fk5Coord(alpha, delta, epochTo);
720 return (boost::format(
"%s(%.7f, %.7f)") %
getClassName() % (*
this)[0].asDegrees() %
721 (*
this)[1].asDegrees())
746 return (boost::format(
"%s(%.7f, %.7f)") %
getClassName() % (*
this)[0].asDegrees() %
747 (*
this)[1].asDegrees())
768 Coord const fk5PoleInEcliptic(ninety, ninety - eclPoleIncl, epoch);
805 return Fk5Coord(alpha, delta, epoch);
813 (boost::format(
"Expected observatory %s, saw %s") % _obs % obs).str());
817 (boost::format(
"Expected date %g, saw %g") %
getEpoch() % date.
get()).str());
828 return (boost::format(
"%s(%.7f, %.7f, %.12f, (%s))") %
getClassName() % (*
this)[0].asDegrees() %
829 (*
this)[1].asDegrees() %
getEpoch() % getObservatory())
847 double const epoch) {
854 "ICRS has no epoch, use overloaded makeCoord with args (system, ra, dec).");
858 "Galactic has no epoch, use overloaded makeCoord with (system, ra, dec).");
865 "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n" 866 "Instantiate TopocentricCoord() directly.");
871 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
892 "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n" 893 "Instantiate TopocentricCoord() directly.");
898 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
904 bool normalize,
geom::Angle const defaultLongitude) {
905 Coord c(p3d, 2000.0, normalize, defaultLongitude);
910 Coord c(p3d, 2000.0, normalize, defaultLongitude);
915 double const epoch) {
934 double const epoch) {
957 "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n" 958 "Instantiate TopocentricCoord() directly.");
962 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, allowed.");
968 return (boost::format(
"%s(%.7f, %.7f, %.2f)") %
getClassName() % (*
this)[0].asDegrees() %
969 (*
this)[1].asDegrees() %
getEpoch())
984 assert(coords.size() > 0);
987 for (
auto &&cc : coords) {
995 sum.
scale(1.0 / coords.size());
1003 if (coords.size() == 0) {
1009 system = coords[0]->getCoordSystem();
1010 for (
auto &&cc : coords) {
1011 if (cc->getCoordSystem() != system) {
1013 (boost::format(
"Coordinates are not all in the same system: %d vs %d") %
1014 cc->getCoordSystem() %
1018 return doAverageCoord(coords, system);
1023 converted.
reserve(coords.size());
1024 for (
auto &&cc : coords) {
1025 converted.
push_back(cc->getCoordSystem() == system ? cc : cc->convert(system));
1027 return doAverageCoord(converted, system);
std::shared_ptr< Coord > makeCoord(CoordSystem const system, lsst::afw::geom::Angle const ra, lsst::afw::geom::Angle const dec, double const epoch)
Factory function to create a Coord of arbitrary type with decimal RA,Dec.
lsst::afw::geom::Angle getLatitude() const
get telescope latitude
virtual TopocentricCoord toTopocentric(Observatory const &obs, lsst::daf::base::DateTime const &obsDate) const
Convert ourself to Altitude/Azimuth: alt, az.
lsst::afw::geom::Angle getLongitude() const
The main access method for the longitudinal coordinate.
virtual void reset(lsst::afw::geom::Angle const longitude, lsst::afw::geom::Angle const latitude)
special reset() overload to make sure no epoch can be set
double get(DateSystem system=MJD, Timescale scale=TAI) const
lsst::afw::geom::Angle Angle
virtual EclipticCoord toEcliptic() const
Convert ourself to Ecliptic: lambda, beta (use current epoch)
lsst::afw::coord::Coord Coord
void scale(double factor)
A class to handle Galactic coordinates (inherits from Coord)
lsst::afw::geom::Angle dmsStringToAngle(std::string const dms)
Convert a dd:mm:ss string to Angle.
virtual IcrsCoord toIcrs() const
Icrs converter for IcrsCoord.
Hold the location of an observatory.
AngleUnit constexpr radians
constant with units of radians
A coordinate class intended to represent offsets and dimensions.
lsst::afw::geom::Angle offset(lsst::afw::geom::Angle const phi, lsst::afw::geom::Angle const arcLen)
offset our current coords along a great circle defined by an angle wrt a declination parallel ...
EclipticCoord precess(double const epochTo) const
precess to new epoch
AngleUnit constexpr degrees
constant with units of degrees
lsst::afw::geom::Angle eclipticPoleInclination(double const epoch)
get the inclination of the ecliptic pole (obliquity) at epoch
virtual void reset(lsst::afw::geom::Angle const longitude, lsst::afw::geom::Angle const latitude)
special reset() overload to make sure no epoch can be set
virtual IcrsCoord toIcrs() const
Convert ourself to ICRS: RA, Dec (basically J2000)
std::pair< lsst::afw::geom::Angle, lsst::afw::geom::Angle > getTangentPlaneOffset(Coord const &c) const
Get the offset on the tangent plane.
virtual TopocentricCoord toTopocentric() const
Convert ourself from Topocentric to Topocentric with no observatory or date arguments.
virtual Fk5Coord toFk5() const
Convert ourself from galactic to Fk5 (no epoch specified)
Coord & operator=(Coord const &)
virtual Fk5Coord toFk5() const
Convert ourself to Fk5 (ie.
virtual GalacticCoord toGalactic() const
Convert ourself to Galactic: l, b.
table::Key< geom::Angle > latitude
A class used to convert scalar POD types such as double to Angle.
lsst::afw::geom::Angle getLatitude() const
The main access method for the latitudinal coordinate.
lsst::afw::geom::Point2D getPosition(lsst::afw::geom::AngleUnit unit=lsst::afw::geom::degrees) const
Return our contents in a Point2D object.
std::ostream & operator<<(std::ostream &os, Coord const &coord)
lsst::afw::geom::Angle getDec() const
virtual GalacticCoord toGalactic() const
Convert ourself to Galactic: l, b.
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
A class representing an angle.
A class to handle topocentric (AltAz) coordinates (inherits from Coord)
void rotate(Coord const &axis, lsst::afw::geom::Angle const theta)
Rotate our current coords about a pole.
Coord transform(Coord const &poleTo, Coord const &poleFrom) const
Transform our current coords to another spherical polar system.
A base class for image defects.
virtual std::string toString() const
Get string representation.
lsst::afw::geom::Angle getRa() const
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
table::Key< geom::Angle > longitude
lsst::afw::coord::IcrsCoord IcrsCoord
Point< double, 2 > Point2D
virtual std::string toString() const
Get string representation.
lsst::afw::geom::Point3D getVector() const
Return our contents in a position vector.
lsst::afw::geom::Angle angularSeparation(Coord const &c) const
compute the angular separation between two Coords
virtual Fk5Coord toFk5() const
Convert outself from Topocentric to Fk5 (use current epoch)
virtual Fk5Coord toFk5() const
Fk5 converter for IcrsCoord.
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
std::string angleToDmsString(lsst::afw::geom::Angle const deg)
a Function to convert a coordinate in decimal degrees to a string with form dd:mm:ss ...
AngleUnit constexpr hours
constant with units of hours
std::string angleToHmsString(lsst::afw::geom::Angle const deg)
a function to convert decimal degrees to a string with form hh:mm:ss.s
virtual Fk5Coord toFk5() const
Convert ourself from Ecliptic to Fk5 (use current epoch)
A class to handle Fk5 coordinates (inherits from Coord)
std::shared_ptr< Coord > convert(CoordSystem system, double epoch=2000) const
Convert to a specified Coord type at a specified epoch.
Extent< double, 3 > Extent3D
#define LSST_EXCEPT(type,...)
A class to handle Ecliptic coordinates (inherits from Coord)
virtual std::string toString() const
Get string representation.
virtual void reset(lsst::afw::geom::Angle const longitude, lsst::afw::geom::Angle const latitude)
virtual std::string toString() const
Get string representation.
AngleUnit constexpr arcseconds
constant with units of arcseconds
virtual Fk5Coord toFk5() const
Convert ourself to Fk5: RA, Dec (use current epoch)
Coord()
Default constructor for the Coord base class.
lsst::afw::geom::Angle hmsStringToAngle(std::string const hms)
Convert a hh:mm:ss string to Angle.
lsst::afw::geom::Angle getLongitude() const
get telescope longitude (positive values are E of Greenwich)
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
virtual EclipticCoord toEcliptic() const
Convert ourself from Ecliptic to Ecliptic ...
virtual EclipticCoord toEcliptic(double const epoch) const
Convert ourself to Ecliptic: lambda, beta (precess to new epoch)
std::pair< lsst::afw::geom::Angle, lsst::afw::geom::Angle > getOffsetFrom(Coord const &c) const
Compute the offset from a coordinate.
CoordSystem makeCoordEnum(std::string const system)
A utility function to get the enum value of a coordinate system from a string name.
Fk5Coord precess(double const epochTo) const
Precess ourselves from whence we are to a new epoch.
virtual EclipticCoord toEcliptic() const
Convert ourself to Ecliptic: lambda, beta (use existing epoch)
virtual GalacticCoord toGalactic() const
Convert ourself from Galactic to Galactic ...
This is the base class for spherical coordinates.
Point< double, 3 > Point3D
virtual TopocentricCoord toTopocentric(Observatory const &obs, lsst::daf::base::DateTime const &obsDate) const
Convert ourself to Altitude/Azimuth: alt, az.
A class to handle Icrs coordinates (inherits from Coord)
std::shared_ptr< Coord > averageCoord(std::vector< std::shared_ptr< Coord const >> const coords, CoordSystem system=UNKNOWN)
Return average of a list of coordinates.
virtual IcrsCoord toIcrs() const
Convert ourself to ICRS: RA, Dec (basically J2000)
virtual std::string getClassName() const