Skip to content

Commit

Permalink
Ensure that coordinates are loaded from disk
Browse files Browse the repository at this point in the history
Not sure yet about any performance implications,
but indexes should be small compared to the
actual data (at least in theory).

Fixes #21
  • Loading branch information
pmav99 committed Jul 7, 2023
1 parent 0866541 commit af4546a
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions inspectds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,33 @@ def infer_dataset_type(path: Path) -> DATASET_TYPE:
return dataset_type


def get_kwargs(dataset_type: DATASET_TYPE) -> dict[str, Any]:
open_dataset_kwargs: dict[str, Any] = {}
if IS_GRIB_AVAILABLE and dataset_type == DATASET_TYPE.GRIB:
open_dataset_kwargs.update(
dict(
engine="cfgrib",
backend_kwargs={"indexpath": ""},
)
)
elif dataset_type == DATASET_TYPE.ZARR:
open_dataset_kwargs.update(
dict(
engine="zarr",
consolidated=False,
)
)
elif dataset_type == DATASET_TYPE.NETCDF:
open_dataset_kwargs.update(
dict(
engine="netcdf4",
)
)
else:
raise ValueError("WTF??? Unknown Dataset type...")
return open_dataset_kwargs


def version_callback(value: bool) -> None:
if value:
typer.echo(f"inspectds version: {version('inspectds')}")
Expand Down Expand Up @@ -134,29 +161,7 @@ def inspect_dataset(
if dataset_type == DATASET_TYPE.AUTO:
dataset_type = infer_dataset_type(path)

open_dataset_kwargs: dict[str, Any] = {}
if IS_GRIB_AVAILABLE and dataset_type == DATASET_TYPE.GRIB:
open_dataset_kwargs.update(
dict(
engine="cfgrib",
backend_kwargs={"indexpath": ""},
)
)
elif dataset_type == DATASET_TYPE.ZARR:
open_dataset_kwargs.update(
dict(
engine="zarr",
consolidated=False,
)
)
elif dataset_type == DATASET_TYPE.NETCDF:
open_dataset_kwargs.update(
dict(
engine="netcdf4",
)
)
else:
raise ValueError("WTF??? Unknown Dataset type...")
open_dataset_kwargs = get_kwargs(dataset_type=dataset_type)

# Some netcdf files are not compatible with Xarray
# More specifically you can't have a dimension as a variable too.
Expand All @@ -182,6 +187,10 @@ def inspect_dataset(
else:
break

# Make sure that all the coordinates are loaded
for coord in ds.coords:
ds[coord].load()

if full:
dimensions = coordinates = variables = variable_attributes = global_attributes = True

Expand Down

0 comments on commit af4546a

Please sign in to comment.