3
3
Classes to handle resource data stored over multiple files
4
4
"""
5
5
import os
6
- from fnmatch import fnmatch
7
6
from glob import glob
7
+ from itertools import chain
8
+ from fnmatch import fnmatch
8
9
9
10
import numpy as np
10
11
import pandas as pd
@@ -33,8 +34,9 @@ def __init__(self, h5_path, res_cls=Resource, hsds=False, hsds_kwargs=None,
33
34
h5_path : str | list
34
35
Unix shell style pattern path with * wildcards to multi-file
35
36
resource file sets. Files must have the same coordinates
36
- but can have different datasets or time indexes. Can also be an
37
- explicit list of multi time files.
37
+ but can have different datasets or time indexes. Can also be
38
+ an explicit list of multi time files, which themselves can
39
+ contain * wildcards.
38
40
res_cls : obj
39
41
Resource class to use to open and access resource data
40
42
hsds : bool
@@ -259,8 +261,9 @@ def _get_file_paths(cls, h5_path, hsds=False, hsds_kwargs=None):
259
261
h5_path : str | list
260
262
Unix shell style pattern path with * wildcards to multi-file
261
263
resource file sets. Files must have the same coordinates
262
- but can have different datasets or time indexes. Can also be an
263
- explicit list of multi time files.
264
+ but can have different datasets or time indexes. Can also be
265
+ an explicit list of multi time files, which themselves can
266
+ contain * wildcards.
264
267
hsds : bool
265
268
Boolean flag to use h5pyd to handle .h5 'files' hosted on AWS
266
269
behind HSDS
@@ -278,10 +281,9 @@ def _get_file_paths(cls, h5_path, hsds=False, hsds_kwargs=None):
278
281
file_paths = cls ._get_hsds_file_paths (h5_path ,
279
282
hsds_kwargs = hsds_kwargs )
280
283
elif isinstance (h5_path , (list , tuple )):
281
- for fp in h5_path :
282
- msg = 'Does not exist: {}' .format (fp )
283
- assert os .path .exists (fp ), msg
284
- file_paths = h5_path
284
+ file_paths = list (chain .from_iterable (glob (fp ) for fp in h5_path ))
285
+ for fp in file_paths :
286
+ assert os .path .exists (fp ), 'Does not exist: {}' .format (fp )
285
287
elif os .path .isdir (h5_path ):
286
288
msg = ('h5_path must be a unix shell style pattern with '
287
289
'wildcard * in order to find files, but received '
@@ -493,8 +495,9 @@ def __init__(self, h5_path, unscale=True, str_decode=True,
493
495
h5_path : str | list
494
496
Unix shell style pattern path with * wildcards to multi-file
495
497
resource file sets. Files must have the same coordinates
496
- but can have different datasets or time indexes. Can also be an
497
- explicit list of multi time files.
498
+ but can have different datasets or time indexes. Can also be
499
+ an explicit list of multi time files, which themselves can
500
+ contain * wildcards.
498
501
unscale : bool
499
502
Boolean flag to automatically unscale variables on extraction
500
503
str_decode : bool
@@ -850,8 +853,9 @@ def __init__(self, h5_path, unscale=True, str_decode=True, hsds=False,
850
853
h5_path : str | list
851
854
Unix shell style pattern path with * wildcards to multi-file
852
855
resource file sets. Files must have the same coordinates
853
- but can have different datasets or time indexes. Can also be an
854
- explicit list of multi time files.
856
+ but can have different datasets or time indexes. Can also be
857
+ an explicit list of multi time files, which themselves can
858
+ contain * wildcards.
855
859
unscale : bool
856
860
Boolean flag to automatically unscale variables on extraction
857
861
str_decode : bool
@@ -885,8 +889,9 @@ def __init__(self, h5_path, unscale=True, str_decode=True, hsds=False,
885
889
h5_path : str | list
886
890
Unix shell style pattern path with * wildcards to multi-file
887
891
resource file sets. Files must have the same coordinates
888
- but can have different datasets or time indexes. Can also be an
889
- explicit list of multi time files.
892
+ but can have different datasets or time indexes. Can also be
893
+ an explicit list of multi time files, which themselves can
894
+ contain * wildcards.
890
895
unscale : bool
891
896
Boolean flag to automatically unscale variables on extraction
892
897
str_decode : bool
@@ -920,8 +925,9 @@ def __init__(self, h5_path, unscale=True, str_decode=True, hsds=False,
920
925
h5_path : str | list
921
926
Unix shell style pattern path with * wildcards to multi-file
922
927
resource file sets. Files must have the same coordinates
923
- but can have different datasets or time indexes. Can also be an
924
- explicit list of multi time files.
928
+ but can have different datasets or time indexes. Can also be
929
+ an explicit list of multi time files, which themselves can
930
+ contain * wildcards.
925
931
unscale : bool
926
932
Boolean flag to automatically unscale variables on extraction
927
933
str_decode : bool
@@ -953,8 +959,9 @@ def __init__(self, h5_path, unscale=True, str_decode=True, hsds=False,
953
959
h5_path : str | list
954
960
Unix shell style pattern path with * wildcards to multi-file
955
961
resource file sets. Files must have the same coordinates
956
- but can have different datasets or time indexes. Can also be an
957
- explicit list of multi time files.
962
+ but can have different datasets or time indexes. Can also be
963
+ an explicit list of multi time files, which themselves can
964
+ contain * wildcards.
958
965
unscale : bool
959
966
Boolean flag to automatically unscale variables on extraction
960
967
str_decode : bool
0 commit comments