Skip to content

Commit a3db4b7

Browse files
committed
ENH add compatibility with other mappers
1 parent a9ed7a2 commit a3db4b7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

voxelwise_tutorials/io.py

+31
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def load_hdf5_array(file_name, key=None, slice=slice(0, None)):
116116
data[k] = hf[k][slice]
117117
return data
118118
else:
119+
# Some keys have been renamed. Use old key on KeyError.
120+
if key not in hf.keys() and key in OLD_KEYS:
121+
key = OLD_KEYS[key]
122+
119123
return hf[key][slice]
120124

121125

@@ -135,12 +139,39 @@ def load_hdf5_sparse_array(file_name, key):
135139
conventions, so cannot be used to load arbitrary sparse arrays.
136140
"""
137141
with h5py.File(file_name, mode='r') as hf:
142+
143+
# Some keys have been renamed. Use old key on KeyError.
144+
if '%s_data' % key not in hf.keys() and key in OLD_KEYS:
145+
key = OLD_KEYS[key]
146+
147+
# The voxel_to_fsaverage mapper is sometimes split between left/right.
148+
if (key == "voxel_to_fsaverage" and '%s_data' % key not in hf.keys()
149+
and "vox_to_fsavg_left_data" in hf.keys()):
150+
left = load_hdf5_sparse_array(file_name, "vox_to_fsavg_left")
151+
right = load_hdf5_sparse_array(file_name, "vox_to_fsavg_right")
152+
return scipy.sparse.vstack([left, right])
153+
138154
data = (hf['%s_data' % key], hf['%s_indices' % key],
139155
hf['%s_indptr' % key])
140156
sparsemat = scipy.sparse.csr_matrix(data, shape=hf['%s_shape' % key])
141157
return sparsemat
142158

143159

160+
# Correspondence between old keys and new keys. {new_key: old_key}
161+
OLD_KEYS = {
162+
"flatmap_mask": "pixmask",
163+
"voxel_to_flatmap": "pixmap",
164+
}
165+
166+
167+
def _concatenate_fsaverage_left_right(file_name):
168+
"""Load the"""
169+
voxel_to_fsavg_L = load_hdf5_sparse_array(file_name, "vox_to_fsavg_left")
170+
voxel_to_fsavg_R = load_hdf5_sparse_array(file_name, "vox_to_fsavg_right")
171+
voxel_to_fsavg = scipy.sparse.vstack([voxel_to_fsavg_L, voxel_to_fsavg_R])
172+
return voxel_to_fsavg
173+
174+
144175
def save_hdf5_dataset(file_name, dataset, mode='w'):
145176
"""Save a dataset of arrays and sparse arrays.
146177

0 commit comments

Comments
 (0)