Skip to content

Commit ef1eeb0

Browse files
committed
Bug fix in FlatSkyMap.query_disc method
The method for determining the box of valid pixels that contain the disc to query used an incorrect calculation for offsetting the disc center to sweep out a circle. This PR fixes this calculation by using a slightly less efficient but reliable method for computing the offset quaternion.
1 parent 53a0bd5 commit ef1eeb0

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

maps/src/FlatSkyProjection.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,9 @@ FlatSkyProjection::QueryDisc(const Quat &q, double radius) const
602602
{
603603
static const size_t npts = 72;
604604
double dd = -2.0 * radius / sqrt(2.0);
605-
auto qd = get_origin_rotator(0, dd);
606-
auto p = qd * q * ~qd;
605+
double alpha, delta;
606+
quat_to_ang(q, alpha, delta);
607+
auto p = ang_to_quat(alpha, delta + (((90*deg - delta) < -dd) ? dd : -dd));
607608
double pva = q.b();
608609
double pvb = q.c();
609610
double pvc = q.d();

maps/src/G3SkyMap.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,10 @@ G3SkyMap::QueryAlphaEllipse(const Quat &q, double a, double b) const
436436
double da = ACOS(COS(rmaj) / COS(rmin)) / cd;
437437

438438
// focus locations
439-
auto qda = get_origin_rotator(da, 0);
440-
auto ql = qda * q * ~qda;
441-
auto qr = ~qda * q * qda;
439+
double alpha, delta;
440+
quat_to_ang(q, alpha, delta);
441+
auto ql = ang_to_quat(alpha - da, delta);
442+
auto qr = ang_to_quat(alpha + da, delta);
442443

443444
// narrow search to pixels within the major disc
444445
auto disc = QueryDisc(q, rmaj);

maps/tests/flatsky_maps.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,35 @@
109109
).ravel()
110110
radius = 5 * x.res
111111

112-
avec = []
113-
dvec = []
114-
rvec = []
115-
masked = set()
116-
117-
for a in numpy.linspace(numpy.min(alpha), numpy.max(alpha), 20):
118-
for d in numpy.linspace(numpy.min(delta), numpy.max(delta), 20):
119-
avec.append(a)
120-
dvec.append(d)
121-
rvec.append(radius)
122-
pix1 = x.query_disc(a, d, radius)
123-
pix2 = numpy.where(
124-
angles.separation(
125-
SkyCoord(
126-
a / core.G3Units.deg * u.degree,
127-
d / core.G3Units.deg * u.degree,
128-
)
129-
).deg * core.G3Units.deg < radius
130-
)[0]
131-
masked |= set(pix2)
132-
assert not (set(pix1) ^ set(pix2))
133-
134-
mask = maps.make_point_source_mask(x, numpy.asarray(avec), numpy.asarray(dvec), numpy.asarray(rvec))
135-
assert not (set(mask.nonzero()) ^ masked)
112+
for alpha1 in numpy.linspace(0, 360, 13) * core.G3Units.deg:
113+
for delta1 in numpy.linspace(-90, 90, 5) * core.G3Units.deg:
114+
avec = []
115+
dvec = []
116+
rvec = []
117+
masked = set()
118+
119+
x = FlatSkyMap(50, 50, core.G3Units.arcmin, proj=MapProjection.ProjZEA, alpha_center=alpha1, delta_center=delta1)
120+
alpha, delta = maps.get_ra_dec_map(x)
121+
angles = SkyCoord(
122+
numpy.asarray(alpha) / core.G3Units.deg * u.degree,
123+
numpy.asarray(delta) / core.G3Units.deg * u.degree,
124+
).ravel()
125+
for a in numpy.linspace(numpy.min(alpha), numpy.max(alpha), 20):
126+
for d in numpy.linspace(numpy.min(delta), numpy.max(delta), 20):
127+
avec.append(a)
128+
dvec.append(d)
129+
rvec.append(radius)
130+
pix1 = x.query_disc(a, d, radius)
131+
pix2 = numpy.where(
132+
angles.separation(
133+
SkyCoord(
134+
a / core.G3Units.deg * u.degree,
135+
d / core.G3Units.deg * u.degree,
136+
)
137+
).deg * core.G3Units.deg < radius
138+
)[0]
139+
masked |= set(pix2)
140+
assert not (set(pix1) ^ set(pix2))
141+
142+
mask = maps.make_point_source_mask(x, numpy.asarray(avec), numpy.asarray(dvec), numpy.asarray(rvec))
143+
assert not (set(mask.nonzero()) ^ masked)

0 commit comments

Comments
 (0)