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) {
325 void Coord::_verifyValues()
const {
329 (boost::format(
"Latitude coord must be: -PI/2 <= lat <= PI/2 (%f).") % _latitude).str());
334 _longitude = longitude.
wrap();
359 double const alphaGP = poleFrom[0];
360 double const deltaGP = poleFrom[1];
361 double const lCP = poleTo[0];
378 double const mc = 1.0 - c;
384 double const ux = u[0];
385 double const uy = u[1];
386 double const uz = u[2];
390 xprime[0] = (ux * ux + (1.0 - ux * ux) * c) * x[0] + (ux * uy * mc - uz * s) * x[1] +
391 (ux * uz * mc + uy * s) * x[2];
392 xprime[1] = (uy * uy + (1.0 - uy * uy) * c) * x[1] + (uy * uz * mc - ux * s) * x[2] +
393 (ux * uy * mc + uz * s) * x[0];
394 xprime[2] = (uz * uz + (1.0 - uz * uz) * c) * x[2] + (uz * ux * mc - uy * s) * x[0] +
395 (uy * uz * mc + ux * s) * x[1];
399 _longitude = lonLat.first;
400 _latitude = lonLat.second;
432 Eigen::Vector3d w = r.cross(u);
433 Eigen::Vector3d v = arcLen *
std::cos(phi) * u + arcLen *
std::sin(phi) * w;
436 Eigen::Vector3d axisVector = r.cross(v);
437 axisVector.normalize();
440 rotate(axisCoord, arcLen);
452 Eigen::Vector3d w2 = r2.cross(u2);
457 v2Coord.
rotate(axisCoord, arcLen);
487 "Cannot make Topocentric with convert() (must also specify Observatory).\n" 488 "Instantiate TopocentricCoord() directly.");
495 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC allowed.");
509 return haversine(alpha1 - alpha2, delta1 - delta2,
std::cos(delta1),
std::cos(delta2));
524 double const cosDelta1 =
std::cos(delta1);
525 double const cosDelta2 =
std::cos(delta2);
527 geom::Angle separation = haversine(dAlpha, dDelta, cosDelta1, cosDelta2);
530 double const y =
std::sin(dAlpha) * cosDelta2;
547 double const sinDelta1 =
std::sin(delta1);
548 double const cosDelta1 =
std::cos(delta1);
549 double const sinDelta2 =
std::sin(delta2);
550 double const cosDelta2 =
std::cos(delta2);
551 double const cosAlphaDiff =
std::cos(alpha2 - alpha1);
552 double const sinAlphaDiff =
std::sin(alpha2 - alpha1);
554 double const div = cosDelta1 * cosAlphaDiff * cosDelta2 + sinDelta1 * sinDelta2;
555 double const xi = cosDelta1 * sinAlphaDiff / div;
556 double const eta = (cosDelta1 * cosAlphaDiff * sinDelta2 - sinDelta1 * cosDelta2) / div;
591 if (fabs(
getEpoch() - 2000.0) > epochTolerance) {
602 if (fabs(
getEpoch() - 2000.0) > epochTolerance) {
644 double const tanAnumerator =
std::sin(H);
656 if (fabs(
getEpoch() - epochTo) < epochTolerance) {
665 double const T = (jd0 - JD2000) / 36525.0;
666 double const t = (jd - jd0) / 36525.0;
667 double const tt = t * t;
668 double const ttt = tt * t;
670 geom::Angle const xi = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (0.30188 - 0.000344 * T) * tt +
673 geom::Angle const z = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (1.09468 + 0.000066 * T) * tt +
676 geom::Angle const theta = ((2004.3109 - 0.85330 * T - 0.000217 * T * T) * t -
677 (0.42665 + 0.000217 * T) * tt - 0.041833 * ttt) *
693 return Fk5Coord(alpha, delta, epochTo);
714 return (boost::format(
"%s(%.7f, %.7f)") %
getClassName() % (*
this)[0].asDegrees() %
715 (*
this)[1].asDegrees())
740 return (boost::format(
"%s(%.7f, %.7f)") %
getClassName() % (*
this)[0].asDegrees() %
741 (*
this)[1].asDegrees())
762 Coord const fk5PoleInEcliptic(ninety, ninety - eclPoleIncl, epoch);
799 return Fk5Coord(alpha, delta, epoch);
807 (boost::format(
"Expected observatory %s, saw %s") % _obs % obs).str());
811 (boost::format(
"Expected date %g, saw %g") %
getEpoch() % date.
get()).str());
822 return (boost::format(
"%s(%.7f, %.7f, %.12f, (%s))") %
getClassName() % (*
this)[0].asDegrees() %
823 (*
this)[1].asDegrees() %
getEpoch() % getObservatory())
841 double const epoch) {
848 "ICRS has no epoch, use overloaded makeCoord with args (system, ra, dec).");
852 "Galactic has no epoch, use overloaded makeCoord with (system, ra, dec).");
859 "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n" 860 "Instantiate TopocentricCoord() directly.");
865 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
886 "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n" 887 "Instantiate TopocentricCoord() directly.");
892 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
898 bool normalize,
geom::Angle const defaultLongitude) {
899 Coord c(p3d, 2000.0, normalize, defaultLongitude);
904 Coord c(p3d, 2000.0, normalize, defaultLongitude);
909 double const epoch) {
928 double const epoch) {
951 "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n" 952 "Instantiate TopocentricCoord() directly.");
956 "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, allowed.");
962 return (boost::format(
"%s(%.7f, %.7f, %.2f)") %
getClassName() % (*
this)[0].asDegrees() %
963 (*
this)[1].asDegrees() %
getEpoch())
978 assert(coords.size() > 0);
981 for (
auto &&cc : coords) {
989 sum.
scale(1.0 / coords.size());
997 if (coords.size() == 0) {
1003 system = coords[0]->getCoordSystem();
1004 for (
auto &&cc : coords) {
1005 if (cc->getCoordSystem() != system) {
1007 (boost::format(
"Coordinates are not all in the same system: %d vs %d") %
1008 cc->getCoordSystem() %
1012 return doAverageCoord(coords, system);
1017 converted.
reserve(coords.size());
1018 for (
auto &&cc : coords) {
1019 converted.
push_back(cc->getCoordSystem() == system ? cc : cc->convert(system));
1021 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)
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