Skip to content

Commit 23542e5

Browse files
committed
Merge branch 'main' of https://github.com/EOPF-Explorer/data-model into chore/titiler-downstream-tests
2 parents 8dc009e + efb6f6e commit 23542e5

5 files changed

Lines changed: 222 additions & 202 deletions

File tree

src/eopf_geozarr/data_api/geozarr/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class TileMatrixLimitJSON(TypedDict):
2525
"filters",
2626
"shards",
2727
"_FillValue",
28+
"fill_value",
2829
} | CF_SCALE_OFFSET_KEYS
2930

3031

@@ -39,6 +40,7 @@ class XarrayDataArrayEncoding(TypedDict):
3940
filters: NotRequired[tuple[object, ...]]
4041
shards: NotRequired[tuple[int, ...] | None]
4142
_FillValue: NotRequired[object]
43+
fill_value: NotRequired[object]
4244
scale_factor: NotRequired[float]
4345
add_offset: NotRequired[float]
4446
dtype: NotRequired[object]

src/eopf_geozarr/s2_optimization/s2_multiscale.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ def create_multiscale_from_datatree(
132132
for data_var in dataset.data_vars:
133133
if dataset[data_var].dtype in (np.dtype("<f8"), np.dtype(">f8")):
134134
dataset[data_var] = dataset[data_var].astype("float32")
135+
# Clear _FillValue from the DataArray's own encoding to prevent
136+
# xarray from raising "Zarr does not support _FillValue in encoding".
137+
if not keep_scale_offset:
138+
for data_var in dataset.data_vars:
139+
dataset[data_var].encoding.pop("_FillValue", None)
135140
else:
136141
# Non-measurement groups: preserve original encoding
137142
encoding = create_original_encoding(dataset)
@@ -185,6 +190,11 @@ def create_multiscale_from_datatree(
185190
keep_scale_offset=keep_scale_offset,
186191
)
187192

193+
# Strip _FillValue from DataArray encoding for downsampled levels too
194+
if not keep_scale_offset:
195+
for data_var in downsampled_dataset.data_vars:
196+
downsampled_dataset[data_var].encoding.pop("_FillValue", None)
197+
188198
# Write dataset
189199
ds_out = stream_write_dataset(
190200
downsampled_dataset,
@@ -269,7 +279,15 @@ def create_measurements_encoding(
269279
keep_keys = XARRAY_ENCODING_KEYS - {"compressors", "shards", "chunks"}
270280

271281
if not keep_scale_offset:
272-
keep_keys = keep_keys - CF_SCALE_OFFSET_KEYS
282+
# When stripping scale/offset, also strip _FillValue since the original
283+
# _FillValue is in raw integer units and meaningless for decoded float data.
284+
keep_keys = keep_keys - CF_SCALE_OFFSET_KEYS - {"_FillValue"}
285+
# Set zarr fill_value to NaN so nodata regions are correctly identified
286+
# as transparent by zarr-aware viewers (e.g. OpenLayers GeoZarr source).
287+
# xarray's zarr backend uses "fill_value" (no underscore) in encoding
288+
# to set the zarr-level fill value, distinct from "_FillValue" which
289+
# controls CF-convention attribute masking.
290+
var_encoding["fill_value"] = float("nan")
273291

274292
for key in keep_keys:
275293
if key in var_data.encoding:

0 commit comments

Comments
 (0)