Created
December 11, 2020 16:16
-
-
Save ntessore/99f72b6c1ed722d6672996e73c4bee5a to your computer and use it in GitHub Desktop.
HEALPix pixel shape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%matplotlib inline\n", | |
"import matplotlib.pyplot as plt" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import healpy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"nside = [1<<i for i in range(15)]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"npix = [healpy.nside2npix(n) for n in nside]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def pixshape(nside, ipix, step=1):\n", | |
" theta, phi = healpy.pix2ang(nside, ipix)\n", | |
" R = [[np.cos(theta)*np.cos(phi), np.cos(theta)*np.sin(phi), -np.sin(theta)],\n", | |
" [ -np.sin(phi), np.cos(phi), 0],\n", | |
" [np.sin(theta)*np.cos(phi), np.sin(theta)*np.sin(phi), np.cos(theta)]]\n", | |
" x = healpy.boundaries(nside, ipix, step=step)\n", | |
" x = np.dot(R, x)\n", | |
" x /= x[2]\n", | |
" return x[0:2]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment