-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_percentarea.py
130 lines (119 loc) · 4.16 KB
/
test_percentarea.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from modules.hms.percent_area import CatchmentGrid
import unittest
import warnings
import json
import time
print("test_percentarea.py")
class PercentAreaTest(unittest.TestCase):
"""
Unit tests for spatially weighted average data
"""
def test_huc8(self):
"""
Test a sample Huc 8
"""
warnings.simplefilter("ignore", ResourceWarning)
try:
result = CatchmentGrid.getIntersectCellsInHuc8('03050204', 'nldas')
self.assertIsNotNone(result)
jsonData = json.loads(result)
self.assertEqual(1860, jsonData['metadata']['number of points'])
except Exception as e:
print("Huc 8 test failed... exception: {}".format(e))
return False
def test_huc12(self):
"""
Test a sample Huc 12
"""
warnings.simplefilter("ignore", ResourceWarning)
try:
result = CatchmentGrid.getIntersectCellsInHuc12('030502040102', 'nldas')
self.assertIsNotNone(result)
jsonData = json.loads(result)
self.assertEqual(100, jsonData['metadata']['number of points'])
except Exception as e:
print("Huc 12 test failed... exception: {}".format(e))
return False
def test_comList(self):
"""
Test a sample List of COM ID's
"""
warnings.simplefilter("ignore", ResourceWarning)
try:
result = CatchmentGrid.getIntersectCellsInComlist('9311811,9311813,9311815,9311817,9311819', 'nldas')
self.assertIsNotNone(result)
jsonData = json.loads(result)
self.assertEqual(7, jsonData['metadata']['number of points'])
except Exception as e:
print("List of COM ID's test failed... exception: {}".format(e))
return False
def test_comID(self):
"""
Test a sample COM ID
"""
warnings.simplefilter("ignore", ResourceWarning)
try:
result = CatchmentGrid.getIntersectCellsInComlist('9311811', 'nldas')
self.assertIsNotNone(result)
jsonData = json.loads(result)
self.assertEqual(1, jsonData['metadata']['number of points'])
except Exception as e:
print("COM ID test failed... exception: {}".format(e))
return False
"""
Test each of NLDAS, GLDAS, DAYMET, and PRISM grids with Huc 8 01010010
"""
def test_nldas(self):
warnings.simplefilter("ignore", ResourceWarning)
try:
nldasResult = CatchmentGrid.getIntersectCellsInHuc8('01010010', 'nldas')
self.assertIsNotNone(nldasResult, 'NLDAS error')
nldasJsonData = json.loads(nldasResult)
self.assertEqual(224, nldasJsonData['metadata']['number of points'])
except Exception as e:
print("NLDAS grid test failed... exception: {}".format(e))
return False
def test_gldas(self):
warnings.simplefilter("ignore", ResourceWarning)
try:
gldasResult = CatchmentGrid.getIntersectCellsInHuc8('01010010', 'gldas')
self.assertIsNotNone(gldasResult, 'GLDAS error')
gldasJsonData = json.loads(gldasResult)
self.assertEqual(181, gldasJsonData['metadata']['number of points'])
except Exception as e:
print("GLDAS grid test failed... exception: {}".format(e))
return False
def test_daymet(self):
warnings.simplefilter("ignore", ResourceWarning)
try:
daymetResult = CatchmentGrid.getIntersectCellsInHuc8('01010010', 'daymet')
self.assertIsNotNone(daymetResult, 'Daymet error')
daymetJsonData = json.loads(daymetResult)
self.assertEqual(162, daymetJsonData['metadata']['number of points'])
except Exception as e:
print("Daymet grid test failed... exception: {}".format(e))
return False
def test_prism(self):
warnings.simplefilter("ignore", ResourceWarning)
try:
prismResult = CatchmentGrid.getIntersectCellsInHuc8('01010010', 'prism')
self.assertIsNotNone(prismResult, 'PRISM error')
prismJsonData = json.loads(prismResult)
self.assertEqual(384, prismJsonData['metadata']['number of points'])
except Exception as e:
print("PRISM grid test failed... exception: {}".format(e))
return False
"""
def sample_test(self):
warnings.simplefilter("ignore", ResourceWarning)
try:
prismResult = CatchmentGrid.getIntersectCellsInComlist('49662', 'prism')
self.assertIsNotNone(prismResult, 'PRISM error')
prismJsonData = json.loads(prismResult)
self.assertEqual(4, prismJsonData['metadata']['number of points'])
except Exception as e:
print("PRISM grid test failed... exception: {}".format(e))
return False
"""
if __name__ == '__main__':
unittest.main()