Skip to content

Commit

Permalink
real space mask for positions to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
smribet committed Nov 1, 2023
1 parent 8ec95f3 commit 9f82c20
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8 deletions.
15 changes: 14 additions & 1 deletion py4DSTEM/process/phase/iterative_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,9 @@ def _set_polar_parameters(self, parameters: dict):
else:
raise ValueError("{} not a recognized parameter".format(symbol))

def _calculate_scan_positions_in_pixels(self, positions: np.ndarray):
def _calculate_scan_positions_in_pixels(
self, positions: np.ndarray, positions_mask
):
"""
Method to compute the initial guess of scan positions in pixels.
Expand All @@ -1544,6 +1546,8 @@ def _calculate_scan_positions_in_pixels(self, positions: np.ndarray):
positions: (J,2) np.ndarray or None
Input probe positions in Å.
If None, a raster scan using experimental parameters is constructed.
positions_mask: np.ndarray, optional
Boolean real space mask to select positions in datacube to skip for reconstruction
Returns
-------
Expand Down Expand Up @@ -1592,6 +1596,15 @@ def _calculate_scan_positions_in_pixels(self, positions: np.ndarray):
positions = np.array([x.ravel(), y.ravel()]).T
positions -= np.min(positions, axis=0)

if positions_mask is not None:
if positions_mask.dtype != "bool":
warnings.warn(
("`positions_mask` converged to `bool` array"),
UserWarning,
)
positions_mask = np.asarray(positions_mask, dtype="bool")
positions = positions[positions_mask.ravel()]

if self._object_padding_px is None:
float_padding = self._region_of_interest_shape / 2
self._object_padding_px = (float_padding, float_padding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class MixedstateMultislicePtychographicReconstruction(PtychographicReconstructio
object_type: str, optional
The object can be reconstructed as a real potential ('potential') or a complex
object ('complex')
positions_mask: np.ndarray, optional
Boolean real space mask to select positions in datacube to skip for reconstruction
verbose: bool, optional
If True, class methods will inherit this and print additional information
device: str, optional
Expand Down Expand Up @@ -115,6 +117,7 @@ def __init__(
initial_probe_guess: np.ndarray = None,
initial_scan_positions: np.ndarray = None,
object_type: str = "complex",
positions_mask: np.ndarray = None,
verbose: bool = True,
device: str = "cpu",
name: str = "multi-slice_ptychographic_reconstruction",
Expand Down Expand Up @@ -201,6 +204,7 @@ def __init__(
self._semiangle_cutoff_pixels = semiangle_cutoff_pixels
self._rolloff = rolloff
self._object_type = object_type
self._positions_mask = positions_mask
self._object_padding_px = object_padding_px
self._verbose = verbose
self._device = device
Expand Down Expand Up @@ -454,7 +458,7 @@ def preprocess(
del self._intensities

self._positions_px = self._calculate_scan_positions_in_pixels(
self._scan_positions
self._scan_positions, self._positions_mask
)

# handle semiangle specified in pixels
Expand Down
6 changes: 5 additions & 1 deletion py4DSTEM/process/phase/iterative_mixedstate_ptychography.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class MixedstatePtychographicReconstruction(PtychographicReconstruction):
initial_scan_positions: np.ndarray, optional
Probe positions in Å for each diffraction intensity
If None, initialized to a grid scan
positions_mask: np.ndarray, optional
Boolean real space mask to select positions in datacube to skip for reconstruction
verbose: bool, optional
If True, class methods will inherit this and print additional information
device: str, optional
Expand Down Expand Up @@ -102,6 +104,7 @@ def __init__(
initial_probe_guess: np.ndarray = None,
initial_scan_positions: np.ndarray = None,
object_type: str = "complex",
positions_mask: np.ndarray = None,
verbose: bool = True,
device: str = "cpu",
name: str = "mixed-state_ptychographic_reconstruction",
Expand Down Expand Up @@ -178,6 +181,7 @@ def __init__(
self._rolloff = rolloff
self._object_type = object_type
self._object_padding_px = object_padding_px
self._positions_mask = positions_mask
self._verbose = verbose
self._device = device
self._preprocessed = False
Expand Down Expand Up @@ -358,7 +362,7 @@ def preprocess(
del self._intensities

self._positions_px = self._calculate_scan_positions_in_pixels(
self._scan_positions
self._scan_positions, self._positions_mask
)

# handle semiangle specified in pixels
Expand Down
6 changes: 5 additions & 1 deletion py4DSTEM/process/phase/iterative_multislice_ptychography.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class MultislicePtychographicReconstruction(PtychographicReconstruction):
object_type: str, optional
The object can be reconstructed as a real potential ('potential') or a complex
object ('complex')
positions_mask: np.ndarray, optional
Boolean real space mask to select positions in datacube to skip for reconstruction
verbose: bool, optional
If True, class methods will inherit this and print additional information
device: str, optional
Expand Down Expand Up @@ -121,6 +123,7 @@ def __init__(
theta_y: float = 0,
middle_focus: bool = False,
object_type: str = "complex",
positions_mask: np.ndarray = None,
verbose: bool = True,
device: str = "cpu",
name: str = "multi-slice_ptychographic_reconstruction",
Expand Down Expand Up @@ -211,6 +214,7 @@ def __init__(
self._semiangle_cutoff_pixels = semiangle_cutoff_pixels
self._rolloff = rolloff
self._object_type = object_type
self._positions_mask = positions_mask
self._object_padding_px = object_padding_px
self._verbose = verbose
self._device = device
Expand Down Expand Up @@ -481,7 +485,7 @@ def preprocess(
del self._intensities

self._positions_px = self._calculate_scan_positions_in_pixels(
self._scan_positions
self._scan_positions, self._positions_mask
)

# handle semiangle specified in pixels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class OverlapMagneticTomographicReconstruction(PtychographicReconstruction):
object_type: str, optional
The object can be reconstructed as a real potential ('potential') or a complex
object ('complex')
positions_mask: np.ndarray, optional
Boolean real space mask to select positions in datacube to skip for reconstruction
name: str, optional
Class name
kwargs:
Expand All @@ -115,6 +117,7 @@ def __init__(
polar_parameters: Mapping[str, float] = None,
object_padding_px: Tuple[int, int] = None,
object_type: str = "potential",
positions_mask: np.ndarray = None,
initial_object_guess: np.ndarray = None,
initial_probe_guess: np.ndarray = None,
initial_scan_positions: Sequence[np.ndarray] = None,
Expand Down Expand Up @@ -179,6 +182,7 @@ def __init__(
self._rolloff = rolloff
self._object_type = object_type
self._object_padding_px = object_padding_px
self._positions_mask = positions_mask
self._verbose = verbose
self._device = device
self._preprocessed = False
Expand Down Expand Up @@ -615,7 +619,7 @@ def preprocess(
tilt_index + 1
]
] = self._calculate_scan_positions_in_pixels(
self._scan_positions[tilt_index]
self._scan_positions[tilt_index], self._positions_mask[tilt_index]
)

# handle semiangle specified in pixels
Expand Down
6 changes: 5 additions & 1 deletion py4DSTEM/process/phase/iterative_overlap_tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class OverlapTomographicReconstruction(PtychographicReconstruction):
object_type: str, optional
The object can be reconstructed as a real potential ('potential') or a complex
object ('complex')
positions_mask: np.ndarray, optional
Boolean real space mask to select positions to ignore in reconstruction
name: str, optional
Class name
kwargs:
Expand All @@ -111,6 +113,7 @@ def __init__(
polar_parameters: Mapping[str, float] = None,
object_padding_px: Tuple[int, int] = None,
object_type: str = "potential",
positions_mask: np.ndarray = None,
initial_object_guess: np.ndarray = None,
initial_probe_guess: np.ndarray = None,
initial_scan_positions: Sequence[np.ndarray] = None,
Expand Down Expand Up @@ -188,6 +191,7 @@ def __init__(
self._rolloff = rolloff
self._object_type = object_type
self._object_padding_px = object_padding_px
self._positions_mask = positions_mask
self._verbose = verbose
self._device = device
self._preprocessed = False
Expand Down Expand Up @@ -555,7 +559,7 @@ def preprocess(
tilt_index + 1
]
] = self._calculate_scan_positions_in_pixels(
self._scan_positions[tilt_index]
self._scan_positions[tilt_index], self._positions_mask[tilt_index]
)

# handle semiangle specified in pixels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class SimultaneousPtychographicReconstruction(PtychographicReconstruction):
object_padding_px: Tuple[int,int], optional
Pixel dimensions to pad objects with
If None, the padding is set to half the probe ROI dimensions
positions_mask: np.ndarray, optional
Boolean real space mask to select positions in datacube to skip for reconstruction
initial_object_guess: np.ndarray, optional
Initial guess for complex-valued object of dimensions (Px,Py)
If None, initialized to 1.0j
Expand Down Expand Up @@ -102,6 +104,7 @@ def __init__(
vacuum_probe_intensity: np.ndarray = None,
polar_parameters: Mapping[str, float] = None,
object_padding_px: Tuple[int, int] = None,
positions_mask: np.ndarray = None,
initial_object_guess: np.ndarray = None,
initial_probe_guess: np.ndarray = None,
initial_scan_positions: np.ndarray = None,
Expand Down Expand Up @@ -167,6 +170,7 @@ def __init__(
self._rolloff = rolloff
self._object_type = object_type
self._object_padding_px = object_padding_px
self._positions_mask = positions_mask
self._verbose = verbose
self._device = device
self._preprocessed = False
Expand Down Expand Up @@ -607,7 +611,7 @@ def preprocess(
self._region_of_interest_shape = np.array(self._amplitudes[0].shape[-2:])

self._positions_px = self._calculate_scan_positions_in_pixels(
self._scan_positions
self._scan_positions, self._positions_mask
)

# handle semiangle specified in pixels
Expand Down
6 changes: 5 additions & 1 deletion py4DSTEM/process/phase/iterative_singleslice_ptychography.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class SingleslicePtychographicReconstruction(PtychographicReconstruction):
object_type: str, optional
The object can be reconstructed as a real potential ('potential') or a complex
object ('complex')
positions_mask: np.ndarray, optional
Boolean real space mask to select positions in datacube to skip for reconstruction
name: str, optional
Class name
kwargs:
Expand All @@ -102,6 +104,7 @@ def __init__(
initial_scan_positions: np.ndarray = None,
object_padding_px: Tuple[int, int] = None,
object_type: str = "complex",
positions_mask: np.ndarray = None,
verbose: bool = True,
device: str = "cpu",
name: str = "ptychographic_reconstruction",
Expand Down Expand Up @@ -163,6 +166,7 @@ def __init__(
self._rolloff = rolloff
self._object_type = object_type
self._object_padding_px = object_padding_px
self._positions_mask = positions_mask
self._verbose = verbose
self._device = device
self._preprocessed = False
Expand Down Expand Up @@ -342,7 +346,7 @@ def preprocess(
del self._intensities

self._positions_px = self._calculate_scan_positions_in_pixels(
self._scan_positions
self._scan_positions, self._positions_mask
)

# handle semiangle specified in pixels
Expand Down

0 comments on commit 9f82c20

Please sign in to comment.