Coverage for HMpTy/htm/tests/test_htm.py : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import print_function
2from builtins import zip
3from builtins import str
4import os
5import unittest
6import shutil
7import yaml
8from HMpTy.utKit import utKit
9from fundamentals import tools
10from os.path import expanduser
11from past.utils import old_div
12home = expanduser("~")
14packageDirectory = utKit("").get_project_root()
15settingsFile = packageDirectory + "/test_settings.yaml"
17su = tools(
18 arguments={"settingsFile": settingsFile},
19 docString=__doc__,
20 logLevel="DEBUG",
21 options_first=False,
22 projectName=None,
23 defaultSettingsFile=False
24)
25arguments, settings, log, dbConn = su.setup()
27# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA
28moduleDirectory = os.path.dirname(__file__)
29pathToInputDir = moduleDirectory + "/input/"
30pathToOutputDir = moduleDirectory + "/output/"
32try:
33 shutil.rmtree(pathToOutputDir)
34except:
35 pass
36# COPY INPUT TO OUTPUT DIR
37shutil.copytree(pathToInputDir, pathToOutputDir)
39# Recursively create missing directories
40if not os.path.exists(pathToOutputDir):
41 os.makedirs(pathToOutputDir)
43class test_htm(unittest.TestCase):
45 def test_lookup01(self):
47 raList1 = ["138.30789"]
48 decList1 = ["+61.09267"]
49 from HMpTy import HTM
50 mesh16 = HTM(
51 depth=16,
52 log=log
53 )
54 print("LOOKUP")
55 htmids = mesh16.lookup_id(raList1, decList1)
56 for h, r, d in zip(htmids, raList1, decList1):
57 print(r, d, " --> ", h)
59 def test_htm_area_function(self):
61 from HMpTy import HTM
62 mesh24 = HTM(
63 depth=24,
64 log=log
65 )
66 mesh16 = HTM(
67 depth=16,
68 log=log
69 )
70 mesh15 = HTM(
71 depth=15,
72 log=log
73 )
74 mesh14 = HTM(
75 depth=14,
76 log=log
77 )
78 mesh13 = HTM(
79 depth=13,
80 log=log
81 )
82 mesh12 = HTM(
83 depth=12,
84 log=log
85 )
86 mesh11 = HTM(
87 depth=11,
88 log=log
89 )
90 mesh10 = HTM(
91 depth=10,
92 log=log
93 )
95 print("DEPTH24:", mesh24.depth)
96 print("AREA24:", mesh24.area * 60 * 60 * 60 * 60, " arcsec^2")
97 print("DEPTH16:", mesh16.depth)
98 print("AREA16:", mesh16.area * 60 * 60 * 60 * 60, " arcsec^2")
99 print("DEPTH15:", mesh15.depth)
100 print("AREA15:", mesh15.area * 60 * 60 * 60 * 60, " arcsec^2")
101 print("DEPTH14:", mesh14.depth)
102 print("AREA14:", mesh14.area * 60 * 60 * 60 * 60, " arcsec^2")
103 print("DEPTH13:", mesh13.depth)
104 print("AREA13:", mesh13.area * 60 * 60 * 60 * 60, " arcsec^2")
105 print("DEPTH12:", mesh12.depth)
106 print("AREA12:", mesh12.area * 60 * 60, " arcmin^2")
107 print("DEPTH11:", mesh11.depth)
108 print("AREA11:", mesh11.area * 60 * 60, " arcmin^2")
109 print("DEPTH10:", mesh10.depth)
110 print("AREA10:", mesh10.area * 60 * 60, " arcmin^2")
112 def test_htm_function(self):
114 from HMpTy import HTM
115 mesh16 = HTM(
116 depth=16,
117 log=log
118 )
119 mesh20 = HTM(
120 depth=20,
121 log=log
122 )
123 mesh24 = HTM(
124 depth=24,
125 log=log
126 )
127 print("DEPTH24:", mesh24.depth)
128 print("AREA24:", mesh24.area * 60 * 60 * 60 * 60, " arcsec^2")
129 print("DEPTH16:", mesh16.depth)
130 print("AREA16:", mesh16.area * 60 * 60 * 60 * 60, " arcsec^2")
131 print("DEPTH20:", mesh20.depth)
132 print("AREA20:", mesh20.area * 60 * 60 * 60 * 60, " arcsec^2")
134 overlappingTrixels = mesh24.intersect(
135 ra="23:25:53.56",
136 dec="+26:54:23.9",
137 radius=0.01,
138 inclusive=False
139 )
140 # print overlappingTrixels
142 overlappingTrixels = mesh24.intersect(
143 ra="23:25:53.56",
144 dec="+26:54:23.9",
145 radius=old_div(10, (60 * 60)),
146 inclusive=True
147 )
148 # print overlappingTrixels
150 twoArcsec = 2.0 / 3600.
151 raList1 = [200.0, 200.0, 200.0, 175.23, 21.36]
152 decList1 = [24.3, 24.3, 24.3, -28.25, -15.32]
153 raList2 = [200.0, 200.0, 200.0, 175.23, 55.25]
154 decList2 = [24.3 + 0.75 * twoArcsec, 24.3 + 0.25 * twoArcsec,
155 24.3 - 0.33 * twoArcsec, -28.25 + 0.58 * twoArcsec, 75.22]
156 matchIndices1, matchIndices2, seps = mesh16.match(
157 ra1=raList1,
158 dec1=decList1,
159 ra2=raList2,
160 dec2=decList2,
161 radius=twoArcsec,
162 maxmatch=0
163 )
165 for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
166 print(raList1[m1], decList1[m1], " -> ", s * 3600.,
167 " arcsec -> ", raList2[m2], decList2[m2])
169 def test_matcher_object(self):
171 raList1 = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36]
172 decList1 = ["+24:18:00.00", 24.3, "+24:18:00.00", -28.25, -15.32]
174 from HMpTy import Matcher
175 coordinateSet = Matcher(
176 log=log,
177 ra=raList1,
178 dec=decList1,
179 depth=16
180 )
182 twoArcsec = 2.0 / 3600.
183 raList2 = [200.0, 200.0, 200.0, 175.23, 55.25]
184 decList2 = [24.3 + 0.75 * twoArcsec, 24.3 + 0.25 * twoArcsec,
185 24.3 - 0.33 * twoArcsec, -28.25 + 0.58 * twoArcsec, 75.22]
187 matchIndices1, matchIndices2, seps = coordinateSet.match(
188 ra=raList2,
189 dec=decList2,
190 radius=twoArcsec,
191 maxmatch=0
192 )
194 for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
195 print(raList1[m1], decList1[m1], " -> ", s * 3600.,
196 " arcsec -> ", raList2[m2], decList2[m2])
198 print("NEARESRT MATCHES ONLY")
199 matchIndices1, matchIndices2, seps = coordinateSet.match(
200 ra=raList2,
201 dec=decList2,
202 radius=twoArcsec,
203 maxmatch=1
204 )
205 for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
206 print(raList1[m1], decList1[m1], " -> ", s * 3600.,
207 " arcsec -> ", raList2[m2], decList2[m2])
209 def test_lookup(self):
211 raList1 = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36]
212 decList1 = ["+24:18:00.00", 24.3, "+24:18:00.00", -28.25, -15.32]
213 from HMpTy import HTM
214 mesh16 = HTM(
215 depth=16,
216 log=log
217 )
218 print("LOOKUP")
219 htmids = mesh16.lookup_id(raList1, decList1)
220 for h, r, d in zip(htmids, raList1, decList1):
221 print(r, d, " --> ", h)
223 def test_htm_function_exception(self):
225 from HMpTy import htm
226 try:
227 this = htm(
228 log=log,
229 settings=settings,
230 fakeKey="break the code"
231 )
232 this.get()
233 assert False
234 except Exception as e:
235 assert True
236 print(str(e))
238 # x-print-testpage-for-pessto-marshall-web-object
240 # x-class-to-test-named-worker-function