42 namespace ex = lsst::pex::exceptions;
43 namespace afwGeom = lsst::afw::geom;
49 int const zonesPerDegree,
50 int const zonesPerStripe,
51 int const maxEntriesPerZoneEstimate
54 _zonesPerDegree(zonesPerDegree),
55 _zonesPerStripe(zonesPerStripe),
56 _maxEntriesPerZoneEstimate(maxEntriesPerZoneEstimate)
58 if (zonesPerDegree < 1 || zonesPerDegree > 3600) {
60 "zone height must be between 1 arc-second and 1 degree");
62 if (zonesPerStripe < 1) {
64 "there must be at least 1 zone per stripe");
66 if (maxEntriesPerZoneEstimate < 1) {
68 "the max entries per zone estimate must be at least 1");
76 int const quo = (-
_minZone) / zonesPerStripe;
77 int const rem = (-
_minZone) % zonesPerStripe;
82 double const minWidth =
static_cast<double>(zonesPerStripe)/
_zonesPerDegree;
83 if (numStripes >= 32768) {
85 "Requested spatial parameters result in more than 32767 stripes");
89 "Requested spatial parameters result in more than 32767 chunks per stripe");
93 for (
int i = 0; i < numStripes; ++i) {
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)
140 double const minWidth
142 assert(stripeId >= _minStripe && stripeId <= _maxStripe &&
"stripe id out of range");
143 assert(minWidth > 0.0 && minWidth < 90.0 &&
"chunk width out of range");
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) {
154 cosWidth = (cosWidth - sinDec*sinDec)/(cosDec*cosDec);
181 assert(stripeId >= _minStripe && stripeId <= _maxStripe &&
"stripe id out of range");
184 double const stripeDecMin = getStripeDecMin(stripeId);
185 double const stripeDecMax = getStripeDecMax(stripeId);
186 double circleDecMin = cenDec - rad;
187 double circleDecMax = cenDec + rad;
190 if (circleDecMax <= stripeDecMin || circleDecMin >= stripeDecMax) {
193 }
else if (circleDecMax >= 89.9) {
195 if (circleDecMax > 90.0) {
196 circleDecMax = 180.0 - circleDecMax;
198 if (stripeDecMax >= circleDecMax) {
201 a =
alpha(rad, cenDec, stripeDecMax);
203 }
else if (circleDecMin <= -89.9) {
205 if (circleDecMin < -90.0) {
206 circleDecMin = -180.0 - circleDecMin;
208 if (stripeDecMin <= circleDecMin) {
211 a =
alpha(rad, cenDec, stripeDecMin);
216 if (decOfMaxAlpha < stripeDecMin) {
217 a =
alpha(rad, cenDec, stripeDecMin);
218 }
else if (decOfMaxAlpha > stripeDecMax) {
219 a =
alpha(rad, cenDec, stripeDecMax);
250 double const centerDec,
253 assert(theta > 0.0 && theta < 10.0 &&
"radius out of range");
254 assert(centerDec >= -90.0 && centerDec <= 90.0 &&
"declination out of range");
255 assert(dec >= -90.0 && dec <= 90.0 &&
"declination out of range");
257 if (std::fabs(centerDec) + theta > 89.9) {
262 double y = std::sqrt(std::fabs(u*u - x*x));
281 double const centerDec
283 assert(theta > 0.0 && theta < 10.0 &&
"radius out of range");
284 assert(centerDec >= -90.0 && centerDec <= 90.0 &&
"declination out of range");
286 if (std::fabs(centerDec) + theta > 89.9) {
309 std::vector<int> & chunkIds,
315 if (numWorkers < 1) {
316 throw LSST_EXCEPT(ex::InvalidParameterError,
"number of workers must be positive");
318 if (workerId < 0 || workerId >= numWorkers) {
320 "Worker id must be between 0 and N - 1, where N is the total number of workers");
326 int rem = s % numWorkers;
330 if (rem != workerId) {
346 if (raMax >= 360.0) {
350 int maxChunk =
static_cast<int>(
std::floor((raMax/360.0)*nc));
351 if (maxChunk == nc) {
354 int chunk =
static_cast<int>(
std::floor((raMin/360.0)*nc));
361 if (raMax < raMin || (raMax == raMin && wrap)) {
362 if (chunk == maxChunk) {
365 for ( ; chunk < fc + nc; ++chunk) {
366 chunkIds.push_back(chunk);
368 for (chunk = 0; chunk <= maxChunk; ++chunk) {
369 chunkIds.push_back(chunk);
372 for ( ; chunk <= maxChunk; ++chunk) {
373 chunkIds.push_back(chunk);
394 std::vector<int> & chunkIds,
400 if (numWorkers < 1) {
402 "number of workers must be positive");
404 if (workerId < 0 || workerId >= numWorkers) {
406 "Worker id must be between 0 and N - 1, where N is the total number of workers");
409 double const raMin = region.
getMinRa();
410 double const raMax = region.
getMaxRa();
415 int rem = s % numWorkers;
419 if (rem != workerId) {
426 int maxChunk = fc +
static_cast<int>(
std::floor((raMax*nc)/360.0)) % nc;
427 int chunk = fc +
static_cast<int>(
std::floor((raMin*nc)/360.0)) % nc;
430 if (chunk == maxChunk) {
433 for ( ; chunk < fc + nc; ++chunk) {
434 chunkIds.push_back(chunk);
436 for (chunk = 0; chunk <= maxChunk; ++chunk) {
437 chunkIds.push_back(chunk);
440 for (; chunk <= maxChunk; ++chunk) {
441 chunkIds.push_back(chunk);
A circular region of the unit sphere (sky).
int getFirstChunkForStripe(int const stripeId) const
void swap(Ellipse< DataT > &a, Ellipse< DataT > &b)
void computeChunkIds(std::vector< int > &chunkIds, CircularRegion const ®ion, ZoneStripeChunkDecomposition const &zsc, int const workerId=0, int const numWorkers=1)
double getRadius() const
Returns the radius of the circle.
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
ZoneStripeChunkDecomposition(int const zonesPerDegree, int const zonesPerStripe, int const maxEntriesPerZoneEstimate)
int decToStripe(double const dec) const
double getMinDec() const
Returns the minimum declination of points in the region.
double getCenterDec() const
Returns the declination of the circle center.
double getMaxDec() const
Returns the maximum declination of points in the region.
double getMinRa() const
Returns the minimum right ascension of points in the region.
double radToDeg(long double angleInRadians)
double getCenterRa() const
Returns the right ascension of the circle center.
double getMaxRa() const
Returns the maximum right ascension of points in the region.
int _maxEntriesPerZoneEstimate
A decomposition of the unit sphere into zones, stripes, and chunks.
double maxAlpha(double const theta, double const centerDec)
A rectangular region (in right ascension and declination) of the unit sphere.
double getMinDec() const
Returns the minimum declination of points in the region.
std::vector< int > _chunksPerStripe
double degToRad(long double angleInDegrees)
#define LSST_EXCEPT(type,...)
double alpha(double const theta, double const centerDec, double const dec)
void swap(ZoneStripeChunkDecomposition &zsc)
int getNumChunksPerStripe(int const stripeId, double const minWidth) const
Extent< int, N > floor(Extent< double, N > const &input)
double getMaxDec() const
Returns the maximum declination of points in the region.
double stripeAndCircleToRaRange(int const stripeId, double const cenRa, double const cenDec, double const rad) const
Include files required for standard LSST Exception handling.
Class and helper functions related to spatial partitioning.