Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VIIRS SDR loading - picked from (xarray)develop branch #177

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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