66import unittest
77
88import xarray as xr
9+
10+ from zappend .api import FileObj
11+ from zappend .api import SliceSource
912from zappend .api import zappend
10- from zappend .fsutil .fileobj import FileObj
1113from .helpers import clear_memory_fs
1214from .helpers import make_test_dataset
1315
@@ -50,6 +52,27 @@ def test_some_slices_local(self):
5052 for slice_dir in slices :
5153 shutil .rmtree (slice_dir , ignore_errors = True )
5254
55+ def test_some_slices_with_class_slice_source (self ):
56+ target_dir = "memory://target.zarr"
57+ slices = [make_test_dataset (), make_test_dataset (), make_test_dataset ()]
58+ zappend (slices , target_dir = target_dir , slice_source = MySliceSource )
59+ ds = xr .open_zarr (target_dir )
60+ self .assertEqual ({"time" : 9 , "y" : 50 , "x" : 100 }, ds .sizes )
61+ self .assertEqual ({"chl" }, set (ds .data_vars ))
62+ self .assertEqual ({"time" , "y" , "x" }, set (ds .coords ))
63+
64+ def test_some_slices_with_func_slice_source (self ):
65+ def process_slice (ctx , slice_ds : xr .Dataset ) -> SliceSource :
66+ return MySliceSource (ctx , slice_ds )
67+
68+ target_dir = "memory://target.zarr"
69+ slices = [make_test_dataset (), make_test_dataset (), make_test_dataset ()]
70+ zappend (slices , target_dir = target_dir , slice_source = process_slice )
71+ ds = xr .open_zarr (target_dir )
72+ self .assertEqual ({"time" : 9 , "y" : 50 , "x" : 100 }, ds .sizes )
73+ self .assertEqual ({"chl" }, set (ds .data_vars ))
74+ self .assertEqual ({"time" , "y" , "x" }, set (ds .coords ))
75+
5376 def test_some_slices_with_profiling (self ):
5477 target_dir = "memory://target.zarr"
5578 slices = [
@@ -74,3 +97,12 @@ def test_some_slices_with_profiling(self):
7497 finally :
7598 if os .path .exists ("prof.out" ):
7699 os .remove ("prof.out" )
100+
101+
102+ class MySliceSource (SliceSource ):
103+ def __init__ (self , ctx , slice_ds ):
104+ super ().__init__ (ctx )
105+ self .slice_ds = slice_ds
106+
107+ def get_dataset (self ) -> xr .Dataset :
108+ return self .slice_ds .drop_vars (["tsm" ])
0 commit comments