Skip to content
Snippets Groups Projects
Commit 03ff55cd authored by Nils-Arne Dreier's avatar Nils-Arne Dreier
Browse files

feat: add spatial chunk shape to grid_id

This is a assumption of the distribute work function and necessary
because the domain decomposition must align with the chunking
parent c21e5208
No related branches found
No related tags found
1 merge request!47[hiopy] refactor variable handling and distribution
......@@ -11,12 +11,15 @@ def grid_id(var, zgroup):
crs = zgroup[var.attrs["grid_mapping"]]
var_group = var.attrs.get("hiopy::var_group", "")
spatial_chunk_shape = var.chunk_shape[-1]
# healpix
if "grid_mapping_name" in crs.attrs and crs.attrs["grid_mapping_name"] == "healpix":
s = var_group + "healpix_"
s += str(crs.attrs["healpix_nside"])
s += str(crs.attrs["healpix_order"])
s += "_" + str(spatial_chunk_shape)
# if the cell dimension has a coordinate, take it into account
if "_ARRAY_DIMENSIONS" in var.attrs and var.attrs["_ARRAY_DIMENSIONS"][-1] in zgroup:
s += hash(str(zgroup[var.attrs["_ARRAY_DIMENSIONS"][-1]][:]))
return s
......@@ -25,7 +28,12 @@ def grid_id(var, zgroup):
if "coordinates" in crs.attrs:
try:
lon, lat = crs.attrs["coordinates"].split(" ")
s = hash(hash(str(zgroup[lat][:])) + hash(str(zgroup[lon][:])) + var_group)
s = hash(
hash(str(zgroup[lat][:]))
+ hash(str(zgroup[lon][:]))
+ var_group
+ spatial_chunk_shape
)
return s
except Exception as e:
raise RuntimeError("Cannot parse coordinates") from e
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment