@@ -192,27 +192,30 @@ def from_hdf5(cls, filepath, keep_flyback=True, **init_kwargs):
192
192
scan_positions_group = f ['electron_events/scan_positions' ]
193
193
scan_shape = [scan_positions_group .attrs [x ] for x in ['Nx' , 'Ny' ]]
194
194
frame_shape = [frames .attrs [x ] for x in ['Nx' , 'Ny' ]]
195
-
195
+
196
196
if keep_flyback :
197
197
data = frames [()] # load the full data set
198
198
scan_positions = scan_positions_group [()]
199
199
else :
200
- # Generate the original scan indices from the scan_shape
201
- orig_indices = np .ravel_multi_index ([ii .ravel () for ii in np .indices (scan_shape )],scan_shape )
202
- # Remove the indices of the last column
203
- crop_indices = np .delete (orig_indices , orig_indices [scan_shape [0 ]- 1 ::scan_shape [0 ]])
204
- # Load only the data needed
205
- data = frames [crop_indices ]
206
- # Reduce the column shape by 1
207
- scan_shape [0 ] = scan_shape [0 ] - 1
200
+ num = frames .shape [0 ] // np .prod (scan_shape , dtype = int ) # number of frames per probe position
201
+ data = np .empty (((scan_shape [0 ]- 1 ) * scan_shape [1 ] * num ), dtype = object )
202
+ new_num_cols = scan_shape [0 ]- 1 # number of columns without flyback
203
+ for ii in range (scan_shape [1 ]):
204
+ start = ii * new_num_cols * num # start of cropped data
205
+ end = (ii + 1 )* new_num_cols * num
206
+ start2 = ii * new_num_cols * num + num * ii # start of uncropped data
207
+ end2 = (ii + 1 )* new_num_cols * num + num * ii
208
+ data [start :end ] = frames [start2 :end2 ]
209
+ scan_shape = (scan_shape [0 ]- 1 , scan_shape [1 ]) # update scan shape
208
210
# Create the proper scan_positions without the flyback column
209
- scan_positions = np .ravel_multi_index ([ii .ravel () for ii in np .indices (scan_shape )],scan_shape )
211
+ scan_positions = np .ravel_multi_index ([ii .ravel () for ii in np .indices (scan_shape )], scan_shape )
210
212
211
213
# Load any metadata
212
214
metadata = {}
213
215
if 'metadata' in f :
214
216
load_h5_to_dict (f ['metadata' ], metadata )
215
217
218
+ # reverse the scan shape to match expected shape
216
219
scan_shape = scan_shape [::- 1 ]
217
220
218
221
if version >= 3 :
0 commit comments