diff --git a/python/stempy/io/sparse_array.py b/python/stempy/io/sparse_array.py index cec4a04b..dd557e58 100644 --- a/python/stempy/io/sparse_array.py +++ b/python/stempy/io/sparse_array.py @@ -192,21 +192,20 @@ def from_hdf5(cls, filepath, keep_flyback=True, **init_kwargs): scan_positions_group = f['electron_events/scan_positions'] scan_shape = [scan_positions_group.attrs[x] for x in ['Nx', 'Ny']] frame_shape = [frames.attrs[x] for x in ['Nx', 'Ny']] - + if keep_flyback: data = frames[()] # load the full data set scan_positions = scan_positions_group[()] else: - # Generate the original scan indices from the scan_shape - orig_indices = np.ravel_multi_index([ii.ravel() for ii in np.indices(scan_shape)],scan_shape) - # Remove the indices of the last column - crop_indices = np.delete(orig_indices, orig_indices[scan_shape[0]-1::scan_shape[0]]) - # Load only the data needed - data = frames[crop_indices] - # Reduce the column shape by 1 - scan_shape[0] = scan_shape[0] - 1 - # Create the proper scan_positions without the flyback column - scan_positions = np.ravel_multi_index([ii.ravel() for ii in np.indices(scan_shape)],scan_shape) + num = frames.shape[0] // scan_positions_group.shape[0] # number of frames per probe position + data = np.empty(((scan_shape[0]-1) * scan_shape[1] * num), dtype=object) + new_num_cols = scan_shape[0]-1 # number of columns without flyback + for ii in range(scan_shape[1]): + start = ii*new_num_cols*4 # start of cropped data + end = (ii+1)*new_num_cols*4 + start2 = ii*new_num_cols*4+4*ii # start of uncropped data + end2 = (ii+1)*new_num_cols*4+4*ii + data[start:end] = frames[start2:end2] # Load any metadata metadata = {}