Skip to content

Commit 00d32b6

Browse files
committed
caiman hdf5 logic: make it both more ambitious and cautious
1 parent 6c5d97e commit 00d32b6

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

caiman/base/movies.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,9 +1657,13 @@ def rgb2gray(rgb):
16571657
return movie(**f).astype(outtype)
16581658

16591659
elif extension in ('.hdf5', '.h5', '.nwb'):
1660+
# TODO: Merge logic here with utilities.py:get_file_size()
16601661
with h5py.File(file_name, "r") as f:
1661-
fkeys = list(f.keys())
1662-
if len(fkeys) == 1: # If the hdf5 file we're parsing has only one dataset inside it, ignore the arg and pick that dataset
1662+
ignore_keys = ['__DATA_TYPES__'] # Known metadata that tools provide, add to this as needed. Sync with utils.py:get_file_size() !!
1663+
fkeys = list(filter(lambda x: x not in ignore_keys, f.keys()))
1664+
if len(fkeys) == 1 and 'Dataset' in str(type(f[fkeys[0]])): # If the hdf5 file we're parsing has only one dataset inside it,
1665+
# ignore the arg and pick that dataset
1666+
# TODO: Consider recursing into a group to find a dataset
16631667
var_name_hdf5 = fkeys[0]
16641668

16651669
if extension == '.nwb': # Apparently nwb files are specially-formatted hdf5 files

caiman/source_extraction/cnmf/utilities.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,9 @@ def get_file_size(file_name, var_name_hdf5='mov'):
10141014
# FIXME this doesn't match the logic in movies.py:load()
10151015
# Consider pulling a lot of the "data source" code out into one place
10161016
with h5py.File(file_name, "r") as f:
1017-
kk = list(f.keys())
1018-
if len(kk) == 1:
1017+
ignore_keys = ['__DATA_TYPES__'] # Known metadata that tools provide, add to this as needed. Sync with movies.my:load() !!
1018+
kk = list(filter(lambda x: x not in ignore_keys, f.keys()))
1019+
if len(kk) == 1 and 'Dataset' in str(type(f[kk[0]])): # TODO: Consider recursing into a group to find a dataset
10191020
siz = f[kk[0]].shape
10201021
elif var_name_hdf5 in f:
10211022
if extension == '.nwb':

0 commit comments

Comments
 (0)