You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed in xarray-contrib/datatree#195, it would be wonderful (and relatively straightforward) to add support for DataTree in cfgrib. This would allow a improved organization of the different datasets that would have been previously been returned from cfgrib.open_datasets() in a single data collection.
As far as implementation, I would propose refactoring the existing open_datasets() to something like:
defopen_datatree(path, backend_kwargs={}, **kwargs):
# type: (str, T.Dict[str, T.Any], T.Any) -> datatree.DataTree""" Open a GRIB file groupping incompatible hypercubes to different datasets via simple heuristics. """squeeze=backend_kwargs.get("squeeze", True)
backend_kwargs=backend_kwargs.copy()
backend_kwargs["squeeze"] =Falsedatasets=open_variable_datasets(path, backend_kwargs=backend_kwargs, **kwargs)
type_of_level_datasets= {} # type: T.Dict[str, T.List[xr.Dataset]]fordsindatasets:
for_, dainds.data_vars.items():
type_of_level=da.attrs.get("GRIB_typeOfLevel", "undef")
type_of_level_datasets.setdefault(type_of_level, []).append(ds)
returndatatree.DataTree.from_dict(type_of_level_datasets)
Then, open_datasets could be re-implemented something like:
(these snippets were edited quick in-between conference sessions; no guarantee that I didn't miss something and these don't work properly as-is)
This all being said, discussions would likely need to happen to decide whether this should be supported before or after integration of DataTree into xarray proper (xref pydata/xarray#7418).
As discussed in xarray-contrib/datatree#195, it would be wonderful (and relatively straightforward) to add support for DataTree in
cfgrib
. This would allow a improved organization of the different datasets that would have been previously been returned fromcfgrib.open_datasets()
in a single data collection.As far as implementation, I would propose refactoring the existing
open_datasets()
to something like:Then,
open_datasets
could be re-implemented something like:(these snippets were edited quick in-between conference sessions; no guarantee that I didn't miss something and these don't work properly as-is)
This all being said, discussions would likely need to happen to decide whether this should be supported before or after integration of DataTree into xarray proper (xref pydata/xarray#7418).
cc @TomNicholas, @blaylockbk
The text was updated successfully, but these errors were encountered: