Skip to content

Commit c3b6277

Browse files
author
Dag Sverre Seljebotn
committed
sharp_make_subset_healpix_geom_info
1 parent cf7de6b commit c3b6277

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

libsharp/sharp_geomhelpers.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,33 @@
3434
#include "sharp_geomhelpers.h"
3535
#include "c_utils.h"
3636
#include "ls_fft.h"
37+
#include <stdio.h>
3738

38-
void sharp_make_weighted_healpix_geom_info (int nside, int stride,
39-
const double *weight, sharp_geom_info **geom_info)
39+
void sharp_make_subset_healpix_geom_info (int nside, int stride, int nrings,
40+
const int *rings, const double *weight, sharp_geom_info **geom_info)
4041
{
4142
const double pi=3.141592653589793238462643383279502884197;
4243
ptrdiff_t npix=(ptrdiff_t)nside*nside*12;
4344
ptrdiff_t ncap=2*(ptrdiff_t)nside*(nside-1);
44-
int nrings=4*nside-1;
4545

4646
double *theta=RALLOC(double,nrings);
4747
double *weight_=RALLOC(double,nrings);
4848
int *nph=RALLOC(int,nrings);
4949
double *phi0=RALLOC(double,nrings);
5050
ptrdiff_t *ofs=RALLOC(ptrdiff_t,nrings);
5151
int *stride_=RALLOC(int,nrings);
52+
ptrdiff_t curofs=0, checkofs; /* checkofs used for assertion introduced when adding rings arg */
5253
for (int m=0; m<nrings; ++m)
5354
{
54-
int ring=m+1;
55+
int ring = (rings==NULL)? (m+1) : rings[m];
5556
ptrdiff_t northring = (ring>2*nside) ? 4*nside-ring : ring;
5657
stride_[m] = stride;
5758
if (northring < nside)
5859
{
5960
theta[m] = 2*asin(northring/(sqrt(6.)*nside));
6061
nph[m] = 4*northring;
6162
phi0[m] = pi/nph[m];
62-
ofs[m] = 2*northring*(northring-1)*stride;
63+
checkofs = 2*northring*(northring-1)*stride;
6364
}
6465
else
6566
{
@@ -71,14 +72,21 @@ void sharp_make_weighted_healpix_geom_info (int nside, int stride,
7172
phi0[m] = 0;
7273
else
7374
phi0[m] = pi/nph[m];
74-
ofs[m] = (ncap + (northring-nside)*nph[m])*stride;
75+
checkofs = (ncap + (northring-nside)*nph[m])*stride;
76+
ofs[m] = curofs;
7577
}
7678
if (northring != ring) /* southern hemisphere */
7779
{
7880
theta[m] = pi-theta[m];
79-
ofs[m] = (npix - nph[m])*stride - ofs[m];
81+
checkofs = (npix - nph[m])*stride - checkofs;
82+
ofs[m] = curofs;
8083
}
8184
weight_[m]=4.*pi/npix*((weight==NULL) ? 1. : weight[northring-1]);
85+
if (rings==NULL) {
86+
UTIL_ASSERT(curofs==checkofs, "Bug in computing ofs[m]");
87+
}
88+
ofs[m] = curofs;
89+
curofs+=nph[m];
8290
}
8391

8492
sharp_make_geom_info (nrings, nph, ofs, stride_, phi0, theta, weight_,
@@ -92,6 +100,12 @@ void sharp_make_weighted_healpix_geom_info (int nside, int stride,
92100
DEALLOC(stride_);
93101
}
94102

103+
void sharp_make_weighted_healpix_geom_info (int nside, int stride,
104+
const double *weight, sharp_geom_info **geom_info)
105+
{
106+
sharp_make_subset_healpix_geom_info(nside, stride, 4 * nside - 1, NULL, weight, geom_info);
107+
}
108+
95109
static inline double one_minus_x2 (double x)
96110
{ return (fabs(x)>0.1) ? (1.+x)*(1.-x) : 1.-x*x; }
97111

libsharp/sharp_geomhelpers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
extern "C" {
3939
#endif
4040

41+
/*! Creates a geometry information describing a HEALPix map with an
42+
Nside parameter \a nside. \a weight contains the relative ring
43+
weights and must have \a 2*nside entries. The rings array contains
44+
the indices of the rings, with 1 being the first ring at the north
45+
pole; if NULL then we take them to be sequential. Pass 4 * nside - 1
46+
as nrings and NULL to rings to get the full HEALPix grid.
47+
\note if \a weight is a null pointer, all weights are assumed to be 1.
48+
\note if \a rings is a null pointer, take all rings
49+
\ingroup geominfogroup */
50+
void sharp_make_subset_healpix_geom_info (int nside, int stride, int nrings,
51+
const int *rings, const double *weight, sharp_geom_info **geom_info);
52+
4153
/*! Creates a geometry information describing a HEALPix map with an
4254
Nside parameter \a nside. \a weight contains the relative ring
4355
weights and must have \a 2*nside entries.

0 commit comments

Comments
 (0)