From bb26e572f096049c03f8eb66d33a353f4d3dfdc2 Mon Sep 17 00:00:00 2001 From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu> Date: Tue, 9 Mar 2021 14:29:13 +0100 Subject: [PATCH] Improved reading routine for hdf files. --- pysegcnn/core/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pysegcnn/core/utils.py b/pysegcnn/core/utils.py index 8026233..74cde0c 100644 --- a/pysegcnn/core/utils.py +++ b/pysegcnn/core/utils.py @@ -46,6 +46,10 @@ SUFFIXES = ['toa_ref', 'toa_rad', 'toa_brt'] # maximum number of filename characters on Windows MAX_FILENAME_CHARS_WINDOWS = 260 +# file suffixes for hierarchical data format +HIERARCHICAL_DATA_FORMAT = ['.h4', '.hdf', '.hdf4', '.hdf5', '.he2', '.h5', + '.he5', 'nc'] + def img2np(path, tile_size=None, tile=None, pad=False, cval=0): r"""Read an image to a :py:class:`numpy.ndarray`. @@ -412,8 +416,8 @@ def read_hdf(path, **kwargs): """ # check if the path points to an hdf file - if not str(path).endswith(('.h4', '.hdf', '.hdf4', '.hdf5', '.he2', '.h5', - '.he5')): + path = pathlib.Path(path) + if path.suffix not in HIERARCHICAL_DATA_FORMAT: raise ValueError('{} is not an hdf file.'.format(path)) # read the hdf dataset @@ -463,8 +467,7 @@ def hdf2tifs(path, outpath, overwrite=False, create_stack=True, **kwargs): """ # check if the path points to an hdf file path = pathlib.Path(path) - if not str(path).endswith(('.h4', '.hdf', '.hdf4', '.hdf5', '.he2', '.h5', - '.he5')): + if path.suffix not in HIERARCHICAL_DATA_FORMAT: raise ValueError('{} is not an hdf file.'.format(path)) # create the output directory for the GeoTiffs -- GitLab