Skip to content

Commit faec582

Browse files
authored
Merge pull request #3069 from mataeui/main
2 parents e51b97f + 128bb9e commit faec582

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

satpy/readers/netcdf_utils.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,20 @@ def _collect_global_attrs(self, obj):
211211
self.file_content[fc_key] = global_attrs[key] = value
212212
self.file_content["/attrs"] = global_attrs
213213

214-
def _get_object_attrs(self, obj):
215-
return obj.__dict__
214+
@staticmethod
215+
def _get_object_attrs(obj):
216+
"""Get object attributes using __dict__ but retrieve recoverable attributes on failure."""
217+
try:
218+
return obj.__dict__
219+
except KeyError:
220+
# Maybe unrecognised datatype.
221+
atts = {}
222+
for attname in obj.ncattrs():
223+
try:
224+
atts[attname] = obj.getncattr(attname)
225+
except KeyError:
226+
LOG.warning(f"Warning: Cannot load object ({obj.name}) attribute ({attname}).")
227+
return atts
216228

217229
def _collect_attrs(self, name, obj):
218230
"""Collect all the attributes for the provided file object."""

0 commit comments

Comments
 (0)