LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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
lsst::afw::geom::Point2Endpoint::Point2Endpoint
Point2Endpoint()
Construct a Point2Endpoint.
Definition: Endpoint.h:271
lsst::afw::geom::Point2Endpoint::pointFromData
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:138
lsst::afw::geom::BaseEndpoint::BaseEndpoint
BaseEndpoint(BaseEndpoint const &)=default
lsst::afw::geom::Point2Endpoint::normalizeFrame
void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a Frame, not a subclass.
Definition: Endpoint.cc:160
lsst::afw::geom::BaseEndpoint::_assertNAxes
void _assertNAxes(int nAxes) const
Definition: Endpoint.cc:74
std::string
STL class.
std::shared_ptr< ast::Frame >
lsst::afw::geom::BaseVectorEndpoint< lsst::geom::Point2D >::Point
lsst::geom::Point2D Point
Definition: Endpoint.h:198
lsst::afw::table::SpherePoint
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35
std::vector::reserve
T reserve(T... args)
std::vector
STL class.
lsst::afw::geom::BaseEndpoint::operator==
virtual bool operator==(BaseEndpoint const &other) const noexcept
Determine whether two endpoints represent the same conversion.
Definition: Endpoint.cc:64
std::vector::size
T size(T... args)
lsst::afw::geom::SpherePointEndpoint::pointFromData
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:201
lsst::afw::geom::BaseEndpoint< lsst::geom::Point2D, std::vector< lsst::geom::Point2D > >::_getNPoints
int _getNPoints(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:183
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::geom::SpherePointEndpoint::dataFromArray
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Definition: Endpoint.cc:187
Endpoint.h
lsst::afw::geom::Point2Endpoint::dataFromPoint
std::vector< double > dataFromPoint(Point const &point) const override
Definition: Endpoint.cc:115
lsst::geom::Point2D
Point< double, 2 > Point2D
Definition: Point.h:324
lsst::afw::geom::GenericEndpoint::pointFromData
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:97
lsst::afw::geom::Point2Endpoint
An endpoint for lsst::geom::Point2D.
Definition: Endpoint.h:261
astshim.h
lsst::afw::geom::SpherePointEndpoint::SpherePointEndpoint
SpherePointEndpoint()
Construct a SpherePointEndpoint.
Definition: Endpoint.h:325
lsst::afw::geom::operator<<
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
Point.h
data
char * data
Definition: BaseRecord.cc:62
lsst::afw::geom::SpherePointEndpoint::arrayFromData
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:206
ast::FrameSet::CURRENT
static constexpr int CURRENT
index of current frame
Definition: FrameSet.h:105
std::ostream
STL class.
lsst::afw::geom::BaseVectorEndpoint
Base class for endpoints with Array = std::vector<Point> where Point has 2 dimensions.
Definition: Endpoint.h:195
other
ItemVariant const * other
Definition: Schema.cc:56
std::to_string
T to_string(T... args)
ast::Frame::permAxes
void permAxes(std::vector< int > perm)
Permute the order in which a Frame's axes occur.
Definition: Frame.h:1138
lsst::afw::geom::BaseEndpoint< lsst::geom::Point2D, std::vector< lsst::geom::Point2D > >::getNAxes
int getNAxes() const
Definition: Endpoint.h:79
std::invalid_argument
STL class.
lsst::afw::geom::GenericEndpoint::dataFromPoint
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:87
lsst::afw::geom::GenericEndpoint::dataFromArray
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Get raw data from an array of points.
Definition: Endpoint.cc:92
lsst::afw::geom::BaseEndpoint::makeFrame
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
result
py::object result
Definition: _schema.cc:429
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
std::ostringstream
STL class.
lsst::geom
Definition: AffineTransform.h:36
os
std::ostream * os
Definition: Schema.cc:746
lsst::afw::geom::BaseVectorEndpoint< lsst::geom::Point2D >::Array
std::vector< lsst::geom::Point2D > Array
Definition: Endpoint.h:197
std::vector::emplace_back
T emplace_back(T... args)
lsst::afw::geom::SpherePointEndpoint::makeFrame
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
lsst::afw::geom::SpherePointEndpoint::dataFromPoint
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:178
lsst::afw::geom::BaseEndpoint
Virtual base class for endpoints, which are helper classes for Transform.
Definition: Endpoint.h:67
lsst.pex::exceptions::InvalidParameterError
Reports invalid arguments.
Definition: Runtime.h:66
lsst::afw::geom::Point2Endpoint::dataFromArray
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Definition: Endpoint.cc:124
lsst::geom::Point< double, 2 >
lsst::afw::geom::SpherePointEndpoint::normalizeFrame
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
lsst::afw::geom::GenericEndpoint
A generic endpoint for data in the format used by ast::Mapping.
Definition: Endpoint.h:226
lsst::geom::radians
constexpr AngleUnit radians
constant with units of radians
Definition: Angle.h:108
lsst::afw::geom::GenericEndpoint::arrayFromData
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:102
SpherePoint.h
lsst::geom::SpherePoint
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
lsst::afw::geom::BaseEndpoint< std::vector< double >, ndarray::Array< double, 2, 2 > >::_getNAxes
int _getNAxes(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:177
lsst::afw::geom::BaseVectorEndpoint::getNPoints
int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.cc:83
lsst::afw::geom::Point2Endpoint::arrayFromData
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:148
lsst::afw::geom::SpherePointEndpoint
An endpoint for lsst::geom::SpherePoint.
Definition: Endpoint.h:315