lsst.afw  13.0-57-g42cae95
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Coord.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 /*
26  * Provide functions to handle coordinates
27  *
28  * Most (nearly all) algorithms adapted from Astronomical Algorithms, 2nd ed. (J. Meeus)
29  *
30  */
31 #include <cmath>
32 #include <limits>
33 #include <cstdio>
34 #include <iomanip>
35 
36 #include "Eigen/Core"
37 #include "Eigen/Geometry"
38 
39 #include "lsst/pex/exceptions.h"
40 #include "boost/algorithm/string.hpp"
41 #include "boost/tuple/tuple.hpp"
42 #include "boost/format.hpp"
43 
44 #include "lsst/afw/coord/Coord.h"
45 #include "lsst/daf/base/DateTime.h"
46 
47 namespace ex = lsst::pex::exceptions;
48 namespace dafBase = lsst::daf::base;
49 
50 namespace lsst {
51 namespace afw {
52 namespace coord {
53 
54 namespace {
55 
56 typedef std::map<std::string, CoordSystem> CoordSystemMap;
57 
58 CoordSystemMap const getCoordSystemMap() {
59  CoordSystemMap idMap;
60  idMap["FK5"] = FK5;
61  idMap["ICRS"] = ICRS;
62  idMap["ECLIPTIC"] = ECLIPTIC;
63  idMap["GALACTIC"] = GALACTIC;
64  idMap["ELON"] = ECLIPTIC;
65  idMap["GLON"] = GALACTIC;
66  idMap["TOPOCENTRIC"] = TOPOCENTRIC;
67  return idMap;
68 }
69 
80 geom::Angle haversine(geom::Angle const dAlpha, geom::Angle const dDelta, double const cosDelta1,
81  double const cosDelta2) {
82  double const havDDelta = std::sin(dDelta / 2.0) * std::sin(dDelta / 2.0);
83  double const havDAlpha = std::sin(dAlpha / 2.0) * std::sin(dAlpha / 2.0);
84  double const havD = havDDelta + cosDelta1 * cosDelta2 * havDAlpha;
85  double const sinDHalf = std::sqrt(havD);
86  geom::Angle dist = (2.0 * std::asin(sinDHalf)) * geom::radians;
87  return dist;
88 }
89 
91 double const epochTolerance = 1.0e-12;
92 
94 std::pair<Fk5Coord, Fk5Coord> commonFk5(Coord const &c1, Coord const &c2) {
95  // make sure they're fk5
96  Fk5Coord fk51 = c1.toFk5();
97  Fk5Coord fk5tmp = c2.toFk5();
98 
99  // make sure they have the same epoch
100  Fk5Coord fk52;
101  if (fabs(fk51.getEpoch() - fk5tmp.getEpoch()) > epochTolerance) {
102  fk52 = fk5tmp.precess(fk51.getEpoch());
103  } else {
104  fk52 = fk5tmp;
105  }
106 
107  return std::make_pair(fk51, fk52);
108 }
109 
110 } // end anonymous namespace
111 
112 CoordSystem makeCoordEnum(std::string const system) {
113  static CoordSystemMap idmap = getCoordSystemMap();
114  if (idmap.find(system) != idmap.end()) {
115  return idmap[system];
116  } else {
117  throw LSST_EXCEPT(ex::InvalidParameterError, "System " + system + " not defined.");
118  }
119 }
120 
121 namespace {
122 
123 double const NaN = std::numeric_limits<double>::quiet_NaN();
124 double const JD2000 = 2451544.50;
125 
126 /*
127  * A local class to handle dd:mm:ss coordinates
128  *
129  * This class allows a decimal or dd:mm:ss coordinate to be
130  * disassembed into d, m, and s components.
131  * It's in an anonymous namespace, but there are public functions
132  * which perform the transformations directly:
133  *
134  * --> std::string dmsStr = degreesToDmsString(double deg);
135  * --> double deg = dmsStringToDegrees(std::string dms);
136  */
137 class Dms {
138 public:
139  Dms(){};
140 
141  // note that isSouth is needed to specify coords between dec = 0, and dec = -1
142  // otherwise, d = -0 gets carried as d = 0 ... need a way to specify it explicitly
143  Dms(int const d, int const m, double const s, bool const isSouth = false) {
144  sign = (d < 0 || isSouth) ? -1 : 1;
145  deg = std::abs(d);
146  min = m;
147  sec = s;
148  };
149  // unit could be "degrees" or "hours"
150  Dms(geom::Angle const deg00, geom::AngleUnit const unit = geom::degrees) {
151  double deg0 = deg00.asAngularUnits(unit);
152  double const absVal = std::fabs(deg0);
153  sign = (deg0 >= 0) ? 1 : -1;
154  deg = static_cast<int>(std::floor(absVal));
155  min = static_cast<int>(std::floor((absVal - deg) * 60.0));
156  sec = ((absVal - deg) * 60.0 - min) * 60.0;
157  }
158 
159  int deg;
160  int min;
161  double sec;
162  int sign;
163 };
164 
169 Coord const &GalacticPoleInFk5() {
170  static Coord pole(192.85950 * geom::degrees, 27.12825 * geom::degrees, 2000.0); // C&O
171  return pole;
172 }
173 
174 Coord const &Fk5PoleInGalactic() {
175  static Coord pole(122.93200 * geom::degrees, 27.12825 * geom::degrees, 2000.0); // C&O
176  return pole;
177 }
178 
183 geom::Angle meanSiderealTimeGreenwich(double const jd
184  ) {
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)) *
189 }
190 
191 /*
192  * A pair of utility functions to go from cartesian to spherical
193  */
194 double const atPoleEpsilon = 0.0; // std::numeric_limits<double>::epsilon();
195 geom::Angle pointToLongitude(geom::Point3D const &p3d, double const defaultLongitude = 0.0) {
196  geom::Angle lon;
197  if (fabs(p3d.getX()) <= atPoleEpsilon && fabs(p3d.getY()) <= atPoleEpsilon) {
198  lon = geom::Angle(0.0);
199  } else {
200  lon = (std::atan2(p3d.getY(), p3d.getX()) * geom::radians).wrap();
201  }
202  return lon;
203 }
204 geom::Angle pointToLatitude(geom::Point3D const &p3d) {
205  geom::Angle lat;
206  if (fabs(p3d.getX()) <= atPoleEpsilon && fabs(p3d.getY()) <= atPoleEpsilon) {
207  lat = (p3d.getZ() >= 0) ? geom::Angle(geom::HALFPI) : geom::Angle(-geom::HALFPI);
208  } else {
209  lat = std::asin(p3d.getZ()) * geom::radians;
210  }
211  return lat;
212 }
213 std::pair<geom::Angle, geom::Angle> pointToLonLat(geom::Point3D const &p3d,
214  double const defaultLongitude = 0.0,
215  bool normalize = true) {
216  std::pair<geom::Angle, geom::Angle> lonLat;
217 
218  if (normalize) {
219  double const inorm = 1.0 / p3d.asEigen().norm();
220  double const x = inorm * p3d.getX();
221  double const y = inorm * p3d.getY();
222  double const z = inorm * p3d.getZ();
223  if (fabs(x) <= atPoleEpsilon && fabs(y) <= atPoleEpsilon) {
224  lonLat.first = 0.0 * geom::radians;
225  lonLat.second = ((z >= 0) ? 1.0 : -1.0) * geom::HALFPI * geom::radians;
226  } else {
227  lonLat.first = (atan2(y, x) * geom::radians).wrap();
228  lonLat.second = asin(z) * geom::radians;
229  }
230  } else {
231  if (fabs(p3d.getX()) <= atPoleEpsilon && fabs(p3d.getY()) <= atPoleEpsilon) {
232  lonLat.first = 0.0 * geom::radians;
233  lonLat.second = ((p3d.getZ() >= 0) ? 1.0 : -1.0) * geom::HALFPI * geom::radians;
234  } else {
235  lonLat.first = (atan2(p3d.getY(), p3d.getX()) * geom::radians).wrap();
236  lonLat.second = asin(p3d.getZ()) * geom::radians;
237  }
238  }
239  return lonLat;
240 }
241 
242 } // end anonymous namespace
243 
244 /* ******************* Public functions ******************* */
245 
246 static std::string angleToXmsString(geom::Angle const a, geom::AngleUnit const unit) {
247  Dms dms(a, unit);
248 
249  // make sure rounding won't give 60.00 for sec or min
250  if ((60.00 - dms.sec) < 0.005) {
251  dms.sec = 0.0;
252  dms.min += 1;
253  if (dms.min == 60) {
254  dms.min = 0;
255  dms.deg += 1;
256  if (dms.deg == 360) {
257  dms.deg = 0;
258  }
259  }
260  }
261 
262  std::string fmt("%02d:%02d:%05.2f");
263  std::string s = (boost::format(fmt) % dms.deg % dms.min % dms.sec).str();
264  if (dms.sign < 0) {
265  s = "-" + s;
266  }
267  return s;
268 }
269 
270 std::string angleToDmsString(geom::Angle const a) { return angleToXmsString(a, geom::degrees); }
271 
272 std::string angleToHmsString(geom::Angle const a) { return angleToXmsString(a, geom::hours); }
273 
281 static geom::Angle xmsStringToAngle(std::string const dms, geom::AngleUnit unit) {
282  if (dms.find(":") == std::string::npos) {
283  throw LSST_EXCEPT(ex::InvalidParameterError,
284  (boost::format("String is not in xx:mm:ss format: %s") % dms).str());
285  }
286  std::vector<std::string> elements;
287  boost::split(elements, dms, boost::is_any_of(":"));
288  if (elements.size() != 3) {
289  throw LSST_EXCEPT(ex::InvalidParameterError,
290  (boost::format("Could not parse string as xx:mm:ss format: %s") % dms).str());
291  }
292  int const deg = abs(atoi(elements[0].c_str()));
293  int const min = atoi(elements[1].c_str());
294  double const sec = atof(elements[2].c_str());
295 
296  geom::Angle ang = (deg + min / 60.0 + sec / 3600.0) * unit;
297  if ((elements[0].c_str())[0] == '-') {
298  ang *= -1.0;
299  }
300  return ang;
301 }
302 
303 geom::Angle hmsStringToAngle(std::string const hms) { return xmsStringToAngle(hms, geom::hours); }
304 
305 geom::Angle dmsStringToAngle(std::string const dms) { return xmsStringToAngle(dms, geom::degrees); }
306 
308  double const T = (epoch - 2000.0) / 100.0;
309  return (23.0 + 26.0 / 60.0 + (21.448 - 46.82 * T - 0.0006 * T * T - 0.0018 * T * T * T) / 3600.0) *
311 }
312 
313 /* ============================================================
314  *
315  * class Coord
316  *
317  * ============================================================*/
318 
319 Coord::Coord(geom::Point2D const &p2d, geom::AngleUnit unit, double const epoch)
320  : _longitude(NaN), _latitude(NaN), _epoch(epoch) {
321  _longitude = geom::Angle(p2d.getX(), unit).wrap();
322  _latitude = geom::Angle(p2d.getY(), unit);
323  _verifyValues();
324 }
325 
326 Coord::Coord(geom::Point3D const &p3d, double const epoch, bool normalize, geom::Angle const defaultLongitude)
327  : _longitude(0. * geom::radians), _latitude(0. * geom::radians), _epoch(epoch) {
328  std::pair<geom::Angle, geom::Angle> lonLat = pointToLonLat(p3d, defaultLongitude, normalize);
329  _longitude = lonLat.first;
330  _latitude = lonLat.second;
331  _epoch = epoch;
332 }
333 
334 Coord::Coord(geom::Angle const ra, geom::Angle const dec, double const epoch)
335  : _longitude(ra.wrap()), _latitude(dec), _epoch(epoch) {
336  _verifyValues();
337 }
338 
339 Coord::Coord(std::string const ra, std::string const dec, double const epoch)
340  : _longitude(hmsStringToAngle(ra).wrap()), _latitude(dmsStringToAngle(dec)), _epoch(epoch) {
341  _verifyValues();
342 }
343 
344 Coord::Coord() : _longitude(geom::Angle(NaN)), _latitude(geom::Angle(NaN)), _epoch(NaN) {}
345 
346 void Coord::_verifyValues() const {
347  if (_latitude.asRadians() < -geom::HALFPI || _latitude.asRadians() > geom::HALFPI) {
348  throw LSST_EXCEPT(
349  ex::InvalidParameterError,
350  (boost::format("Latitude coord must be: -PI/2 <= lat <= PI/2 (%f).") % _latitude).str());
351  }
352 }
353 
354 void Coord::reset(geom::Angle const longitude, geom::Angle const latitude, double const epoch) {
355  _longitude = longitude.wrap();
356  _latitude = latitude;
357  _epoch = epoch;
358  _verifyValues();
359 }
360 
362  // treat HOURS specially, they must mean hours for RA, degrees for Dec
363  if (unit == geom::hours) {
364  return geom::Point2D(getLongitude().asHours(), getLatitude().asDegrees());
365  } else {
366  return geom::Point2D(getLongitude().asAngularUnits(unit), getLatitude().asAngularUnits(unit));
367  }
368 }
369 
371  double lng = getLongitude();
372  double lat = getLatitude();
373  double const x = std::cos(lng) * std::cos(lat);
374  double const y = std::sin(lng) * std::cos(lat);
375  double const z = std::sin(lat);
376  return geom::Point3D(x, y, z);
377 }
378 
379 Coord Coord::transform(Coord const &poleTo, Coord const &poleFrom) const {
380  double const alphaGP = poleFrom[0];
381  double const deltaGP = poleFrom[1];
382  double const lCP = poleTo[0];
383 
384  double const alpha = getLongitude();
385  double const delta = getLatitude();
386 
387  geom::Angle const l = (lCP - std::atan2(std::sin(alpha - alphaGP),
388  std::tan(delta) * std::cos(deltaGP) -
389  std::cos(alpha - alphaGP) * std::sin(deltaGP))) *
391  geom::Angle const b = std::asin((std::sin(deltaGP) * std::sin(delta) +
392  std::cos(deltaGP) * std::cos(delta) * std::cos(alpha - alphaGP))) *
394  return Coord(l, b);
395 }
396 
397 void Coord::rotate(Coord const &axis, geom::Angle const theta) {
398  double const c = std::cos(theta);
399  double const mc = 1.0 - c;
400  double const s = std::sin(theta);
401 
402  // convert to cartesian
403  geom::Point3D const x = getVector();
404  geom::Point3D const u = axis.getVector();
405  double const ux = u[0];
406  double const uy = u[1];
407  double const uz = u[2];
408 
409  // rotate
410  geom::Point3D xprime;
411  xprime[0] = (ux * ux + (1.0 - ux * ux) * c) * x[0] + (ux * uy * mc - uz * s) * x[1] +
412  (ux * uz * mc + uy * s) * x[2];
413  xprime[1] = (uy * uy + (1.0 - uy * uy) * c) * x[1] + (uy * uz * mc - ux * s) * x[2] +
414  (ux * uy * mc + uz * s) * x[0];
415  xprime[2] = (uz * uz + (1.0 - uz * uz) * c) * x[2] + (uz * ux * mc - uy * s) * x[0] +
416  (uy * uz * mc + ux * s) * x[1];
417 
418  // in-situ
419  std::pair<geom::Angle, geom::Angle> lonLat = pointToLonLat(xprime);
420  _longitude = lonLat.first;
421  _latitude = lonLat.second;
422 }
423 
425  // let v = vector in the direction arcLen points (tangent to surface of sphere)
426  // thus: |v| = arcLen
427  // angle phi = orientation of v in a tangent plane, measured wrt to a parallel of declination
428 
429  // To do the rotation, use rotate() method.
430  // - must provide an axis of rotation: take the cross product r x v to get that axis (pole)
431 
432  // get the vector r
433  Eigen::Vector3d r = getVector().asEigen();
434 
435  // Get the vector v:
436  // let u = unit vector lying on a parallel of declination
437  // let w = unit vector along line of longitude = r x u
438  // the vector v must satisfy the following:
439  // |v| = arcLen
440  // r . v = 0
441  // u . v = |v| cos(phi) = arcLen*cos(phi)
442  // w . v = |v| sin(phi) = arcLen*sin(phi)
443 
444  // v is a linear combination of u and w
445  // v = arcLen*cos(phi)*u + arcLen*sin(phi)*w
446 
447  // Thus, we must:
448  // - create u vector
449  // - solve w vector (r cross u)
450  // - compute v
451  Eigen::Vector3d u;
452  u << -std::sin(getLongitude()), std::cos(getLongitude()), 0.0;
453  Eigen::Vector3d w = r.cross(u);
454  Eigen::Vector3d v = arcLen * std::cos(phi) * u + arcLen * std::sin(phi) * w;
455 
456  // take r x v to get the axis
457  Eigen::Vector3d axisVector = r.cross(v);
458  axisVector.normalize();
459  Coord axisCoord = Coord(geom::Point3D(axisVector), getEpoch());
460 
461  rotate(axisCoord, arcLen);
462 
463  // now get the position angle at our destination
464  // u2 . v2 = arcLen*cos(phi2)
465  // w2 . v2 = arcLen*sin(phi2)
466  // if we normalize v2:
467  // phi2 = atan2(w2.v2, u2.v2)
468  //
469  // we need to compute u2, and then rotate v (exactly as we rotated r) to get v2
470  Eigen::Vector3d r2 = getVector().asEigen();
471  Eigen::Vector3d u2;
472  u2 << -std::sin(getLongitude()), std::cos(getLongitude()), 0.0;
473  Eigen::Vector3d w2 = r2.cross(u2);
474 
475  // make v a unit vector and rotate v exactly as we rotated r
476  v.normalize();
477  Coord v2Coord = Coord(geom::Point3D(v), getEpoch());
478  v2Coord.rotate(axisCoord, arcLen);
479  Eigen::Vector3d v2 = v2Coord.getVector().asEigen();
480 
481  geom::Angle phi2 = std::atan2(w2.dot(v2), u2.dot(v2)) * geom::radians;
482 
483  return phi2;
484 }
485 
486 std::shared_ptr<Coord> Coord::convert(CoordSystem system, double epoch) const {
487  switch (system) {
488  case FK5: {
489  Fk5Coord c1 = this->toFk5(epoch);
490  return std::shared_ptr<Fk5Coord>(
491  new Fk5Coord(c1.getLongitude(), c1.getLatitude(), c1.getEpoch()));
492  } break;
493  case ICRS: {
494  IcrsCoord c2 = this->toIcrs();
495  return std::shared_ptr<IcrsCoord>(new IcrsCoord(c2.getLongitude(), c2.getLatitude()));
496  } break;
497  case GALACTIC: {
498  GalacticCoord c4 = this->toGalactic();
499  return std::shared_ptr<GalacticCoord>(new GalacticCoord(c4.getLongitude(), c4.getLatitude()));
500  } break;
501  case ECLIPTIC: {
502  EclipticCoord c5 = this->toEcliptic(epoch);
503  return std::shared_ptr<EclipticCoord>(
504  new EclipticCoord(c5.getLongitude(), c5.getLatitude(), c5.getEpoch()));
505  } break;
506  case TOPOCENTRIC:
507  throw LSST_EXCEPT(ex::InvalidParameterError,
508  "Cannot make Topocentric with convert() (must also specify Observatory).\n"
509  "Instantiate TopocentricCoord() directly.");
510  break;
511  case UNKNOWN:
512  throw LSST_EXCEPT(ex::InvalidParameterError, "Cannot convert to UNKNOWN coordinate system");
513  break;
514  default:
515  throw LSST_EXCEPT(ex::InvalidParameterError,
516  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC allowed.");
517  break;
518  }
519 }
520 
522  // work in Fk5, no matter what two derived classes we're given (eg Fk5 and Galactic)
523  // we'll put them in the same system.
524  std::pair<Fk5Coord, Fk5Coord> const &fk5 = commonFk5(*this, c);
525  geom::Angle const alpha1 = fk5.first.getRa();
526  geom::Angle const delta1 = fk5.first.getDec();
527  geom::Angle const alpha2 = fk5.second.getRa();
528  geom::Angle const delta2 = fk5.second.getDec();
529 
530  return haversine(alpha1 - alpha2, delta1 - delta2, std::cos(delta1), std::cos(delta2));
531 }
532 
533 std::pair<geom::Angle, geom::Angle> Coord::getOffsetFrom(Coord const &c) const {
534  // work in Fk5, no matter what two derived classes we're given (eg Fk5 and Galactic)
535  // we'll put them in the same system.
536  std::pair<Fk5Coord, Fk5Coord> const &fk5 = commonFk5(*this, c);
537  geom::Angle const alpha1 = fk5.first.getRa();
538  geom::Angle const delta1 = fk5.first.getDec();
539  geom::Angle const alpha2 = fk5.second.getRa();
540  geom::Angle const delta2 = fk5.second.getDec();
541 
542  geom::Angle const dAlpha = alpha1 - alpha2;
543  geom::Angle const dDelta = delta1 - delta2;
544 
545  double const cosDelta1 = std::cos(delta1);
546  double const cosDelta2 = std::cos(delta2);
547 
548  geom::Angle separation = haversine(dAlpha, dDelta, cosDelta1, cosDelta2);
549 
550  // Formula from http://www.movable-type.co.uk/scripts/latlong.html
551  double const y = std::sin(dAlpha) * cosDelta2;
552  double const x = cosDelta1 * std::sin(delta2) - std::sin(delta1) * cosDelta2 * std::cos(dAlpha);
553  geom::Angle bearing = std::atan2(y, x) * geom::radians - 90.0 * geom::degrees;
554 
555  return std::make_pair(bearing, separation);
556 }
557 
558 std::pair<geom::Angle, geom::Angle> Coord::getTangentPlaneOffset(Coord const &c) const {
559  // work in Fk5, no matter what two derived classes we're given (eg Fk5 and Galactic)
560  // we'll put them in the same system.
561  std::pair<Fk5Coord, Fk5Coord> const &fk5 = commonFk5(*this, c);
562  geom::Angle const alpha1 = fk5.first.getRa();
563  geom::Angle const delta1 = fk5.first.getDec();
564  geom::Angle const alpha2 = fk5.second.getRa();
565  geom::Angle const delta2 = fk5.second.getDec();
566 
567  // This is a projection of coord2 to the tangent plane at coord1
568  double const sinDelta1 = std::sin(delta1);
569  double const cosDelta1 = std::cos(delta1);
570  double const sinDelta2 = std::sin(delta2);
571  double const cosDelta2 = std::cos(delta2);
572  double const cosAlphaDiff = std::cos(alpha2 - alpha1);
573  double const sinAlphaDiff = std::sin(alpha2 - alpha1);
574 
575  double const div = cosDelta1 * cosAlphaDiff * cosDelta2 + sinDelta1 * sinDelta2;
576  double const xi = cosDelta1 * sinAlphaDiff / div;
577  double const eta = (cosDelta1 * cosAlphaDiff * sinDelta2 - sinDelta1 * cosDelta2) / div;
578 
579  return std::make_pair(xi * geom::radians, eta * geom::radians);
580 }
581 
582 Fk5Coord Coord::toFk5(double const epoch) const {
583  return Fk5Coord(getLongitude(), getLatitude(), getEpoch()).precess(epoch);
584 }
586 
587 IcrsCoord Coord::toIcrs() const { return this->toFk5().toIcrs(); }
588 
589 GalacticCoord Coord::toGalactic() const { return this->toFk5().toGalactic(); }
590 
591 EclipticCoord Coord::toEcliptic(double const epoch) const { return this->toFk5(epoch).toEcliptic(); }
592 EclipticCoord Coord::toEcliptic() const { return this->toFk5().toEcliptic(); }
593 
595  lsst::daf::base::DateTime const &obsDate) const {
596  return this->toFk5().toTopocentric(obs, obsDate);
597 }
598 
599 /* ============================================================
600  *
601  * class Fk5Coord
602  *
603  * ============================================================*/
604 
605 Fk5Coord Fk5Coord::toFk5(double const epoch) const {
606  return Fk5Coord(getLongitude(), getLatitude(), getEpoch()).precess(epoch);
607 }
609 
611  // only do the precession to 2000 if we're not already there.
612  if (fabs(getEpoch() - 2000.0) > epochTolerance) {
613  Fk5Coord c = precess(2000.0);
614  return IcrsCoord(c.getLongitude(), c.getLatitude());
615  } else {
616  return IcrsCoord(getLongitude(), getLatitude());
617  }
618 }
619 
621  // if we're epoch==2000, we can transform, otherwise we need to precess first
622  Fk5Coord c;
623  if (fabs(getEpoch() - 2000.0) > epochTolerance) {
624  c = precess(2000.0);
625  } else {
626  c = *this;
627  }
628 
629  Coord ct = c.transform(Fk5PoleInGalactic(), GalacticPoleInFk5());
630  return GalacticCoord(ct.getLongitude(), ct.getLatitude());
631 }
632 
633 EclipticCoord Fk5Coord::toEcliptic(double const epoch) const {
634  geom::Angle const eclPoleIncl = eclipticPoleInclination(epoch);
635  Coord const eclPoleInEquatorial(270.0 * geom::degrees, (90.0 * geom::degrees) - eclPoleIncl, epoch);
636  Coord const equPoleInEcliptic(90.0 * geom::degrees, (90.0 * geom::degrees) - eclPoleIncl, epoch);
637  Coord c = transform(equPoleInEcliptic, eclPoleInEquatorial);
638  return EclipticCoord(c.getLongitude(), c.getLatitude(), epoch);
639 }
641 
643  lsst::daf::base::DateTime const &obsDate) const {
644  // make sure we precess to the epoch
645  Fk5Coord fk5 = precess(obsDate.get(dafBase::DateTime::EPOCH));
646 
647  // greenwich sidereal time
648  geom::Angle theta0 = meanSiderealTimeGreenwich(obsDate.get(dafBase::DateTime::JD)).wrap();
649 
650  // lat/long of the observatory
651  geom::Angle const phi = obs.getLatitude();
652  geom::Angle const L = obs.getLongitude();
653 
654  // ra/dec of the target
655  geom::Angle const alpha = fk5.getRa();
656  geom::Angle const delta = fk5.getDec();
657 
658  geom::Angle const H = theta0 + L - alpha;
659 
660  // compute the altitude, h
661  double const sinh = std::sin(phi) * std::sin(delta) + std::cos(phi) * std::cos(delta) * std::cos(H);
662  geom::Angle const h = std::asin(sinh) * geom::radians;
663 
664  // compute the azimuth, A
665  double const tanAnumerator = std::sin(H);
666  double const tanAdenominator = (std::cos(H) * std::sin(phi) - std::tan(delta) * std::cos(phi));
667 
668  // Equations used here assume azimuth is with respect to South
669  // but we use the North as our origin ... must add 180 deg
670  geom::Angle A = ((180.0 * geom::degrees) + atan2(tanAnumerator, tanAdenominator) * geom::radians).wrap();
671 
672  return TopocentricCoord(A, h, obsDate.get(dafBase::DateTime::EPOCH), obs);
673 }
674 
675 Fk5Coord Fk5Coord::precess(double const epochTo) const {
676  // return a copy if the epochs are the same
677  if (fabs(getEpoch() - epochTo) < epochTolerance) {
678  return Fk5Coord(getLongitude(), getLatitude(), getEpoch());
679  }
680 
681  dafBase::DateTime const dateFrom(getEpoch(), dafBase::DateTime::EPOCH, dafBase::DateTime::TAI);
682  dafBase::DateTime const dateTo(epochTo, dafBase::DateTime::EPOCH, dafBase::DateTime::TAI);
683  double const jd0 = dateFrom.get(dafBase::DateTime::JD);
684  double const jd = dateTo.get(dafBase::DateTime::JD);
685 
686  double const T = (jd0 - JD2000) / 36525.0;
687  double const t = (jd - jd0) / 36525.0;
688  double const tt = t * t;
689  double const ttt = tt * t;
690 
691  geom::Angle const xi = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (0.30188 - 0.000344 * T) * tt +
692  0.017998 * ttt) *
694  geom::Angle const z = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (1.09468 + 0.000066 * T) * tt +
695  0.018203 * ttt) *
697  geom::Angle const theta = ((2004.3109 - 0.85330 * T - 0.000217 * T * T) * t -
698  (0.42665 + 0.000217 * T) * tt - 0.041833 * ttt) *
700 
701  Fk5Coord fk5 = this->toFk5();
702  geom::Angle const alpha0 = fk5.getRa();
703  geom::Angle const delta0 = fk5.getDec();
704 
705  double const a = std::cos(delta0) * std::sin((alpha0 + xi));
706  double const b =
707  std::cos(theta) * std::cos(delta0) * std::cos((alpha0 + xi)) - std::sin(theta) * std::sin(delta0);
708  double const c =
709  std::sin(theta) * std::cos(delta0) * std::cos((alpha0 + xi)) + std::cos(theta) * std::sin(delta0);
710 
711  geom::Angle const alpha = (std::atan2(a, b) + z) * geom::radians;
712  geom::Angle const delta = std::asin(c) * geom::radians;
713 
714  return Fk5Coord(alpha, delta, epochTo);
715 }
716 
717 /* ============================================================
718  *
719  * class IcrsCoord
720  *
721  * ============================================================*/
722 
724  Coord::reset(longitude, latitude, 2000.0);
725 }
726 
727 Fk5Coord IcrsCoord::toFk5(double const epoch) const {
728  return Fk5Coord(getLongitude(), getLatitude(), 2000.0).precess(epoch);
729 }
730 Fk5Coord IcrsCoord::toFk5() const { return Fk5Coord(getLongitude(), getLatitude(), 2000.0); }
731 
733 
734 std::string IcrsCoord::toString() const {
735  return (boost::format("%s(%.7f, %.7f)") % getClassName() % (*this)[0].asDegrees() %
736  (*this)[1].asDegrees())
737  .str();
738 }
739 
740 /* ============================================================
741  *
742  * class GalacticCoord
743  *
744  * ============================================================*/
745 
746 void GalacticCoord::reset(geom::Angle const longitudeDeg, geom::Angle const latitudeDeg) {
747  Coord::reset(longitudeDeg, latitudeDeg, 2000.0);
748 }
749 
750 Fk5Coord GalacticCoord::toFk5(double const epoch) const {
751  // transform to fk5
752  // galactic coords are ~constant, and the poles used are for epoch=2000, so we get J2000
753  Coord c = transform(GalacticPoleInFk5(), Fk5PoleInGalactic());
754  return Fk5Coord(c.getLongitude(), c.getLatitude(), 2000.0).precess(epoch);
755 }
756 Fk5Coord GalacticCoord::toFk5() const { return this->toFk5(2000.0); }
757 
759 
760 std::string GalacticCoord::toString() const {
761  return (boost::format("%s(%.7f, %.7f)") % getClassName() % (*this)[0].asDegrees() %
762  (*this)[1].asDegrees())
763  .str();
764 }
765 
766 /* ============================================================
767  *
768  * class EclipticCoord
769  *
770  * ============================================================*/
771 
772 EclipticCoord EclipticCoord::toEcliptic(double const epoch) const {
773  return EclipticCoord(getLongitude(), getLatitude(), getEpoch()).precess(epoch);
774 }
777 }
778 
779 Fk5Coord EclipticCoord::toFk5(double const epoch) const {
780  geom::Angle const eclPoleIncl = eclipticPoleInclination(epoch);
781  geom::Angle ninety = 90. * geom::degrees;
782  Coord const eclipticPoleInFk5(270.0 * geom::degrees, ninety - eclPoleIncl, epoch);
783  Coord const fk5PoleInEcliptic(ninety, ninety - eclPoleIncl, epoch);
784  Coord c = transform(eclipticPoleInFk5, fk5PoleInEcliptic);
785  return Fk5Coord(c.getLongitude(), c.getLatitude(), epoch);
786 }
787 Fk5Coord EclipticCoord::toFk5() const { return this->toFk5(getEpoch()); }
788 
789 EclipticCoord EclipticCoord::precess(double const epochTo) const {
790  return this->toFk5().precess(epochTo).toEcliptic();
791 }
792 
793 /* ============================================================
794  *
795  * class TopocentricCoord
796  *
797  * ============================================================*/
798 
799 Fk5Coord TopocentricCoord::toFk5(double const epoch) const {
800  geom::Angle const phi = _obs.getLatitude();
801  geom::Angle const L = _obs.getLongitude();
802 
803  // Equations used here assume azimuth is with respect to South
804  // but we use the North as our origin.
805  geom::Angle A = (getAzimuth() + 180.0 * geom::degrees).wrap();
806  geom::Angle const h = getAltitude();
807 
808  double const jd = dafBase::DateTime(epoch, dafBase::DateTime::EPOCH, dafBase::DateTime::TAI)
809  .get(dafBase::DateTime::JD);
810  geom::Angle theta0 = meanSiderealTimeGreenwich(jd).wrap();
811 
812  double const tanHnum = std::sin(A);
813  double const tanHdenom = std::cos(A) * std::sin(phi) + std::tan(h) * std::cos(phi);
814  geom::Angle H = std::atan2(tanHnum, tanHdenom) * geom::radians;
815 
816  geom::Angle const alpha = theta0 + L - H;
817  double const sinDelta = std::sin(phi) * std::sin(h) - std::cos(phi) * std::cos(h) * std::cos(A);
818  geom::Angle const delta = (std::asin(sinDelta)) * geom::radians;
819 
820  return Fk5Coord(alpha, delta, epoch);
821 }
822 Fk5Coord TopocentricCoord::toFk5() const { return this->toFk5(getEpoch()); }
823 
825  lsst::daf::base::DateTime const &date) const {
826  if (obs != _obs) {
827  throw LSST_EXCEPT(ex::InvalidParameterError,
828  (boost::format("Expected observatory %s, saw %s") % _obs % obs).str());
829  }
830  if (fabs(date.get() - getEpoch()) > std::numeric_limits<double>::epsilon()) {
831  throw LSST_EXCEPT(ex::InvalidParameterError,
832  (boost::format("Expected date %g, saw %g") % getEpoch() % date.get()).str());
833  }
834 
835  return TopocentricCoord(getLongitude(), getLatitude(), getEpoch(), _obs);
836 }
837 
839  return TopocentricCoord(getLongitude(), getLatitude(), getEpoch(), _obs);
840 }
841 
842 std::string TopocentricCoord::toString() const {
843  return (boost::format("%s(%.7f, %.7f, %.12f, (%s))") % getClassName() % (*this)[0].asDegrees() %
844  (*this)[1].asDegrees() % getEpoch() % getObservatory())
845  .str();
846 }
847 
848 /* ===============================================================================
849  *
850  * Factory function definitions:
851  *
852  * Each makeCoord() function has overloaded variants with and without epoch specified.
853  * It was tempting to specify default values, but some coordinate systems have
854  * no epoch, and this would be confusing to the user. In its current form,
855  * any epochless coordinate system requested with an epoch specified will throw an exception.
856  * The epochless factories will always work, but assume default epoch = 2000.
857  *
858  * ===============================================================================
859  */
860 
861 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Angle const ra, geom::Angle const dec,
862  double const epoch) {
863  switch (system) {
864  case FK5:
865  return std::shared_ptr<Fk5Coord>(new Fk5Coord(ra, dec, epoch));
866  break;
867  case ICRS:
868  throw LSST_EXCEPT(ex::InvalidParameterError,
869  "ICRS has no epoch, use overloaded makeCoord with args (system, ra, dec).");
870  break;
871  case GALACTIC:
872  throw LSST_EXCEPT(ex::InvalidParameterError,
873  "Galactic has no epoch, use overloaded makeCoord with (system, ra, dec).");
874  break;
875  case ECLIPTIC:
876  return std::shared_ptr<EclipticCoord>(new EclipticCoord(ra, dec, epoch));
877  break;
878  case TOPOCENTRIC:
879  throw LSST_EXCEPT(ex::InvalidParameterError,
880  "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n"
881  "Instantiate TopocentricCoord() directly.");
882  break;
883  default:
884  throw LSST_EXCEPT(
885  ex::InvalidParameterError,
886  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
887  break;
888  }
889 }
890 
891 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Angle const ra, geom::Angle const dec) {
892  switch (system) {
893  case FK5:
894  return std::shared_ptr<Fk5Coord>(new Fk5Coord(ra, dec, 2000.0));
895  break;
896  case ICRS:
897  return std::shared_ptr<IcrsCoord>(new IcrsCoord(ra, dec));
898  break;
899  case GALACTIC:
900  return std::shared_ptr<GalacticCoord>(new GalacticCoord(ra, dec));
901  break;
902  case ECLIPTIC:
903  return std::shared_ptr<EclipticCoord>(new EclipticCoord(ra, dec, 2000.0));
904  break;
905  case TOPOCENTRIC:
906  throw LSST_EXCEPT(ex::InvalidParameterError,
907  "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n"
908  "Instantiate TopocentricCoord() directly.");
909  break;
910  default:
911  throw LSST_EXCEPT(
912  ex::InvalidParameterError,
913  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
914  break;
915  }
916 }
917 
918 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point3D const &p3d, double const epoch,
919  bool normalize, geom::Angle const defaultLongitude) {
920  Coord c(p3d, 2000.0, normalize, defaultLongitude);
921  return makeCoord(system, c.getLongitude(), c.getLatitude(), epoch);
922 }
923 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point3D const &p3d, bool normalize,
924  geom::Angle const defaultLongitude) {
925  Coord c(p3d, 2000.0, normalize, defaultLongitude);
926  return makeCoord(system, c.getLongitude(), c.getLatitude());
927 }
928 
929 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point2D const &p2d, geom::AngleUnit unit,
930  double const epoch) {
931  if (unit == geom::hours) {
932  return makeCoord(system, geom::Angle(p2d.getX(), geom::hours), geom::Angle(p2d.getY(), geom::degrees),
933  epoch);
934  } else {
935  return makeCoord(system, geom::Angle(p2d.getX(), unit), geom::Angle(p2d.getY(), unit), epoch);
936  }
937 }
938 
939 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point2D const &p2d, geom::AngleUnit unit) {
940  if (unit == geom::hours) {
941  return makeCoord(system, geom::Angle(p2d.getX(), geom::hours),
942  geom::Angle(p2d.getY(), geom::degrees));
943  } else {
944  return makeCoord(system, geom::Angle(p2d.getX(), unit), geom::Angle(p2d.getY(), unit));
945  }
946 }
947 
948 std::shared_ptr<Coord> makeCoord(CoordSystem const system, std::string const ra, std::string const dec,
949  double const epoch) {
950  return makeCoord(system, dmsStringToAngle(ra), dmsStringToAngle(dec), epoch);
951 }
952 std::shared_ptr<Coord> makeCoord(CoordSystem const system, std::string const ra, std::string const dec) {
953  return makeCoord(system, dmsStringToAngle(ra), dmsStringToAngle(dec));
954 }
955 
956 std::shared_ptr<Coord> makeCoord(CoordSystem const system) {
957  switch (system) {
958  case FK5:
959  return std::shared_ptr<Fk5Coord>(new Fk5Coord());
960  break;
961  case ICRS:
962  return std::shared_ptr<IcrsCoord>(new IcrsCoord());
963  break;
964  case GALACTIC:
965  return std::shared_ptr<GalacticCoord>(new GalacticCoord());
966  break;
967  case ECLIPTIC:
968  return std::shared_ptr<EclipticCoord>(new EclipticCoord());
969  break;
970  case TOPOCENTRIC:
971  throw LSST_EXCEPT(ex::InvalidParameterError,
972  "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n"
973  "Instantiate TopocentricCoord() directly.");
974  break;
975  default:
976  throw LSST_EXCEPT(ex::InvalidParameterError,
977  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, allowed.");
978  break;
979  }
980 }
981 
982 std::string Coord::toString() const {
983  return (boost::format("%s(%.7f, %.7f, %.2f)") % getClassName() % (*this)[0].asDegrees() %
984  (*this)[1].asDegrees() % getEpoch())
985  .str();
986 }
987 
988 std::ostream &operator<<(std::ostream &os, Coord const &coord) {
989  os << coord.toString();
990  return os;
991 }
992 
993 namespace {
994 
995 // Heavy lifting for averageCoord
996 std::shared_ptr<Coord> doAverageCoord(std::vector<std::shared_ptr<Coord const>> const coords,
997  CoordSystem system) {
998  assert(system != UNKNOWN); // Handled by caller
999  assert(coords.size() > 0); // Handled by caller
1000  geom::Point3D sum(0, 0, 0);
1001  geom::Point3D corr(0, 0, 0); // Kahan summation correction
1002  for (auto &&cc : coords) {
1003  geom::Point3D const point = cc->getVector();
1004  // Kahan summation
1005  geom::Extent3D const add = point - corr;
1006  geom::Point3D const temp = sum + add;
1007  corr = (temp - geom::Extent3D(sum)) - add;
1008  sum = temp;
1009  }
1010  sum.scale(1.0 / coords.size());
1011  return makeCoord(system, sum);
1012 }
1013 
1014 } // anonymous namespace
1015 
1016 std::shared_ptr<Coord> averageCoord(std::vector<std::shared_ptr<Coord const>> const coords,
1017  CoordSystem system) {
1018  if (coords.size() == 0) {
1019  throw LSST_EXCEPT(ex::LengthError, "No coordinates provided to average");
1020  }
1021 
1022  if (system == UNKNOWN) {
1023  // Determine which system we're using, and check that every coordinate is in that system
1024  system = coords[0]->getCoordSystem();
1025  for (auto &&cc : coords) {
1026  if (cc->getCoordSystem() != system) {
1027  throw LSST_EXCEPT(ex::InvalidParameterError,
1028  (boost::format("Coordinates are not all in the same system: %d vs %d") %
1029  cc->getCoordSystem() %
1030  system).str());
1031  }
1032  }
1033  return doAverageCoord(coords, system);
1034  }
1035 
1036  // Convert everything to the nominated coordinate system if necessary
1037  std::vector<std::shared_ptr<Coord const>> converted;
1038  converted.reserve(coords.size());
1039  for (auto &&cc : coords) {
1040  converted.push_back(cc->getCoordSystem() == system ? cc : cc->convert(system));
1041  }
1042  return doAverageCoord(converted, system);
1043 }
1044 }
1045 }
1046 } // end lsst::afw::coord
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.
Definition: Coord.cc:861
virtual std::string getClassName() const
Definition: Coord.h:554
virtual GalacticCoord toGalactic() const
Convert ourself to Galactic: l, b.
Definition: Coord.cc:620
double sec
Definition: Coord.cc:161
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
Definition: Coord.cc:746
virtual Fk5Coord toFk5() const
Convert outself from Topocentric to Fk5 (use current epoch)
Definition: Coord.cc:822
lsst::afw::geom::Angle Angle
Definition: misc.h:36
lsst::afw::coord::Coord Coord
Definition: misc.h:33
virtual std::string toString() const
Get string representation.
Definition: Coord.cc:734
void scale(double factor)
Definition: Point.h:118
table::Key< geom::Angle > longitude
Definition: VisitInfo.cc:167
A class to handle Galactic coordinates (inherits from Coord)
Definition: Coord.h:411
lsst::afw::geom::Angle dmsStringToAngle(std::string const dms)
Convert a dd:mm:ss string to Angle.
Definition: Coord.cc:305
lsst::afw::geom::Angle getAltitude() const
Definition: Coord.h:569
lsst::afw::geom::Angle getAzimuth() const
Definition: Coord.h:568
virtual TopocentricCoord toTopocentric(Observatory const &obs, lsst::daf::base::DateTime const &obsDate) const
Convert ourself to Altitude/Azimuth: alt, az.
Definition: Coord.cc:642
double constexpr HALFPI
Definition: Angle.h:23
std::pair< lsst::afw::geom::Angle, lsst::afw::geom::Angle > getTangentPlaneOffset(Coord const &c) const
Get the offset on the tangent plane.
Definition: Coord.cc:558
Hold the location of an observatory.
Definition: Observatory.h:41
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
lsst::afw::geom::Point2D getPosition(lsst::afw::geom::AngleUnit unit=lsst::afw::geom::degrees) const
Return our contents in a Point2D object.
Definition: Coord.cc:361
A coordinate class intended to represent offsets and dimensions.
virtual Fk5Coord toFk5() const
Convert ourself from Ecliptic to Fk5 (use current epoch)
Definition: Coord.cc:787
lsst::afw::geom::Angle getLongitude() const
The main access method for the longitudinal coordinate.
Definition: Coord.h:163
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 ...
Definition: Coord.cc:424
virtual GalacticCoord toGalactic() const
Convert ourself to Galactic: l, b.
Definition: Coord.cc:589
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:88
lsst::afw::geom::Angle eclipticPoleInclination(double const epoch)
get the inclination of the ecliptic pole (obliquity) at epoch
Definition: Coord.cc:307
virtual EclipticCoord toEcliptic(double const epoch) const
Convert ourself to Ecliptic: lambda, beta (precess to new epoch)
Definition: Coord.cc:633
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
Definition: Coord.cc:723
virtual std::string toString() const
Get string representation.
Definition: Coord.cc:842
virtual Fk5Coord toFk5() const
Convert ourself from galactic to Fk5 (no epoch specified)
Definition: Coord.cc:756
virtual Fk5Coord toFk5() const
Convert ourself to Fk5 (ie.
Definition: Coord.cc:608
virtual std::string toString() const
Get string representation.
Definition: Coord.cc:982
virtual Fk5Coord toFk5() const
Convert ourself to Fk5: RA, Dec (use current epoch)
Definition: Coord.cc:585
virtual IcrsCoord toIcrs() const
Convert ourself to ICRS: RA, Dec (basically J2000)
Definition: Coord.cc:610
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:52
std::shared_ptr< Coord > convert(CoordSystem system, double epoch=2000) const
Convert to a specified Coord type at a specified epoch.
Definition: Coord.cc:486
EclipticCoord precess(double const epochTo) const
precess to new epoch
Definition: Coord.cc:789
virtual TopocentricCoord toTopocentric() const
Convert ourself from Topocentric to Topocentric with no observatory or date arguments.
Definition: Coord.cc:838
Coord transform(Coord const &poleTo, Coord const &poleFrom) const
Transform our current coords to another spherical polar system.
Definition: Coord.cc:379
std::ostream & operator<<(std::ostream &os, Coord const &coord)
Definition: Coord.cc:988
virtual std::string getClassName() const
Definition: Coord.h:301
Extent< int, N > floor(Extent< double, N > const &input)
Return the component-wise floor (round towards more negative).
TopocentricCoord(lsst::afw::geom::Point2D const &p2d, lsst::afw::geom::AngleUnit unit, double const epoch, Observatory const &obs)
Definition: Coord.h:537
A class representing an angle.
Definition: Angle.h:102
A class to handle topocentric (AltAz) coordinates (inherits from Coord)
Definition: Coord.h:535
void rotate(Coord const &axis, lsst::afw::geom::Angle const theta)
Rotate our current coords about a pole.
Definition: Coord.cc:397
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
Definition: Angle.h:370
int sign
Definition: Coord.cc:162
lsst::afw::geom::Angle angularSeparation(Coord const &c) const
compute the angular separation between two Coords
Definition: Coord.cc:521
lsst::afw::geom::Angle getLongitude() const
get telescope longitude (positive values are E of Greenwich)
Definition: Observatory.cc:47
lsst::afw::coord::IcrsCoord IcrsCoord
Definition: misc.h:35
Point< double, 2 > Point2D
Definition: Point.h:273
table::Key< geom::Angle > latitude
Definition: VisitInfo.cc:166
virtual GalacticCoord toGalactic() const
Convert ourself from Galactic to Galactic ...
Definition: Coord.cc:758
virtual std::string getClassName() const
Definition: Coord.h:427
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 ...
Definition: Coord.cc:270
AngleUnit constexpr hours
constant with units of hours
Definition: Angle.h:89
double x
std::string angleToHmsString(lsst::afw::geom::Angle const deg)
a function to convert decimal degrees to a string with form hh:mm:ss.s
Definition: Coord.cc:272
lsst::afw::geom::Point3D getVector() const
Return our contents in a position vector.
Definition: Coord.cc:370
Fk5Coord precess(double const epochTo) const
Precess ourselves from whence we are to a new epoch.
Definition: Coord.cc:675
A class to handle Fk5 coordinates (inherits from Coord)
Definition: Coord.h:339
Extent< double, 3 > Extent3D
Definition: Extent.h:345
virtual std::string toString() const
Get string representation.
Definition: Coord.cc:760
A class to handle Ecliptic coordinates (inherits from Coord)
Definition: Coord.h:469
Observatory getObservatory() const
Definition: Coord.h:563
double getEpoch() const
Definition: Coord.h:128
int deg
Definition: Coord.cc:159
virtual void reset(lsst::afw::geom::Angle const longitude, lsst::afw::geom::Angle const latitude)
Definition: Coord.h:112
AngleUnit constexpr arcseconds
constant with units of arcseconds
Definition: Angle.h:91
int min
Definition: Coord.cc:160
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
virtual IcrsCoord toIcrs() const
Convert ourself to ICRS: RA, Dec (basically J2000)
Definition: Coord.cc:587
Coord()
Default constructor for the Coord base class.
Definition: Coord.cc:344
lsst::afw::geom::Angle hmsStringToAngle(std::string const hms)
Convert a hh:mm:ss string to Angle.
Definition: Coord.cc:303
constexpr double asRadians() const noexcept
Return an Angle&#39;s value in radians.
Definition: Angle.h:139
std::shared_ptr< Coord > averageCoord(std::vector< std::shared_ptr< Coord const >> const coords, CoordSystem system=UNKNOWN)
Return average of a list of coordinates.
Definition: Coord.cc:1016
std::pair< lsst::afw::geom::Angle, lsst::afw::geom::Angle > getOffsetFrom(Coord const &c) const
Compute the offset from a coordinate.
Definition: Coord.cc:533
lsst::afw::geom::Angle getDec() const
Definition: Coord.h:367
CoordSystem makeCoordEnum(std::string const system)
A utility function to get the enum value of a coordinate system from a string name.
Definition: Coord.cc:112
virtual std::string getClassName() const
Definition: Coord.h:144
virtual TopocentricCoord toTopocentric(Observatory const &obs, lsst::daf::base::DateTime const &obsDate) const
Convert ourself to Altitude/Azimuth: alt, az.
Definition: Coord.cc:594
virtual IcrsCoord toIcrs() const
Icrs converter for IcrsCoord.
Definition: Coord.cc:732
lsst::afw::geom::Angle getLatitude() const
The main access method for the latitudinal coordinate.
Definition: Coord.h:170
virtual EclipticCoord toEcliptic() const
Convert ourself to Ecliptic: lambda, beta (use current epoch)
Definition: Coord.cc:640
lsst::afw::geom::Angle getRa() const
Definition: Coord.h:366
This is the base class for spherical coordinates.
Definition: Coord.h:63
Point< double, 3 > Point3D
Definition: Point.h:274
lsst::afw::geom::Angle getLatitude() const
get telescope latitude
Definition: Observatory.cc:49
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:288
virtual EclipticCoord toEcliptic() const
Convert ourself to Ecliptic: lambda, beta (use existing epoch)
Definition: Coord.cc:592
virtual EclipticCoord toEcliptic() const
Convert ourself from Ecliptic to Ecliptic ...
Definition: Coord.cc:775
virtual Fk5Coord toFk5() const
Fk5 converter for IcrsCoord.
Definition: Coord.cc:730