@@ -20,26 +20,71 @@ def write_levels(
2020 source_storage_options : dict [str , Any ] | None = None ,
2121 target_path : str | None = None ,
2222 num_levels : int | None = None ,
23- agg_methods : dict [str , Any ] | None = None ,
23+ tile_size : tuple [int , int ] | None = None ,
24+ agg_methods : str | dict [str , Any ] | None = None ,
2425 use_saved_levels : bool = False ,
2526 link_level_zero : bool = False ,
2627 xy_dim_names : tuple [str , str ] | None = None ,
27- tile_size : tuple [int , int ] | None = None ,
2828 ** zappend_config ,
2929):
30- """Writes a dataset at `source_path` to a xcube multi-level
31- dataset at `target_path`.
30+ """Writes a dataset at `source_path` to `target_path` using the
31+ [multi-level dataset format](https://xcube.readthedocs.io/en/latest/mldatasets.html)
32+ as specified by
33+ [xcube](https://github.com/xcube-dev/xcube).
3234
3335 The source dataset is opened and subdivided into dataset slices
34- along the append dimension given by `append_dim`, which defaults to `"time"`.
35- The slice size in the append dimension is one and also the target dataset's
36- chunk size in the append dimension will be one.
36+ along the append dimension given by `append_dim`, which defaults
37+ to `"time"`. The slice size in the append dimension is one.
38+ Each slice is downsampled to the number of levels and each slice level
39+ dataset is created/appended the target dataset's individual level
40+ datasets.
41+
42+ The target dataset's chunk size in the spatial x- and y-dimensions will
43+ be the same as the specified (or derived) tile size.
44+ The append dimension will be one. The chunking will be reflected as the
45+ `variables` configuration parameter passed to each `zappend()` call.
46+ If configuration parameter `variables` is also given as part of
47+ `zappend_config`, it will be merged with the chunk definitions.
48+
49+ Important: This function requires the `xcube` package to be installed.
3750
3851 Args:
3952 source_path: The source dataset path.
4053 source_storage_options: Storage options for the source
4154 dataset's filesystem.
42- target_path:
55+ target_path: The source multi-level dataset path.
56+ Filename extension should be `.levels`, by convention.
57+ If not given, `target_dir` should be passed as part of the
58+ `zappend_config`. (The name `target_path` is used here for
59+ consistency with `source_path`.)
60+ num_levels: Optional number of levels.
61+ If not given, a reasonable number of levels is computed
62+ from `tile_size`.
63+ tile_size: Optional tile size in the x- and y-dimension in pixels.
64+ If not given, the tile size is computed from the source
65+ dataset's chunk sizes in the x- and y-dimensions.
66+ xy_dim_names:
67+ Optional dimension names that identify the x- and y-dimensions.
68+ If not given, derived from the source dataset's grid mapping,
69+ if any.
70+ agg_methods: An aggregation method for all data variables or a
71+ mapping that provides the aggregation method for a variable
72+ name. Possible aggregation methods are
73+ `"first"`, `"min"`, `"max"`, `"mean"`, `"median"`.
74+ use_saved_levels: Whether a given, already written resolution level
75+ serves as input to aggregation for the next level. If `False`,
76+ the default, each resolution level other than zero is computed
77+ from the source dataset. If `True`, the function may perform
78+ significantly faster, but be aware that the aggregation
79+ methods `"first"` and `"median"` will produce inaccurate results.
80+ link_level_zero: Whether to _not_ write the level zero of the target
81+ multi-level dataset and link it instead. In this case, a link
82+ file `{target_path}/0.link` will be written.
83+ If `False`, the default, a level dataset `{target_path}/0.zarr`
84+ will be written instead.
85+ zappend_config:
86+ Configuration passed to the `zappend()` call for each
87+ slice in the append dimension.
4388 """
4489 from xcube .core .tilingscheme import get_num_levels
4590 from xcube .core .gridmapping import GridMapping
0 commit comments