MCPcopy Create free account
hub / github.com/bopen/xarray-sentinel / to_group_netcdf

Function to_group_netcdf

xarray_sentinel/reformat.py:32–51  ·  view source on GitHub ↗
(
    product_path: esa_safe.PathType,
    output_store: str,
    groups: Dict[str, str] | None = None,
    **kwargs: Any,
)

Source from the content-addressed store, hash-verified

30# Apparently there is no way to save SLC images because "netcdf4" doesn't support complex data
31# and "h5netcdf" crashes on an issue related to dimension names
32def to_group_netcdf(
33 product_path: esa_safe.PathType,
34 output_store: str,
35 groups: Dict[str, str] | None = None,
36 **kwargs: Any,
37) -> None:
38 root = xr.open_dataset(product_path, engine="sentinel-1")
39 root.to_netcdf(output_store, mode="w", **kwargs)
40
41 if groups is None:
42 groups = {g: g for g in root.attrs["subgroups"]}
43
44 for group_out, group_in in groups.items():
45 try:
46 group_ds = xr.open_dataset(
47 product_path, engine="sentinel-1", group=group_in
48 )
49 group_ds.to_netcdf(output_store, mode="a", group=group_out, **kwargs)
50 except FileNotFoundError:
51 pass

Callers

nothing calls this directly

Calls 1

open_datasetMethod · 0.80

Tested by

no test coverage detected