LSST Applications  21.0.0+c4f5df5339,21.0.0+e70536a077,21.0.0-1-ga51b5d4+7c60f8a6ea,21.0.0-10-g560fb7b+411cd868f8,21.0.0-10-gcf60f90+8c49d86aa0,21.0.0-13-gc485e61d+38156233bf,21.0.0-16-g7a993c7b9+1041c3824f,21.0.0-2-g103fe59+d9ceee3e5a,21.0.0-2-g1367e85+0b2f7db15a,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+0b2f7db15a,21.0.0-2-g7f82c8f+feb9862f5e,21.0.0-2-g8f08a60+9c9a9cfcc8,21.0.0-2-ga326454+feb9862f5e,21.0.0-2-gde069b7+bedfc5e1fb,21.0.0-2-gecfae73+417509110f,21.0.0-2-gfc62afb+0b2f7db15a,21.0.0-3-g21c7a62+a91f7c0b59,21.0.0-3-g357aad2+062581ff1a,21.0.0-3-g4be5c26+0b2f7db15a,21.0.0-3-g65f322c+85aa0ead76,21.0.0-3-g7d9da8d+c4f5df5339,21.0.0-3-gaa929c8+411cd868f8,21.0.0-3-gc44e71e+fd4029fd48,21.0.0-3-ge02ed75+5d9b90b8aa,21.0.0-38-g070523fc+44fda2b515,21.0.0-4-g591bb35+5d9b90b8aa,21.0.0-4-g88306b8+3cdc83ea97,21.0.0-4-gc004bbf+d52368b591,21.0.0-4-gccdca77+a5c54364a0,21.0.0-5-g7ebb681+81e2098694,21.0.0-5-gdf36809+87b8d260e6,21.0.0-6-g2d4f3f3+e70536a077,21.0.0-6-g4e60332+5d9b90b8aa,21.0.0-6-g5ef7dad+3f4e29eeae,21.0.0-7-gc8ca178+0f5e56d48f,21.0.0-9-g9eb8d17+cc2c7a81aa,master-gac4afde19b+5d9b90b8aa,w.2021.07
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 <typeinfo>
28 #include <vector>
29 
30 #include "astshim.h"
31 #include "lsst/geom/Point.h"
32 #include "lsst/geom/SpherePoint.h"
33 #include "lsst/afw/geom/Endpoint.h"
34 
35 namespace lsst {
36 namespace afw {
37 namespace geom {
38 namespace {
39 
40 /*
41 Get a pointer to a frame
42 
43 If frame is a FrameSet then return a copy of its current frame, else return the original argument
44 */
46  auto frameSetPtr = std::dynamic_pointer_cast<ast::FrameSet>(framePtr);
47  if (frameSetPtr) {
48  return frameSetPtr->getFrame(ast::FrameSet::CURRENT);
49  }
50  return framePtr;
51 }
52 
53 } // namespace
54 
55 template <typename Point, typename Array>
56 BaseEndpoint<Point, Array>::BaseEndpoint(int nAxes) : _nAxes(nAxes) {
57  if (nAxes <= 0) {
59  "nAxes = " + std::to_string(nAxes) + "; must be > 0");
60  }
61 }
62 
63 template <typename Point, typename Array>
65  return this->getNAxes() == other.getNAxes() && typeid(*this) == typeid(other);
66 }
67 
68 template <typename Point, typename Array>
70  return std::make_shared<ast::Frame>(getNAxes());
71 }
72 
73 template <typename Point, typename Array>
75  if (nAxes != this->getNAxes()) {
77  os << "number of axes provided " << nAxes << " != " << this->getNAxes() << " required";
78  throw std::invalid_argument(os.str());
79  }
80 }
81 
82 template <typename Point>
84  return arr.size();
85 }
86 
88  this->_assertNAxes(_getNAxes(point));
89  return point;
90 }
91 
92 ndarray::Array<double, 2, 2> GenericEndpoint::dataFromArray(Array const& arr) const {
93  this->_assertNAxes(_getNAxes(arr));
94  return ndarray::copy(arr);
95 }
96 
98  this->_assertNAxes(data.size());
99  return data;
100 }
101 
102 ndarray::Array<double, 2, 2> GenericEndpoint::arrayFromData(ndarray::Array<double, 2, 2> const& data) const {
103  this->_assertNAxes(_getNAxes(data));
104  return ndarray::copy(data);
105 }
106 
108  if (nAxes != 2) {
110  os << "nAxes = " << nAxes << " != 2";
112  }
113 }
114 
116  const int nAxes = this->getNAxes();
118  for (int axInd = 0; axInd < nAxes; ++axInd) {
119  result[axInd] = point[axInd];
120  }
121  return result;
122 }
123 
124 ndarray::Array<double, 2, 2> Point2Endpoint::dataFromArray(Array const& arr) const {
125  const int nAxes = this->getNAxes();
126  const int nPoints = this->getNPoints(arr);
127  ndarray::Array<double, 2, 2> data = ndarray::allocate(ndarray::makeVector(nAxes, nPoints));
128  auto dataColIter = data.transpose().begin();
129  for (auto const& point : arr) {
130  for (int axInd = 0; axInd < nAxes; ++axInd) {
131  (*dataColIter)[axInd] = point[axInd];
132  }
133  ++dataColIter;
134  }
135  return data;
136 }
137 
139  const int nAxes = this->getNAxes();
140  this->_assertNAxes(this->_getNAxes(data));
141  Point result;
142  for (int axInd = 0; axInd < nAxes; ++axInd) {
143  result[axInd] = data[axInd];
144  }
145  return result;
146 }
147 
149  ndarray::Array<double, 2, 2> const& data) const {
150  this->_assertNAxes(this->_getNAxes(data));
151  int const nPoints = this->_getNPoints(data);
152  Array array;
153  array.reserve(nPoints);
154  for (auto const& dataCol : data.transpose()) {
155  array.emplace_back(dataCol[0], dataCol[1]);
156  }
157  return array;
158 }
159 
161  // use getCurrentFrame because if framePtr points to a FrameSet we want the name of its current frame
162  std::string className = getCurrentFrame(framePtr)->getClassName();
163  if (className != "Frame") {
165  os << "frame is a " << className << ", not a Frame";
167  }
168 }
169 
171  if (nAxes != 2) {
173  os << "nAxes = " << nAxes << " != 2";
175  }
176 }
177 
179  const int nAxes = this->getNAxes();
181  for (int axInd = 0; axInd < nAxes; ++axInd) {
182  result[axInd] = point[axInd].asRadians();
183  }
184  return result;
185 }
186 
187 ndarray::Array<double, 2, 2> SpherePointEndpoint::dataFromArray(Array const& arr) const {
188  const int nAxes = this->getNAxes();
189  const int nPoints = this->getNPoints(arr);
190  ndarray::Array<double, 2, 2> data = ndarray::allocate(ndarray::makeVector(nAxes, nPoints));
191  auto dataColIter = data.transpose().begin();
192  for (auto const& point : arr) {
193  for (int axInd = 0; axInd < nAxes; ++axInd) {
194  (*dataColIter)[axInd] = point[axInd].asRadians();
195  }
196  ++dataColIter;
197  }
198  return data;
199 }
200 
202  this->_assertNAxes(this->_getNAxes(data));
204 }
205 
207  ndarray::Array<double, 2, 2> const& data) const {
208  this->_assertNAxes(this->_getNAxes(data));
209  int const nPoints = this->_getNPoints(data);
210  Array array;
211  array.reserve(nPoints);
212  for (auto const& dataCol : data.transpose()) {
213  array.emplace_back(lsst::geom::SpherePoint(dataCol[0], dataCol[1], lsst::geom::radians));
214  }
215  return array;
216 }
217 
219  return std::make_shared<ast::SkyFrame>();
220 }
221 
223  // use getCurrentFrame because if framePtr points to a FrameSet we want its current frame
224  auto currentFramePtr = getCurrentFrame(framePtr);
225  auto skyFramePtr = std::dynamic_pointer_cast<ast::SkyFrame>(currentFramePtr);
226  if (!skyFramePtr) {
228  os << "frame is a " << currentFramePtr->getClassName() << ", not a SkyFrame";
230  }
231  if (skyFramePtr->getLonAxis() != 1) {
232  // axes are swapped to Lat, Lon; swap them back to the usual Lon, Lat
233  // warning: be sure to call permAxes on the original framePtr argument,
234  // as otherwise it will have no effect if framePtr points to a FrameSet
235  std::vector<int> perm = {2, 1};
236  framePtr->permAxes(perm);
237  }
238 }
239 
241  os << "GenericEndpoint(" << endpoint.getNAxes() << ")";
242  return os;
243 }
244 
246  os << "Point2Endpoint()";
247  return os;
248 }
249 
251  os << "SpherePointEndpoint()";
252  return os;
253 }
254 
255 // explicit instantiations
256 template class BaseEndpoint<std::vector<double>, ndarray::Array<double, 2, 2>>;
257 template class BaseEndpoint<lsst::geom::Point2D, std::vector<lsst::geom::Point2D>>;
258 template class BaseEndpoint<lsst::geom::SpherePoint, std::vector<lsst::geom::SpherePoint>>;
259 
260 template class BaseVectorEndpoint<lsst::geom::Point2D>;
261 template class BaseVectorEndpoint<lsst::geom::SpherePoint>;
262 
263 } // namespace geom
264 } // namespace afw
265 } // namespace lsst
py::object result
Definition: _schema.cc:429
char * data
Definition: BaseRecord.cc:62
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
ItemVariant const * other
Definition: Schema.cc:56
std::ostream * os
Definition: Schema.cc:746
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:69
BaseEndpoint(BaseEndpoint const &)=default
virtual bool operator==(BaseEndpoint const &other) const noexcept
Determine whether two endpoints represent the same conversion.
Definition: Endpoint.cc:64
void _assertNAxes(int nAxes) const
Definition: Endpoint.cc:74
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:83
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:87
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:102
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:97
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Definition: Endpoint.cc:92
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:124
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:115
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:138
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:148
void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a Frame, not a subclass.
Definition: Endpoint.cc:160
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:187
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:178
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:206
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:218
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:201
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:222
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:240
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35
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)