2.1.2. fakecbed.discretized.CroppedCBEDPattern

class CroppedCBEDPattern(cbed_pattern=None, cropping_window_center=None, cropping_window_dims_in_pixels=None, principal_disk_idx=0, disk_boundary_sample_size=512, mask_frame=(0, 0, 0, 0), skip_validation_and_conversion=False)[source]

Bases: PreSerializableAndUpdatable

A discretized cropped fake convergent beam electron diffraction (CBED) pattern.

A series of parameters need to be specified in order to create an image of a cropped fake CBED pattern, which are: the set of parameters of a discretized fake CBED pattern; the spatial dimensions and the target center of the cropping window to be applied to said pattern; an index specifying the CBED disk, should it exist, for which to analyze in further detail than any other CBED disk in the pattern; the number of points to sample from the boundary of the unclipped support of the CBED disk specified by the aforementioned index, again should the disk exist; and the mask frame to be applied after cropping the fake CBED pattern.

Parameters:
cbed_patternfakecbed.discretized.CBEDPattern | None, optional

The discretized fake CBED pattern for which to crop. If cbed_pattern is set to None, then the parameter will be reassigned to the value fakecbed.discretized.CBEDPattern().

cropping_window_centerarray_like (float, shape=(2,)) | None, optional

If cropping_window_center is set to None, then the center of the cropping window is set to the fractional coordinates of the discretized fake CBED pattern corresponding to the pixel that is (h_dim+1)//2-1 pixels to the right of the upper left corner pixel, and (v_dim+1)//2-1 pixels below the same corner, where h_dim and v_dim are the horizontal and vertical dimensions of the discretized fake CBED pattern in units of pixels. Otherwise, if cropping_window_center is set to a pair of floating-point numbers, then cropping_window_center[0] and cropping_window_center[1] specify the fractional horizontal and vertical coordinates, respectively, of the center of the cropping window prior to the subpixel shift to the nearest pixel. Note that the crop is applied after the subpixel shift to the nearest pixel. Moreover, note that the fractional coordinate pair \(\left(0, 0\right)\) corresponds to the bottom left corner of the fake CBED pattern.

We define the center of the cropping window to be (N_W_h+1)//2 - 1 pixels to the right of the upper left corner of the cropping window, and (N_W_v+1)//2 - 1 pixels below the same corner, where N_W_h and N_W_v are the horizontal and vertical dimensions of the cropping window in units of pixels.

cropping_window_dims_in_pixelsarray_like (int, shape=(2,)) | None, optional

If cropping_window_dims_in_pixels is set to None, then the dimensions of the cropping window are set to the dimensions of discretized fake CBED pattern. Otherwise, if cropping_window_dims_in_pixels is set to a pair of positive integers, then cropping_window_dims_in_pixels[0] and cropping_window_dims_in_pixels[1] specify the horizontal and vertical dimensions of the cropping window in units of pixels.

principal_disk_idxint, optional

A nonnegative integer specifying the CBED disk, should it exist, for which to analyze in further detail than any other CBED disk in the pattern. Assuming that cbed_pattern has already been reassigned if necessary, and that principal_disk_idx < len(cbed_pattern.core_attrs["undistorted_disks"]), then principal_disk_idx specifies the CBED disk constructed from the undistorted intensity pattern stored in cbed_pattern.core_attrs["undistorted_disks"][prinicpal_disk_idx]. If principal_disk_idx >= len(cbed_pattern.core_attrs["undistorted_disks"]), then principal_disk_idx specifies a nonexistent CBED disk. See the summary documentation for the class fakecbed.discretized.CBEDPattern, in particular the description of the construction parameter undistorted_disks therein, for additional context.

disk_boundary_sample_sizeint, optional

The number of points to sample from the boundary of the unclipped support of the CBED disk specified by principal_disk_idx, should the disk exist, upon calling the method fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords. Must be a positive integer.

mask_framearray_like (int, shape=(4,)), optional

mask_frame specifies the mask frame to be applied after cropping the fake CBED pattern. mask_frame[0], mask_frame[1], mask_frame[2], and mask_frame[3] are the widths, in units of pixels, of the left, right, bottom, and top sides of the mask frame respectively.

skip_validation_and_conversionbool, optional

Let validation_and_conversion_funcs and core_attrs denote the attributes validation_and_conversion_funcs and core_attrs respectively, both of which being dict objects.

Let params_to_be_mapped_to_core_attrs denote the dict representation of the constructor parameters excluding the parameter skip_validation_and_conversion, where each dict key key is a different constructor parameter name, excluding the name "skip_validation_and_conversion", and params_to_be_mapped_to_core_attrs[key] would yield the value of the constructor parameter with the name given by key.

If skip_validation_and_conversion is set to False, then for each key key in params_to_be_mapped_to_core_attrs, core_attrs[key] is set to validation_and_conversion_funcs[key] (params_to_be_mapped_to_core_attrs).

Otherwise, if skip_validation_and_conversion is set to True, then core_attrs is set to params_to_be_mapped_to_core_attrs.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values of params_to_be_mapped_to_core_attrs, as it is guaranteed that no copies or conversions are made in this case.

Attributes:
core_attrs

dict: The “core attributes”.

de_pre_serialization_funcs

dict: The de-pre-serialization functions.

device

torch.device: The device on which computationally intensive

disk_absence_registry

torch.Tensor: The disk absence registry of the cropped fake CBED

disk_clipping_registry

torch.Tensor: The disk clipping registry of the cropped fake CBED

disk_overlap_map

torch.Tensor: The image of the disk overlap map of the cropped

disk_supports

torch.Tensor: The image stack of the disk supports of the cropped

illumination_support

torch.Tensor: The illumination support of the cropped fake CBED

image

torch.Tensor: The image of the cropped fake CBED pattern.

image_has_been_overridden

bool: Equals True if the image of the fake cropped CBED

num_disks

int: The total number of CBED disks defined, \(N_{\text{D}}\).

pre_serialization_funcs

dict: The pre-serialization functions.

principal_disk_boundary_pts_in_cropped_image_fractional_coords

torch.Tensor | None: The sample of points on the boundary of the

principal_disk_boundary_pts_in_uncropped_image_fractional_coords

torch.Tensor | None: The sample of points on the boundary of the

principal_disk_bounding_box_in_cropped_image_fractional_coords

tuple | None: The bounding box of the unclipped support of the

principal_disk_bounding_box_in_uncropped_image_fractional_coords

tuple | None: The bounding box of the unclipped support of the

principal_disk_is_absent

bool: Equals True if the “principal” CBED disk either does not

principal_disk_is_clipped

bool: Equals True if the “principal” CBED disk either does not

principal_disk_is_overlapping

bool: Equals True if the “principal” CBED disk exists and is

signal

hyperspy._signals.signal2d.Signal2D: The hyperspy signal

validation_and_conversion_funcs

dict: The validation and conversion functions.

Methods

de_pre_serialize([serializable_rep, ...])

Construct an instance from a serializable representation.

dump([filename, overwrite])

Serialize instance and save the result in a JSON file.

dumps()

Serialize instance.

get_core_attrs([deep_copy])

Return the core attributes.

get_de_pre_serialization_funcs()

Return the de-pre-serialization functions.

get_disk_absence_registry([deep_copy])

Return the disk absence registry of the cropped fake CBED pattern.

get_disk_clipping_registry([deep_copy])

Return the disk clipping registry of the cropped fake CBED pattern.

get_disk_overlap_map([deep_copy])

Return the image of the disk overlap map of the cropped fake CBED pattern.

get_disk_supports([deep_copy])

Return the image stack of the disk supports of the cropped fake CBED pattern.

get_illumination_support([deep_copy])

Return the illumination support of the cropped fake CBED pattern.

get_image([deep_copy])

Return the image of the cropped fake CBED pattern.

get_pre_serialization_funcs()

Return the pre-serialization functions.

get_principal_disk_boundary_pts_in_cropped_image_fractional_coords([...])

Return the sample of points on the boundary of the "principal" CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

get_principal_disk_boundary_pts_in_uncropped_image_fractional_coords([...])

Return the sample of points on the boundary of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

get_principal_disk_bounding_box_in_cropped_image_fractional_coords([...])

Return the bounding box of the "principal" CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

get_principal_disk_bounding_box_in_uncropped_image_fractional_coords([...])

Return the bounding box of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

get_signal([deep_copy])

Return the hyperspy signal representation of the cropped fake CBED pattern.

get_validation_and_conversion_funcs()

Return the validation and conversion functions.

load([filename, skip_validation_and_conversion])

Construct an instance from a serialized representation that is stored in a JSON file.

loads([serialized_rep, ...])

Construct an instance from a serialized representation.

pre_serialize()

Pre-serialize instance.

update(new_core_attr_subset_candidate[, ...])

Update a subset of the core attributes.

execute_post_core_attrs_update_actions

Methods

de_pre_serialize

Construct an instance from a serializable representation.

dump

Serialize instance and save the result in a JSON file.

dumps

Serialize instance.

execute_post_core_attrs_update_actions

get_core_attrs

Return the core attributes.

get_de_pre_serialization_funcs

Return the de-pre-serialization functions.

get_disk_absence_registry

Return the disk absence registry of the cropped fake CBED pattern.

get_disk_clipping_registry

Return the disk clipping registry of the cropped fake CBED pattern.

get_disk_overlap_map

Return the image of the disk overlap map of the cropped fake CBED pattern.

get_disk_supports

Return the image stack of the disk supports of the cropped fake CBED pattern.

get_illumination_support

Return the illumination support of the cropped fake CBED pattern.

get_image

Return the image of the cropped fake CBED pattern.

get_pre_serialization_funcs

Return the pre-serialization functions.

get_principal_disk_boundary_pts_in_cropped_image_fractional_coords

Return the sample of points on the boundary of the "principal" CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

get_principal_disk_boundary_pts_in_uncropped_image_fractional_coords

Return the sample of points on the boundary of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

get_principal_disk_bounding_box_in_cropped_image_fractional_coords

Return the bounding box of the "principal" CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

get_principal_disk_bounding_box_in_uncropped_image_fractional_coords

Return the bounding box of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

get_signal

Return the hyperspy signal representation of the cropped fake CBED pattern.

get_validation_and_conversion_funcs

Return the validation and conversion functions.

load

Construct an instance from a serialized representation that is stored in a JSON file.

loads

Construct an instance from a serialized representation.

pre_serialize

Pre-serialize instance.

update

Update a subset of the core attributes.

Attributes

core_attrs

dict: The "core attributes".

de_pre_serialization_funcs

dict: The de-pre-serialization functions.

device

torch.device: The device on which computationally intensive PyTorch operations are performed and attributes of the type torch.Tensor are stored.

disk_absence_registry

torch.Tensor: The disk absence registry of the cropped fake CBED pattern.

disk_clipping_registry

torch.Tensor: The disk clipping registry of the cropped fake CBED pattern.

disk_overlap_map

torch.Tensor: The image of the disk overlap map of the cropped fake CBED pattern.

disk_supports

torch.Tensor: The image stack of the disk supports of the cropped fake CBED pattern.

illumination_support

torch.Tensor: The illumination support of the cropped fake CBED pattern.

image

torch.Tensor: The image of the cropped fake CBED pattern.

image_has_been_overridden

bool: Equals True if the image of the fake cropped CBED pattern has been overridden.

num_disks

int: The total number of CBED disks defined, \(N_{\text{D}}\).

pre_serialization_funcs

dict: The pre-serialization functions.

principal_disk_boundary_pts_in_cropped_image_fractional_coords

torch.Tensor | None: The sample of points on the boundary of the unclipped support of the "principal" CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

principal_disk_boundary_pts_in_uncropped_image_fractional_coords

torch.Tensor | None: The sample of points on the boundary of the unclipped support of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

principal_disk_bounding_box_in_cropped_image_fractional_coords

tuple | None: The bounding box of the unclipped support of the "principal" CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

principal_disk_bounding_box_in_uncropped_image_fractional_coords

tuple | None: The bounding box of the unclipped support of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

principal_disk_is_absent

bool: Equals True if the "principal" CBED disk either does not exists, or it exists and is absent from the image of the cropped fake CBED pattern.

principal_disk_is_clipped

bool: Equals True if the "principal" CBED disk either does not exists, or it exists and is clipped in image of the cropped fake CBED pattern.

principal_disk_is_overlapping

bool: Equals True if the "principal" CBED disk exists and is overlapping with another CBED disk in the image of the cropped fake CBED pattern.

signal

hyperspy._signals.signal2d.Signal2D: The hyperspy signal representation of the cropped fake CBED pattern.

validation_and_conversion_funcs

dict: The validation and conversion functions.

property core_attrs

dict: The “core attributes”.

The keys of core_attrs are the same as the attribute validation_and_conversion_funcs, which is also a dict object.

Note that core_attrs should be considered read-only.

property de_pre_serialization_funcs

dict: The de-pre-serialization functions.

de_pre_serialization_funcs has the same keys as the attribute validation_and_conversion_funcs, which is also a dict object.

Let validation_and_conversion_funcs and pre_serialization_funcs denote the attributes validation_and_conversion_funcs pre_serialization_funcs respectively, the last of which being a dict object as well.

Let core_attrs_candidate_1 be any dict object that has the same keys as validation_and_conversion_funcs, where for each dict key key in core_attrs_candidate_1, validation_and_conversion_funcs[key](core_attrs_candidate_1) does not raise an exception.

Let serializable_rep be a dict object that has the same keys as core_attrs_candidate_1, where for each dict key key in core_attrs_candidate_1, serializable_rep[key] is set to pre_serialization_funcs[key](core_attrs_candidate_1[key]).

The items of de_pre_serialization_funcs are expected to be set to callable objects that would lead to de_pre_serialization_funcs[key](serializable_rep[key]) not raising an exception for each dict key key in serializable_rep.

Let core_attrs_candidate_2 be a dict object that has the same keys as serializable_rep, where for each dict key key in validation_and_conversion_funcs, core_attrs_candidate_2[key] is set to de_pre_serialization_funcs[key](serializable_rep[key]).

The items of de_pre_serialization_funcs are also expected to be set to callable objects that would lead to validation_and_conversion_funcs[key](core_attrs_candidate_2) not raising an exception for each dict key key in core_attrs_candidate_2.

Note that de_pre_serialization_funcs should be considered read-only.

classmethod de_pre_serialize(serializable_rep={}, skip_validation_and_conversion=False)

Construct an instance from a serializable representation.

Parameters:
serializable_repdict, optional

A dict object that has the same keys as the attribute validation_and_conversion_funcs, which is also a dict object.

Let validation_and_conversion_funcs and de_pre_serialization_funcs denote the attributes validation_and_conversion_funcs de_pre_serialization_funcs respectively, the last of which being a dict object as well.

The items of serializable_rep are expected to be objects that would lead to de_pre_serialization_funcs[key](serializable_rep[key]) not raising an exception for each dict key key in serializable_rep.

Let core_attrs_candidate be a dict object that has the same keys as serializable_rep, where for each dict key key in serializable_rep, core_attrs_candidate[key] is set to de_pre_serialization_funcs[key](serializable_rep[key])``.

The items of serializable_rep are also expected to be set to objects that would lead to validation_and_conversion_funcs[key](core_attrs_candidate) not raising an exception for each dict key key in serializable_rep.

skip_validation_and_conversionbool, optional

Let core_attrs denote the attribute core_attrs, which is a dict object.

If skip_validation_and_conversion is set to False, then for each key key in serializable_rep, core_attrs[key] is set to validation_and_conversion_funcs[key] (core_attrs_candidate), with validation_and_conversion_funcs and core_attrs_candidate_1 being introduced in the above description of serializable_rep.

Otherwise, if skip_validation_and_conversion is set to True, then core_attrs is set to core_attrs_candidate.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values of core_attrs_candidate, as it is guaranteed that no copies or conversions are made in this case.

Returns:
instance_of_current_clsCurrent class

An instance constructed from the serializable representation serializable_rep.

property device

torch.device: The device on which computationally intensive PyTorch operations are performed and attributes of the type torch.Tensor are stored.

Note that device should be considered read-only.

property disk_absence_registry

torch.Tensor: The disk absence registry of the cropped fake CBED pattern.

See the summary documentation for the classes fakecbed.discretized.CBEDPattern, and fakecbed.discretized.CroppedCBEDPattern for additional context.

Let num_disks, and disk_supports denote the attributes fakecbed.discretized.CroppedCBEDPattern.num_disks, and fakecbed.discretized.CroppedCBEDPattern.disk_supports respectively. Moreover, let k be a nonnegative integer less than num_disks.

disk_absence_registry is a one-dimensional PyTorch tensor of length equal to num_disks. If disk_absence_registry[k] is equal to False, then the image stored in disk_supports[k] has at least one nonzero pixel. Otherwise, if disk_absence_registry[k] is equal to True, then the opposite of the above scenario is true.

Note that disk_absence_registry should be considered read-only.

property disk_clipping_registry

torch.Tensor: The disk clipping registry of the cropped fake CBED pattern.

See the summary documentation for the classes fakecbed.discretized.CBEDPattern, and fakecbed.discretized.CroppedCBEDPattern for additional context.

Let num_disks, disk_supports, illumination_support, and image denote the attributes fakecbed.discretized.CroppedCBEDPattern.num_disks, fakecbed.discretized.CroppedCBEDPattern.disk_supports, fakecbed.discretized.CroppedCBEDPattern.illumination_support, and fakecbed.discretized.CroppedCBEDPattern.image respectively. Moreover, let k be a nonnegative integer less than num_disks.

disk_clipping_registry is a one-dimensional PyTorch tensor of length equal to num_disks. If disk_clipping_registry[k] is equal to False, then the image stored in disk_supports[k] has at least one nonzero pixel, and that the position of every nonzero pixel of said image is at least two pixels away from (i.e. at least pixel-wise next-nearest neighbours to) the position of every zero-valued pixel of the image stored in illumination_support, at least two pixels away from the position of every pixel inside any of the mask frames that appears in the image stored in image, and at least one pixel away from every pixel bordering the image stored in image. Otherwise, if disk_clipping_registry[k] is equal to True, then the opposite of the above scenario is true.

Note that there are potentially two mask frames that may appear in the image stored in image: the mask frame applied to the uncropped fake CBED pattern, and the mask frame that is applied after cropping the fake CBED pattern.

Note that disk_clipping_registry should be considered read-only.

property disk_overlap_map

torch.Tensor: The image of the disk overlap map of the cropped fake CBED pattern.

See the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.signal for additional context.

Let signal, device, and core_attrs denote the attributes fakecbed.discretized.CroppedCBEDPattern.signal, fakecbed.discretized.CroppedCBEDPattern.device, and core_attrs respectively.

disk_overlap_map is calculated effectively by:

N_W_h, N_W_v = core_attrs["cropping_window_dims_in_pixels"]
L, R, B, T = core_attrs["mask_frame"]

disk_overlap_map = signal.data[2]
disk_overlap_map = torch.from_numpy(disk_overlap_map)
disk_overlap_map = disk_overlap_map.to(device=device, dtype=int)
disk_overlap_map[:T, :] = 0
disk_overlap_map[max(N_W_v-B, 0):, :] = 0
disk_overlap_map[:, :L] = 0
disk_overlap_map[:, max(N_W_h-R, 0):] = 0

Note that disk_overlap_map should be considered read-only.

property disk_supports

torch.Tensor: The image stack of the disk supports of the cropped fake CBED pattern.

See the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.signal for additional context.

Let signal, device, and core_attrs denote the attributes fakecbed.discretized.CroppedCBEDPattern.signal, fakecbed.discretized.CroppedCBEDPattern.device, and core_attrs respectively.

disk_supports is calculated effectively by:

N_W_h, N_W_v = core_attrs["cropping_window_dims_in_pixels"]
L, R, B, T = core_attrs["mask_frame"]

disk_supports = signal.data[3:]
disk_supports = torch.from_numpy(disk_supports)
disk_supports = disk_supports.to(device=device, dtype=bool)
disk_supports[:, :T, :] = 0
disk_supports[:, max(N_W_v-B, 0):, :] = 0
disk_supports[:, :, :L] = 0
disk_supports[:, :, max(N_W_h-R, 0):] = 0

Note that disk_supports should be considered read-only.

dump(filename='serialized_rep_of_fancytype.json', overwrite=False)

Serialize instance and save the result in a JSON file.

Parameters:
filenamestr, optional

The relative or absolute path to the JSON file in which to store the serialized representation of an instance.

overwritebool, optional

If overwrite is set to False and a file exists at the path filename, then the serialized instance is not written to that file and an exception is raised. Otherwise, the serialized instance will be written to that file barring no other issues occur.

Returns:
dumps()

Serialize instance.

Returns:
serialized_repdict

A serialized representation of an instance.

get_core_attrs(deep_copy=True)

Return the core attributes.

Parameters:
deep_copybool, optional

Let core_attrs denote the attribute core_attrs, which is a dict object.

If deep_copy is set to True, then a deep copy of core_attrs is returned. Otherwise, a shallow copy of core_attrs is returned.

Returns:
core_attrsdict

The attribute core_attrs.

classmethod get_de_pre_serialization_funcs()[source]

Return the de-pre-serialization functions.

Returns:
de_pre_serialization_funcsdict

The attribute de_pre_serialization_funcs.

get_disk_absence_registry(deep_copy=True)[source]

Return the disk absence registry of the cropped fake CBED pattern.

Parameters:
deep_copybool, optional

Let disk_absence_registry denote the attribute fakecbed.discretized.CroppedCBEDPattern.disk_absence_registry.

If deep_copy is set to True, then a deep copy of disk_absence_registry is returned. Otherwise, a reference to disk_absence_registry is returned.

Returns:
disk_absence_registrytorch.Tensor (bool, ndim=1)

The attribute fakecbed.discretized.CroppedCBEDPattern.disk_absence_registry.

get_disk_clipping_registry(deep_copy=True)[source]

Return the disk clipping registry of the cropped fake CBED pattern.

Parameters:
deep_copybool, optional

Let disk_clipping_registry denote the attribute fakecbed.discretized.CroppedCBEDPattern.disk_clipping_registry.

If deep_copy is set to True, then a deep copy of disk_clipping_registry is returned. Otherwise, a reference to disk_clipping_registry is returned.

Returns:
disk_clipping_registrytorch.Tensor (bool, ndim=1)

The attribute fakecbed.discretized.CroppedCBEDPattern.disk_clipping_registry.

get_disk_overlap_map(deep_copy=True)[source]

Return the image of the disk overlap map of the cropped fake CBED pattern.

Parameters:
deep_copybool, optional

Let disk_overlap_map denote the attribute fakecbed.discretized.CroppedCBEDPattern.disk_overlap_map.

If deep_copy is set to True, then a deep copy of disk_overlap_map is returned. Otherwise, a reference to disk_overlap_map is returned.

Returns:
disk_overlap_maptorch.Tensor (int, ndim=2)

The attribute fakecbed.discretized.CroppedCBEDPattern.disk_overlap_map.

get_disk_supports(deep_copy=True)[source]

Return the image stack of the disk supports of the cropped fake CBED pattern.

Parameters:
deep_copybool, optional

Let disk_supports denote the attribute fakecbed.discretized.CroppedCBEDPattern.disk_supports.

If deep_copy is set to True, then a deep copy of disk_supports is returned. Otherwise, a reference to disk_supports is returned.

Returns:
disk_supportstorch.Tensor (bool, ndim=3)

The attribute fakecbed.discretized.CroppedCBEDPattern.disk_supports.

get_illumination_support(deep_copy=True)[source]

Return the illumination support of the cropped fake CBED pattern.

Parameters:
deep_copybool, optional

Let illumination_support denote the attribute fakecbed.discretized.CroppedCBEDPattern.illumination_support.

If deep_copy is set to True, then a deep copy of illumination_support is returned. Otherwise, a reference to illumination_support is returned.

Returns:
illumination_supporttorch.Tensor (float, ndim=2)

The attribute fakecbed.discretized.CroppedCBEDPattern.illumination_support.

get_image(deep_copy=True)[source]

Return the image of the cropped fake CBED pattern.

Parameters:
deep_copybool, optional

Let image denote the attribute fakecbed.discretized.CroppedCBEDPattern.image.

If deep_copy is set to True, then a deep copy of image is returned. Otherwise, a reference to image is returned.

Returns:
imagetorch.Tensor (float, ndim=2)

The attribute fakecbed.discretized.CroppedCBEDPattern.image.

classmethod get_pre_serialization_funcs()[source]

Return the pre-serialization functions.

Returns:
pre_serialization_funcsdict

The attribute pre_serialization_funcs.

get_principal_disk_boundary_pts_in_cropped_image_fractional_coords(deep_copy=True)[source]

Return the sample of points on the boundary of the “principal” CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

Let core_attrs denote the attribute core_attrs.

Parameters:
deep_copybool, optional

Let principal_disk_boundary_pts_in_cropped_image_fractional_coords denote the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords.

If deep_copy is set to True, then a deep copy of principal_disk_boundary_pts_in_cropped_image_fractional_coords is returned. Otherwise, a reference to principal_disk_boundary_pts_in_cropped_image_fractional_coords is returned.

Returns:
principal_disk_boundary_pts_in_cropped_image_fractional_coordstorch.Tensor (float, shape=(core_attrs[“disk_boundary_sample_size”], 2)) | None

The attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords.

get_principal_disk_boundary_pts_in_uncropped_image_fractional_coords(deep_copy=True)[source]

Return the sample of points on the boundary of the “principal” CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

Let core_attrs denote the attribute core_attrs.

Parameters:
deep_copybool, optional

Let principal_disk_boundary_pts_in_uncropped_image_fractional_coords denote the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords.

If deep_copy is set to True, then a deep copy of principal_disk_boundary_pts_in_uncropped_image_fractional_coords is returned. Otherwise, a reference to principal_disk_boundary_pts_in_uncropped_image_fractional_coords is returned.

Returns:
principal_disk_boundary_pts_in_uncropped_image_fractional_coordstorch.Tensor (float, shape=(core_attrs[“disk_boundary_sample_size”], 2)) | None

The attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords.

get_principal_disk_bounding_box_in_cropped_image_fractional_coords(deep_copy=True)[source]

Return the bounding box of the “principal” CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

Let core_attrs denote the attribute core_attrs.

Parameters:
deep_copybool, optional

Let principal_disk_bounding_box_in_cropped_image_fractional_coords denote the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_cropped_image_fractional_coords.

If deep_copy is set to True, then a deep copy of principal_disk_bounding_box_in_cropped_image_fractional_coords is returned. Otherwise, a reference to principal_disk_bounding_box_in_cropped_image_fractional_coords is returned.

Returns:
principal_disk_bounding_box_in_cropped_image_fractional_coordstorch.Tensor (float, shape=(core_attrs[“disk_boundary_sample_size”], 2)) | None

The attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_cropped_image_fractional_coords.

get_principal_disk_bounding_box_in_uncropped_image_fractional_coords(deep_copy=True)[source]

Return the bounding box of the “principal” CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

Let core_attrs denote the attribute core_attrs.

Parameters:
deep_copybool, optional

Let principal_disk_bounding_box_in_uncropped_image_fractional_coords denote the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_uncropped_image_fractional_coords.

If deep_copy is set to True, then a deep copy of principal_disk_bounding_box_in_uncropped_image_fractional_coords is returned. Otherwise, a reference to principal_disk_bounding_box_in_uncropped_image_fractional_coords is returned.

Returns:
principal_disk_bounding_box_in_uncropped_image_fractional_coordstorch.Tensor (float, shape=(core_attrs[“disk_boundary_sample_size”], 2)) | None

The attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_uncropped_image_fractional_coords.

get_signal(deep_copy=True)[source]

Return the hyperspy signal representation of the cropped fake CBED pattern.

Parameters:
deep_copybool, optional

Let signal denote the attribute fakecbed.discretized.CroppedCBEDPattern.signal.

If deep_copy is set to True, then a deep copy of signal is returned. Otherwise, a reference to signal is returned.

Returns:
signalhyperspy._signals.signal2d.Signal2D

The attribute fakecbed.discretized.CroppedCBEDPattern.signal.

classmethod get_validation_and_conversion_funcs()[source]

Return the validation and conversion functions.

Returns:
validation_and_conversion_funcsdict

The attribute validation_and_conversion_funcs.

property illumination_support

torch.Tensor: The illumination support of the cropped fake CBED pattern.

See the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.signal for additional context.

Let signal, and device denote the attributes fakecbed.discretized.CroppedCBEDPattern.signal, and fakecbed.discretized.CroppedCBEDPattern.device respectively.

illumination_support is calculated effectively by:

illumination_support = signal.data[1]
illumination_support = torch.from_numpy(illumination_support)
illumination_support = illumination_support.to(device=device, 
                                               dtype=bool)

Note that illumination_support should be considered read-only.

property image

torch.Tensor: The image of the cropped fake CBED pattern.

See the documentation for the attribute fakecbed.discretized.CBEDPattern.signal for additional context.

Let signal, device, and core_attrs denote the attributes fakecbed.discretized.CroppedCBEDPattern.signal, fakecbed.discretized.CroppedCBEDPattern.device, and core_attrs respectively.

image is calculated effectively by:

N_W_h, N_W_v = core_attrs["cropping_window_dims_in_pixels"]
L, R, B, T = core_attrs["mask_frame"]

image = signal.data[0]
image_dtype = image.dtype
image = torch.from_numpy(image)
image = image.to(device=device, dtype=image_dtype)
image[:T, :] = 0
image[max(N_W_v-B, 0):, :] = 0
image[:, :L] = 0
image[:, max(N_W_h-R, 0):] = 0

Note that image should be considered read-only.

property image_has_been_overridden

bool: Equals True if the image of the fake cropped CBED pattern has been overridden.

See the summary documentation for the classes fakecbed.discretized.CBEDPattern and fakecbed.discretized.CroppedCBEDPattern for additional context, as well as the documentation for the attribute fakecbed.discretized.CBEDPattern.image_has_been_overridden.

Let core_attrs denote the attribute core_attrs.

image_has_been_overridden is calculated effectively by:

cbed_pattern = core_attrs["cbed_pattern"]
image_has_been_overridden = cbed_pattern.image_has_been_overridden

Note that image_has_been_overridden should be considered read-only.

classmethod load(filename='serialized_rep_of_fancytype.json', skip_validation_and_conversion=False)

Construct an instance from a serialized representation that is stored in a JSON file.

Users can save serialized representations to JSON files using the method fancytypes.PreSerializable.dump().

Parameters:
filenamestr, optional

The relative or absolute path to the JSON file that is storing the serialized representation of an instance.

filename is expected to be such that json.load(open(filename, "r")) does not raise an exception.

Let serializable_rep=json.load(open(filename, "r")).

Let validation_and_conversion_funcs and de_pre_serialization_funcs denote the attributes validation_and_conversion_funcs de_pre_serialization_funcs respectively, both of which being dict objects as well.

filename is also expected to be such that de_pre_serialization_funcs[key](serializable_rep[key]) does not raise an exception for each dict key key in de_pre_serialization_funcs.

Let core_attrs_candidate be a dict object that has the same keys as de_pre_serialization_funcs, where for each dict key key in serializable_rep, core_attrs_candidate[key] is set to de_pre_serialization_funcs[key](serializable_rep[key])``.

filename is also expected to be such that validation_and_conversion_funcs[key](core_attrs_candidate) does not raise an exception for each dict key key in serializable_rep.

skip_validation_and_conversionbool, optional

Let core_attrs denote the attribute core_attrs, which is a dict object.

Let core_attrs_candidate be as defined in the above description of filename.

If skip_validation_and_conversion is set to False, then for each key key in core_attrs_candidate, core_attrs[key] is set to validation_and_conversion_funcs[key] (core_attrs_candidate), , with validation_and_conversion_funcs and core_attrs_candidate being introduced in the above description of filename.

Otherwise, if skip_validation_and_conversion is set to True, then core_attrs is set to core_attrs_candidate.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values of core_attrs_candidate, as it is guaranteed that no copies or conversions are made in this case.

Returns:
instance_of_current_clsCurrent class

An instance constructed from the serialized representation stored in the JSON file.

classmethod loads(serialized_rep='{}', skip_validation_and_conversion=False)

Construct an instance from a serialized representation.

Users can generate serialized representations using the method dumps().

Parameters:
serialized_repstr | bytes | bytearray, optional

The serialized representation.

serialized_rep is expected to be such that json.loads(serialized_rep) does not raise an exception.

Let serializable_rep=json.loads(serialized_rep).

Let validation_and_conversion_funcs and de_pre_serialization_funcs denote the attributes validation_and_conversion_funcs de_pre_serialization_funcs respectively, both of which being dict objects as well.

serialized_rep is also expected to be such that de_pre_serialization_funcs[key](serializable_rep[key]) does not raise an exception for each dict key key in de_pre_serialization_funcs.

Let core_attrs_candidate be a dict object that has the same keys as serializable_rep, where for each dict key key in de_pre_serialization_funcs, core_attrs_candidate[key] is set to de_pre_serialization_funcs[key](serializable_rep[key])``.

serialized_rep is also expected to be such that validation_and_conversion_funcs[key](core_attrs_candidate) does not raise an exception for each dict key key in serializable_rep.

skip_validation_and_conversionbool, optional

Let core_attrs denote the attribute core_attrs, which is a dict object.

If skip_validation_and_conversion is set to False, then for each key key in core_attrs_candidate, core_attrs[key] is set to validation_and_conversion_funcs[key] (core_attrs_candidate), with validation_and_conversion_funcs and core_attrs_candidate_1 being introduced in the above description of serialized_rep.

Otherwise, if skip_validation_and_conversion is set to True, then core_attrs is set to core_attrs_candidate.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values of core_attrs_candidate, as it is guaranteed that no copies or conversions are made in this case.

Returns:
instance_of_current_clsCurrent class

An instance constructed from the serialized representation.

property num_disks

int: The total number of CBED disks defined, \(N_{\text{D}}\).

See the summary documentation for the class fakecbed.discretized.CBEDPattern for additional context.

Let core_attrs denote the attribute core_attrs. num_disks is equal to core_attrs["cbed_pattern"].num_disks.

Note that num_disks should be considered read-only.

property pre_serialization_funcs

dict: The pre-serialization functions.

pre_serialization_funcs has the same keys as the attribute validation_and_conversion_funcs, which is also a dict object.

Let validation_and_conversion_funcs and core_attrs denote the attributes validation_and_conversion_funcs and core_attrs respectively, the last of which being a dict object as well.

For each dict key key in core_attrs, pre_serialization_funcs[key](core_attrs[key]) is expected to yield a serializable object, i.e. it should yield an object that can be passed into the function json.dumps without raising an exception.

Note that pre_serialization_funcs should be considered read-only.

pre_serialize()

Pre-serialize instance.

Returns:
serializable_repdict

A serializable representation of an instance.

property principal_disk_boundary_pts_in_cropped_image_fractional_coords

torch.Tensor | None: The sample of points on the boundary of the unclipped support of the “principal” CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

See the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords for additional context.

Let core_attrs, principal_disk_boundary_pts_in_uncropped_image_fractional_coords, and signal, denote the attributes core_attrs fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords, and fakecbed.discretized.CroppedCBEDPattern.signal respectively.

principal_disk_boundary_pts_in_cropped_image_fractional_coords is calculated effectively by:

import torch

cbed_pattern = core_attrs["cbed_pattern"]
N_x = cbed_pattern.core_attrs["num_pixels_across_pattern"]
N_y = N_x

N_W_h, N_W_v = core_attrs["cropping_window_dims_in_pixels"]

boundary_pts_in_uncropped_image_fractional_coords = \
    principal_disk_boundary_pts_in_uncropped_image_fractional_coords

if boundary_pts_in_uncropped_image_fractional_coords is not None:

    kwargs = \
        {"input": boundary_pts_in_uncropped_image_fractional_coords}
    boundary_pts_in_cropped_image_fractional_coords = \
        torch.zeros_like(**kwargs)

    boundary_pts_in_cropped_image_fractional_coords[:, 0] = \
        ((boundary_pts_in_uncropped_image_fractional_coords[:, 0]
          - signal.axes_manager[1].offset) * (N_x/N_W_h)
         + (0.5/N_W_h))
    boundary_pts_in_cropped_image_fractional_coords[:, 1] = \
        ((boundary_pts_in_uncropped_image_fractional_coords[:, 1]
          - signal.axes_manager[2].offset) * (N_y/N_W_v)
         + (1-(1-0.5)/N_W_v))
else:
    boundary_pts_in_cropped_image_fractional_coords = \
        None

principal_disk_boundary_pts_in_cropped_image_fractional_coords = \
    boundary_pts_in_cropped_image_fractional_coords

Note that principal_disk_boundary_pts_in_cropped_image_fractional_coords should be considered read-only.

property principal_disk_boundary_pts_in_uncropped_image_fractional_coords

torch.Tensor | None: The sample of points on the boundary of the unclipped support of the “principal” CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

See the summary documentation for the classes fakecbed.discretized.CBEDPattern and fakecbed.discretized.CroppedCBEDPattern for additional context.

Let core_attrs denote the attribute core_attrs. Furthermore, let cbed_pattern, disk_boundary_sample_size, and principal_disk_idx denote core_attrs["cbed_pattern"], core_attrs["disk_boundary_sample_size"], and core_attrs["principal_disk_idx"] respectively.

The “principal” CBED disk refers to the CBED disk, should it exist, that is specified by the nonnegative integer principal_disk_idx. If principal_disk_idx < len(cbed_pattern.core_attrs["undistorted_disks"]), then principal_disk_idx specifies the CBED disk constructed from the undistorted intensity pattern stored in cbed_pattern.core_attrs["undistorted_disks"][prinicpal_disk_idx]. If principal_disk_idx >= len(cbed_pattern.core_attrs["undistorted_disks"]), then principal_disk_idx specifies a nonexistent CBED disk.

If principal_disk_idx specifies a nonexistent CBED disk, then principal_disk_boundary_pts_in_uncropped_image_fractional_coords is set to None.

The remainder of the documentation for the current attribute describes how said attribute is calculated, assuming that the principal CBED disk exists. In fakecbed, the undistorted shape of the support of every CBED disk is assumed to be an ellipse, which incidentally can be a circle if the eccentricity is zero. The definitions of the center, the semi-major axis, the eccentricity, and the rotation angle of a ellipse that are adopted in fakecbed are given implictly in the documentation for the class fakecbed.shapes.Ellipse. Let \(\left(u_{x;c;\text{PDS}},u_{y;c;\text{PDS}}\right)\), \(a_{\text{PDS}}\), \(e_{\text{PDS}}\), and \(\theta_{\text{PDS}}\) be the center, the semi-major axis, the eccentricity, and the rotation angle of the principal CBED disk support.

Let \(u_{x}\) and \(u_{y}\) be the fractional horizontal and vertical coordinates, respectively, of a point in an undistorted image, where \(\left(u_{x},u_{y}\right)=\left(0,0\right)\) is the bottom left corner of the image. Similarly, let \(q_{x}\) and \(q_{y}\) be the fractional horizontal and vertical coordinates, respectively, of a point in a distorted image, where \(\left(q_{x},q_{y}\right)=\left(0,0\right)\) is the bottom left corner of the image. The core attribute cbed_pattern specifies a distortion model, which can be accessed via cbed_pattern.core_attrs["distortion_model"]. The distortion model specifies a coordinate transformation, \(\left(T_{⌑;x}\left(u_{x},u_{y}\right), T_{⌑;x}\left(u_{x},u_{y}\right)\right)\), which maps a given coordinate pair \(\left(u_{x},u_{y}\right)\) to a corresponding coordinate pair \(\left(q_{x},q_{y}\right)\).

Next, let \(N_{\mathcal{I};x} and N_{\mathcal{I};y}\) be the number of pixels in the image of the uncropped fake CBED pattern, where we assume that

(2.1.2.1)\[N_{\mathcal{I};x}=N_{\mathcal{I};y},\]

Furthermore, let \(N_{\text{max-iter}}=30, and let N_{\text{SS}}\) be disk_boundary_sample_size.

Next, let \(\partial S_{\text{PDS};x;l}\) and \(\partial S_{\text{PDS};y;l}\) denote principal_disk_boundary_pts_in_uncropped_image_fractional_coords[l, 0] and principal_disk_boundary_pts_in_uncropped_image_fractional_coords[l, 1] respectively, where ``principal_disk_boundary_pts_in_uncropped_image_fractional_coords is the current attribute, and l is equal to the value of \(l\). The current attribute is calculated effectively by executing the following steps:

  1. Calculate

(2.1.2.2)\[X_{1} \leftarrow \left\{ l^{\prime}\right\}_{l^{\prime}=0}^{N_{\text{SS}}-1}.\]
  1. Calculate

(2.1.2.3)\[X_{2} \leftarrow \left\{ l^{\prime}\right\}_{l^{\prime}=0}^{N_{\text{SS}}-2}\]
  1. Calculate

(2.1.2.4)\[m \leftarrow 0.\]
  1. Calculate

(2.1.2.5)\[N_{\text{iter}} \leftarrow 0.\]
  1. Calculate

(2.1.2.6)\[\phi_{l}\leftarrow\frac{2\pi l}{N_{\text{SS}}} \text{ for }l\in X_{1}.\]
  1. Calculate

(2.1.2.7)\[j\leftarrow\min\left(\left\{ N_{\text{iter}}+1,1\right\} \right).\]
  1. Calculate

(2.1.2.8)\[u_{x;l}\leftarrow u_{x;c;\text{PDS}} +a_{\text{PDS}}\cos\left(\phi_{l}+\theta_{\text{PDS}}\right) \text{ for }l\in X_{1},\]

and

(2.1.2.9)\[u_{y;l}\leftarrow u_{y;c;\text{PDS}} +a_{\text{PDS}}\sqrt{1-e_{\text{PDS}}^{2}} \sin\left(\phi_{l}+\theta_{\text{PDS}}\right)\text{ for }l\in X_{1}.\]
  1. Calculate

(2.1.2.10)\[q_{x;l}\leftarrow T_{⌑;x}\left(u_{x;l},u_{y;l}\right) \text{ for }l\in X_{1},\]

and

(2.1.2.11)\[q_{y;l}\leftarrow T_{⌑;y}\left(u_{x;l},u_{y;l}\right) \text{ for }l\in X_{1}.\]
  1. If \(m=0\), then go to step 10, otherwise go to step 21.

  2. Calculate

(2.1.2.12)\[n\leftarrow\text{argmax}_{l\in X_{1}}\left(u_{x;l}\right).\]
  1. Calculate

(2.1.2.13)\[\Delta_{q;l}\leftarrow\sqrt{\sum_{\alpha\in\left\{ x,y\right\} } \left[q_{\alpha;l\mod N_{\text{SS}}} -q_{\alpha;\left\{ l+1\right\} \mod N_{\text{SS}}}\right]^{2}} \text{ for }l\in X_{j}.\]

12. If \(N_{\text{iter}}=0\) then go to step 13, otherwise go to step 15.

  1. Calculate

(2.1.2.14)\[\phi_{\vdash}\leftarrow\phi_{\left(n-16\right)\mod N_{\text{SS}}},\]

and

(2.1.2.15)\[\phi_{\dashv}\leftarrow\phi_{\left(n+16\right)\mod N_{\text{SS}}}.\]
  1. Go to step 16.

  2. Calculate

(2.1.2.16)\[\phi_{\vdash}\leftarrow \phi_{\max\left(\left\{n-16,0\right\}\right)},\]

and

(2.1.2.17)\[\phi_{\dashv}\leftarrow \phi_{\min\left(\left\{n+16,N_{\text{SS}}-1\right\}\right)}.\]
  1. If \(\phi_{\vdash}>\phi_{\dashv}\), then calculate

(2.1.2.18)\[\phi_{\dashv}\leftarrow\phi_{\dashv}+2\pi.\]
  1. Calculate

(2.1.2.19)\[\phi_{l}\leftarrow \phi_{\vdash}+l\frac{\phi_{\dashv}-\phi_{\vdash}}{N_{\text{SS}}-1} \text{ for }l\in X_{1}.\]

18. If \(100 N_{\mathcal{I};x}\max\left( \left\{\Delta_{q;l}\right\}_{l\in S_{m}}\right) \le 1\) or \(N_{\text{iter}}=N_{\text{max-iter}}\), then calculate

(2.1.2.20)\[m \leftarrow 1,\]
(2.1.2.21)\[\phi_{\vdash}\leftarrow\phi_{n}\mod\left\{ 2\pi\right\},\]

and

(2.1.2.22)\[\phi_{\dashv}\leftarrow\phi_{\vdash}+2\pi.\]
  1. Calculate

(2.1.2.23)\[N_{\text{iter}}\leftarrow N_{\text{iter}}+1.\]
  1. Go to step 6.

  2. Calculate

(2.1.2.24)\[\partial S_{\text{PDS};x;l}\leftarrow q_{x;l}\text{ for }l\in X_{1},\]

and

(2.1.2.25)\[\partial S_{\text{PDS};y;l}\leftarrow q_{y;l}\text{ for }l\in X_{1}.\]

A consequence of the above algorithm is that \(\left(\partial S_{\text{PDS};x;0},\partial S_{\text{PDS};y;0}\right)\) is the right-most point of the entire sample of points \(\left\{ \left(\partial S_{\text{PDS};x;l},\partial S_{\text{PDS};y;l}\right)\right\} _{l\in S_{1}}\) on the boundary of the principal CBED disk.

Note that principal_disk_boundary_pts_in_uncropped_image_fractional_coords should be considered read-only.

property principal_disk_bounding_box_in_cropped_image_fractional_coords

tuple | None: The bounding box of the unclipped support of the “principal” CBED disk, should it exist, in fractional coordinates of the cropped CBED pattern.

See the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords for additional context.

Let principal_disk_boundary_pts_in_cropped_image_fractional_coords denote the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords.

principal_disk_bounding_box_in_cropped_image_fractional_coords is calculated effectively by:

import torch

pts = \
    principal_disk_boundary_pts_in_cropped_image_fractional_coords

if pts is not None:
    bounding_box = (torch.amin(pts[:, 0]).item(),
                    torch.amax(pts[:, 0]).item(),
                    torch.amin(pts[:, 1]).item(),
                    torch.amax(pts[:, 1]).item())
else:
    bounding_box = None

principal_disk_bounding_box_in_cropped_image_fractional_coords = \
    bounding_box

Note that principal_disk_bounding_box_in_cropped_image_fractional_coords should be considered read-only.

property principal_disk_bounding_box_in_uncropped_image_fractional_coords

tuple | None: The bounding box of the unclipped support of the “principal” CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.

See the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords for additional context.

Let principal_disk_boundary_pts_in_uncropped_image_fractional_coords denote the attribute fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords.

principal_disk_bounding_box_in_uncropped_image_fractional_coords is calculated effectively by:

import torch

pts = \
    principal_disk_boundary_pts_in_uncropped_image_fractional_coords

if pts is not None:
    bounding_box = (torch.amin(pts[:, 0]).item(),
                    torch.amax(pts[:, 0]).item(),
                    torch.amin(pts[:, 1]).item(),
                    torch.amax(pts[:, 1]).item())
else:
    bounding_box = None

principal_disk_bounding_box_in_uncropped_image_fractional_coords = \
    bounding_box

Note that principal_disk_bounding_box_in_uncropped_image_fractional_coords should be considered read-only.

property principal_disk_is_absent

bool: Equals True if the “principal” CBED disk either does not exists, or it exists and is absent from the image of the cropped fake CBED pattern.

See the summary documentation for the class fakecbed.discretized.CroppedCBEDPattern for additional context, as well as the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.disk_absence_registry.

Let core_attrs, num_disks, and disk_absence_registry denote the attributes core_attrs, fakecbed.discretized.CroppedCBEDPattern.num_disks, and fakecbed.discretized.CroppedCBEDPattern.disk_absence_registry respectively.

principal_disk_is_absent is calculated effectively by:

principal_disk_idx = \
    core_attrs["principal_disk_idx"]
principal_disk_is_absent = \
    (disk_absence_registry[principal_disk_idx].item()
     if (principal_disk_idx < num_disks)
     else True)

Note that principal_disk_is_absent should be considered read-only.

property principal_disk_is_clipped

bool: Equals True if the “principal” CBED disk either does not exists, or it exists and is clipped in image of the cropped fake CBED pattern.

See the summary documentation for the class fakecbed.discretized.CroppedCBEDPattern for additional context, as well as the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.disk_clipping_registry.

Let core_attrs, num_disks, and disk_clipping_registry denote the attributes core_attrs, fakecbed.discretized.CroppedCBEDPattern.num_disks, and fakecbed.discretized.CroppedCBEDPattern.disk_clipping_registry respectively.

principal_disk_is_clipped is calculated effectively by:

principal_disk_idx = \
    core_attrs["principal_disk_idx"]
principal_disk_is_clipped = \
    (disk_clipping_registry[principal_disk_idx].item()
     if (principal_disk_idx < num_disks)
     else True)

Note that principal_disk_is_clipped should be considered read-only.

property principal_disk_is_overlapping

bool: Equals True if the “principal” CBED disk exists and is overlapping with another CBED disk in the image of the cropped fake CBED pattern.

See the summary documentation for the class fakecbed.discretized.CroppedCBEDPattern for additional context, as well as the documentation for the attribute fakecbed.discretized.CroppedCBEDPattern.disk_overlap_map.

Let core_attrs, num_disks, disk_supports, and disk_overlap_map denote the attributes core_attrs, fakecbed.discretized.CroppedCBEDPattern.num_disks, fakecbed.discretized.CroppedCBEDPattern.disk_supports, and fakecbed.discretized.CroppedCBEDPattern.disk_overlap_map respectively.

principal_disk_is_overlapping is calculated effectively by:

principal_disk_idx = core_attrs["principal_disk_idx"]

principal_disk_support = (disk_supports[principal_disk_idx]
                          if (principal_disk_idx < num_disks)
                          else torch.zeros_like(disk_overlap_map))

principal_disk_is_overlapping = \
    torch.any(disk_overlap_map*principal_disk_support > 1.5).item()

Note that principal_disk_is_overlapping should be considered read-only.

property signal

hyperspy._signals.signal2d.Signal2D: The hyperspy signal representation of the cropped fake CBED pattern.

See the summary documentation for the classes fakecbed.discretized.CBEDPattern and fakecbed.discretized.CroppedCBEDPattern for additional context.

Let disk_clipping_registry, disk_absence_registry, principal_disk_is_clipped, principal_disk_is_absent, principal_disk_is_overlapping, principal_disk_bounding_box_in_uncropped_image_fractional_coords, principal_disk_bounding_box_in_cropped_image_fractional_coords, principal_disk_boundary_pts_in_uncropped_image_fractional_coords, principal_disk_boundary_pts_in_cropped_image_fractional_coords, and core_attrs denote the attributes fakecbed.discretized.CroppedCBEDPattern.disk_clipping_registry, fakecbed.discretized.CroppedCBEDPattern.disk_absence_registry, fakecbed.discretized.CroppedCBEDPattern.principal_disk_is_clipped, fakecbed.discretized.CroppedCBEDPattern.principal_disk_is_absent, fakecbed.discretized.CroppedCBEDPattern.principal_disk_is_overlapping, fakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_uncropped_image_fractional_coords, fakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_cropped_image_fractional_coords, fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords, fakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords, and core_attrs respectively. Furthermore, let pre_serialize denote the method pre_serialize().

signal is calculated effectively by:

import empix
import numpy as np

cbed_pattern = core_attrs["cbed_pattern"]
N_W_h, N_W_v = core_attrs["cropping_window_dims_in_pixels"]
L, R, B, T = core_attrs["mask_frame"]

cbed_pattern_signal = cbed_pattern.signal

title = "Cropped " + cbed_pattern_signal.metadata.General.title

cropping_window_center = \
    core_attrs["cropping_window_center"]
cropping_window_dims_in_pixels = \
    core_attrs["cropping_window_dims_in_pixels"]

kwargs = {"center": cropping_window_center,
          "window_dims": cropping_window_dims_in_pixels,
          "pad_mode": "zeros",
          "apply_symmetric_mask": False}
optional_params = empix.OptionalCroppingParams(**kwargs)

kwargs = {"input_signal": cbed_pattern_signal,
          "optional_params": optional_params}
signal = empix.crop(**kwargs)

signal.data[:, :T, :] = 0
signal.data[:, max(N_W_v-B, 0):, :] = 0
signal.data[:, :, :L] = 0
signal.data[:, :, max(N_W_h-R, 0):] = 0

# Normalize ``signal.data[0]``.
matrix = signal.data[0]
if matrix.max()-matrix.min() > 0:
    normalization_weight = 1 / (matrix.max()-matrix.min())
    normalization_bias = -normalization_weight*matrix.min()
    matrix = (matrix*normalization_weight
              + normalization_bias).clip(min=0, max=1)
else:
    matrix = np.zeros_like(matrix)
signal.data[0] = matrix

kwargs = {"item_path": "General.title", "value": title}
signal.metadata.set_item(**kwargs)

kwargs["item_path"] = "FakeCBED.pre_serialized_core_attrs"
kwargs["value"] = pre_serialize()
signal.metadata.set_item(**kwargs)

def _convert_attr_to_metadata_item(attr):
    if isinstance(attr, (tuple, bool)):
        metadata_item = \
            attr
    else:
        if len(attr.shape) == 1:
            metadata_item = \
                tuple(elem
                      for elem
                      in attr.cpu().detach().clone().tolist())
        else:
            metadata_item = \
                tuple(tuple(pt)
                      for pt
                      in attr.cpu().detach().clone().tolist())

    return metadata_item

attr = disk_clipping_registry
kwargs["item_path"] = "FakeCBED.disk_clipping_registry"
kwargs["value"] = _convert_attr_to_metadata_item(attr)
signal.metadata.set_item(**kwargs)

attr = disk_absence_registry
kwargs["item_path"] = "FakeCBED.disk_absence_registry"
kwargs["value"] = _convert_attr_to_metadata_item(attr)
signal.metadata.set_item(**kwargs)

attr = principal_disk_is_clipped
kwargs["item_path"] = "FakeCBED.principal_disk_is_clipped"
kwargs["value"] = _convert_attr_to_metadata_item(attr)
signal.metadata.set_item(**kwargs)

attr = principal_disk_is_absent
kwargs["item_path"] = "FakeCBED.principal_disk_is_absent"
kwargs["value"] = _convert_attr_to_metadata_item(attr)
signal.metadata.set_item(**kwargs)

attr = principal_disk_is_overlapping
kwargs["item_path"] = "FakeCBED.principal_disk_is_overlapping"
kwargs["value"] = _convert_attr_to_metadata_item(attr)
signal.metadata.set_item(**kwargs)

attr = \
    principal_disk_bounding_box_in_uncropped_image_fractional_coords
kwargs["item_path"] = \
    ("FakeCBED.principal_disk_bounding_box"
     "_in_uncropped_image_fractional_coords")
kwargs["value"] = \
    _convert_attr_to_metadata_item(attr)
_ = \
    signal.metadata.set_item(**kwargs)

attr = \
    principal_disk_bounding_box_in_cropped_image_fractional_coords
kwargs["item_path"] = \
    ("FakeCBED.principal_disk_bounding_box"
     "_in_cropped_image_fractional_coords")
kwargs["value"] = \
    _convert_attr_to_metadata_item(attr)
_ = \
    signal.metadata.set_item(**kwargs)

attr = \
    principal_disk_boundary_pts_in_uncropped_image_fractional_coords
kwargs["item_path"] = \
    ("FakeCBED.principal_disk_boundary_pts"
     "_in_uncropped_image_fractional_coords")
kwargs["value"] = \
    _convert_attr_to_metadata_item(attr)
_ = \
    signal.metadata.set_item(**kwargs)

attr = \
    principal_disk_boundary_pts_in_cropped_image_fractional_coords
kwargs["item_path"] = \
    ("FakeCBED.principal_disk_boundary_pts"
     "_in_cropped_image_fractional_coords")
kwargs["value"] = \
    _convert_attr_to_metadata_item(attr)
_ = \
    signal.metadata.set_item(**kwargs)

signal.axes_manager[0].name = \
    "cropped fake CBED pattern attribute"
signal.axes_manager[1].name = \
    "fractional horizontal coordinate of uncropped fake CBED pattern"
signal.axes_manager[2].name = \
    "fractional vertical coordinate of uncropped fake CBED pattern"

Note that signal should be considered read-only.

update(new_core_attr_subset_candidate, skip_validation_and_conversion=False)[source]

Update a subset of the core attributes.

Parameters:
new_core_attr_subset_candidatedict, optional

A dict object.

skip_validation_and_conversionbool, optional

Let validation_and_conversion_funcs and core_attrs denote the attributes validation_and_conversion_funcs and core_attrs respectively, both of which being dict objects.

If skip_validation_and_conversion is set to False, then for each key key in core_attrs that is also in new_core_attr_subset_candidate, core_attrs[key] is set to validation_and_conversion_funcs[key] (new_core_attr_subset_candidate).

Otherwise, if skip_validation_and_conversion is set to True, then for each key key in core_attrs that is also in new_core_attr_subset_candidate, core_attrs[key] is set to new_core_attr_subset_candidate[key]. This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values of new_core_attr_subset_candidate, as it is guaranteed that no copies or conversions are made in this case.

property validation_and_conversion_funcs

dict: The validation and conversion functions.

The keys of validation_and_conversion_funcs are the names of the constructor parameters, excluding skip_validation_and_conversion if it exists as a construction parameter.

Let core_attrs denote the attribute core_attrs, which is also a dict object.

For each dict key key in core_attrs, validation_and_conversion_funcs[key](core_attrs) is expected to not raise an exception.

Note that validation_and_conversion_funcs should be considered read-only.