Skip to content

Commit

Permalink
getting weird error with netcdf not being able to write model meta da…
Browse files Browse the repository at this point in the history
…ta as attrs, needs to be serialized another way, added error handling here
  • Loading branch information
grantbuster committed Nov 13, 2024
1 parent 5a275ab commit a74ed5c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sup3r/preprocessing/cachers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sup3r.preprocessing.base import Container
from sup3r.preprocessing.names import Dimension
from sup3r.preprocessing.utilities import _mem_check, log_args, _lowered
from sup3r.utilities.utilities import safe_cast
from sup3r.utilities.utilities import safe_cast, safe_serialize
from rex.utilities.utilities import to_records_array

from .utilities import _check_for_cache
Expand Down Expand Up @@ -475,7 +475,16 @@ def write_netcdf(
ncfile.variables[dset][:] = np.asarray(data_var.data)

for attr_name, attr_value in attrs.items():
ncfile.setncattr(attr_name, safe_cast(attr_value))
attr_value = safe_cast(attr_value)
try:
ncfile.setncattr(attr_name, attr_value)
except Exception as e:
msg = (f'Could not write {attr_name} as attribute, '
f'serializing with json dumps, '
f'received error: "{e}"')
logger.warning(msg)
warn(msg)
ncfile.setncattr(attr_name, safe_serialize(attr_value))

for feature in features:
cls.write_netcdf_chunks(
Expand Down

0 comments on commit a74ed5c

Please sign in to comment.