Skip to content

Commit 5c66dbf

Browse files
authoredOct 20, 2020
Merge pull request #25 from Swarali-glitch/patch-1
Create sphere_healpy.md
2 parents 14d743b + 7ec3b92 commit 5c66dbf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎sphere_healpy.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Plot a sphere and pixel centers on it using Healpix package
2+
3+
*tags:* python, healpix, healpy
4+
5+
### Snippet
6+
```
7+
8+
from mayavi import mlab
9+
import numpy as np
10+
import healpy as hp
11+
12+
# Create a sphere
13+
r = 1.0
14+
pi = np.pi
15+
cos = np.cos
16+
sin = np.sin
17+
phi, theta = np.mgrid[0:pi:101j, 0:2 * pi:101j]
18+
19+
x = r*sin(phi)*cos(theta)
20+
y = r*sin(phi)*sin(theta)
21+
z = r*cos(phi)
22+
23+
mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(400, 300))
24+
mlab.clf()
25+
26+
pix_centers = hp.pix2vec(1, np.arange(12))
27+
xx, yy, zz = pix_centers
28+
29+
30+
mlab.mesh(x , y , z, color=(0.0,0.5,0.5))
31+
mlab.points3d(xx, yy, zz, scale_factor=0.2)
32+
33+
34+
mlab.show()
35+
```

0 commit comments

Comments
 (0)