Coverage for HMpTy/mysql/tests/test_conesearch.py : 91%

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 str
3import os
4import unittest
5import shutil
6import yaml
7from HMpTy.utKit import utKit
8from fundamentals import tools
9from os.path import expanduser
10home = expanduser("~")
12packageDirectory = utKit("").get_project_root()
13settingsFile = packageDirectory + "/test_settings.yaml"
15su = tools(
16 arguments={"settingsFile": settingsFile},
17 docString=__doc__,
18 logLevel="DEBUG",
19 options_first=False,
20 projectName=None,
21 defaultSettingsFile=False
22)
23arguments, settings, log, dbConn = su.setup()
25# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA
26moduleDirectory = os.path.dirname(__file__)
27pathToInputDir = moduleDirectory + "/input/"
28pathToOutputDir = moduleDirectory + "/output/"
30try:
31 shutil.rmtree(pathToOutputDir)
32except:
33 pass
34# COPY INPUT TO OUTPUT DIR
35shutil.copytree(pathToInputDir, pathToOutputDir)
37# Recursively create missing directories
38if not os.path.exists(pathToOutputDir):
39 os.makedirs(pathToOutputDir)
41# RELOAD TEST DATA
42from fundamentals.mysql import execute_mysql_script
43exception = execute_mysql_script(
44 pathToScript=pathToInputDir + "/transientBucket.sql",
45 log=log,
46 dbConn=dbConn
47)
50class test_conesearch(unittest.TestCase):
52 def test_get_trixel_ids_that_overlap_conesearch_circles(self):
54 from HMpTy.mysql import conesearch
55 cs = conesearch(
56 log=log,
57 dbConn=dbConn,
58 tableName="transientBucket",
59 columns="transientBucketId, spectralType",
60 ra="23:25:53.56",
61 dec="+26:54:23.9",
62 radiusArcsec=5
63 )
64 print("SINGLE COORDINATE CONESEARCH TRIXEL IDs")
65 print(cs._get_trixel_ids_that_overlap_conesearch_circles())
67 raList1 = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36]
68 decList1 = ["+24:18:00.00", 24.3, "+24:18:00.00", -28.25, -15.32]
70 from HMpTy.mysql import conesearch
71 cs = conesearch(
72 log=log,
73 dbConn=dbConn,
74 tableName="transientBucket",
75 columns="transientBucketId, spectralType",
76 ra=raList1,
77 dec=decList1,
78 radiusArcsec=5
79 )
80 print("COORDINATE LIST CONESEARCH TRIXEL IDs")
81 print(cs._get_trixel_ids_that_overlap_conesearch_circles())
83 def test_conesearch_function(self):
85 from HMpTy.mysql import conesearch
86 cs = conesearch(
87 log=log,
88 dbConn=dbConn,
89 tableName="transientBucket",
90 columns="transientBucketId, spectralType",
91 ra="23:25:53.56",
92 dec="+26:54:23.9",
93 radiusArcsec=5
94 )
95 print(cs.query)
97 def test_conesearch_function2(self):
99 from HMpTy.mysql import conesearch
100 cs = conesearch(
101 log=log,
102 dbConn=dbConn,
103 tableName="transientBucket",
104 columns="transientBucketId, spectralType",
105 ra=351.47321,
106 dec=26.90664,
107 radiusArcsec=5
108 )
109 print(cs.query)
111 def test_conesearch_function3(self):
113 raList1 = ["23:25:53.56", "02:10:08.16",
114 "13:20:00.00", 1.47329, 35.34279]
115 decList1 = ["+26:54:23.9", "-48:38:24.3",
116 "+24:18:00.00", 8.43016, -42.34428]
118 from HMpTy.mysql import conesearch
119 cs = conesearch(
120 log=log,
121 dbConn=dbConn,
122 tableName="transientBucket",
123 columns="transientBucketId, spectralType",
124 ra=raList1,
125 dec=decList1,
126 radiusArcsec=10,
127 separations=True
128 )
129 matchIndies, matches = cs.search()
130 for row in matches.list:
131 print(row)
133 def test_conesearch_function4(self):
135 raList1 = ["23:25:53.56", "02:10:08.16",
136 "13:20:00.00", 1.47329, 35.34279]
137 decList1 = ["+26:54:23.9", "-48:38:24.3",
138 "+24:18:00.00", 8.43016, -42.34428]
140 from HMpTy.mysql import conesearch
141 cs = conesearch(
142 log=log,
143 dbConn=dbConn,
144 tableName="transientBucket",
145 columns="transientBucketId, spectralType",
146 ra=raList1,
147 dec=decList1,
148 radiusArcsec=7200
149 )
150 matchIndies, matches = cs.search()
152 def test_conesearch_distinct_function(self):
154 raList1 = ["23:25:53.56", "02:10:08.16",
155 "13:20:00.00", 1.47329, 35.34279]
156 decList1 = ["+26:54:23.9", "-48:38:24.3",
157 "+24:18:00.00", 8.43016, -42.34428]
159 from HMpTy.mysql import conesearch
160 cs = conesearch(
161 log=log,
162 dbConn=dbConn,
163 tableName="transientBucket",
164 columns="transientBucketId, spectralType",
165 ra=raList1,
166 dec=decList1,
167 radiusArcsec=10,
168 separations=True,
169 distinct=True
170 )
171 matchIndies, matches = cs.search()
172 for row in matches.list:
173 print(row)
175 def test_conesearch_sql_where_function(self):
177 raList1 = ["23:25:53.56", "02:10:08.16",
178 "13:20:00.00", 1.47329, 35.34279]
179 decList1 = ["+26:54:23.9", "-48:38:24.3",
180 "+24:18:00.00", 8.43016, -42.34428]
182 print("WHERE CLAUSE ADDED")
183 from HMpTy.mysql import conesearch
184 cs = conesearch(
185 log=log,
186 dbConn=dbConn,
187 tableName="transientBucket",
188 columns="transientBucketId, spectralType",
189 ra=raList1,
190 dec=decList1,
191 radiusArcsec=10,
192 separations=True,
193 distinct=False,
194 sqlWhere="spectralType is not null"
195 )
196 matchIndies, matches = cs.search()
197 for row in matches.list:
198 pass
199 print(row)
201 def test_conesearch_sql_where_function2(self):
203 raList1 = ["23:25:53.56", "02:10:08.16",
204 "13:20:00.00", 1.47329, 35.34279]
205 decList1 = ["+26:54:23.9", "-48:38:24.3",
206 "+24:18:00.00", 8.43016, -42.34428]
208 print("WHERE CLAUSE ADDED & DISTINCT")
209 from HMpTy.mysql import conesearch
210 cs = conesearch(
211 log=log,
212 dbConn=dbConn,
213 tableName="transientBucket",
214 columns="transientBucketId, spectralType",
215 ra=raList1,
216 dec=decList1,
217 radiusArcsec=10,
218 separations=True,
219 distinct=True,
220 sqlWhere="spectralType is not null"
221 )
222 matchIndies, matches = cs.search()
223 for row in matches.list:
224 pass
225 print(row)
227 def test_documentaion_function(self):
229 raList1 = ["23:25:53.56", "02:10:08.16",
230 "13:20:00.00", 1.47329, 35.34279]
231 decList1 = ["+26:54:23.9", "-48:38:24.3",
232 "+24:18:00.00", 8.43016, -42.34428]
234 print("TUTORIAL")
235 from HMpTy.mysql import conesearch
236 cs = conesearch(
237 log=log,
238 dbConn=dbConn,
239 tableName="transientBucket",
240 columns="transientBucketId, spectralType",
241 ra=raList1,
242 dec=decList1,
243 radiusArcsec=10,
244 separations=False,
245 distinct=False,
246 sqlWhere=False
247 )
248 print(cs.query)
249 matchIndies, matches = cs.search()
250 for row in matches.list:
251 pass
252 print(row)
254 def test_documentaion_functio2(self):
256 raList1 = ["23:25:53.56", "02:10:08.16",
257 "13:20:00.00", 1.47329, 35.34279]
258 decList1 = ["+26:54:23.9", "-48:38:24.3",
259 "+24:18:00.00", 8.43016, -42.34428]
261 print("TUTORIAL")
262 from HMpTy.mysql import conesearch
263 cs = conesearch(
264 log=log,
265 dbConn=dbConn,
266 tableName="transientBucket",
267 columns="transientBucketId, spectralType",
268 ra=raList1,
269 dec=decList1,
270 radiusArcsec=10,
271 separations=True,
272 distinct=True,
273 sqlWhere="spectralType is not null"
274 )
275 print(cs.query)
276 matchIndies, matches = cs.search()
277 for row in matches.list:
278 pass
279 print(row)
281 print(matches.table())
282 matches.table(filepath=pathToOutputDir + "results.dat")
284 print(matches.mysql(tableName="mysql_table", filepath=None))
286 def test_conesearch_function_exception(self):
288 from HMpTy.mysql import conesearch
289 try:
290 this = conesearch(
291 log=log,
293 fakeKey="break the code"
294 )
295 this.get()
296 assert False
297 except Exception as e:
298 assert True
299 print(str(e))
301 # x-print-testpage-for-pessto-marshall-web-object
303 # x-class-to-test-named-worker-function