Skip to content

Commit aff258b

Browse files
committed
fix bug where map.resample still used the old corner version
1 parent 5a25511 commit aff258b

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

pixell/enmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def preflat(self):
9898
def npix(self): return np.prod(self.shape[-2:])
9999
@property
100100
def geometry(self): return self.shape, self.wcs
101-
def resample(self, oshape, off=(0,0), method="fft", border="wrap", corner=False, order=3): return resample(self, oshape, off=off, method=method, border=border, corner=corner, order=order)
101+
def resample(self, oshape, off=(0,0), method="fft", border="wrap", corner=True, order=3): return resample(self, oshape, off=off, method=method, border=border, corner=corner, order=order)
102102
def project(self, shape, wcs, mode="spline", order=3, border="constant", cval=0, safe=True): return project(self, shape, wcs, order, mode=mode, border=border, cval=cval, safe=safe)
103103
def extract(self, shape, wcs, omap=None, wrap="auto", op=lambda a,b:b, cval=0, iwcs=None, reverse=False): return extract(self, shape, wcs, omap=omap, wrap=wrap, op=op, cval=cval, iwcs=iwcs, reverse=reverse)
104104
def extract_pixbox(self, pixbox, omap=None, wrap="auto", op=lambda a,b:b, cval=0, iwcs=None, reverse=False): return extract_pixbox(self, pixbox, omap=omap, wrap=wrap, op=op, cval=cval, iwcs=iwcs, reverse=reverse)
@@ -478,7 +478,7 @@ def pix2sky(shape, wcs, pix, safe=True, corner=False, bcheck=False):
478478
coords = np.asarray(wcs.wcs_pix2world(*(tuple(pflat)[::-1]+(0,)))[::-1])*get_unit(wcs)
479479
coords = coords.reshape(pix.shape)
480480
if safe and not wcsutils.is_plain(wcs):
481-
coords = utils.unwind(coords, refmode="middle")
481+
coords[1] = utils.unwind(coords[1], refmode="middle")
482482
return coords
483483

484484
def sky2pix(shape, wcs, coords, safe=True, corner=False, bcheck=False):

pixell/reproject.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
except NameError: basestring = str
99

1010
def thumbnails(imap, coords, r=5*utils.arcmin, res=None, proj=None, apod=2*utils.arcmin,
11-
order=3, oversample=4, pol=None, oshape=None, owcs=None, extensive=False, verbose=False,
12-
filter=None,pixwin=False,pixwin_order=0):
11+
method="mixed", order=3, oversample=4, pol=None, oshape=None, owcs=None,
12+
extensive=False, verbose=False, filter=None,pixwin=False,pixwin_order=0):
1313
"""Given an enmap [...,ny,nx] and a set of coordinates in a numpy array
1414
coords with shape (n,2) and ordering [n,{dec,ra}], extract a set
1515
of thumbnail images [n,...,thumby,thumbx] centered on each set of
@@ -73,7 +73,7 @@ def thumbnails(imap, coords, r=5*utils.arcmin, res=None, proj=None, apod=2*utils
7373
# Define our output maps, which we will fill below
7474
omaps = enmap.zeros((nsrc,)+imap.shape[:-2]+oshape, owcs, imap.dtype)
7575
for si, pixbox in enumerate(pixboxes):
76-
if oversample > 1:
76+
if method == "nufft" or method == "mixed" and oversample > 1:
7777
# Make the pixbox fft-friendly
7878
for i in range(2):
7979
pixbox[1,i] = pixbox[0,i] + fft.fft_len(pixbox[1,i]-pixbox[0,i], direction="above", factors=[2,3,5])
@@ -86,13 +86,16 @@ def thumbnails(imap, coords, r=5*utils.arcmin, res=None, proj=None, apod=2*utils
8686
print("%4d/%d %6.2f %6.2f %8.2f %dx%d" % (si+1, nsrc, coords[si,0]/utils.degree, coords[si,1]/utils.degree, np.max(ithumb), ithumb.shape[-2], ithumb.shape[-1]))
8787
# Oversample using fourier if requested. We do this because fourier
8888
# interpolation is better than spline interpolation overall
89-
if oversample > 1:
89+
if method == "mixed" and oversample > 1:
9090
fshape = utils.nint(np.array(oshape[-2:])*oversample)
9191
ithumb = ithumb.resample(fshape, method="fft")
92-
# I apologize for the syntax. There should be a better way of doing this
92+
# I apologize for the syntax. There should be a better way to do this
9393
ipos = coordinates.transform("cel", ["cel",[[0,0,coords[si,1],coords[si,0]],False]], opos[::-1], pol=pol)
9494
ipos, rest = ipos[1::-1], ipos[2:]
95-
omaps[si] = ithumb.at(ipos, mode="spline", order=order)
95+
if method in ["spline", "mixed"]: ipol_mode = "spline"
96+
elif method in ["nufft"]: ipol_mode = "nufft"
97+
else: raise ValueError("Unrecognized method '%s'" % (str(method)))
98+
omaps[si] = ithumb.at(ipos, mode=ipol_mode, order=order)
9699
# Apply the polarization rotation. The sign is flipped because we computed the
97100
# rotation from the output to the input
98101
if pol: omaps[si] = enmap.rotate_pol(omaps[si], -rest[0])

pixell/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def unwind(a, period=2*np.pi, axes=[-1], ref=0, refmode="left", mask_nan=False):
232232
period-wrapping. I.e. [0.07,0.02,6.25,6.20] would
233233
become [0.07,0.02,-0.03,-0.08] with the default period
234234
of 2*pi."""
235+
if a.ndim == 0: return a
235236
res = rewind(a, period=period, ref=ref)
236237
for axis in axes:
237238
with flatview(res, axes=[axis]) as flat:

tests/test_pixell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,8 @@ def test_thumbnails(self):
10781078
# with gnomonic/tangent projection
10791079
proj = "tan"
10801080
r = 10*u.arcmin
1081-
ret = reproject.thumbnails(omap, srcs[:,:2], r=r, res=res, proj=proj,
1082-
apod=2*u.arcmin, order=3, oversample=2,pixwin=False)
1081+
ret = reproject.thumbnails(omap, srcs[:,:2], r=r, res=res, proj=proj,
1082+
apod=2*u.arcmin, order=3, oversample=4, pixwin=False)
10831083

10841084
# Create a reference source at the equator to compare this against
10851085
ishape,iwcs = enmap.geometry(shape=ret.shape,res=res,pos=(0,0),proj=proj)

0 commit comments

Comments
 (0)