1
1
import logging
2
2
3
3
from cfapyx import CFANetCDF
4
+ import xarray as xr
4
5
5
6
TESTDIR = 'cfapyx/tests/test_space'
6
7
@@ -27,5 +28,41 @@ def test_cfa_write(self, testdir=TESTDIR):
27
28
28
29
print ('Integration tests: Write - complete' )
29
30
31
+ FILE = f'{ testdir } /testrain.nca'
32
+
33
+ # Local testing: Add CFAPyX before tests
34
+ try :
35
+ ds = xr .open_dataset (FILE , engine = 'CFA' )
36
+ except Exception as err :
37
+ assert isinstance (err , ImportError )
38
+ print ('Integration tests: Read(pure) - skipped' )
39
+ return
40
+
41
+ ## Test global dataset
42
+ assert not hasattr (ds ,'address' )
43
+ assert not hasattr (ds ,'shape' )
44
+ assert not hasattr (ds ,'location' )
45
+
46
+ assert 'p' in ds
47
+ assert ds ['p' ].shape == (20 , 180 , 360 )
48
+
49
+ # Using selection with lat/lon values NOT index values
50
+ p_sel = ds ['p' ].isel (time = slice (0 ,3 ),latitude = slice (140 ,145 ), longitude = slice (90 ,100 ))
51
+
52
+ assert p_sel .shape == (3 , 5 , 10 )
53
+ assert not hasattr (p_sel , 'aggregated_data' )
54
+ assert not hasattr (p_sel , 'aggregated_dimensions' )
55
+ p_mean = p_sel .mean (dim = 'time' )
56
+
57
+ assert p_mean .shape == (5 , 10 )
58
+ assert abs (p_mean [0 ][0 ].to_numpy () - 0.635366 ) < 0.01 , "Pure Data Invalid"
59
+
60
+ p_value = p_sel .mean ()
61
+
62
+ assert p_value .shape == ()
63
+ assert abs (p_value .to_numpy () - 0.511954 ) < 0.01 , "Pure Data Invalid"
64
+
65
+ print ('Integration tests: Write-Read(pure) - complete' )
66
+
30
67
if __name__ == '__main__' :
31
68
TestCFAWrite ().test_cfa_write ()
0 commit comments