LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
SpatialUtil.h
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 
33 #ifndef LSST_AP_SPATIAL_UTIL_H
34 #define LSST_AP_SPATIAL_UTIL_H
35 
36 #include <cassert>
37 #include <cmath>
38 
39 #include <algorithm>
40 #include <vector>
41 
42 #include "Common.h"
43 #include "CircularRegion.h"
44 #include "RectangularRegion.h"
45 
46 
47 namespace lsst { namespace ap {
48 
49 namespace {
50  double const RA_DEC_SCALE = 1.19304647111111111111111111111e07; // 1073741824.0/90.0
51 }
52 
70 
71 public :
72 
74  int const zonesPerDegree,
75  int const zonesPerStripe,
76  int const maxEntriesPerZoneEstimate
77  );
78 
80 
82  if (this != &zsc) {
84  swap(copy);
85  }
86  return *this;
87  }
88 
89  int getNumChunksPerStripe(int const stripeId, double const minWidth) const;
90 
92  int const stripeId,
93  double const cenRa,
94  double const cenDec,
95  double const rad
96  ) const;
97 
103  int getNumChunksPerStripe(int const stripeId) const {
104  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
105  return _chunksPerStripe[stripeId - _minStripe];
106  }
107 
112  int getFirstChunkForStripe(int const stripeId) const {
113  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
114  return stripeId << 16;
115  }
116 
118  int radecToChunk(double const ra, double const dec) const {
119  int const s = decToStripe(dec);
120  int const nc = getNumChunksPerStripe(s);
121  int c = static_cast<int>(std::floor((ra/360.0)*nc));
122  if (c >= nc) {
123  --c;
124  }
125  return (c + getFirstChunkForStripe(s));
126  }
127 
132  int decToZone(double const dec) const {
133  assert(dec >= -90.0 && dec <= 90.0 && "declination out of bounds");
134  int const zoneId = static_cast<int>(std::floor(dec*_zonesPerDegree));
135  return (zoneId > _maxZone) ? _maxZone : zoneId;
136  }
137 
139  double getZoneDecMin(int const zone) const {
140  assert(zone >= _minZone && zone <= _maxZone && "zone id out of bounds");
141  double d = static_cast<double>(zone)/_zonesPerDegree;
142  return d <= -90.0 ? -90.0 : d;
143  }
144 
146  double getZoneDecMax(int const zone) const {
147  assert(zone >= _minZone && zone <= _maxZone && "zone id out of bounds");
148  double d = static_cast<double>(zone + 1)/_zonesPerDegree;
149  return d >= 90.0 ? 90.0 : d;
150  }
151 
156  int decToStripe(double const dec) const {
157  assert(dec >= -90.0 && dec <= 90.0 && "declination out of bounds");
158  double zoneId = std::floor(dec*_zonesPerDegree);
159  return (zoneId > _maxZoneAsDouble) ? _maxStripe :
160  static_cast<int>(std::floor(zoneId/_zonesPerStripe));
161  }
162 
164  static int chunkToStripe(int const chunkId) {
165  return chunkId >> 16;
166  }
167 
169  static int chunkToSequence(int const chunkId) {
170  return chunkId & 0x7fff;
171  }
172 
174  double getStripeDecMin(int const stripeId) const {
175  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
176  double d = static_cast<double>(stripeId*_zonesPerStripe)/_zonesPerDegree;
177  return d <= -90.0 ? -90.0 : d;
178  }
179 
181  double getStripeDecMax(int const stripeId) const {
182  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
183  double d = static_cast<double>((stripeId + 1)*_zonesPerStripe)/_zonesPerDegree;
184  return d >= 90.0 ? 90.0 : d;
185  }
186 
188  int getStripeZoneMin(int const stripeId) const {
189  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
190  return stripeId*_zonesPerStripe;
191  }
192 
194  int getStripeZoneMax(int const stripeId) const {
195  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
196  return stripeId*_zonesPerStripe + _zonesPerStripe - 1;
197  }
198 
199  int getZonesPerStripe() const { return _zonesPerStripe; }
200 
207  }
208 
210 
211 private :
212 
213  std::vector<int> _chunksPerStripe;
214 
219  int _minZone;
220  int _maxZone;
223 };
224 
226  a.swap(b);
227 }
228 
229 
230 double alpha(double const theta, double const centerDec, double const dec);
231 
232 double maxAlpha(double const theta, double const centerDec);
233 
234 void computeChunkIds(
235  std::vector<int> & chunkIds,
236  CircularRegion const & region,
237  ZoneStripeChunkDecomposition const & zsc,
238  int const workerId = 0,
239  int const numWorkers = 1
240 );
241 
242 void computeChunkIds(
243  std::vector<int> & chunkIds,
244  RectangularRegion const & region,
245  ZoneStripeChunkDecomposition const & zsc,
246  int const workerId = 0,
247  int const numWorkers = 1
248 );
249 
251 inline boost::uint32_t raToScaledInteger(double const ra) {
252  assert(ra >= 0.0 && ra < 360.0);
253  double d = std::floor(ra*RA_DEC_SCALE);
254  return d >= 4294967295.0 ? 4294967295u : static_cast<uint32_t>(d);
255 }
256 
258 inline boost::uint32_t deltaRaToScaledInteger(double const delta) {
259  assert(delta >= 0.0 && delta <= 180.0);
260  return static_cast<int32_t>(std::ceil(delta*RA_DEC_SCALE));
261 }
262 
264 inline boost::int32_t decToScaledInteger(double const dec) {
265  assert(dec >= -90.0 && dec <= 90.0);
266  return static_cast<int32_t>(std::floor(dec*RA_DEC_SCALE));
267 }
268 
270 inline boost::int32_t deltaDecToScaledInteger(double const delta) {
271  assert(delta >= 0.0 && delta <= 90.0);
272  return static_cast<int32_t>(std::ceil(delta*RA_DEC_SCALE));
273 }
274 
276 inline double clampDec(double const dec) {
277  if (dec <= -90.0) {
278  return -90.0;
279  } else if (dec >= 90.0) {
280  return 90.0;
281  }
282  return dec;
283 }
284 
285 
286 }} // end of namespace lsst::ap
287 
288 #endif // LSST_AP_SPATIAL_UTIL_H
int getFirstChunkForStripe(int const stripeId) const
Definition: SpatialUtil.h:112
void swap(Ellipse< DataT > &a, Ellipse< DataT > &b)
Definition: EllipseTypes.h:90
double clampDec(double const dec)
Definition: SpatialUtil.h:276
void computeChunkIds(std::vector< int > &chunkIds, CircularRegion const &region, ZoneStripeChunkDecomposition const &zsc, int const workerId=0, int const numWorkers=1)
Definition: SpatialUtil.cc:308
boost::int32_t deltaDecToScaledInteger(double const delta)
Definition: SpatialUtil.h:270
boost::uint32_t deltaRaToScaledInteger(double const delta)
Definition: SpatialUtil.h:258
double getZoneDecMax(int const zone) const
Definition: SpatialUtil.h:146
int decToZone(double const dec) const
Definition: SpatialUtil.h:132
int getStripeZoneMin(int const stripeId) const
Definition: SpatialUtil.h:188
ZoneStripeChunkDecomposition & operator=(ZoneStripeChunkDecomposition const &zsc)
Definition: SpatialUtil.h:81
int getStripeZoneMax(int const stripeId) const
Definition: SpatialUtil.h:194
ZoneStripeChunkDecomposition(int const zonesPerDegree, int const zonesPerStripe, int const maxEntriesPerZoneEstimate)
Definition: SpatialUtil.cc:48
int decToStripe(double const dec) const
Definition: SpatialUtil.h:156
double getStripeDecMax(int const stripeId) const
Definition: SpatialUtil.h:181
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
boost::uint32_t raToScaledInteger(double const ra)
Definition: SpatialUtil.h:251
boost::int32_t decToScaledInteger(double const dec)
Definition: SpatialUtil.h:264
Extent< int, N > ceil(Extent< double, N > const &input)
int d
Definition: KDTree.cc:89
A decomposition of the unit sphere into zones, stripes, and chunks.
Definition: SpatialUtil.h:69
double maxAlpha(double const theta, double const centerDec)
Definition: SpatialUtil.cc:279
int radecToChunk(double const ra, double const dec) const
Definition: SpatialUtil.h:118
double getZoneDecMin(int const zone) const
Definition: SpatialUtil.h:139
Master header file for the association pipeline.
double alpha(double const theta, double const centerDec, double const dec)
Definition: SpatialUtil.cc:248
int getNumChunksPerStripe(int const stripeId) const
Definition: SpatialUtil.h:103
void swap(ZoneStripeChunkDecomposition &zsc)
Definition: SpatialUtil.cc:112
int getNumChunksPerStripe(int const stripeId, double const minWidth) const
Definition: SpatialUtil.cc:138
Extent< int, N > floor(Extent< double, N > const &input)
double stripeAndCircleToRaRange(int const stripeId, double const cenRa, double const cenDec, double const rad) const
Definition: SpatialUtil.cc:175
static int chunkToSequence(int const chunkId)
Definition: SpatialUtil.h:169
afw::table::Key< double > b
static int chunkToStripe(int const chunkId)
Definition: SpatialUtil.h:164
Class describing a circular region on the sky.
Class describing a rectangular (in ra and dec) region on the sky.
double getStripeDecMin(int const stripeId) const
Definition: SpatialUtil.h:174