@@ -459,10 +459,53 @@ Or use default polling:
459459
460460### Slice Sources
461461
462- Using the ` zappend ` command, slice dataset are provided as local filesystem paths
463- or by paths into other filesystems in case the slice datasets are provided by a URI.
464- This section describes additional options to pass slice datasets to the ` slices `
465- argument of the [ ` zappend ` ] ( api.md ) Python function.
462+ A _ slice source_ is an object that provides a slice dataset of type ` xarray.Dataset `
463+ for given parameters of any type.
464+
465+ The optional ` slice_source ` configuration setting is used to specify a custom
466+ slice source. If not specified, ` zappend ` selects the slice source based on the type
467+ of a given slice object. These types are described in following subsections.
468+
469+ If given, the value of the ` slice_source ` setting is a class derived from
470+ ` zappend.api.SliceSource ` , or a function that creates an instance of
471+ ` zappend.api.SliceSource ` , or the fully qualified name of the aforementioned.
472+ In the case ` slice_source ` is given, the _ slices_ argument passed to the CLI
473+ command and Python function become parameters to the specified class constructor
474+ or factory function.
475+ The individual slice items in the ` SLICES ` arguments of the ` zappend ` CLI
476+ command are of type ` str ` , typically interpreted as file paths or URIs.
477+ The individual slice items passed in the ` slices ` argument of the
478+ ` zappend.api.zappend() ` function can be of any type, but the ` tuple ` , ` list ` ,
479+ and ` dict ` types have a special meaning:
480+
481+ * ` tuple ` : a pair of the form ` (args, kwargs) ` , where ` args ` is a list
482+ or tuple of positional arguments and ` kwargs ` is a dictionary of keyword
483+ arguments;
484+ * ` list ` : positional arguments only;
485+ * ` dict ` : keyword arguments only;
486+ * Any other type is interpreted as single positional argument.
487+
488+ In addition, your class constructor or factory function specified by ` slice_source `
489+ may specify a positional or keyword argument named ` ctx ` , which will receive the
490+ current processing context of type ` zappend.api.Context ` .
491+
492+ If the ` slice_source ` setting is _ not_ specified, the slice items passed as ` slices `
493+ argument to the [ ` zappend ` ] ( api.md ) Python function can be one of the types described
494+ in the following subsections.
495+
496+ #### ` str ` and ` zappend.api.FileObj `
497+
498+ A slice object of type ` str ` is interpreted as local file path or URI, in the case
499+ the path has a protocol prefix, such as ` s3:// ` .
500+
501+ An alternative to providing the slice dataset as path or URI is using the ` FileObj `
502+ class, which combines a URI with dedicated filesystem storage options.
503+
504+ ``` python
505+ from zappend.api import FileObj
506+
507+ slice_obj = FileObj(slice_uri, storage_options = dict (... ))
508+ ```
466509
467510#### ` xarray.Dataset `
468511
@@ -504,19 +547,10 @@ at the cost of additional i/o. It therefore defaults to `false`.
504547Often you want to perform some custom cleanup after a slice has been processed and
505548appended to the target dataset. In this case you can write your own
506549` zappend.api.SliceSource ` by implementing its ` get_dataset() ` and ` dispose() `
507- methods. Slice source instances are supposed to be created by _ slice factories_ ,
508- see below.
509-
510- #### ` zappend.api.FileObj `
511-
512- An alternative to providing the slice dataset as path or URI is using the ` FileObj `
513- class, which combines a URI with dedicated filesystem storage options.
550+ methods.
514551
515- ``` python
516- from zappend.api import FileObj
517-
518- slice_obj = FileObj(slice_uri, storage_options = dict (... ))
519- ```
552+ Slice source instances are supposed to be created by _ slice factories_ , see
553+ subsection below.
520554
521555#### ` zappend.api.SliceFactory `
522556
@@ -532,10 +566,8 @@ processed. Slice factories are created from the custom slice source and the slic
532566using the utility function [ to_slice_factories()] [ zappend.slice.factory.to_slice_factories ] :
533567
534568``` python
535- from typing import Iterable
536569import numpy as np
537570import xarray as xr
538- from zappend.api import SliceFactory
539571from zappend.api import SliceSource
540572from zappend.api import to_slice_factories
541573from zappend.api import zappend
@@ -578,6 +610,14 @@ zappend(to_slice_factories(MySliceSource, ["slice-1.nc", "slice-2.nc", "slice-3.
578610 target_dir = " target.zarr" )
579611```
580612
613+ Note, the above example can be simplified by using the ` slice_source ` setting directly:
614+
615+ ``` python
616+ zappend([" slice-1.nc" , " slice-2.nc" , " slice-3.nc" ],
617+ target_dir = " target.zarr" ,
618+ slice_source = MySliceSource)
619+ ```
620+
581621## Logging
582622
583623The ` zappend ` logging output is configured using the ` logging ` setting.
0 commit comments