Skip to content

Commit

Permalink
update is_geospatial() function to support multiscale datasets (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 authored Dec 14, 2024
1 parent 2781893 commit 5101c28
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions leap_data_management_utils/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def load_store(store: str, engine: str) -> xr.Dataset:
return xr.open_dataset(url, engine=engine, chunks={}, decode_cf=False)


def is_geospatial(ds: xr.Dataset) -> bool:
def is_geospatial(ds: xr.Dataset, is_multiscale: bool) -> bool:
if is_multiscale:
return 'x' in ds.dims and 'y' in ds.dims
cf_axes = ds.cf.axes

# Regex patterns that match 'lat', 'latitude', 'lon', 'longitude' and also allow prefixes
Expand Down Expand Up @@ -230,13 +232,16 @@ def check_single_store(store: Store) -> None:
if is_public:
# check if the store is geospatial
if multiscale_path:
ds = xr.open_datatree(multiscale_path, engine='zarr', chunks={}, decode_cf=False)
dt = xr.open_datatree(multiscale_path, engine='zarr', chunks={}, decode_cf=False)
ds = dt['0'].ds
is_geospatial_store = is_geospatial(ds, True)

else:
ds = load_store(
store.url,
store.xarray_open_kwargs.engine if store.xarray_open_kwargs else 'zarr',
)
is_geospatial_store = is_geospatial(ds)
is_geospatial_store = is_geospatial(ds, False)
store.geospatial = is_geospatial_store
# get last_updated_timestamp
store.last_updated = ds.attrs.get('pangeo_forge_build_timestamp', None)
Expand Down

0 comments on commit 5101c28

Please sign in to comment.