Skip to content

Commit

Permalink
change the algorithm to remove the flyback to incorporate multiple fr…
Browse files Browse the repository at this point in the history
…ames per probe position
  • Loading branch information
Peter Ercius ncem-gauss jupyter committed Aug 22, 2024
1 parent 84d8e39 commit 1121133
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions python/stempy/io/sparse_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 1121133

Please sign in to comment.