|
1 | | -from typing import Any, Iterable, Union |
| 1 | +from typing import Any, Iterable, Literal, Union |
2 | 2 |
|
3 | 3 | import pystac |
4 | 4 | from xarray.backends import BackendEntrypoint |
|
8 | 8 |
|
9 | 9 |
|
10 | 10 | class STACBackend(BackendEntrypoint): |
11 | | - description = "Open pystac objects in Xarray" |
| 11 | + description = "Open STAC objects in Xarray" |
12 | 12 | open_dataset_parameters = ("filename_or_obj", "drop_variables") |
13 | 13 | url = "https://github.com/stac-utils/xpystac" |
14 | 14 |
|
15 | 15 | def open_dataset( |
16 | 16 | self, |
17 | 17 | filename_or_obj: Any, |
18 | 18 | drop_variables: Union[str, Iterable[str], None] = None, |
| 19 | + stacking_library: Union[Literal["odc.stac", "stackstac"], None] = None, |
19 | 20 | **kwargs, |
20 | 21 | ): |
21 | | - return to_xarray(filename_or_obj, drop_variables=drop_variables, **kwargs) |
| 22 | + """Given a PySTAC object return an xarray dataset |
| 23 | +
|
| 24 | + The behavior of this method depends on the type of PySTAC object: |
| 25 | +
|
| 26 | + * Asset: if the asset points to a kerchunk file or a zarr file, |
| 27 | + reads the metadata in that file to construct the coordinates of the |
| 28 | + dataset. If the asset points to a COG, read that. |
| 29 | + * Item: stacks all the assets into a dataset with 1 more dimension than |
| 30 | + any given asset. |
| 31 | + * ItemCollection (output of pystac_client.search): stacks all the |
| 32 | + assets in all the items into a dataset with 2 more dimensions than |
| 33 | + any given asset. |
| 34 | +
|
| 35 | + Parameters |
| 36 | + ---------- |
| 37 | + filename_or_obj : PySTAC object (Item, ItemCollection, Asset) |
| 38 | + The object from which to read data. |
| 39 | + stacking_library : "odc.stac", "stackstac", optional |
| 40 | + When stacking multiple items, this argument determines which library |
| 41 | + to use. Defaults to ``odc.stac`` if available and otherwise ``stackstac``. |
| 42 | + """ |
| 43 | + return to_xarray( |
| 44 | + filename_or_obj, |
| 45 | + drop_variables=drop_variables, |
| 46 | + stacking_library=stacking_library, |
| 47 | + **kwargs, |
| 48 | + ) |
22 | 49 |
|
23 | 50 | def guess_can_open(self, filename_or_obj: Any): |
24 | 51 | return isinstance( |
|
0 commit comments