1
1
"""Tests for sliderule-python icesat2 api."""
2
2
3
3
import pytest
4
- from requests .exceptions import ConnectTimeout , ConnectionError
5
4
import sliderule
6
5
from sliderule import icesat2
7
- from pathlib import Path
8
- import os .path
9
6
10
- SERVER = "icesat2sliderule.org"
11
7
ASSET = "nsidc-s3"
12
8
13
9
ATL03_FILE1 = "ATL03_20181019065445_03150111_004_01.h5"
20
16
21
17
@pytest .mark .network
22
18
class TestApi :
23
- def test_time (self ):
24
- icesat2 .init (SERVER )
19
+ def test_time (self , server ):
20
+ icesat2 .init (server )
25
21
rqst = {
26
22
"time" : "NOW" ,
27
23
"input" : "NOW" ,
@@ -39,37 +35,37 @@ def test_time(self):
39
35
again = d ["time" ]
40
36
assert now == again
41
37
42
- def test_h5 (self ):
43
- icesat2 .init (SERVER )
44
- epoch_offset = icesat2 .h5 ("ancillary_data/atlas_sdp_gps_epoch" , ATL03_FILE1 , ASSET )[0 ]
38
+ def test_h5 (self , server , asset ):
39
+ icesat2 .init (server )
40
+ epoch_offset = icesat2 .h5 ("ancillary_data/atlas_sdp_gps_epoch" , ATL03_FILE1 , asset )[0 ]
45
41
assert epoch_offset == 1198800018.0
46
42
47
- def test_h5_types (self ):
48
- icesat2 .init (SERVER )
49
- heights_64 = icesat2 .h5 ("/gt1l/land_ice_segments/h_li" , ATL06_FILE1 , ASSET )
43
+ def test_h5_types (self , server , asset ):
44
+ icesat2 .init (server )
45
+ heights_64 = icesat2 .h5 ("/gt1l/land_ice_segments/h_li" , ATL06_FILE1 , asset )
50
46
expected_64 = [45.95665 , 45.999374 , 46.017857 , 46.015575 , 46.067562 , 46.099796 , 46.14037 , 46.105526 , 46.096024 , 46.12297 ]
51
- heights_32 = icesat2 .h5 ("/gt1l/land_ice_segments/h_li" , ATL06_FILE2 , ASSET )
47
+ heights_32 = icesat2 .h5 ("/gt1l/land_ice_segments/h_li" , ATL06_FILE2 , asset )
52
48
expected_32 = [350.46988 , 352.08688 , 352.43243 , 353.19345 , 353.69543 , 352.25998 , 350.15366 , 346.37888 , 342.47903 , 341.51 ]
53
- bckgrd_32nf = icesat2 .h5 ("/gt1l/bckgrd_atlas/bckgrd_rate" , ATL03_FILE2 , ASSET )
49
+ bckgrd_32nf = icesat2 .h5 ("/gt1l/bckgrd_atlas/bckgrd_rate" , ATL03_FILE2 , asset )
54
50
expected_32nf = [29311.684 , 6385.937 , 6380.8413 , 28678.951 , 55349.168 , 38201.082 , 19083.434 , 38045.67 , 34942.434 , 38096.266 ]
55
51
for c in zip (heights_64 , expected_64 , heights_32 , expected_32 , bckgrd_32nf , expected_32nf ):
56
52
assert (round (c [0 ]) == round (c [1 ])) and (round (c [2 ]) == round (c [3 ])) and (round (c [4 ]) == round (c [5 ]))
57
53
58
- def test_variable_length (self ):
59
- icesat2 .init (SERVER )
60
- v = icesat2 .h5 ("/gt1r/geolocation/segment_ph_cnt" , ATL03_FILE1 , ASSET )
54
+ def test_variable_length (self , server , asset ):
55
+ icesat2 .init (server )
56
+ v = icesat2 .h5 ("/gt1r/geolocation/segment_ph_cnt" , ATL03_FILE1 , asset )
61
57
assert v [0 ] == 258 and v [1 ] == 256 and v [2 ] == 273
62
58
63
- def test_h5p (self ):
64
- icesat2 .init (SERVER )
59
+ def test_h5p (self , server , asset ):
60
+ icesat2 .init (server )
65
61
datasets = [
66
62
{"dataset" : "/gt1l/land_ice_segments/h_li" , "numrows" : 5 },
67
63
{"dataset" : "/gt1r/land_ice_segments/h_li" , "numrows" : 5 },
68
64
{"dataset" : "/gt2l/land_ice_segments/h_li" , "numrows" : 5 },
69
65
{"dataset" : "/gt2r/land_ice_segments/h_li" , "numrows" : 5 },
70
66
{"dataset" : "/gt3l/land_ice_segments/h_li" , "numrows" : 5 },
71
67
{"dataset" : "/gt3r/land_ice_segments/h_li" , "numrows" : 5 } ]
72
- rsps = icesat2 .h5p (datasets , ATL06_FILE1 , ASSET )
68
+ rsps = icesat2 .h5p (datasets , ATL06_FILE1 , asset )
73
69
expected = {'/gt1l/land_ice_segments/h_li' : [45.95665 , 45.999374 , 46.017857 , 46.015575 , 46.067562 ],
74
70
'/gt1r/land_ice_segments/h_li' : [45.980865 , 46.02602 , 46.02262 , 46.03137 , 46.073578 ],
75
71
'/gt2l/land_ice_segments/h_li' : [45.611526 , 45.588196 , 45.53242 , 45.48105 , 45.443752 ],
@@ -80,10 +76,10 @@ def test_h5p(self):
80
76
for index in range (len (expected [dataset ])):
81
77
assert round (rsps [dataset ][index ]) == round (expected [dataset ][index ])
82
78
83
- def test_geospatial1 (self ):
84
- icesat2 .init (SERVER )
79
+ def test_geospatial1 (self , server , asset ):
80
+ icesat2 .init (server )
85
81
test = {
86
- "asset" : ASSET ,
82
+ "asset" : asset ,
87
83
"pole" : "north" ,
88
84
"lat" : 40.0 ,
89
85
"lon" : 60.0 ,
@@ -125,10 +121,10 @@ def test_geospatial1(self):
125
121
assert d ["lat" ] == 40.0 and d ["lon" ] == 60.0
126
122
assert d ["x" ] == 0.466307658155 and d ["y" ] == 0.80766855588292
127
123
128
- def test_geospatial2 (self ):
129
- icesat2 .init (SERVER )
124
+ def test_geospatial2 (self , server , asset ):
125
+ icesat2 .init (server )
130
126
test = {
131
- "asset" : ASSET ,
127
+ "asset" : asset ,
132
128
"pole" : "north" ,
133
129
"lat" : 30.0 ,
134
130
"lon" : 100.0 ,
@@ -138,10 +134,10 @@ def test_geospatial2(self):
138
134
d = sliderule .source ("geo" , test )
139
135
assert abs (d ["lat" ] - 30.0 ) < 0.0001 and d ["lon" ] == 100.0
140
136
141
- def test_geospatial3 (self ):
142
- icesat2 .init (SERVER )
137
+ def test_geospatial3 (self , server , asset ):
138
+ icesat2 .init (server )
143
139
test = {
144
- "asset" : ASSET ,
140
+ "asset" : asset ,
145
141
"pole" : "north" ,
146
142
"lat" : 30.0 ,
147
143
"lon" : 100.0 ,
@@ -151,10 +147,10 @@ def test_geospatial3(self):
151
147
d = sliderule .source ("geo" , test )
152
148
assert abs (d ["lat" ] - 30.0 ) < 0.0001 and d ["lon" ] == - 100.0
153
149
154
- def test_geospatial4 (self ):
155
- icesat2 .init (SERVER )
150
+ def test_geospatial4 (self , server , asset ):
151
+ icesat2 .init (server )
156
152
test = {
157
- "asset" : ASSET ,
153
+ "asset" : asset ,
158
154
"pole" : "north" ,
159
155
"lat" : 30.0 ,
160
156
"lon" : 100.0 ,
@@ -164,16 +160,16 @@ def test_geospatial4(self):
164
160
d = sliderule .source ("geo" , test )
165
161
assert abs (d ["lat" ] - 30.0 ) < 0.0001 and d ["lon" ] == - 80.0
166
162
167
- def test_definition (self ):
168
- icesat2 .init (SERVER )
163
+ def test_definition (self , server ):
164
+ icesat2 .init (server )
169
165
rqst = {
170
166
"rectype" : "atl06rec.elevation" ,
171
167
}
172
168
d = sliderule .source ("definition" , rqst )
173
169
assert d ["delta_time" ]["offset" ] == 192
174
170
175
- def test_version (self ):
176
- icesat2 .init (SERVER )
171
+ def test_version (self , server ):
172
+ icesat2 .init (server )
177
173
rsps = sliderule .source ("version" , {})
178
174
assert 'server' in rsps
179
175
assert 'version' in rsps ['server' ]
0 commit comments