Skip to content

Commit

Permalink
Consistent handling of RA sign (#157)
Browse files Browse the repository at this point in the history
Ensure that RA angles for G3SkyMap objects are in the range (0, 360 deg).

Also fix a bug in the RA check in flat sky map compatibility.
  • Loading branch information
arahlin authored Jul 10, 2024
1 parent c51f327 commit 314d84e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
17 changes: 8 additions & 9 deletions maps/src/FlatSkyProjection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ bool FlatSkyProjection::IsCompatible(const FlatSkyProjection & other) const
"(ProjNone) will raise an error.", proj_, other.proj_, ProjNone);
return check;
}
double da = fmod(fabs(alpha0_ - other.alpha0_), 360 * deg);
if (da > 180 * deg)
da = 360 * deg - da;
return (check &&
(proj_ == other.proj_) &&
(fabs(delta0_ - other.delta0_) < 1e-8) &&
(fmod(fabs(alpha0_ - other.alpha0_), 360 * deg) < 1e-8) &&
(da < 1e-8) &&
(fabs(x0_ - other.x0_) < 1e-8) &&
(fabs(y0_ - other.y0_) < 1e-8));
}
Expand Down Expand Up @@ -187,6 +190,8 @@ void FlatSkyProjection::SetProj(MapProjection proj)

void FlatSkyProjection::SetAlphaCenter(double alpha)
{
if (alpha < 0)
alpha += 360 * deg;
alpha0_ = alpha;
q0_ = get_origin_rotator(alpha0_, delta0_);
}
Expand Down Expand Up @@ -307,14 +312,8 @@ FlatSkyProjection::XYToAngle(double x, double y) const
break;
}

static const double circ = 360 * deg;
static const double halfcirc = 180 * deg;
double dalpha = alpha - alpha0_;

if (dalpha > halfcirc)
alpha -= circ;
if (dalpha < -halfcirc)
alpha += circ;
if (alpha < 0)
alpha += 360 * deg;

return {alpha, delta};
}
Expand Down
4 changes: 2 additions & 2 deletions maps/src/HealpixSkyMapInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ HealpixSkyMapInfo::PixelToAngle(size_t pixel) const
else
pix2ang_ring64(nside_, pixel, &delta, &alpha);

if (alpha > M_PI)
alpha -= twopi;
if (alpha < 0)
alpha += twopi;

if (delta < 0 || delta > 180 * G3Units::deg)
return {0., 0.};
Expand Down
2 changes: 2 additions & 0 deletions maps/src/pointing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ quat_to_ang(quat q, double &alpha, double &delta)
QNORM(q);
delta = ASIN(q.R_component_4()) * G3Units::rad;
alpha = ATAN2(q.R_component_3(), q.R_component_2())*G3Units::rad;
if (alpha < 0)
alpha += 360 * G3Units::deg;
}

static boost::python::tuple
Expand Down

0 comments on commit 314d84e

Please sign in to comment.