@@ -116,6 +116,10 @@ def load_hdf5_array(file_name, key=None, slice=slice(0, None)):
116
116
data [k ] = hf [k ][slice ]
117
117
return data
118
118
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
+
119
123
return hf [key ][slice ]
120
124
121
125
@@ -135,12 +139,39 @@ def load_hdf5_sparse_array(file_name, key):
135
139
conventions, so cannot be used to load arbitrary sparse arrays.
136
140
"""
137
141
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
+
138
154
data = (hf ['%s_data' % key ], hf ['%s_indices' % key ],
139
155
hf ['%s_indptr' % key ])
140
156
sparsemat = scipy .sparse .csr_matrix (data , shape = hf ['%s_shape' % key ])
141
157
return sparsemat
142
158
143
159
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
+
144
175
def save_hdf5_dataset (file_name , dataset , mode = 'w' ):
145
176
"""Save a dataset of arrays and sparse arrays.
146
177
0 commit comments