-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sample positions uniformly over HEALPix pixel (#344)
- Loading branch information
Showing
6 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# healpix map information | ||
nside: 2 | ||
|
||
# sample 500 galaxies in healpix pixel 5 | ||
positions: !skypy.position.uniform_in_pixel | ||
nside: $nside | ||
ipix: 5 | ||
size: 500 |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,12 @@ test = | |
all = | ||
camb | ||
classy @ git+https://github.com/skypyproject/[email protected]#egg=classy | ||
healpy | ||
skypy-data @ https://github.com/skypyproject/skypy-data/archive/master.tar.gz | ||
specutils | ||
docs = | ||
sphinx-astropy | ||
healpy | ||
matplotlib | ||
|
||
[options.package_data] | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
healpy = pytest.importorskip('healpy') | ||
|
||
|
||
def test_uniform_in_pixel_correctness(): | ||
from skypy.position import uniform_in_pixel | ||
|
||
# 768 healpix pixels | ||
nside = 8 | ||
npix = healpy.nside2npix(nside) | ||
|
||
ipix = np.random.randint(npix) | ||
|
||
size = 1000 | ||
pos = uniform_in_pixel(nside, ipix, size=size) | ||
assert len(pos) == size | ||
|
||
lon, lat = pos.ra.deg, pos.dec.deg | ||
apix = healpy.ang2pix(nside, lon, lat, lonlat=True) | ||
np.testing.assert_array_equal(apix, ipix) | ||
|
||
|
||
@pytest.mark.flaky | ||
def test_uniform_in_pixel_distribution(): | ||
from scipy.stats import kstest | ||
|
||
from skypy.position import uniform_in_pixel | ||
|
||
# 48 healpix pixels | ||
nside = 2 | ||
npix = healpy.nside2npix(nside) | ||
|
||
# sample entire sky with 20 positions per pixel | ||
size = 20 | ||
theta, phi = np.empty(npix*size), np.empty(npix*size) | ||
for ipix in range(npix): | ||
pos = uniform_in_pixel(nside, ipix, size=size) | ||
assert len(pos) == size | ||
theta[ipix*size:(ipix+1)*size] = np.pi/2 - pos.dec.rad | ||
phi[ipix*size:(ipix+1)*size] = pos.ra.rad | ||
|
||
# test for uniform distribution | ||
D, p = kstest(theta, lambda t: (1 - np.cos(t))/2) | ||
assert p > 0.01, 'D = {}, p = {}'.format(D, p) | ||
D, p = kstest(phi, 'uniform', args=(0, 2*np.pi)) | ||
assert p > 0.01, 'D = {}, p = {}'.format(D, p) |