lsst.afw  13.0-73-gb2a4e38
 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 double const atPoleEpsilon = 0.0; // std::numeric_limits<double>::epsilon();
192 std::pair<geom::Angle, geom::Angle> pointToLonLat(geom::Point3D const &p3d,
193  double const defaultLongitude = 0.0,
194  bool normalize = true) {
195  std::pair<geom::Angle, geom::Angle> lonLat;
196 
197  if (normalize) {
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) {
203  lonLat.first = 0.0 * geom::radians;
204  lonLat.second = ((z >= 0) ? 1.0 : -1.0) * geom::HALFPI * geom::radians;
205  } else {
206  lonLat.first = (atan2(y, x) * geom::radians).wrap();
207  lonLat.second = asin(z) * geom::radians;
208  }
209  } else {
210  if (fabs(p3d.getX()) <= atPoleEpsilon && fabs(p3d.getY()) <= atPoleEpsilon) {
211  lonLat.first = 0.0 * geom::radians;
212  lonLat.second = ((p3d.getZ() >= 0) ? 1.0 : -1.0) * geom::HALFPI * geom::radians;
213  } else {
214  lonLat.first = (atan2(p3d.getY(), p3d.getX()) * geom::radians).wrap();
215  lonLat.second = asin(p3d.getZ()) * geom::radians;
216  }
217  }
218  return lonLat;
219 }
220 
221 } // end anonymous namespace
222 
223 /* ******************* Public functions ******************* */
224 
225 static std::string angleToXmsString(geom::Angle const a, geom::AngleUnit const unit) {
226  Dms dms(a, unit);
227 
228  // make sure rounding won't give 60.00 for sec or min
229  if ((60.00 - dms.sec) < 0.005) {
230  dms.sec = 0.0;
231  dms.min += 1;
232  if (dms.min == 60) {
233  dms.min = 0;
234  dms.deg += 1;
235  if (dms.deg == 360) {
236  dms.deg = 0;
237  }
238  }
239  }
240 
241  std::string fmt("%02d:%02d:%05.2f");
242  std::string s = (boost::format(fmt) % dms.deg % dms.min % dms.sec).str();
243  if (dms.sign < 0) {
244  s = "-" + s;
245  }
246  return s;
247 }
248 
249 std::string angleToDmsString(geom::Angle const a) { return angleToXmsString(a, geom::degrees); }
250 
251 std::string angleToHmsString(geom::Angle const a) { return angleToXmsString(a, geom::hours); }
252 
260 static geom::Angle xmsStringToAngle(std::string const dms, geom::AngleUnit unit) {
261  if (dms.find(":") == std::string::npos) {
262  throw LSST_EXCEPT(ex::InvalidParameterError,
263  (boost::format("String is not in xx:mm:ss format: %s") % dms).str());
264  }
265  std::vector<std::string> elements;
266  boost::split(elements, dms, boost::is_any_of(":"));
267  if (elements.size() != 3) {
268  throw LSST_EXCEPT(ex::InvalidParameterError,
269  (boost::format("Could not parse string as xx:mm:ss format: %s") % dms).str());
270  }
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());
274 
275  geom::Angle ang = (deg + min / 60.0 + sec / 3600.0) * unit;
276  if ((elements[0].c_str())[0] == '-') {
277  ang *= -1.0;
278  }
279  return ang;
280 }
281 
282 geom::Angle hmsStringToAngle(std::string const hms) { return xmsStringToAngle(hms, geom::hours); }
283 
284 geom::Angle dmsStringToAngle(std::string const dms) { return xmsStringToAngle(dms, geom::degrees); }
285 
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) *
290 }
291 
292 /* ============================================================
293  *
294  * class Coord
295  *
296  * ============================================================*/
297 
298 Coord::Coord(geom::Point2D const &p2d, geom::AngleUnit unit, double const epoch)
299  : _longitude(NaN), _latitude(NaN), _epoch(epoch) {
300  _longitude = geom::Angle(p2d.getX(), unit).wrap();
301  _latitude = geom::Angle(p2d.getY(), unit);
302  _verifyValues();
303 }
304 
305 Coord::Coord(geom::Point3D const &p3d, double const epoch, bool normalize, geom::Angle const defaultLongitude)
306  : _longitude(0. * geom::radians), _latitude(0. * geom::radians), _epoch(epoch) {
307  std::pair<geom::Angle, geom::Angle> lonLat = pointToLonLat(p3d, defaultLongitude, normalize);
308  _longitude = lonLat.first;
309  _latitude = lonLat.second;
310  _epoch = epoch;
311 }
312 
313 Coord::Coord(geom::Angle const ra, geom::Angle const dec, double const epoch)
314  : _longitude(ra.wrap()), _latitude(dec), _epoch(epoch) {
315  _verifyValues();
316 }
317 
318 Coord::Coord(std::string const ra, std::string const dec, double const epoch)
319  : _longitude(hmsStringToAngle(ra).wrap()), _latitude(dmsStringToAngle(dec)), _epoch(epoch) {
320  _verifyValues();
321 }
322 
323 Coord::Coord() : _longitude(geom::Angle(NaN)), _latitude(geom::Angle(NaN)), _epoch(NaN) {}
324 
325 void Coord::_verifyValues() const {
326  if (_latitude.asRadians() < -geom::HALFPI || _latitude.asRadians() > geom::HALFPI) {
327  throw LSST_EXCEPT(
328  ex::InvalidParameterError,
329  (boost::format("Latitude coord must be: -PI/2 <= lat <= PI/2 (%f).") % _latitude).str());
330  }
331 }
332 
333 void Coord::reset(geom::Angle const longitude, geom::Angle const latitude, double const epoch) {
334  _longitude = longitude.wrap();
335  _latitude = latitude;
336  _epoch = epoch;
337  _verifyValues();
338 }
339 
341  // treat HOURS specially, they must mean hours for RA, degrees for Dec
342  if (unit == geom::hours) {
343  return geom::Point2D(getLongitude().asHours(), getLatitude().asDegrees());
344  } else {
345  return geom::Point2D(getLongitude().asAngularUnits(unit), getLatitude().asAngularUnits(unit));
346  }
347 }
348 
350  double lng = getLongitude();
351  double lat = getLatitude();
352  double const x = std::cos(lng) * std::cos(lat);
353  double const y = std::sin(lng) * std::cos(lat);
354  double const z = std::sin(lat);
355  return geom::Point3D(x, y, z);
356 }
357 
358 Coord Coord::transform(Coord const &poleTo, Coord const &poleFrom) const {
359  double const alphaGP = poleFrom[0];
360  double const deltaGP = poleFrom[1];
361  double const lCP = poleTo[0];
362 
363  double const alpha = getLongitude();
364  double const delta = getLatitude();
365 
366  geom::Angle const l = (lCP - std::atan2(std::sin(alpha - alphaGP),
367  std::tan(delta) * std::cos(deltaGP) -
368  std::cos(alpha - alphaGP) * std::sin(deltaGP))) *
370  geom::Angle const b = std::asin((std::sin(deltaGP) * std::sin(delta) +
371  std::cos(deltaGP) * std::cos(delta) * std::cos(alpha - alphaGP))) *
373  return Coord(l, b);
374 }
375 
376 void Coord::rotate(Coord const &axis, geom::Angle const theta) {
377  double const c = std::cos(theta);
378  double const mc = 1.0 - c;
379  double const s = std::sin(theta);
380 
381  // convert to cartesian
382  geom::Point3D const x = getVector();
383  geom::Point3D const u = axis.getVector();
384  double const ux = u[0];
385  double const uy = u[1];
386  double const uz = u[2];
387 
388  // rotate
389  geom::Point3D xprime;
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];
396 
397  // in-situ
398  std::pair<geom::Angle, geom::Angle> lonLat = pointToLonLat(xprime);
399  _longitude = lonLat.first;
400  _latitude = lonLat.second;
401 }
402 
404  // let v = vector in the direction arcLen points (tangent to surface of sphere)
405  // thus: |v| = arcLen
406  // angle phi = orientation of v in a tangent plane, measured wrt to a parallel of declination
407 
408  // To do the rotation, use rotate() method.
409  // - must provide an axis of rotation: take the cross product r x v to get that axis (pole)
410 
411  // get the vector r
412  Eigen::Vector3d r = getVector().asEigen();
413 
414  // Get the vector v:
415  // let u = unit vector lying on a parallel of declination
416  // let w = unit vector along line of longitude = r x u
417  // the vector v must satisfy the following:
418  // |v| = arcLen
419  // r . v = 0
420  // u . v = |v| cos(phi) = arcLen*cos(phi)
421  // w . v = |v| sin(phi) = arcLen*sin(phi)
422 
423  // v is a linear combination of u and w
424  // v = arcLen*cos(phi)*u + arcLen*sin(phi)*w
425 
426  // Thus, we must:
427  // - create u vector
428  // - solve w vector (r cross u)
429  // - compute v
430  Eigen::Vector3d u;
431  u << -std::sin(getLongitude()), std::cos(getLongitude()), 0.0;
432  Eigen::Vector3d w = r.cross(u);
433  Eigen::Vector3d v = arcLen * std::cos(phi) * u + arcLen * std::sin(phi) * w;
434 
435  // take r x v to get the axis
436  Eigen::Vector3d axisVector = r.cross(v);
437  axisVector.normalize();
438  Coord axisCoord = Coord(geom::Point3D(axisVector), getEpoch());
439 
440  rotate(axisCoord, arcLen);
441 
442  // now get the position angle at our destination
443  // u2 . v2 = arcLen*cos(phi2)
444  // w2 . v2 = arcLen*sin(phi2)
445  // if we normalize v2:
446  // phi2 = atan2(w2.v2, u2.v2)
447  //
448  // we need to compute u2, and then rotate v (exactly as we rotated r) to get v2
449  Eigen::Vector3d r2 = getVector().asEigen();
450  Eigen::Vector3d u2;
451  u2 << -std::sin(getLongitude()), std::cos(getLongitude()), 0.0;
452  Eigen::Vector3d w2 = r2.cross(u2);
453 
454  // make v a unit vector and rotate v exactly as we rotated r
455  v.normalize();
456  Coord v2Coord = Coord(geom::Point3D(v), getEpoch());
457  v2Coord.rotate(axisCoord, arcLen);
458  Eigen::Vector3d v2 = v2Coord.getVector().asEigen();
459 
460  geom::Angle phi2 = std::atan2(w2.dot(v2), u2.dot(v2)) * geom::radians;
461 
462  return phi2;
463 }
464 
465 std::shared_ptr<Coord> Coord::convert(CoordSystem system, double epoch) const {
466  switch (system) {
467  case FK5: {
468  Fk5Coord c1 = this->toFk5(epoch);
469  return std::shared_ptr<Fk5Coord>(
470  new Fk5Coord(c1.getLongitude(), c1.getLatitude(), c1.getEpoch()));
471  } break;
472  case ICRS: {
473  IcrsCoord c2 = this->toIcrs();
474  return std::shared_ptr<IcrsCoord>(new IcrsCoord(c2.getLongitude(), c2.getLatitude()));
475  } break;
476  case GALACTIC: {
477  GalacticCoord c4 = this->toGalactic();
478  return std::shared_ptr<GalacticCoord>(new GalacticCoord(c4.getLongitude(), c4.getLatitude()));
479  } break;
480  case ECLIPTIC: {
481  EclipticCoord c5 = this->toEcliptic(epoch);
482  return std::shared_ptr<EclipticCoord>(
483  new EclipticCoord(c5.getLongitude(), c5.getLatitude(), c5.getEpoch()));
484  } break;
485  case TOPOCENTRIC:
486  throw LSST_EXCEPT(ex::InvalidParameterError,
487  "Cannot make Topocentric with convert() (must also specify Observatory).\n"
488  "Instantiate TopocentricCoord() directly.");
489  break;
490  case UNKNOWN:
491  throw LSST_EXCEPT(ex::InvalidParameterError, "Cannot convert to UNKNOWN coordinate system");
492  break;
493  default:
494  throw LSST_EXCEPT(ex::InvalidParameterError,
495  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC allowed.");
496  break;
497  }
498 }
499 
501  // work in Fk5, no matter what two derived classes we're given (eg Fk5 and Galactic)
502  // we'll put them in the same system.
503  std::pair<Fk5Coord, Fk5Coord> const &fk5 = commonFk5(*this, c);
504  geom::Angle const alpha1 = fk5.first.getRa();
505  geom::Angle const delta1 = fk5.first.getDec();
506  geom::Angle const alpha2 = fk5.second.getRa();
507  geom::Angle const delta2 = fk5.second.getDec();
508 
509  return haversine(alpha1 - alpha2, delta1 - delta2, std::cos(delta1), std::cos(delta2));
510 }
511 
512 std::pair<geom::Angle, geom::Angle> Coord::getOffsetFrom(Coord const &c) const {
513  // work in Fk5, no matter what two derived classes we're given (eg Fk5 and Galactic)
514  // we'll put them in the same system.
515  std::pair<Fk5Coord, Fk5Coord> const &fk5 = commonFk5(*this, c);
516  geom::Angle const alpha1 = fk5.first.getRa();
517  geom::Angle const delta1 = fk5.first.getDec();
518  geom::Angle const alpha2 = fk5.second.getRa();
519  geom::Angle const delta2 = fk5.second.getDec();
520 
521  geom::Angle const dAlpha = alpha1 - alpha2;
522  geom::Angle const dDelta = delta1 - delta2;
523 
524  double const cosDelta1 = std::cos(delta1);
525  double const cosDelta2 = std::cos(delta2);
526 
527  geom::Angle separation = haversine(dAlpha, dDelta, cosDelta1, cosDelta2);
528 
529  // Formula from http://www.movable-type.co.uk/scripts/latlong.html
530  double const y = std::sin(dAlpha) * cosDelta2;
531  double const x = cosDelta1 * std::sin(delta2) - std::sin(delta1) * cosDelta2 * std::cos(dAlpha);
532  geom::Angle bearing = std::atan2(y, x) * geom::radians - 90.0 * geom::degrees;
533 
534  return std::make_pair(bearing, separation);
535 }
536 
537 std::pair<geom::Angle, geom::Angle> Coord::getTangentPlaneOffset(Coord const &c) const {
538  // work in Fk5, no matter what two derived classes we're given (eg Fk5 and Galactic)
539  // we'll put them in the same system.
540  std::pair<Fk5Coord, Fk5Coord> const &fk5 = commonFk5(*this, c);
541  geom::Angle const alpha1 = fk5.first.getRa();
542  geom::Angle const delta1 = fk5.first.getDec();
543  geom::Angle const alpha2 = fk5.second.getRa();
544  geom::Angle const delta2 = fk5.second.getDec();
545 
546  // This is a projection of coord2 to the tangent plane at coord1
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);
553 
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;
557 
558  return std::make_pair(xi * geom::radians, eta * geom::radians);
559 }
560 
561 Fk5Coord Coord::toFk5(double const epoch) const {
562  return Fk5Coord(getLongitude(), getLatitude(), getEpoch()).precess(epoch);
563 }
565 
566 IcrsCoord Coord::toIcrs() const { return this->toFk5().toIcrs(); }
567 
568 GalacticCoord Coord::toGalactic() const { return this->toFk5().toGalactic(); }
569 
570 EclipticCoord Coord::toEcliptic(double const epoch) const { return this->toFk5(epoch).toEcliptic(); }
571 EclipticCoord Coord::toEcliptic() const { return this->toFk5().toEcliptic(); }
572 
574  lsst::daf::base::DateTime const &obsDate) const {
575  return this->toFk5().toTopocentric(obs, obsDate);
576 }
577 
578 /* ============================================================
579  *
580  * class Fk5Coord
581  *
582  * ============================================================*/
583 
584 Fk5Coord Fk5Coord::toFk5(double const epoch) const {
585  return Fk5Coord(getLongitude(), getLatitude(), getEpoch()).precess(epoch);
586 }
588 
590  // only do the precession to 2000 if we're not already there.
591  if (fabs(getEpoch() - 2000.0) > epochTolerance) {
592  Fk5Coord c = precess(2000.0);
593  return IcrsCoord(c.getLongitude(), c.getLatitude());
594  } else {
595  return IcrsCoord(getLongitude(), getLatitude());
596  }
597 }
598 
600  // if we're epoch==2000, we can transform, otherwise we need to precess first
601  Fk5Coord c;
602  if (fabs(getEpoch() - 2000.0) > epochTolerance) {
603  c = precess(2000.0);
604  } else {
605  c = *this;
606  }
607 
608  Coord ct = c.transform(Fk5PoleInGalactic(), GalacticPoleInFk5());
609  return GalacticCoord(ct.getLongitude(), ct.getLatitude());
610 }
611 
612 EclipticCoord Fk5Coord::toEcliptic(double const epoch) const {
613  geom::Angle const eclPoleIncl = eclipticPoleInclination(epoch);
614  Coord const eclPoleInEquatorial(270.0 * geom::degrees, (90.0 * geom::degrees) - eclPoleIncl, epoch);
615  Coord const equPoleInEcliptic(90.0 * geom::degrees, (90.0 * geom::degrees) - eclPoleIncl, epoch);
616  Coord c = transform(equPoleInEcliptic, eclPoleInEquatorial);
617  return EclipticCoord(c.getLongitude(), c.getLatitude(), epoch);
618 }
620 
622  lsst::daf::base::DateTime const &obsDate) const {
623  // make sure we precess to the epoch
624  Fk5Coord fk5 = precess(obsDate.get(dafBase::DateTime::EPOCH));
625 
626  // greenwich sidereal time
627  geom::Angle theta0 = meanSiderealTimeGreenwich(obsDate.get(dafBase::DateTime::JD)).wrap();
628 
629  // lat/long of the observatory
630  geom::Angle const phi = obs.getLatitude();
631  geom::Angle const L = obs.getLongitude();
632 
633  // ra/dec of the target
634  geom::Angle const alpha = fk5.getRa();
635  geom::Angle const delta = fk5.getDec();
636 
637  geom::Angle const H = theta0 + L - alpha;
638 
639  // compute the altitude, h
640  double const sinh = std::sin(phi) * std::sin(delta) + std::cos(phi) * std::cos(delta) * std::cos(H);
641  geom::Angle const h = std::asin(sinh) * geom::radians;
642 
643  // compute the azimuth, A
644  double const tanAnumerator = std::sin(H);
645  double const tanAdenominator = (std::cos(H) * std::sin(phi) - std::tan(delta) * std::cos(phi));
646 
647  // Equations used here assume azimuth is with respect to South
648  // but we use the North as our origin ... must add 180 deg
649  geom::Angle A = ((180.0 * geom::degrees) + atan2(tanAnumerator, tanAdenominator) * geom::radians).wrap();
650 
651  return TopocentricCoord(A, h, obsDate.get(dafBase::DateTime::EPOCH), obs);
652 }
653 
654 Fk5Coord Fk5Coord::precess(double const epochTo) const {
655  // return a copy if the epochs are the same
656  if (fabs(getEpoch() - epochTo) < epochTolerance) {
657  return Fk5Coord(getLongitude(), getLatitude(), getEpoch());
658  }
659 
660  dafBase::DateTime const dateFrom(getEpoch(), dafBase::DateTime::EPOCH, dafBase::DateTime::TAI);
661  dafBase::DateTime const dateTo(epochTo, dafBase::DateTime::EPOCH, dafBase::DateTime::TAI);
662  double const jd0 = dateFrom.get(dafBase::DateTime::JD);
663  double const jd = dateTo.get(dafBase::DateTime::JD);
664 
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;
669 
670  geom::Angle const xi = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (0.30188 - 0.000344 * T) * tt +
671  0.017998 * ttt) *
673  geom::Angle const z = ((2306.2181 + 1.39656 * T - 0.000139 * T * T) * t + (1.09468 + 0.000066 * T) * tt +
674  0.018203 * ttt) *
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) *
679 
680  Fk5Coord fk5 = this->toFk5();
681  geom::Angle const alpha0 = fk5.getRa();
682  geom::Angle const delta0 = fk5.getDec();
683 
684  double const a = std::cos(delta0) * std::sin((alpha0 + xi));
685  double const b =
686  std::cos(theta) * std::cos(delta0) * std::cos((alpha0 + xi)) - std::sin(theta) * std::sin(delta0);
687  double const c =
688  std::sin(theta) * std::cos(delta0) * std::cos((alpha0 + xi)) + std::cos(theta) * std::sin(delta0);
689 
690  geom::Angle const alpha = (std::atan2(a, b) + z) * geom::radians;
691  geom::Angle const delta = std::asin(c) * geom::radians;
692 
693  return Fk5Coord(alpha, delta, epochTo);
694 }
695 
696 /* ============================================================
697  *
698  * class IcrsCoord
699  *
700  * ============================================================*/
701 
703  Coord::reset(longitude, latitude, 2000.0);
704 }
705 
706 Fk5Coord IcrsCoord::toFk5(double const epoch) const {
707  return Fk5Coord(getLongitude(), getLatitude(), 2000.0).precess(epoch);
708 }
709 Fk5Coord IcrsCoord::toFk5() const { return Fk5Coord(getLongitude(), getLatitude(), 2000.0); }
710 
712 
713 std::string IcrsCoord::toString() const {
714  return (boost::format("%s(%.7f, %.7f)") % getClassName() % (*this)[0].asDegrees() %
715  (*this)[1].asDegrees())
716  .str();
717 }
718 
719 /* ============================================================
720  *
721  * class GalacticCoord
722  *
723  * ============================================================*/
724 
725 void GalacticCoord::reset(geom::Angle const longitudeDeg, geom::Angle const latitudeDeg) {
726  Coord::reset(longitudeDeg, latitudeDeg, 2000.0);
727 }
728 
729 Fk5Coord GalacticCoord::toFk5(double const epoch) const {
730  // transform to fk5
731  // galactic coords are ~constant, and the poles used are for epoch=2000, so we get J2000
732  Coord c = transform(GalacticPoleInFk5(), Fk5PoleInGalactic());
733  return Fk5Coord(c.getLongitude(), c.getLatitude(), 2000.0).precess(epoch);
734 }
735 Fk5Coord GalacticCoord::toFk5() const { return this->toFk5(2000.0); }
736 
738 
739 std::string GalacticCoord::toString() const {
740  return (boost::format("%s(%.7f, %.7f)") % getClassName() % (*this)[0].asDegrees() %
741  (*this)[1].asDegrees())
742  .str();
743 }
744 
745 /* ============================================================
746  *
747  * class EclipticCoord
748  *
749  * ============================================================*/
750 
751 EclipticCoord EclipticCoord::toEcliptic(double const epoch) const {
752  return EclipticCoord(getLongitude(), getLatitude(), getEpoch()).precess(epoch);
753 }
756 }
757 
758 Fk5Coord EclipticCoord::toFk5(double const epoch) const {
759  geom::Angle const eclPoleIncl = eclipticPoleInclination(epoch);
760  geom::Angle ninety = 90. * geom::degrees;
761  Coord const eclipticPoleInFk5(270.0 * geom::degrees, ninety - eclPoleIncl, epoch);
762  Coord const fk5PoleInEcliptic(ninety, ninety - eclPoleIncl, epoch);
763  Coord c = transform(eclipticPoleInFk5, fk5PoleInEcliptic);
764  return Fk5Coord(c.getLongitude(), c.getLatitude(), epoch);
765 }
766 Fk5Coord EclipticCoord::toFk5() const { return this->toFk5(getEpoch()); }
767 
768 EclipticCoord EclipticCoord::precess(double const epochTo) const {
769  return this->toFk5().precess(epochTo).toEcliptic();
770 }
771 
772 /* ============================================================
773  *
774  * class TopocentricCoord
775  *
776  * ============================================================*/
777 
778 Fk5Coord TopocentricCoord::toFk5(double const epoch) const {
779  geom::Angle const phi = _obs.getLatitude();
780  geom::Angle const L = _obs.getLongitude();
781 
782  // Equations used here assume azimuth is with respect to South
783  // but we use the North as our origin.
784  geom::Angle A = (getAzimuth() + 180.0 * geom::degrees).wrap();
785  geom::Angle const h = getAltitude();
786 
787  double const jd = dafBase::DateTime(epoch, dafBase::DateTime::EPOCH, dafBase::DateTime::TAI)
788  .get(dafBase::DateTime::JD);
789  geom::Angle theta0 = meanSiderealTimeGreenwich(jd).wrap();
790 
791  double const tanHnum = std::sin(A);
792  double const tanHdenom = std::cos(A) * std::sin(phi) + std::tan(h) * std::cos(phi);
793  geom::Angle H = std::atan2(tanHnum, tanHdenom) * geom::radians;
794 
795  geom::Angle const alpha = theta0 + L - H;
796  double const sinDelta = std::sin(phi) * std::sin(h) - std::cos(phi) * std::cos(h) * std::cos(A);
797  geom::Angle const delta = (std::asin(sinDelta)) * geom::radians;
798 
799  return Fk5Coord(alpha, delta, epoch);
800 }
801 Fk5Coord TopocentricCoord::toFk5() const { return this->toFk5(getEpoch()); }
802 
804  lsst::daf::base::DateTime const &date) const {
805  if (obs != _obs) {
806  throw LSST_EXCEPT(ex::InvalidParameterError,
807  (boost::format("Expected observatory %s, saw %s") % _obs % obs).str());
808  }
809  if (fabs(date.get() - getEpoch()) > std::numeric_limits<double>::epsilon()) {
810  throw LSST_EXCEPT(ex::InvalidParameterError,
811  (boost::format("Expected date %g, saw %g") % getEpoch() % date.get()).str());
812  }
813 
814  return TopocentricCoord(getLongitude(), getLatitude(), getEpoch(), _obs);
815 }
816 
818  return TopocentricCoord(getLongitude(), getLatitude(), getEpoch(), _obs);
819 }
820 
821 std::string TopocentricCoord::toString() const {
822  return (boost::format("%s(%.7f, %.7f, %.12f, (%s))") % getClassName() % (*this)[0].asDegrees() %
823  (*this)[1].asDegrees() % getEpoch() % getObservatory())
824  .str();
825 }
826 
827 /* ===============================================================================
828  *
829  * Factory function definitions:
830  *
831  * Each makeCoord() function has overloaded variants with and without epoch specified.
832  * It was tempting to specify default values, but some coordinate systems have
833  * no epoch, and this would be confusing to the user. In its current form,
834  * any epochless coordinate system requested with an epoch specified will throw an exception.
835  * The epochless factories will always work, but assume default epoch = 2000.
836  *
837  * ===============================================================================
838  */
839 
840 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Angle const ra, geom::Angle const dec,
841  double const epoch) {
842  switch (system) {
843  case FK5:
844  return std::shared_ptr<Fk5Coord>(new Fk5Coord(ra, dec, epoch));
845  break;
846  case ICRS:
847  throw LSST_EXCEPT(ex::InvalidParameterError,
848  "ICRS has no epoch, use overloaded makeCoord with args (system, ra, dec).");
849  break;
850  case GALACTIC:
851  throw LSST_EXCEPT(ex::InvalidParameterError,
852  "Galactic has no epoch, use overloaded makeCoord with (system, ra, dec).");
853  break;
854  case ECLIPTIC:
855  return std::shared_ptr<EclipticCoord>(new EclipticCoord(ra, dec, epoch));
856  break;
857  case TOPOCENTRIC:
858  throw LSST_EXCEPT(ex::InvalidParameterError,
859  "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n"
860  "Instantiate TopocentricCoord() directly.");
861  break;
862  default:
863  throw LSST_EXCEPT(
864  ex::InvalidParameterError,
865  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
866  break;
867  }
868 }
869 
870 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Angle const ra, geom::Angle const dec) {
871  switch (system) {
872  case FK5:
873  return std::shared_ptr<Fk5Coord>(new Fk5Coord(ra, dec, 2000.0));
874  break;
875  case ICRS:
876  return std::shared_ptr<IcrsCoord>(new IcrsCoord(ra, dec));
877  break;
878  case GALACTIC:
879  return std::shared_ptr<GalacticCoord>(new GalacticCoord(ra, dec));
880  break;
881  case ECLIPTIC:
882  return std::shared_ptr<EclipticCoord>(new EclipticCoord(ra, dec, 2000.0));
883  break;
884  case TOPOCENTRIC:
885  throw LSST_EXCEPT(ex::InvalidParameterError,
886  "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n"
887  "Instantiate TopocentricCoord() directly.");
888  break;
889  default:
890  throw LSST_EXCEPT(
891  ex::InvalidParameterError,
892  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, and TOPOCENTRIC allowed.");
893  break;
894  }
895 }
896 
897 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point3D const &p3d, double const epoch,
898  bool normalize, geom::Angle const defaultLongitude) {
899  Coord c(p3d, 2000.0, normalize, defaultLongitude);
900  return makeCoord(system, c.getLongitude(), c.getLatitude(), epoch);
901 }
902 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point3D const &p3d, bool normalize,
903  geom::Angle const defaultLongitude) {
904  Coord c(p3d, 2000.0, normalize, defaultLongitude);
905  return makeCoord(system, c.getLongitude(), c.getLatitude());
906 }
907 
908 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point2D const &p2d, geom::AngleUnit unit,
909  double const epoch) {
910  if (unit == geom::hours) {
911  return makeCoord(system, geom::Angle(p2d.getX(), geom::hours), geom::Angle(p2d.getY(), geom::degrees),
912  epoch);
913  } else {
914  return makeCoord(system, geom::Angle(p2d.getX(), unit), geom::Angle(p2d.getY(), unit), epoch);
915  }
916 }
917 
918 std::shared_ptr<Coord> makeCoord(CoordSystem const system, geom::Point2D const &p2d, geom::AngleUnit unit) {
919  if (unit == geom::hours) {
920  return makeCoord(system, geom::Angle(p2d.getX(), geom::hours),
921  geom::Angle(p2d.getY(), geom::degrees));
922  } else {
923  return makeCoord(system, geom::Angle(p2d.getX(), unit), geom::Angle(p2d.getY(), unit));
924  }
925 }
926 
927 std::shared_ptr<Coord> makeCoord(CoordSystem const system, std::string const ra, std::string const dec,
928  double const epoch) {
929  return makeCoord(system, dmsStringToAngle(ra), dmsStringToAngle(dec), epoch);
930 }
931 std::shared_ptr<Coord> makeCoord(CoordSystem const system, std::string const ra, std::string const dec) {
932  return makeCoord(system, dmsStringToAngle(ra), dmsStringToAngle(dec));
933 }
934 
935 std::shared_ptr<Coord> makeCoord(CoordSystem const system) {
936  switch (system) {
937  case FK5:
938  return std::shared_ptr<Fk5Coord>(new Fk5Coord());
939  break;
940  case ICRS:
941  return std::shared_ptr<IcrsCoord>(new IcrsCoord());
942  break;
943  case GALACTIC:
944  return std::shared_ptr<GalacticCoord>(new GalacticCoord());
945  break;
946  case ECLIPTIC:
947  return std::shared_ptr<EclipticCoord>(new EclipticCoord());
948  break;
949  case TOPOCENTRIC:
950  throw LSST_EXCEPT(ex::InvalidParameterError,
951  "Cannot make Topocentric with makeCoord() (must also specify Observatory).\n"
952  "Instantiate TopocentricCoord() directly.");
953  break;
954  default:
955  throw LSST_EXCEPT(ex::InvalidParameterError,
956  "Undefined CoordSystem: only FK5, ICRS, GALACTIC, ECLIPTIC, allowed.");
957  break;
958  }
959 }
960 
961 std::string Coord::toString() const {
962  return (boost::format("%s(%.7f, %.7f, %.2f)") % getClassName() % (*this)[0].asDegrees() %
963  (*this)[1].asDegrees() % getEpoch())
964  .str();
965 }
966 
967 std::ostream &operator<<(std::ostream &os, Coord const &coord) {
968  os << coord.toString();
969  return os;
970 }
971 
972 namespace {
973 
974 // Heavy lifting for averageCoord
975 std::shared_ptr<Coord> doAverageCoord(std::vector<std::shared_ptr<Coord const>> const coords,
976  CoordSystem system) {
977  assert(system != UNKNOWN); // Handled by caller
978  assert(coords.size() > 0); // Handled by caller
979  geom::Point3D sum(0, 0, 0);
980  geom::Point3D corr(0, 0, 0); // Kahan summation correction
981  for (auto &&cc : coords) {
982  geom::Point3D const point = cc->getVector();
983  // Kahan summation
984  geom::Extent3D const add = point - corr;
985  geom::Point3D const temp = sum + add;
986  corr = (temp - geom::Extent3D(sum)) - add;
987  sum = temp;
988  }
989  sum.scale(1.0 / coords.size());
990  return makeCoord(system, sum);
991 }
992 
993 } // anonymous namespace
994 
995 std::shared_ptr<Coord> averageCoord(std::vector<std::shared_ptr<Coord const>> const coords,
996  CoordSystem system) {
997  if (coords.size() == 0) {
998  throw LSST_EXCEPT(ex::LengthError, "No coordinates provided to average");
999  }
1000 
1001  if (system == UNKNOWN) {
1002  // Determine which system we're using, and check that every coordinate is in that system
1003  system = coords[0]->getCoordSystem();
1004  for (auto &&cc : coords) {
1005  if (cc->getCoordSystem() != system) {
1006  throw LSST_EXCEPT(ex::InvalidParameterError,
1007  (boost::format("Coordinates are not all in the same system: %d vs %d") %
1008  cc->getCoordSystem() %
1009  system).str());
1010  }
1011  }
1012  return doAverageCoord(coords, system);
1013  }
1014 
1015  // Convert everything to the nominated coordinate system if necessary
1016  std::vector<std::shared_ptr<Coord const>> converted;
1017  converted.reserve(coords.size());
1018  for (auto &&cc : coords) {
1019  converted.push_back(cc->getCoordSystem() == system ? cc : cc->convert(system));
1020  }
1021  return doAverageCoord(converted, system);
1022 }
1023 }
1024 }
1025 } // 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:840
virtual std::string getClassName() const
Definition: Coord.h:554
virtual GalacticCoord toGalactic() const
Convert ourself to Galactic: l, b.
Definition: Coord.cc:599
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:725
virtual Fk5Coord toFk5() const
Convert outself from Topocentric to Fk5 (use current epoch)
Definition: Coord.cc:801
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:713
void scale(double factor)
Definition: Point.h:118
table::Key< geom::Angle > longitude
Definition: VisitInfo.cc:166
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:284
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:621
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:537
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:340
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:766
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:403
virtual GalacticCoord toGalactic() const
Convert ourself to Galactic: l, b.
Definition: Coord.cc:568
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:286
virtual EclipticCoord toEcliptic(double const epoch) const
Convert ourself to Ecliptic: lambda, beta (precess to new epoch)
Definition: Coord.cc:612
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:702
virtual std::string toString() const
Get string representation.
Definition: Coord.cc:821
virtual Fk5Coord toFk5() const
Convert ourself from galactic to Fk5 (no epoch specified)
Definition: Coord.cc:735
virtual Fk5Coord toFk5() const
Convert ourself to Fk5 (ie.
Definition: Coord.cc:587
virtual std::string toString() const
Get string representation.
Definition: Coord.cc:961
virtual Fk5Coord toFk5() const
Convert ourself to Fk5: RA, Dec (use current epoch)
Definition: Coord.cc:564
virtual IcrsCoord toIcrs() const
Convert ourself to ICRS: RA, Dec (basically J2000)
Definition: Coord.cc:589
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:465
EclipticCoord precess(double const epochTo) const
precess to new epoch
Definition: Coord.cc:768
virtual TopocentricCoord toTopocentric() const
Convert ourself from Topocentric to Topocentric with no observatory or date arguments.
Definition: Coord.cc:817
Coord transform(Coord const &poleTo, Coord const &poleFrom) const
Transform our current coords to another spherical polar system.
Definition: Coord.cc:358
std::ostream & operator<<(std::ostream &os, Coord const &coord)
Definition: Coord.cc:967
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:376
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:500
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:165
virtual GalacticCoord toGalactic() const
Convert ourself from Galactic to Galactic ...
Definition: Coord.cc:737
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:249
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:251
lsst::afw::geom::Point3D getVector() const
Return our contents in a position vector.
Definition: Coord.cc:349
Fk5Coord precess(double const epochTo) const
Precess ourselves from whence we are to a new epoch.
Definition: Coord.cc:654
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:739
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:566
Coord()
Default constructor for the Coord base class.
Definition: Coord.cc:323
lsst::afw::geom::Angle hmsStringToAngle(std::string const hms)
Convert a hh:mm:ss string to Angle.
Definition: Coord.cc:282
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:995
std::pair< lsst::afw::geom::Angle, lsst::afw::geom::Angle > getOffsetFrom(Coord const &c) const
Compute the offset from a coordinate.
Definition: Coord.cc:512
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:573
virtual IcrsCoord toIcrs() const
Icrs converter for IcrsCoord.
Definition: Coord.cc:711
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:619
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:571
virtual EclipticCoord toEcliptic() const
Convert ourself from Ecliptic to Ecliptic ...
Definition: Coord.cc:754
virtual Fk5Coord toFk5() const
Fk5 converter for IcrsCoord.
Definition: Coord.cc:709