Skip to content

Commit c3e80f5

Browse files
committed
xarray utils testing
1 parent 3bc167f commit c3e80f5

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

Binary file not shown.
Binary file not shown.

tests/test_xarray_util.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from glob import glob
2+
import xarray as xr
3+
from pyxlma.xarray_util import *
4+
5+
def test_get_1d_dims():
6+
lma = xr.open_dataset('tests/truth/lma_netcdf/lma_stats.nc')
7+
dims_1d = get_1d_dims(lma)
8+
print(lma)
9+
assert dims_1d == ['number_of_flashes']
10+
11+
12+
def test_gen_1d_datasets():
13+
lma = xr.open_dataset('tests/truth/lma_netcdf/lma_stats.nc')
14+
datasets_1d = list(gen_1d_datasets(lma))
15+
assert len(datasets_1d) == 1
16+
assert list(datasets_1d[0].dims.keys()) == ['number_of_flashes']
17+
18+
19+
def test_get_1d_datasets():
20+
lma = xr.open_dataset('tests/truth/lma_netcdf/lma_stats.nc')
21+
datasets_1d = get_1d_datasets(lma)
22+
assert len(datasets_1d) == 1
23+
assert list(datasets_1d[0].dims.keys()) == ['number_of_flashes']
24+
25+
26+
def test_get_scalar_vars():
27+
lma = xr.open_dataset('tests/truth/lma_netcdf/lma_stats.nc')
28+
scalar_vars = get_scalar_vars(lma)
29+
assert scalar_vars == ['network_center_latitude', 'network_center_longitude', 'network_center_altitude',
30+
'flash_distance_separation_threshold', 'flash_time_separation_threshold']
31+
32+
33+
def test_concat_1d_dims_no_scalars():
34+
glm_datasets = [xr.open_dataset(path) for path in glob('examples/network_samples/OR_GLM*.nc')]
35+
concatenated = concat_1d_dims(glm_datasets)
36+
assert dict(concatenated.dims) == {'number_of_events': 29664, 'number_of_groups': 10420, 'number_of_flashes': 606,
37+
'number_of_time_bounds': 6, 'number_of_wavelength_bounds': 6, 'number_of_field_of_view_bounds': 6}
38+
39+
40+
def test_concat_1d_dims_scalars():
41+
glm_datasets = [xr.open_dataset(path) for path in glob('examples/network_samples/OR_GLM*.nc')]
42+
concatenated = concat_1d_dims(glm_datasets, stack_scalars='scalars')
43+
assert dict(concatenated.dims) == {'number_of_events': 29664, 'number_of_groups': 10420, 'number_of_flashes': 606, 'number_of_time_bounds': 6,
44+
'number_of_wavelength_bounds': 6, 'number_of_field_of_view_bounds': 6, 'scalars': 3}
45+
46+
47+
if __name__ == "__main__":
48+
test_get_1d_dims()
49+
test_gen_1d_datasets()
50+
test_get_1d_datasets()
51+
test_get_scalar_vars()
52+
test_concat_1d_dims_no_scalars()
53+
test_concat_1d_dims_scalars()

0 commit comments

Comments
 (0)