LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Endpoint.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include <ostream>
24 #include <sstream>
25 #include <string>
26 #include <memory>
27 #include <vector>
28 
29 #include "astshim.h"
30 #include "lsst/geom/Point.h"
31 #include "lsst/geom/SpherePoint.h"
32 #include "lsst/afw/geom/Endpoint.h"
33 
34 namespace lsst {
35 namespace afw {
36 namespace geom {
37 namespace {
38 
39 /*
40 Get a pointer to a frame
41 
42 If frame is a FrameSet then return a copy of its current frame, else return the original argument
43 */
45  auto frameSetPtr = std::dynamic_pointer_cast<ast::FrameSet>(framePtr);
46  if (frameSetPtr) {
47  return frameSetPtr->getFrame(ast::FrameSet::CURRENT);
48  }
49  return framePtr;
50 }
51 
52 } // namespace
53 
54 template <typename Point, typename Array>
55 BaseEndpoint<Point, Array>::BaseEndpoint(int nAxes) : _nAxes(nAxes) {
56  if (nAxes <= 0) {
58  "nAxes = " + std::to_string(nAxes) + "; must be > 0");
59  }
60 }
61 
62 template <typename Point, typename Array>
63 bool BaseEndpoint<Point, Array>::operator==(BaseEndpoint const& other) const noexcept {
64  return this->getNAxes() == other.getNAxes() && typeid(*this) == typeid(other);
65 }
66 
67 template <typename Point, typename Array>
69  return std::make_shared<ast::Frame>(getNAxes());
70 }
71 
72 template <typename Point, typename Array>
74  if (nAxes != this->getNAxes()) {
76  os << "number of axes provided " << nAxes << " != " << this->getNAxes() << " required";
77  throw std::invalid_argument(os.str());
78  }
79 }
80 
81 template <typename Point>
83  return arr.size();
84 }
85 
87  this->_assertNAxes(_getNAxes(point));
88  return point;
89 }
90 
91 ndarray::Array<double, 2, 2> GenericEndpoint::dataFromArray(Array const& arr) const {
92  this->_assertNAxes(_getNAxes(arr));
93  return ndarray::copy(arr);
94 }
95 
97  this->_assertNAxes(data.size());
98  return data;
99 }
100 
101 ndarray::Array<double, 2, 2> GenericEndpoint::arrayFromData(ndarray::Array<double, 2, 2> const& data) const {
102  this->_assertNAxes(_getNAxes(data));
103  return ndarray::copy(data);
104 }
105 
107  if (nAxes != 2) {
109  os << "nAxes = " << nAxes << " != 2";
111  }
112 }
113 
115  const int nAxes = this->getNAxes();
117  for (int axInd = 0; axInd < nAxes; ++axInd) {
118  result[axInd] = point[axInd];
119  }
120  return result;
121 }
122 
123 ndarray::Array<double, 2, 2> Point2Endpoint::dataFromArray(Array const& arr) const {
124  const int nAxes = this->getNAxes();
125  const int nPoints = this->getNPoints(arr);
126  ndarray::Array<double, 2, 2> data = ndarray::allocate(ndarray::makeVector(nAxes, nPoints));
127  auto dataColIter = data.transpose().begin();
128  for (auto const& point : arr) {
129  for (int axInd = 0; axInd < nAxes; ++axInd) {
130  (*dataColIter)[axInd] = point[axInd];
131  }
132  ++dataColIter;
133  }
134  return data;
135 }
136 
138  const int nAxes = this->getNAxes();
139  this->_assertNAxes(this->_getNAxes(data));
140  Point result;
141  for (int axInd = 0; axInd < nAxes; ++axInd) {
142  result[axInd] = data[axInd];
143  }
144  return result;
145 }
146 
148  ndarray::Array<double, 2, 2> const& data) const {
149  this->_assertNAxes(this->_getNAxes(data));
150  int const nPoints = this->_getNPoints(data);
151  Array array;
152  array.reserve(nPoints);
153  for (auto const& dataCol : data.transpose()) {
154  array.emplace_back(dataCol[0], dataCol[1]);
155  }
156  return array;
157 }
158 
160  // use getCurrentFrame because if framePtr points to a FrameSet we want the name of its current frame
161  std::string className = getCurrentFrame(framePtr)->getClassName();
162  if (className != "Frame") {
164  os << "frame is a " << className << ", not a Frame";
166  }
167 }
168 
170  if (nAxes != 2) {
172  os << "nAxes = " << nAxes << " != 2";
174  }
175 }
176 
178  const int nAxes = this->getNAxes();
180  for (int axInd = 0; axInd < nAxes; ++axInd) {
181  result[axInd] = point[axInd].asRadians();
182  }
183  return result;
184 }
185 
186 ndarray::Array<double, 2, 2> SpherePointEndpoint::dataFromArray(Array const& arr) const {
187  const int nAxes = this->getNAxes();
188  const int nPoints = this->getNPoints(arr);
189  ndarray::Array<double, 2, 2> data = ndarray::allocate(ndarray::makeVector(nAxes, nPoints));
190  auto dataColIter = data.transpose().begin();
191  for (auto const& point : arr) {
192  for (int axInd = 0; axInd < nAxes; ++axInd) {
193  (*dataColIter)[axInd] = point[axInd].asRadians();
194  }
195  ++dataColIter;
196  }
197  return data;
198 }
199 
201  this->_assertNAxes(this->_getNAxes(data));
203 }
204 
206  ndarray::Array<double, 2, 2> const& data) const {
207  this->_assertNAxes(this->_getNAxes(data));
208  int const nPoints = this->_getNPoints(data);
209  Array array;
210  array.reserve(nPoints);
211  for (auto const& dataCol : data.transpose()) {
212  array.emplace_back(lsst::geom::SpherePoint(dataCol[0], dataCol[1], lsst::geom::radians));
213  }
214  return array;
215 }
216 
218  return std::make_shared<ast::SkyFrame>();
219 }
220 
222  // use getCurrentFrame because if framePtr points to a FrameSet we want its current frame
223  auto currentFramePtr = getCurrentFrame(framePtr);
224  auto skyFramePtr = std::dynamic_pointer_cast<ast::SkyFrame>(currentFramePtr);
225  if (!skyFramePtr) {
227  os << "frame is a " << currentFramePtr->getClassName() << ", not a SkyFrame";
229  }
230  if (skyFramePtr->getLonAxis() != 1) {
231  // axes are swapped to Lat, Lon; swap them back to the usual Lon, Lat
232  // warning: be sure to call permAxes on the original framePtr argument,
233  // as otherwise it will have no effect if framePtr points to a FrameSet
234  std::vector<int> perm = {2, 1};
235  framePtr->permAxes(perm);
236  }
237 }
238 
240  os << "GenericEndpoint(" << endpoint.getNAxes() << ")";
241  return os;
242 }
243 
245  os << "Point2Endpoint()";
246  return os;
247 }
248 
250  os << "SpherePointEndpoint()";
251  return os;
252 }
253 
254 // explicit instantiations
255 template class BaseEndpoint<std::vector<double>, ndarray::Array<double, 2, 2>>;
256 template class BaseEndpoint<lsst::geom::Point2D, std::vector<lsst::geom::Point2D>>;
257 template class BaseEndpoint<lsst::geom::SpherePoint, std::vector<lsst::geom::SpherePoint>>;
258 
259 template class BaseVectorEndpoint<lsst::geom::Point2D>;
260 template class BaseVectorEndpoint<lsst::geom::SpherePoint>;
261 
262 } // namespace geom
263 } // namespace afw
264 } // namespace lsst
py::object result
Definition: _schema.cc:429
char * data
Definition: BaseRecord.cc:61
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
std::ostream * os
Definition: Schema.cc:557
void permAxes(std::vector< int > perm)
Permute the order in which a Frame's axes occur.
Definition: Frame.h:1138
static constexpr int CURRENT
index of current frame
Definition: FrameSet.h:105
Virtual base class for endpoints, which are helper classes for Transform.
Definition: Endpoint.h:67
int _getNPoints(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:183
virtual std::shared_ptr< ast::Frame > makeFrame() const
Create a Frame that can be used with this end point in a Transform.
Definition: Endpoint.cc:68
BaseEndpoint(BaseEndpoint const &)=default
virtual bool operator==(BaseEndpoint const &other) const noexcept
Determine whether two endpoints represent the same conversion.
Definition: Endpoint.cc:63
void _assertNAxes(int nAxes) const
Definition: Endpoint.cc:73
int _getNAxes(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:177
Base class for endpoints with Array = std::vector<Point> where Point has 2 dimensions.
Definition: Endpoint.h:195
int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.cc:82
A generic endpoint for data in the format used by ast::Mapping.
Definition: Endpoint.h:226
std::vector< double > dataFromPoint(Point const &point) const override
Definition: Endpoint.cc:86
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:101
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:96
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Definition: Endpoint.cc:91
An endpoint for lsst::geom::Point2D.
Definition: Endpoint.h:261
Point2Endpoint()
Construct a Point2Endpoint.
Definition: Endpoint.h:271
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Get raw data from an array of points.
Definition: Endpoint.cc:123
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:114
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:137
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:147
void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a Frame, not a subclass.
Definition: Endpoint.cc:159
An endpoint for lsst::geom::SpherePoint.
Definition: Endpoint.h:315
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Get raw data from an array of points.
Definition: Endpoint.cc:186
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:177
SpherePointEndpoint()
Construct a SpherePointEndpoint.
Definition: Endpoint.h:325
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:205
std::shared_ptr< ast::Frame > makeFrame() const override
Create a Frame that can be used with this end point in a Transform.
Definition: Endpoint.cc:217
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:200
void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a SkyFrame and set longitude axis to 0, latitude to 1.
Definition: Endpoint.cc:221
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
Reports invalid arguments.
Definition: Runtime.h:66
std::ostream & operator<<(std::ostream &os, GenericEndpoint const &endpoint)
Print "GenericEndpoint(_n_)" to the ostream where _n_ is the number of axes, e.g. "GenericAxes(4)".
Definition: Endpoint.cc:239
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:34
Point< double, 2 > Point2D
Definition: Point.h:324
constexpr AngleUnit radians
constant with units of radians
Definition: Angle.h:108
A base class for image defects.
T size(T... args)
T to_string(T... args)