-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
79 lines (66 loc) · 2.27 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Unit tests for PDF class
"""
import sys
import os
import numpy as np
import scipy.stats as sps
import healpy as hp
import unittest
import comsky
NSIDE = 256
class UtilsTestCase(unittest.TestCase):
def setUp(self):
"""
Make any objects that are used in multiple tests.
"""
self.files = []
def tearDown(self):
"Clean up any mock data files created by the tests."
for ff in self.files:
os.unlink(ff)
def test_point_source(self):
nSrc = 1000
l = 184.55746
b = -5.78436
mSrc = comsky.utils.MakePointSource(nSrc, NSIDE, l, b)
sampSrc = comsky.utils.MakePointSource(nSrc, NSIDE, l, b, sample=True)
def test_galactic(self):
nIso = 1000
mIso = comsky.utils.MakeIsotropicBackground(nIso, NSIDE)
sampIso = comsky.utils.MakeIsotropicBackground(nIso, NSIDE, sample=True)
def test_isotropic(self):
nGal = 10000
mGal = comsky.utils.MakeGalacticBackground(nGal, NSIDE)
sampGal = comsky.utils.MakeGalacticBackground(nGal, NSIDE, sample=True)
def testPSFConvolve(self):
nSrc = 10000
l = 0
b = 90
mPSF = comsky.utils.MakePointSource(nSrc, NSIDE, l, b)
almPSF = hp.sphtfunc.map2alm(mPSF)
vecNorth = np.array([0., 0., 1.])
mGalTrue = np.zeros(hp.pixelfunc.nside2npix(NSIDE))
sel = hp.query_disc(NSIDE, vecNorth, np.radians(92))
mGalTrue[sel] += 1.
sel = hp.query_disc(NSIDE, vecNorth, np.radians(88))
mGalTrue[sel] -= 1.
mGalConv = comsky.utils.ConvolveUsingAlm(mGalTrue, almPSF)
def testSamplePoints(self):
npts = 100
l = 0
b = 0
rad = 30
phi_dist = sps.uniform(scale=2*np.pi)
theta, phi = hp.pixelfunc.lonlat2thetaphi(l, b)
pts = comsky.utils.SamplePointsFromRings(phi, theta, np.radians(rad), phi_dist)
def testAddRing(self):
nside = 256
m = np.zeros((hp.pixelfunc.nside2npix(nside)))
l = 0
b = 0
theta, phi = hp.pixelfunc.lonlat2thetaphi(l, b)
ipix = hp.pixelfunc.ang2pix(nside, theta, phi)
comsky.utils.AddRingToMap(m, ipix, nside, radius=30, width=5)
if __name__ == '__main__':
unittest.main()