Skip to content

Commit

Permalink
simplify rebin
Browse files Browse the repository at this point in the history
  • Loading branch information
arahlin committed Sep 20, 2023
1 parent 3ff69d2 commit d9e356e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions maps/include/maps/HealpixSkyMapInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class HealpixSkyMapInfo : public G3FrameObject {
std::vector<double> PixelToAngle(size_t pixel) const;
size_t AngleToPixel(double alpha, double delta) const;

size_t RebinPixel(size_t pixel, size_t scale) const;

void GetRebinAngles(size_t pixel, size_t scale,
std::vector<double> & alphas, std::vector<double> & deltas) const;

Expand Down
10 changes: 2 additions & 8 deletions maps/src/HealpixSkyMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1047,18 +1047,12 @@ G3SkyMapPtr HealpixSkyMap::Rebin(size_t scale, bool norm) const
else
return out;

const size_t scale2 = scale * scale;
const double sqscal = norm ? scale2 : 1.0;
const double sqscal = norm ? scale * scale : 1.0;

for (auto i : *this) {
if (i.second == 0)
continue;
ssize_t ip = i.first;
if (!nested())
ring2nest64(nside(), ip, &ip);
ip /= scale2;
if (!nested())
nest2ring64(out->nside(), ip, &ip);
size_t ip = info_.RebinPixel(i.first, scale);
(*out)[ip] += i.second / sqscal;
}

Expand Down
14 changes: 14 additions & 0 deletions maps/src/HealpixSkyMapInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ HealpixSkyMapInfo::PixelToAngle(size_t pixel) const
return {alpha, delta};
}

size_t
HealpixSkyMapInfo::RebinPixel(size_t pixel, size_t scale) const
{
ssize_t pix = pixel;

if (!nested_)
ring2nest64(nside_, pix, &pix);
pix /= scale * scale;
if (!nested_)
nest2ring64(nside_ / scale, pix, &pix);

return pix;
}

void
HealpixSkyMapInfo::GetRebinAngles(size_t pixel, size_t scale,
std::vector<double> & alphas, std::vector<double> & deltas) const
Expand Down

0 comments on commit d9e356e

Please sign in to comment.