2626
2727def open_slice_source (
2828 ctx : Context ,
29- slice_obj : SliceObj | SliceFactory | Any ,
29+ slice_item : SliceObj | SliceFactory | Any ,
3030 slice_index : int = 0 ,
3131) -> SliceSource :
32- """Open the slice source for given slice object `slice_obj `.
32+ """Open the slice source for given slice object `slice_item `.
3333
3434 The intended and only use of the returned slice source is as context
3535 manager. When used as context manager the slice source yields a slice
@@ -39,7 +39,7 @@ def open_slice_source(
3939 class derived from `zappend.slice.SliceSource` or a function that returns
4040 instances of `zappend.slice.SliceSource`. The retrieved slice source will
4141 be returned by this function. The class or function will receive positional
42- and keyword arguments derived from `slice_obj ` as follows:
42+ and keyword arguments derived from `slice_item ` as follows:
4343
4444 * `tuple`: a pair of the form `(args, kwargs)`, where `args` is a list
4545 or tuple of positional arguments and `kwargs` is a dictionary of keyword
@@ -49,7 +49,7 @@ class derived from `zappend.slice.SliceSource` or a function that returns
4949 * Any other type is interpreted as single positional argument.
5050
5151 If `slice_source` is not specified in the configuration, the slice object
52- `slice_obj ` may have one of the following types:
52+ `slice_item ` may have one of the following types:
5353
5454 * `str`: A local file path or URI pointing to a dataset file such as a
5555 Zarr or NetCDF. If it is a URI, the `ctx.slice_storage_options` apply.
@@ -63,54 +63,46 @@ class derived from `zappend.slice.SliceSource` or a function that returns
6363
6464 Args:
6565 ctx: The processing context
66- slice_obj: A slice object
66+ slice_item: An slice item
6767 slice_index: Optional slice index, used for dataset identification
6868
6969 Returns:
7070 A new slice source instance
7171 """
7272 _slice_source = ctx .config .slice_source
7373 if _slice_source is not None :
74- slice_args , slice_kwargs = normalize_slice_arg (slice_obj )
75- slice_factory = to_slice_factory (_slice_source , * slice_args , ** slice_kwargs )
76- slice_source = slice_factory (ctx )
77- if not isinstance (slice_source , SliceSource ):
78- raise TypeError (
79- f"expected an instance of SliceSource"
80- f" returned from { _slice_source .__name__ !r} ,"
81- f" but got { type (slice_source )} "
82- )
83- return slice_source
74+ slice_args , slice_kwargs = normalize_slice_arg (slice_item )
75+ slice_item = to_slice_factory (_slice_source , * slice_args , ** slice_kwargs )
8476
85- return _get_slice_dataset_recursively (ctx , slice_obj , slice_index )
77+ return _get_slice_dataset_recursively (ctx , slice_item , slice_index )
8678
8779
8880def _get_slice_dataset_recursively (
8981 ctx : Context ,
90- slice_obj : SliceObj | SliceFactory ,
82+ slice_item : SliceObj | SliceFactory ,
9183 slice_index : int ,
9284) -> SliceSource :
93- if isinstance (slice_obj , SliceSource ):
94- return slice_obj
95- if isinstance (slice_obj , (str , FileObj )):
96- if isinstance (slice_obj , str ):
85+ if isinstance (slice_item , SliceSource ):
86+ return slice_item
87+ if isinstance (slice_item , (str , FileObj )):
88+ if isinstance (slice_item , str ):
9789 slice_file = FileObj (
98- slice_obj , storage_options = ctx .config .slice_storage_options
90+ slice_item , storage_options = ctx .config .slice_storage_options
9991 )
10092 else :
101- slice_file = slice_obj
93+ slice_file = slice_item
10294 return PersistentSliceSource (ctx , slice_file )
103- if isinstance (slice_obj , xr .Dataset ):
95+ if isinstance (slice_item , xr .Dataset ):
10496 if ctx .config .persist_mem_slices :
105- return TemporarySliceSource (ctx , slice_obj , slice_index )
97+ return TemporarySliceSource (ctx , slice_item , slice_index )
10698 else :
107- return MemorySliceSource (ctx , slice_obj , slice_index )
108- if callable (slice_obj ):
109- slice_factory : SliceFactory = slice_obj
110- slice_obj = slice_factory (ctx )
111- return _get_slice_dataset_recursively (ctx , slice_obj , slice_index )
99+ return MemorySliceSource (ctx , slice_item , slice_index )
100+ if callable (slice_item ):
101+ slice_factory : SliceFactory = slice_item
102+ slice_item = slice_factory (ctx )
103+ return _get_slice_dataset_recursively (ctx , slice_item , slice_index )
112104 raise TypeError (
113- "slice_obj must be a"
105+ "slice_item must be a"
114106 " str,"
115107 " zappend.fsutil.FileObj,"
116108 " zappend.slice.SliceSource,"
0 commit comments