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
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
lsst::ap::ZoneStripeChunkDecomposition Class Reference

A decomposition of the unit sphere into zones, stripes, and chunks. More...

#include <SpatialUtil.h>

Public Member Functions

 ZoneStripeChunkDecomposition (int const zonesPerDegree, int const zonesPerStripe, int const maxEntriesPerZoneEstimate)
 
 ZoneStripeChunkDecomposition (ZoneStripeChunkDecomposition const &zsc)
 
ZoneStripeChunkDecompositionoperator= (ZoneStripeChunkDecomposition const &zsc)
 
int getNumChunksPerStripe (int const stripeId, double const minWidth) const
 
double stripeAndCircleToRaRange (int const stripeId, double const cenRa, double const cenDec, double const rad) const
 
int getNumChunksPerStripe (int const stripeId) const
 
int getFirstChunkForStripe (int const stripeId) const
 
int radecToChunk (double const ra, double const dec) const
 
int decToZone (double const dec) const
 
double getZoneDecMin (int const zone) const
 
double getZoneDecMax (int const zone) const
 
int decToStripe (double const dec) const
 
double getStripeDecMin (int const stripeId) const
 
double getStripeDecMax (int const stripeId) const
 
int getStripeZoneMin (int const stripeId) const
 
int getStripeZoneMax (int const stripeId) const
 
int getZonesPerStripe () const
 
int getMaxEntriesPerZoneEstimate () const
 
void swap (ZoneStripeChunkDecomposition &zsc)
 

Static Public Member Functions

static int chunkToStripe (int const chunkId)
 
static int chunkToSequence (int const chunkId)
 

Private Attributes

std::vector< int > _chunksPerStripe
 
double _zonesPerDegree
 
double _maxZoneAsDouble
 
int _zonesPerStripe
 
int _maxEntriesPerZoneEstimate
 
int _minZone
 
int _maxZone
 
int _minStripe
 
int _maxStripe
 

Detailed Description

A decomposition of the unit sphere into zones, stripes, and chunks.

Stripes refer to declination ranges. These are further divided into equal width (in right ascension) chunks for the purposes of memory management and/or disk storage. This allows an LSST FOV to be described by a small number (10-100) of spatial chunks that map to some unit of physical storage (e.g. files, database tables).

For cross-matching, spatial data is organized into very fine declination ranges, dubbed zones, many of which combine to form a stripe. Specifically, a stripe consists of N zones, where N is a positive integer.

ZoneStripeChunkDecomposition instances are responsible for mapping declinations/positions to integer zone, stripe, and chunk ids – these are obtained by simple quantization of declination and right ascension.

Definition at line 69 of file SpatialUtil.h.

Constructor & Destructor Documentation

lsst::ap::ZoneStripeChunkDecomposition::ZoneStripeChunkDecomposition ( int const  zonesPerDegree,
int const  zonesPerStripe,
int const  maxEntriesPerZoneEstimate 
)

Definition at line 48 of file SpatialUtil.cc.

52  :
54  _zonesPerDegree(zonesPerDegree),
55  _zonesPerStripe(zonesPerStripe),
56  _maxEntriesPerZoneEstimate(maxEntriesPerZoneEstimate)
57 {
58  if (zonesPerDegree < 1 || zonesPerDegree > 3600) {
59  throw LSST_EXCEPT(ex::RangeError,
60  "zone height must be between 1 arc-second and 1 degree");
61  }
62  if (zonesPerStripe < 1) {
63  throw LSST_EXCEPT(ex::RangeError,
64  "there must be at least 1 zone per stripe");
65  }
66  if (maxEntriesPerZoneEstimate < 1) {
67  throw LSST_EXCEPT(ex::RangeError,
68  "the max entries per zone estimate must be at least 1");
69  }
70  _minZone = -90*zonesPerDegree;
71  _maxZone = 90*zonesPerDegree - 1;
72  _maxZoneAsDouble = static_cast<double>(_maxZone);
73 
74  // C89/C++ standard says: rounding direction of division when either operand is negative
75  // is implementation defined. Therefore, implement round to -Infinity by hand.
76  int const quo = (-_minZone) / zonesPerStripe;
77  int const rem = (-_minZone) % zonesPerStripe;
78  _minStripe = (rem == 0) ? -quo : -1 - quo;
79  _maxStripe = _maxZone/zonesPerStripe;
80 
81  int const numStripes = _maxStripe - _minStripe + 1;
82  double const minWidth = static_cast<double>(zonesPerStripe)/_zonesPerDegree;
83  if (numStripes >= 32768) {
84  throw LSST_EXCEPT(ex::RangeError,
85  "Requested spatial parameters result in more than 32767 stripes");
86  }
87  if (getNumChunksPerStripe(0, minWidth) >= 32768) {
88  throw LSST_EXCEPT(ex::RangeError,
89  "Requested spatial parameters result in more than 32767 chunks per stripe");
90  }
91 
92  _chunksPerStripe.reserve(numStripes);
93  for (int i = 0; i < numStripes; ++i) {
94  _chunksPerStripe.push_back(getNumChunksPerStripe(i + _minStripe, minWidth));
95  }
96 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int getNumChunksPerStripe(int const stripeId, double const minWidth) const
Definition: SpatialUtil.cc:138
lsst::ap::ZoneStripeChunkDecomposition::ZoneStripeChunkDecomposition ( ZoneStripeChunkDecomposition const &  zsc)

Definition at line 99 of file SpatialUtil.cc.

99  :
100  _chunksPerStripe(zsc._chunksPerStripe),
101  _zonesPerDegree (zsc._zonesPerDegree),
102  _maxZoneAsDouble(zsc._maxZoneAsDouble),
103  _zonesPerStripe (zsc._zonesPerStripe),
104  _maxEntriesPerZoneEstimate(zsc._maxEntriesPerZoneEstimate),
105  _minZone (zsc._minZone),
106  _maxZone (zsc._maxZone),
107  _minStripe (zsc._minStripe),
108  _maxStripe (zsc._maxStripe)
109 {}

Member Function Documentation

static int lsst::ap::ZoneStripeChunkDecomposition::chunkToSequence ( int const  chunkId)
inlinestatic

Returns the sequence number of the given chunk (within its stripe).

Definition at line 169 of file SpatialUtil.h.

169  {
170  return chunkId & 0x7fff;
171  }
static int lsst::ap::ZoneStripeChunkDecomposition::chunkToStripe ( int const  chunkId)
inlinestatic

Returns the id of the stripe the given chunk belongs to.

Definition at line 164 of file SpatialUtil.h.

164  {
165  return chunkId >> 16;
166  }
int lsst::ap::ZoneStripeChunkDecomposition::decToStripe ( double const  dec) const
inline

Returns the id of the stripe that any point with the given declination belongs to.

Precondition
dec >= -90.0 && dec <= 90.0

Definition at line 156 of file SpatialUtil.h.

156  {
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  }
Extent< int, N > floor(Extent< double, N > const &input)
int lsst::ap::ZoneStripeChunkDecomposition::decToZone ( double const  dec) const
inline

Returns the id of the zone that any point with the given declination belongs to.

Precondition
dec >= -90.0 && dec <= 90.0

Definition at line 132 of file SpatialUtil.h.

132  {
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  }
Extent< int, N > floor(Extent< double, N > const &input)
int lsst::ap::ZoneStripeChunkDecomposition::getFirstChunkForStripe ( int const  stripeId) const
inline

Returns the id of the first chunk (the one with the smallest id) in the given declination stripe.

Definition at line 112 of file SpatialUtil.h.

112  {
113  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
114  return stripeId << 16;
115  }
int lsst::ap::ZoneStripeChunkDecomposition::getMaxEntriesPerZoneEstimate ( ) const
inline

Returns an estimate of the largest number of entries that can fall within the intersection of a zone and an LSST FOV. Always returns a non-negative integer.

Definition at line 205 of file SpatialUtil.h.

205  {
207  }
int lsst::ap::ZoneStripeChunkDecomposition::getNumChunksPerStripe ( int const  stripeId,
double const  minWidth 
) const

Computes and returns the maximum number of equal-width chunks that can fit into the given declination stripe, where each chunk has the given minimum width. The minimum width for a chunk is defined as the minimum allowable distance between two points in non-adjacent chunks belonging to the same stripe.

Parameters
[in]stripeIdthe stripe to determine a chunk count for
[in]minWidththe minimum width of a chunk (in degrees)

Definition at line 138 of file SpatialUtil.cc.

141  {
142  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of range");
143  assert(minWidth > 0.0 && minWidth < 90.0 && "chunk width out of range");
144 
145  double d1 = std::fabs(getStripeDecMin(stripeId));
146  double d2 = std::fabs(getStripeDecMax(stripeId));
147  double maxAbsDec = d1 < d2 ? d2 : d1;
148  if (maxAbsDec > 89.9) {
149  return 1;
150  }
151  double cosWidth = std::cos(afwGeom::degToRad(minWidth));
152  double sinDec = std::sin(afwGeom::degToRad(maxAbsDec));
153  double cosDec = std::cos(afwGeom::degToRad(maxAbsDec));
154  cosWidth = (cosWidth - sinDec*sinDec)/(cosDec*cosDec);
155  if (cosWidth < 0) {
156  return 1;
157  }
158  return static_cast<int>(std::floor(afwGeom::TWOPI/std::acos(cosWidth)));
159 }
double getStripeDecMax(int const stripeId) const
Definition: SpatialUtil.h:181
double const TWOPI
Definition: Angle.h:19
double degToRad(long double angleInDegrees)
Definition: RaDecStr.cc:67
Extent< int, N > floor(Extent< double, N > const &input)
double getStripeDecMin(int const stripeId) const
Definition: SpatialUtil.h:174
int lsst::ap::ZoneStripeChunkDecomposition::getNumChunksPerStripe ( int const  stripeId) const
inline

Computes and returns the maximum number of equal-width chunks that can fit into the given declination stripe (where each chunk has a minimum width equal to the stripe height).

Definition at line 103 of file SpatialUtil.h.

103  {
104  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
105  return _chunksPerStripe[stripeId - _minStripe];
106  }
double lsst::ap::ZoneStripeChunkDecomposition::getStripeDecMax ( int const  stripeId) const
inline

Returns a non-inclusive upper bound on the declination of points within the given stripe.

Definition at line 181 of file SpatialUtil.h.

181  {
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  }
int d
Definition: KDTree.cc:89
double lsst::ap::ZoneStripeChunkDecomposition::getStripeDecMin ( int const  stripeId) const
inline

Returns the minimum declination of points within the given stripe.

Definition at line 174 of file SpatialUtil.h.

174  {
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  }
int d
Definition: KDTree.cc:89
int lsst::ap::ZoneStripeChunkDecomposition::getStripeZoneMax ( int const  stripeId) const
inline

Returns the largest zone within the given stripe.

Definition at line 194 of file SpatialUtil.h.

194  {
195  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
196  return stripeId*_zonesPerStripe + _zonesPerStripe - 1;
197  }
int lsst::ap::ZoneStripeChunkDecomposition::getStripeZoneMin ( int const  stripeId) const
inline

Returns the smallest zone within the given stripe.

Definition at line 188 of file SpatialUtil.h.

188  {
189  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of bounds");
190  return stripeId*_zonesPerStripe;
191  }
double lsst::ap::ZoneStripeChunkDecomposition::getZoneDecMax ( int const  zone) const
inline

Returns a non-inclusive upper bound on the declination of points within the given zone.

Definition at line 146 of file SpatialUtil.h.

146  {
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  }
int d
Definition: KDTree.cc:89
double lsst::ap::ZoneStripeChunkDecomposition::getZoneDecMin ( int const  zone) const
inline

Returns the minimum declination of points within the given zone.

Definition at line 139 of file SpatialUtil.h.

139  {
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  }
int d
Definition: KDTree.cc:89
int lsst::ap::ZoneStripeChunkDecomposition::getZonesPerStripe ( ) const
inline

Definition at line 199 of file SpatialUtil.h.

ZoneStripeChunkDecomposition& lsst::ap::ZoneStripeChunkDecomposition::operator= ( ZoneStripeChunkDecomposition const &  zsc)
inline

Definition at line 81 of file SpatialUtil.h.

81  {
82  if (this != &zsc) {
84  swap(copy);
85  }
86  return *this;
87  }
ZoneStripeChunkDecomposition(int const zonesPerDegree, int const zonesPerStripe, int const maxEntriesPerZoneEstimate)
Definition: SpatialUtil.cc:48
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
void swap(ZoneStripeChunkDecomposition &zsc)
Definition: SpatialUtil.cc:112
int lsst::ap::ZoneStripeChunkDecomposition::radecToChunk ( double const  ra,
double const  dec 
) const
inline

Returns the id of the chunk containing the given position

Definition at line 118 of file SpatialUtil.h.

118  {
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  }
int getFirstChunkForStripe(int const stripeId) const
Definition: SpatialUtil.h:112
int decToStripe(double const dec) const
Definition: SpatialUtil.h:156
int getNumChunksPerStripe(int const stripeId, double const minWidth) const
Definition: SpatialUtil.cc:138
Extent< int, N > floor(Extent< double, N > const &input)
double lsst::ap::ZoneStripeChunkDecomposition::stripeAndCircleToRaRange ( int const  stripeId,
double const  cenRa,
double const  cenDec,
double const  rad 
) const

Computes the intersection of the given declination stripe and circular region, then returns the range of right ascension values in the intersection as a difference in ra from the circle center.

Parameters
[in]stripeIdid of the declination stripe
[in]cenRaright ascension of circle center (degrees)
[in]cenDecdeclination of circle center (degrees)
[in]radradius of circle (degrees)
Returns
alpha, such that points in the intersection of the input circle and stripe have right ascensions between [cenRa - alpha, cenRa + alpha].

Definition at line 175 of file SpatialUtil.cc.

180  {
181  assert(stripeId >= _minStripe && stripeId <= _maxStripe && "stripe id out of range");
182 
183  // find dec extents of stripe and circle
184  double const stripeDecMin = getStripeDecMin(stripeId);
185  double const stripeDecMax = getStripeDecMax(stripeId);
186  double circleDecMin = cenDec - rad;
187  double circleDecMax = cenDec + rad;
188  double a = 0.0;
189 
190  if (circleDecMax <= stripeDecMin || circleDecMin >= stripeDecMax) {
191  // the circle doesn't intersect the stripe
192  a = 0.0;
193  } else if (circleDecMax >= 89.9) {
194  // the circle contains (or is very close to) the north pole
195  if (circleDecMax > 90.0) {
196  circleDecMax = 180.0 - circleDecMax;
197  }
198  if (stripeDecMax >= circleDecMax) {
199  a = 180.0;
200  } else {
201  a = alpha(rad, cenDec, stripeDecMax);
202  }
203  } else if (circleDecMin <= -89.9) {
204  // the circle contains (or is very close to) the south pole
205  if (circleDecMin < -90.0) {
206  circleDecMin = -180.0 - circleDecMin;
207  }
208  if (stripeDecMin <= circleDecMin) {
209  a = 180.0;
210  } else {
211  a = alpha(rad, cenDec, stripeDecMin);
212  }
213  } else {
214  // the circle does not contain a pole
215  double decOfMaxAlpha = afwGeom::radToDeg(std::asin(std::sin(afwGeom::degToRad(cenDec))/std::cos(afwGeom::degToRad(rad))));
216  if (decOfMaxAlpha < stripeDecMin) {
217  a = alpha(rad, cenDec, stripeDecMin);
218  } else if (decOfMaxAlpha > stripeDecMax) {
219  a = alpha(rad, cenDec, stripeDecMax);
220  } else {
221  // dec of max alpha value is within the stripe
222  a = maxAlpha(rad, cenDec);
223  }
224  }
225  return a;
226 }
double getStripeDecMax(int const stripeId) const
Definition: SpatialUtil.h:181
double radToDeg(long double angleInRadians)
Definition: RaDecStr.cc:61
double maxAlpha(double const theta, double const centerDec)
Definition: SpatialUtil.cc:279
double degToRad(long double angleInDegrees)
Definition: RaDecStr.cc:67
double alpha(double const theta, double const centerDec, double const dec)
Definition: SpatialUtil.cc:248
double getStripeDecMin(int const stripeId) const
Definition: SpatialUtil.h:174
void lsst::ap::ZoneStripeChunkDecomposition::swap ( ZoneStripeChunkDecomposition zsc)

Definition at line 112 of file SpatialUtil.cc.

112  {
113  using std::swap;
114 
115  if (this != &zsc) {
116  swap(_chunksPerStripe, zsc._chunksPerStripe);
117  swap(_zonesPerDegree, zsc._zonesPerDegree);
118  swap(_maxZoneAsDouble, zsc._maxZoneAsDouble);
119  swap(_maxEntriesPerZoneEstimate, zsc._maxEntriesPerZoneEstimate);
120  swap(_zonesPerStripe, zsc._zonesPerStripe);
121  swap(_minZone, zsc._minZone);
122  swap(_maxZone, zsc._maxZone);
123  swap(_minStripe, zsc._minStripe);
124  swap(_maxStripe, zsc._maxStripe);
125  }
126 }
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:291
void swap(ZoneStripeChunkDecomposition &zsc)
Definition: SpatialUtil.cc:112

Member Data Documentation

std::vector<int> lsst::ap::ZoneStripeChunkDecomposition::_chunksPerStripe
private

Definition at line 213 of file SpatialUtil.h.

int lsst::ap::ZoneStripeChunkDecomposition::_maxEntriesPerZoneEstimate
private

Definition at line 218 of file SpatialUtil.h.

int lsst::ap::ZoneStripeChunkDecomposition::_maxStripe
private

Definition at line 222 of file SpatialUtil.h.

int lsst::ap::ZoneStripeChunkDecomposition::_maxZone
private

Definition at line 220 of file SpatialUtil.h.

double lsst::ap::ZoneStripeChunkDecomposition::_maxZoneAsDouble
private

Definition at line 216 of file SpatialUtil.h.

int lsst::ap::ZoneStripeChunkDecomposition::_minStripe
private

Definition at line 221 of file SpatialUtil.h.

int lsst::ap::ZoneStripeChunkDecomposition::_minZone
private

Definition at line 219 of file SpatialUtil.h.

double lsst::ap::ZoneStripeChunkDecomposition::_zonesPerDegree
private

Definition at line 215 of file SpatialUtil.h.

int lsst::ap::ZoneStripeChunkDecomposition::_zonesPerStripe
private

Definition at line 217 of file SpatialUtil.h.


The documentation for this class was generated from the following files: