Skip to content

Commit

Permalink
Merge pull request #177 from pytroll/bugfix-viirs
Browse files Browse the repository at this point in the history
Bugfix viirs loading - picked from (xarray)develop branch
  • Loading branch information
djhoese committed Feb 1, 2018
2 parents 06248d5 + eb4b89c commit 2be7326
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion satpy/readers/hdf5_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def __init__(self, filename, filename_info, filetype_info):
def _collect_attrs(self, name, attrs):
for key, value in six.iteritems(attrs):
value = np.squeeze(value)
self.file_content["{}/attr/{}".format(name, key)] = np2str(value)
fc_key = "{}/attr/{}".format(name, key)
try:
self.file_content[fc_key] = np2str(value)
except ValueError:
self.file_content[fc_key] = value

def collect_metadata(self, name, obj):
if isinstance(obj, h5py.Dataset):
Expand Down
18 changes: 15 additions & 3 deletions satpy/readers/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@


def np2str(value):
"""Convert an np.string_ to str."""
if issubclass(value.dtype.type, np.string_):
"""Convert an `numpy.string_` to str.
Args:
value (ndarray): scalar or 1-element numpy array to convert
Raises:
ValueError: if value is array larger than 1-element or it is not of
type np.string_ or it is not a numpy array
"""
if hasattr(value, 'dtype') and \
issubclass(value.dtype.type, np.string_) and value.size == 1:
value = np.asscalar(value)
if not isinstance(value, str):
# python 3 - was scalar numpy array of bytes
# otherwise python 2 - scalar numpy array of 'str'
value = value.decode()
return value
return value
else:
raise ValueError("Array is not a string type or is larger than 1")


def get_geostationary_angle_extent(geos_area):
Expand Down

0 comments on commit 2be7326

Please sign in to comment.