Skip to content

Conversation

@bobleesj
Copy link
Collaborator

What does this PR do?

Closes #149

Adds Dataset5dstem class for 5D-STEM data (time series, tilt series, dose fractionation, etc.).

# Construction
Dataset5dstem.from_file(file_path, file_type=None, **kwargs)
Dataset5dstem.from_array(array, name=None, origin=None, sampling=None, units=None,
                         signal_units="arb. units", stack_type="generic", stack_values=None)
Dataset5dstem.from_4dstem(datasets, stack_type="generic", stack_values=None, name=None)

# Properties
data.shape              # (frames, scan_row, scan_col, k_row, k_col)
data.array              # underlying numpy array
data.stack_type         # "time", "tilt", "energy", "dose", "focus", "generic"
data.stack_values       # explicit values for stack axis (or None)
data.virtual_images     # dict[str, Dataset3d] of cached virtual images
data.virtual_detectors  # dict[str, dict] of detector configs
data.origin             # origin for each dimension
data.sampling           # sampling for each dimension
data.units              # units for each dimension
len(data)               # number of frames

# Diffraction pattern properties -> Dataset3d (frames, k_row, k_col)
data.dp_mean            # mean DP per frame
data.dp_max             # max DP per frame
data.dp_median          # median DP per frame

# Indexing - shape (4, 6, 7, 3, 5) example
data[2]              # -> Dataset4dstem (6, 7, 3, 5) single frame
data[1:3]            # -> Dataset5dstem (2, 6, 7, 3, 5) substack
data[:, 4, 1]        # -> Dataset3d (4, 3, 5) single scan position
data[:, 1:5, 2:6]    # -> Dataset5dstem (4, 4, 4, 3, 5) scan crop
data[..., 0:2, 1:4]  # -> Dataset5dstem (4, 6, 7, 2, 3) k-space crop

# Iteration
for frame in data:   # yields Dataset4dstem

# Stack reductions -> Dataset4dstem
data.stack_mean()
data.stack_sum()
data.stack_max()
data.stack_min()
data.stack_std()

# Virtual imaging -> Dataset3d (frames, scan_row, scan_col)
data.get_virtual_image(mask=None, mode=None, geometry=None, name="virtual_image", attach=True)
# mode="circle":  geometry=((cy, cx), radius) or (None, radius) for auto center
# mode="annular": geometry=((cy, cx), (r_inner, r_outer)) or (None, (r_inner, r_outer))
# Full auto:      geometry=None  # auto-detects both center and radius
# Per-frame:      geometry=[((cy0, cx0), r0), ((cy1, cx1), r1), ...]

# Virtual image management
data.show_virtual_images(figsize=None, **kwargs)
data.regenerate_virtual_images()
data.update_virtual_detector(name, mask=None, mode=None, geometry=None)
data.clear_virtual_images()
data.clear_all_virtual_data()

# Visualization
data.show()  # raises NotImplementedError - use data[i].dp_mean.show() instead

# Binning
data.bin(2)                   # bins all dims including stack
data.bin(2, axes=(1,2,3,4))   # preserves stack

# Copy
data.copy()

# String representations
repr(data)  # Dataset5dstem(shape=..., dtype=..., stack_type='...')
str(data)   # multi-line formatted output

What should the PR reviewer do?

This PR is built atop of #150.

Demo:

data = read_5dstem("/Users/macbook/data/toma/data_PULENC5R0VFJP4SDI1SX6EVZC.h5")
print(data)

Prints

Dataset5dstem '5D-STEM dataset'
  shape: (10, 512, 512, 12, 12) (10 frames)
  stack_type: 'time'
  scan sampling: [0.00390625 0.00390625] ['nm', 'nm']
  k sampling: [0.00612091 0.00612091] ['rad', 'rad']

I will ask for review @gvarnavi after #150 merged and share a notebook.

- Add docstring with examples to from_array()
- Add docstring with examples to from_shape()
- Use "Frame N" as default title (appropriate for time series/tomography)
- Add suptitle parameter with proper layout adjustment
- Add show() that raises NotImplementedError with helpful message
- Add show_virtual_images(), regenerate_virtual_images(),
  update_virtual_detector(), clear_virtual_images(), clear_all_virtual_data()
- Add from_file() classmethod
- Support auto-fit center per frame with geometry=(None, radius)
- Support per-frame geometry with list of geometries
- Add __str__ and __repr__ to Dataset4dstem for consistency
- Add tests for all new features
- Add geometry=None support for full auto-detection (center + radius)
- Update Dataset4dstem docstring: scan_y/x -> scan_row/col, dp_y/x -> k_row/col
- Add test for full auto-detection virtual imaging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5DSTEM data structure API design discussion

1 participant