Skip to content

Commit

Permalink
Reordered get_encodings()
Browse files Browse the repository at this point in the history
  • Loading branch information
bdestombe committed Aug 28, 2023
1 parent 8d3d349 commit 1f16cd4
Show file tree
Hide file tree
Showing 3 changed files with 4,861 additions and 118 deletions.
2,177 changes: 2,119 additions & 58 deletions docs/examples/02_surface_water.ipynb

Large diffs are not rendered by default.

2,775 changes: 2,727 additions & 48 deletions docs/examples/09_schoonhoven.ipynb

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions nlmod/dims/attributes_encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"top": dict(dval_max=0.005),
"kh": dict(dval_max=1e-6),
"kv": dict(dval_max=1e-6),
"ss": dict(dval_max=0.005),
"ss": dict(dval_max=1e-8),
"sy": dict(dval_max=0.005),
"porosity": dict(dval_max=0.005),
"recharge": dict(dval_max=0.0005),
Expand Down Expand Up @@ -157,16 +157,21 @@ def get_encodings(
TODO: add support for strings
"""
encodings = {}
encodings = dict()
for varname, da in ds.data_vars.items():
encodings[varname] = dict(
fletcher32=True, # Store checksums to detect corruption
)
encoding = encodings[varname]
# Encoding for strings is not supported by netCDF
if np.issubdtype(da.dtype, np.character):
continue

assert "_FillValue" not in da.attrs, (
f"Custom fillvalues are not supported. {varname} has a fillvalue set.")

encoding = dict(
zlib=True,
complevel=5,
fletcher32=True # Store checksums to detect corruption
)

isfloat = np.issubdtype(da.dtype, np.floating)
isint = np.issubdtype(da.dtype, np.integer)

Expand All @@ -193,6 +198,8 @@ def get_encodings(
else:
encoding["dtype"] = "float32"



elif isint and allowed_to_read_data_vars_for_minmax:
vmin = int(da.min())
vmax = int(da.max())
Expand All @@ -206,14 +213,10 @@ def get_encodings(
else:
pass

# set the compression
if isfloat or isint:
# Strings dont support compression. Only floats and ints for now.
encoding["zlib"] = True
encoding["complevel"] = 5

if set_encoding_inplace:
da.encoding = encoding
else:
encodings[varname] = encoding

if not set_encoding_inplace:
return encodings
Expand Down

0 comments on commit 1f16cd4

Please sign in to comment.