Skip to content

Commit 815efae

Browse files
committed
Update healpy to upstream 1.10.3 release.
1 parent 340ae3d commit 815efae

7 files changed

Lines changed: 191 additions & 41 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ other work used to streamline that process.
3131
Current basis of this source is:
3232

3333
Healpix_3.31_2016Aug26.tar.gz md5 = c0dc75e57f237b634fec97df55997918
34-
healpy-1.10.1.tar.gz md5 = ee8750957a6fdfdafbef54e54788ec9b
34+
healpy-1.10.3.tar.gz md5 = 6491777d1bcbd36d356551bf240d3a2f
3535

3636
Source changes from future releases will have to be merged by hand, so your
3737
patience is appreciated.

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dnl
55
dnl +------------------------
66
dnl | Initialize package info
77
dnl +------------------------
8-
AC_INIT([HEALPix], [3.31.1], [work@theodorekisner.com], [healpix-autotools], [https://github.com/tskisner/healpix-autotools])
8+
AC_INIT([HEALPix], [3.31.2], [work@theodorekisner.com], [healpix-autotools], [https://github.com/tskisner/healpix-autotools])
99
AC_CONFIG_SRCDIR([Makefile.am])
1010
AM_INIT_AUTOMAKE([foreign tar-ustar])
1111
AC_CONFIG_HEADERS(config.h)

src/healpy/healpy/fitsfunc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""Provides input and output functions for Healpix maps, alm, and cl.
2121
"""
2222
from __future__ import with_statement
23+
from __future__ import division
2324

2425
import six
2526
import gzip
@@ -208,7 +209,7 @@ def write_map(filename,m,nest=False,dtype=np.float32,fits_IDL=True,coord=None,pa
208209
mm2 = np.asarray(mm)
209210
cols.append(pf.Column(name=cn,
210211
format='1024%s' % curr_fitsformat,
211-
array=mm2.reshape(mm2.size/1024,1024),
212+
array=mm2.reshape(mm2.size//1024,1024),
212213
unit=cu))
213214
else:
214215
cols.append(pf.Column(name=cn,

src/healpy/healpy/pixelfunc.py

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,40 @@ def check_theta_valid(theta):
127127
if not((theta >= 0).all() and (theta <= np.pi + 1e-5).all()):
128128
raise ValueError('THETA is out of range [0,pi]')
129129

130+
def lonlat2thetaphi(lon,lat):
131+
""" Transform longitude and latitude (deg) into co-latitude and longitude (rad)
132+
133+
Parameters
134+
----------
135+
lon : int or array-like
136+
Longitude in degrees
137+
lat : int or array-like
138+
Latitude in degrees
139+
140+
Returns
141+
-------
142+
theta, phi : float, scalar or array-like
143+
The co-latitude and longitude in radians
144+
"""
145+
return np.pi/2. - np.radians(lat),np.radians(lon)
146+
147+
def thetaphi2lonlat(theta,phi):
148+
""" Transform co-latitude and longitude (rad) into longitude and latitude (deg)
149+
150+
Parameters
151+
----------
152+
theta : int or array-like
153+
Co-latitude in radians
154+
phi : int or array-like
155+
Longitude in radians
156+
157+
Returns
158+
-------
159+
lon, lat : float, scalar or array-like
160+
The longitude and latitude in degrees
161+
"""
162+
return np.degrees(phi), 90. - np.degrees(theta)
163+
130164
def maptype(m):
131165
"""Describe the type of the map (valid, single, sequence of maps).
132166
Checks : the number of maps, that all maps have same length and that this
@@ -345,8 +379,8 @@ def ma(m, badval = UNSEEN, rtol = 1e-5, atol = 1e-8, copy = True):
345379
else:
346380
return tuple([ma(mm) for mm in m])
347381

348-
def ang2pix(nside,theta,phi,nest=False):
349-
"""ang2pix : nside,theta[rad],phi[rad],nest=False -> ipix (default:RING)
382+
def ang2pix(nside,theta,phi,nest=False,lonlat=False):
383+
"""ang2pix : nside,theta[rad],phi[rad],nest=False,lonlat=False -> ipix (default:RING)
350384
351385
Parameters
352386
----------
@@ -356,6 +390,9 @@ def ang2pix(nside,theta,phi,nest=False):
356390
Angular coordinates of a point on the sphere
357391
nest : bool, optional
358392
if True, assume NESTED pixel ordering, otherwise, RING pixel ordering
393+
lonlat : bool
394+
If True, input angles are assumed to be longitude and latitude in degree,
395+
otherwise, they are co-latitude and longitude in radians.
359396
360397
Returns
361398
-------
@@ -381,16 +418,21 @@ def ang2pix(nside,theta,phi,nest=False):
381418
382419
>>> hp.ang2pix([1, 2, 4, 8, 16], np.pi/2, 0)
383420
array([ 4, 12, 72, 336, 1440])
421+
422+
>>> hp.ang2pix([1, 2, 4, 8, 16], 0, 0, lonlat=True)
423+
array([ 4, 12, 72, 336, 1440])
384424
"""
425+
if lonlat:
426+
theta,phi = lonlat2thetaphi(theta,phi)
385427
check_theta_valid(theta)
386428
check_nside(nside)
387429
if nest:
388430
return pixlib._ang2pix_nest(nside,theta,phi)
389431
else:
390432
return pixlib._ang2pix_ring(nside,theta,phi)
391433

392-
def pix2ang(nside,ipix,nest=False):
393-
"""pix2ang : nside,ipix,nest=False -> theta[rad],phi[rad] (default RING)
434+
def pix2ang(nside,ipix,nest=False,lonlat=False):
435+
"""pix2ang : nside,ipix,nest=False,lonlat=False -> theta[rad],phi[rad] (default RING)
394436
395437
Parameters
396438
----------
@@ -400,6 +442,9 @@ def pix2ang(nside,ipix,nest=False):
400442
Pixel indices
401443
nest : bool, optional
402444
if True, assume NESTED pixel ordering, otherwise, RING pixel ordering
445+
lonlat : bool, optional
446+
If True, return angles will be longitude and latitude in degree,
447+
otherwise, angles will be longitude and co-latitude in radians (default)
403448
404449
Returns
405450
-------
@@ -422,12 +467,20 @@ def pix2ang(nside,ipix,nest=False):
422467
423468
>>> hp.pix2ang([1, 2, 4, 8], 11)
424469
(array([ 2.30052398, 0.84106867, 0.41113786, 0.2044802 ]), array([ 5.49778714, 5.89048623, 5.89048623, 5.89048623]))
470+
471+
>>> hp.pix2ang([1, 2, 4, 8], 11, lonlat=True)
472+
(array([ 315. , 337.5, 337.5, 337.5]), array([-41.8103149 , 41.8103149 , 66.44353569, 78.28414761]))
425473
"""
426474
check_nside(nside)
427475
if nest:
428-
return pixlib._pix2ang_nest(nside, ipix)
476+
theta,phi = pixlib._pix2ang_nest(nside, ipix)
477+
else:
478+
theta,phi = pixlib._pix2ang_ring(nside,ipix)
479+
480+
if lonlat:
481+
return thetaphi2lonlat(theta,phi)
429482
else:
430-
return pixlib._pix2ang_ring(nside,ipix)
483+
return theta, phi
431484

432485
def xyf2pix(nside,x,y,face,nest=False):
433486
"""xyf2pix : nside,x,y,face,nest=False -> ipix (default:RING)
@@ -588,7 +641,7 @@ def pix2vec(nside,ipix,nest=False):
588641
else:
589642
return pixlib._pix2vec_ring(nside,ipix)
590643

591-
def ang2vec(theta, phi):
644+
def ang2vec(theta, phi, lonlat=False):
592645
"""ang2vec : convert angles to 3D position vector
593646
594647
Parameters
@@ -597,6 +650,9 @@ def ang2vec(theta, phi):
597650
colatitude in radians measured southward from north pole (in [0,pi]).
598651
phi : float, scalar or array-like
599652
longitude in radians measured eastward (in [0, 2*pi]).
653+
lonlat : bool
654+
If True, input angles are assumed to be longitude and latitude in degree,
655+
otherwise, they are co-latitude and longitude in radians.
600656
601657
Returns
602658
-------
@@ -608,19 +664,24 @@ def ang2vec(theta, phi):
608664
--------
609665
vec2ang, rotator.dir2vec, rotator.vec2dir
610666
"""
667+
if lonlat:
668+
theta,phi = lonlat2thetaphi(theta,phi)
611669
check_theta_valid(theta)
612670
sintheta = np.sin(theta)
613671
return np.array([sintheta*np.cos(phi),
614672
sintheta*np.sin(phi),
615673
np.cos(theta)]).T
616674

617-
def vec2ang(vectors):
675+
def vec2ang(vectors, lonlat=False):
618676
"""vec2ang: vectors [x, y, z] -> theta[rad], phi[rad]
619677
620678
Parameters
621679
----------
622680
vectors : float, array-like
623681
the vector(s) to convert, shape is (3,) or (N, 3)
682+
lonlat : bool, optional
683+
If True, return angles will be longitude and latitude in degree,
684+
otherwise, angles will be longitude and co-latitude in radians (default)
624685
625686
Returns
626687
-------
@@ -636,7 +697,10 @@ def vec2ang(vectors):
636697
theta = np.arccos(vectors[:,2]/dnorm)
637698
phi = np.arctan2(vectors[:,1],vectors[:,0])
638699
phi[phi < 0] += 2*np.pi
639-
return theta, phi
700+
if lonlat:
701+
return thetaphi2lonlat(theta,phi)
702+
else:
703+
return theta, phi
640704

641705
def ring2nest(nside, ipix):
642706
"""Convert pixel number from RING ordering to NESTED ordering.
@@ -1122,7 +1186,7 @@ def isnpixok(npix):
11221186
nside = np.sqrt(npix/12.)
11231187
return isnsideok(nside)
11241188

1125-
def get_interp_val(m,theta,phi,nest=False):
1189+
def get_interp_val(m,theta,phi,nest=False,lonlat=False):
11261190
"""Return the bi-linear interpolation value of a map using 4 nearest neighbours.
11271191
11281192
Parameters
@@ -1133,6 +1197,9 @@ def get_interp_val(m,theta,phi,nest=False):
11331197
angular coordinates of point at which to interpolate the map
11341198
nest : bool
11351199
if True, the is assumed to be in NESTED ordering.
1200+
lonlat : bool
1201+
If True, input angles are assumed to be longitude and latitude in degree,
1202+
otherwise, they are co-latitude and longitude in radians.
11361203
11371204
Returns
11381205
-------
@@ -1153,11 +1220,16 @@ def get_interp_val(m,theta,phi,nest=False):
11531220
>>> hp.get_interp_val(np.arange(12.), np.pi/2, np.pi/2 + 2*np.pi)
11541221
5.0
11551222
>>> hp.get_interp_val(np.arange(12.), np.linspace(0, np.pi, 10), 0)
1223+
array([ 1.5 , 1.5 , 1.5 , 2.20618428, 3.40206143,
1224+
5.31546486, 7.94639458, 9.5 , 9.5 , 9.5 ])
1225+
>>> hp.get_interp_val(np.arange(12.), 0, np.linspace(90, -90, 10), lonlat=True)
11561226
array([ 1.5 , 1.5 , 1.5 , 2.20618428, 3.40206143,
11571227
5.31546486, 7.94639458, 9.5 , 9.5 , 9.5 ])
11581228
"""
11591229
m2=m.ravel()
11601230
nside=npix2nside(m2.size)
1231+
if lonlat:
1232+
theta,phi = lonlat2thetaphi(theta,phi)
11611233
if nest:
11621234
r=pixlib._get_interpol_nest(nside,theta,phi)
11631235
else:
@@ -1170,7 +1242,7 @@ def get_interp_val(m,theta,phi,nest=False):
11701242
def get_neighbours(nside, theta, phi=None, nest=False):
11711243
raise NameError("get_neighbours has been renamed to get_interp_weights")
11721244

1173-
def get_interp_weights(nside,theta,phi=None,nest=False):
1245+
def get_interp_weights(nside,theta,phi=None,nest=False,lonlat=False):
11741246
"""Return the 4 closest pixels on the two rings above and below the
11751247
location and corresponding weights.
11761248
Weights are provided for bilinear interpolation along latitude and longitude
@@ -1184,6 +1256,9 @@ def get_interp_weights(nside,theta,phi=None,nest=False):
11841256
otherwise theta[rad],phi[rad] are angular coordinates
11851257
nest : bool
11861258
if ``True``, NESTED ordering, otherwise RING ordering.
1259+
lonlat : bool
1260+
If True, input angles are assumed to be longitude and latitude in degree,
1261+
otherwise, they are co-latitude and longitude in radians.
11871262
11881263
Returns
11891264
-------
@@ -1204,6 +1279,9 @@ def get_interp_weights(nside,theta,phi=None,nest=False):
12041279
>>> hp.get_interp_weights(1, 0, 0)
12051280
(array([1, 2, 3, 0]), array([ 0.25, 0.25, 0.25, 0.25]))
12061281
1282+
>>> hp.get_interp_weights(1, 0, 90, lonlat=True)
1283+
(array([1, 2, 3, 0]), array([ 0.25, 0.25, 0.25, 0.25]))
1284+
12071285
>>> hp.get_interp_weights(1, [0, np.pi/2], 0)
12081286
(array([[ 1, 4],
12091287
[ 2, 5],
@@ -1216,6 +1294,8 @@ def get_interp_weights(nside,theta,phi=None,nest=False):
12161294
check_nside(nside)
12171295
if phi == None:
12181296
theta,phi = pix2ang(nside,theta,nest=nest)
1297+
elif lonlat:
1298+
theta,phi = lonlat2thetaphi(theta,phi)
12191299
if nest:
12201300
r=pixlib._get_interpol_nest(nside,theta,phi)
12211301
else:
@@ -1224,7 +1304,7 @@ def get_interp_weights(nside,theta,phi=None,nest=False):
12241304
w=np.array(r[4:8])
12251305
return (p,w)
12261306

1227-
def get_all_neighbours(nside, theta, phi=None, nest=False):
1307+
def get_all_neighbours(nside, theta, phi=None, nest=False, lonlat=False):
12281308
"""Return the 8 nearest pixels.
12291309
12301310
Parameters
@@ -1236,6 +1316,9 @@ def get_all_neighbours(nside, theta, phi=None, nest=False):
12361316
otherwise, theta[rad],phi[rad] are angular coordinates
12371317
nest : bool
12381318
if ``True``, pixel number will be NESTED ordering, otherwise RING ordering.
1319+
lonlat : bool
1320+
If True, input angles are assumed to be longitude and latitude in degree,
1321+
otherwise, they are co-latitude and longitude in radians.
12391322
12401323
Returns
12411324
-------
@@ -1257,10 +1340,13 @@ def get_all_neighbours(nside, theta, phi=None, nest=False):
12571340
12581341
>>> hp.get_all_neighbours(1, np.pi/2, np.pi/2)
12591342
array([ 8, 4, 0, -1, 1, 6, 9, -1])
1343+
1344+
>>> hp.get_all_neighbours(1, 90, 0, lonlat=True)
1345+
array([ 8, 4, 0, -1, 1, 6, 9, -1])
12601346
"""
12611347
check_nside(nside)
12621348
if phi is not None:
1263-
theta = ang2pix(nside,theta, phi,nest=nest)
1349+
theta = ang2pix(nside, theta, phi, nest=nest, lonlat=lonlat)
12641350
if nest:
12651351
r=pixlib._get_neighbors_nest(nside,theta)
12661352
else:

0 commit comments

Comments
 (0)