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:
PreSerializableAndUpdatableA 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_pattern
fakecbed.discretized.CBEDPattern| None, optional The discretized fake CBED pattern for which to crop. If
cbed_patternis set toNone, then the parameter will be reassigned to the valuefakecbed.discretized.CBEDPattern().- cropping_window_centerarray_like (float, shape=(2,)) | None, optional
If
cropping_window_centeris set toNone, 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-1pixels to the right of the upper left corner pixel, and(v_dim+1)//2-1pixels below the same corner, whereh_dimandv_dimare the horizontal and vertical dimensions of the discretized fake CBED pattern in units of pixels. Otherwise, ifcropping_window_centeris set to a pair of floating-point numbers, thencropping_window_center[0]andcropping_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 - 1pixels to the right of the upper left corner of the cropping window, and(N_W_v+1)//2 - 1pixels below the same corner, whereN_W_handN_W_vare 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_pixelsis set toNone, then the dimensions of the cropping window are set to the dimensions of discretized fake CBED pattern. Otherwise, ifcropping_window_dims_in_pixelsis set to a pair of positive integers, thencropping_window_dims_in_pixels[0]andcropping_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_patternhas already been reassigned if necessary, and thatprincipal_disk_idx < len(cbed_pattern.core_attrs["undistorted_disks"]), thenprincipal_disk_idxspecifies the CBED disk constructed from the undistorted intensity pattern stored incbed_pattern.core_attrs["undistorted_disks"][prinicpal_disk_idx]. Ifprincipal_disk_idx >= len(cbed_pattern.core_attrs["undistorted_disks"]), thenprincipal_disk_idxspecifies a nonexistent CBED disk. See the summary documentation for the classfakecbed.discretized.CBEDPattern, in particular the description of the construction parameterundistorted_diskstherein, 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 methodfakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords. Must be a positive integer.- mask_framearray_like (int, shape=(4,)), optional
mask_framespecifies the mask frame to be applied after cropping the fake CBED pattern.mask_frame[0],mask_frame[1],mask_frame[2], andmask_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_funcsandcore_attrsdenote the attributesvalidation_and_conversion_funcsandcore_attrsrespectively, both of which being dict objects.Let
params_to_be_mapped_to_core_attrsdenote the dict representation of the constructor parameters excluding the parameterskip_validation_and_conversion, where each dict keykeyis a different constructor parameter name, excluding the name"skip_validation_and_conversion", andparams_to_be_mapped_to_core_attrs[key]would yield the value of the constructor parameter with the name given bykey.If
skip_validation_and_conversionis set toFalse, then for each keykeyinparams_to_be_mapped_to_core_attrs,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (params_to_be_mapped_to_core_attrs).Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set toparams_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 ofparams_to_be_mapped_to_core_attrs, as it is guaranteed that no copies or conversions are made in this case.
- cbed_pattern
- Attributes:
core_attrsdict: The “core attributes”.
de_pre_serialization_funcsdict: The de-pre-serialization functions.
devicetorch.device: The device on which computationally intensive
disk_absence_registrytorch.Tensor: The disk absence registry of the cropped fake CBED
disk_clipping_registrytorch.Tensor: The disk clipping registry of the cropped fake CBED
disk_overlap_maptorch.Tensor: The image of the disk overlap map of the cropped
disk_supportstorch.Tensor: The image stack of the disk supports of the cropped
illumination_supporttorch.Tensor: The illumination support of the cropped fake CBED
imagetorch.Tensor: The image of the cropped fake CBED pattern.
image_has_been_overriddenbool: Equals
Trueif the image of the fake cropped CBEDnum_disksint: The total number of CBED disks defined, \(N_{\text{D}}\).
pre_serialization_funcsdict: The pre-serialization functions.
principal_disk_boundary_pts_in_cropped_image_fractional_coordstorch.Tensor | None: The sample of points on the boundary of the
principal_disk_boundary_pts_in_uncropped_image_fractional_coordstorch.Tensor | None: The sample of points on the boundary of the
principal_disk_bounding_box_in_cropped_image_fractional_coordstuple | None: The bounding box of the unclipped support of the
principal_disk_bounding_box_in_uncropped_image_fractional_coordstuple | None: The bounding box of the unclipped support of the
principal_disk_is_absentbool: Equals
Trueif the “principal” CBED disk either does notprincipal_disk_is_clippedbool: Equals
Trueif the “principal” CBED disk either does notprincipal_disk_is_overlappingbool: Equals
Trueif the “principal” CBED disk exists and issignalhyperspy._signals.signal2d.Signal2D: The hyperspy signal
validation_and_conversion_funcsdict: 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.
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.
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.
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 instance.
update(new_core_attr_subset_candidate[, ...])Update a subset of the core attributes.
execute_post_core_attrs_update_actions
Methods
Construct an instance from a serializable representation.
Serialize instance and save the result in a JSON file.
Serialize instance.
execute_post_core_attrs_update_actionsReturn the core attributes.
Return the de-pre-serialization functions.
Return the disk absence registry of the cropped fake CBED pattern.
Return the disk clipping registry of the cropped fake CBED pattern.
Return the image of the disk overlap map of the cropped fake CBED pattern.
Return the image stack of the disk supports of the cropped fake CBED pattern.
Return the illumination support of the cropped fake CBED pattern.
Return the image of the cropped fake CBED pattern.
Return the pre-serialization functions.
get_principal_disk_boundary_pts_in_cropped_image_fractional_coordsReturn 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_coordsReturn 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_coordsReturn 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_coordsReturn the bounding box of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.
Return the hyperspy signal representation of the cropped fake CBED pattern.
Return the validation and conversion functions.
Construct an instance from a serialized representation that is stored in a JSON file.
Construct an instance from a serialized representation.
Pre-serialize instance.
Update a subset of the core attributes.
Attributes
dict: The "core attributes".
dict: The de-pre-serialization functions.
torch.device: The device on which computationally intensive PyTorch operations are performed and attributes of the type
torch.Tensorare stored.torch.Tensor: The disk absence registry of the cropped fake CBED pattern.
torch.Tensor: The disk clipping registry of the cropped fake CBED pattern.
torch.Tensor: The image of the disk overlap map of the cropped fake CBED pattern.
torch.Tensor: The image stack of the disk supports of the cropped fake CBED pattern.
torch.Tensor: The illumination support of the cropped fake CBED pattern.
torch.Tensor: The image of the cropped fake CBED pattern.
bool: Equals
Trueif the image of the fake cropped CBED pattern has been overridden.int: The total number of CBED disks defined, \(N_{\text{D}}\).
dict: The pre-serialization functions.
principal_disk_boundary_pts_in_cropped_image_fractional_coordstorch.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_coordstorch.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_coordstuple | 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_coordstuple | None: The bounding box of the unclipped support of the "principal" CBED disk, should it exist, in fractional coordinates of the uncropped CBED pattern.
bool: Equals
Trueif the "principal" CBED disk either does not exists, or it exists and is absent from the image of the cropped fake CBED pattern.bool: Equals
Trueif the "principal" CBED disk either does not exists, or it exists and is clipped in image of the cropped fake CBED pattern.bool: Equals
Trueif the "principal" CBED disk exists and is overlapping with another CBED disk in the image of the cropped fake CBED pattern.hyperspy._signals.signal2d.Signal2D: The hyperspy signal representation of the cropped fake CBED pattern.
dict: The validation and conversion functions.
- property core_attrs
dict: The “core attributes”.
The keys of
core_attrsare the same as the attributevalidation_and_conversion_funcs, which is also a dict object.Note that
core_attrsshould be considered read-only.
- property de_pre_serialization_funcs
dict: The de-pre-serialization functions.
de_pre_serialization_funcshas the same keys as the attributevalidation_and_conversion_funcs, which is also a dict object.Let
validation_and_conversion_funcsandpre_serialization_funcsdenote the attributesvalidation_and_conversion_funcspre_serialization_funcsrespectively, the last of which being a dict object as well.Let
core_attrs_candidate_1be any dict object that has the same keys asvalidation_and_conversion_funcs, where for each dict keykeyincore_attrs_candidate_1,validation_and_conversion_funcs[key](core_attrs_candidate_1)does not raise an exception.Let
serializable_repbe a dict object that has the same keys ascore_attrs_candidate_1, where for each dict keykeyincore_attrs_candidate_1,serializable_rep[key]is set topre_serialization_funcs[key](core_attrs_candidate_1[key]).The items of
de_pre_serialization_funcsare expected to be set to callable objects that would lead tode_pre_serialization_funcs[key](serializable_rep[key])not raising an exception for each dict keykeyinserializable_rep.Let
core_attrs_candidate_2be a dict object that has the same keys asserializable_rep, where for each dict keykeyinvalidation_and_conversion_funcs,core_attrs_candidate_2[key]is set tode_pre_serialization_funcs[key](serializable_rep[key]).The items of
de_pre_serialization_funcsare also expected to be set to callable objects that would lead tovalidation_and_conversion_funcs[key](core_attrs_candidate_2)not raising an exception for each dict keykeyincore_attrs_candidate_2.Note that
de_pre_serialization_funcsshould 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_funcsandde_pre_serialization_funcsdenote the attributesvalidation_and_conversion_funcsde_pre_serialization_funcsrespectively, the last of which being a dict object as well.The items of
serializable_repare expected to be objects that would lead tode_pre_serialization_funcs[key](serializable_rep[key])not raising an exception for each dict keykeyinserializable_rep.Let
core_attrs_candidatebe a dict object that has the same keys asserializable_rep, where for each dict keykeyinserializable_rep,core_attrs_candidate[key]is set to de_pre_serialization_funcs[key](serializable_rep[key])``.The items of
serializable_repare also expected to be set to objects that would lead tovalidation_and_conversion_funcs[key](core_attrs_candidate)not raising an exception for each dict keykeyinserializable_rep.- skip_validation_and_conversionbool, optional
Let
core_attrsdenote the attributecore_attrs, which is a dict object.If
skip_validation_and_conversionis set toFalse, then for each keykeyinserializable_rep,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate), withvalidation_and_conversion_funcsandcore_attrs_candidate_1being introduced in the above description ofserializable_rep.Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set tocore_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 ofcore_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.Tensorare stored.Note that
deviceshould 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, andfakecbed.discretized.CroppedCBEDPatternfor additional context.Let
num_disks, anddisk_supportsdenote the attributesfakecbed.discretized.CroppedCBEDPattern.num_disks, andfakecbed.discretized.CroppedCBEDPattern.disk_supportsrespectively. Moreover, letkbe a nonnegative integer less thannum_disks.disk_absence_registryis a one-dimensional PyTorch tensor of length equal tonum_disks. Ifdisk_absence_registry[k]is equal toFalse, then the image stored indisk_supports[k]has at least one nonzero pixel. Otherwise, ifdisk_absence_registry[k]is equal toTrue, then the opposite of the above scenario is true.Note that
disk_absence_registryshould 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, andfakecbed.discretized.CroppedCBEDPatternfor additional context.Let
num_disks,disk_supports,illumination_support, andimagedenote the attributesfakecbed.discretized.CroppedCBEDPattern.num_disks,fakecbed.discretized.CroppedCBEDPattern.disk_supports,fakecbed.discretized.CroppedCBEDPattern.illumination_support, andfakecbed.discretized.CroppedCBEDPattern.imagerespectively. Moreover, letkbe a nonnegative integer less thannum_disks.disk_clipping_registryis a one-dimensional PyTorch tensor of length equal tonum_disks. Ifdisk_clipping_registry[k]is equal toFalse, then the image stored indisk_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 inillumination_support, at least two pixels away from the position of every pixel inside any of the mask frames that appears in the image stored inimage, and at least one pixel away from every pixel bordering the image stored inimage. Otherwise, ifdisk_clipping_registry[k]is equal toTrue, 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_registryshould 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.signalfor additional context.Let
signal,device, andcore_attrsdenote the attributesfakecbed.discretized.CroppedCBEDPattern.signal,fakecbed.discretized.CroppedCBEDPattern.device, andcore_attrsrespectively.disk_overlap_mapis 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_mapshould 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.signalfor additional context.Let
signal,device, andcore_attrsdenote the attributesfakecbed.discretized.CroppedCBEDPattern.signal,fakecbed.discretized.CroppedCBEDPattern.device, andcore_attrsrespectively.disk_supportsis 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_supportsshould 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
overwriteis set toFalseand a file exists at the pathfilename, 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_attrsdenote the attributecore_attrs, which is a dict object.If
deep_copyis set toTrue, then a deep copy ofcore_attrsis returned. Otherwise, a shallow copy ofcore_attrsis 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_registrydenote the attributefakecbed.discretized.CroppedCBEDPattern.disk_absence_registry.If
deep_copyis set toTrue, then a deep copy ofdisk_absence_registryis returned. Otherwise, a reference todisk_absence_registryis 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_registrydenote the attributefakecbed.discretized.CroppedCBEDPattern.disk_clipping_registry.If
deep_copyis set toTrue, then a deep copy ofdisk_clipping_registryis returned. Otherwise, a reference todisk_clipping_registryis 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_mapdenote the attributefakecbed.discretized.CroppedCBEDPattern.disk_overlap_map.If
deep_copyis set toTrue, then a deep copy ofdisk_overlap_mapis returned. Otherwise, a reference todisk_overlap_mapis 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_supportsdenote the attributefakecbed.discretized.CroppedCBEDPattern.disk_supports.If
deep_copyis set toTrue, then a deep copy ofdisk_supportsis returned. Otherwise, a reference todisk_supportsis 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_supportdenote the attributefakecbed.discretized.CroppedCBEDPattern.illumination_support.If
deep_copyis set toTrue, then a deep copy ofillumination_supportis returned. Otherwise, a reference toillumination_supportis 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
imagedenote the attributefakecbed.discretized.CroppedCBEDPattern.image.If
deep_copyis set toTrue, then a deep copy ofimageis returned. Otherwise, a reference toimageis 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_attrsdenote the attributecore_attrs.- Parameters:
- deep_copybool, optional
Let
principal_disk_boundary_pts_in_cropped_image_fractional_coordsdenote the attributefakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords.If
deep_copyis set toTrue, then a deep copy ofprincipal_disk_boundary_pts_in_cropped_image_fractional_coordsis returned. Otherwise, a reference toprincipal_disk_boundary_pts_in_cropped_image_fractional_coordsis 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_attrsdenote the attributecore_attrs.- Parameters:
- deep_copybool, optional
Let
principal_disk_boundary_pts_in_uncropped_image_fractional_coordsdenote the attributefakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords.If
deep_copyis set toTrue, then a deep copy ofprincipal_disk_boundary_pts_in_uncropped_image_fractional_coordsis returned. Otherwise, a reference toprincipal_disk_boundary_pts_in_uncropped_image_fractional_coordsis 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_attrsdenote the attributecore_attrs.- Parameters:
- deep_copybool, optional
Let
principal_disk_bounding_box_in_cropped_image_fractional_coordsdenote the attributefakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_cropped_image_fractional_coords.If
deep_copyis set toTrue, then a deep copy ofprincipal_disk_bounding_box_in_cropped_image_fractional_coordsis returned. Otherwise, a reference toprincipal_disk_bounding_box_in_cropped_image_fractional_coordsis returned.
- Returns:
- principal_disk_bounding_box_in_cropped_image_fractional_coordsarray_like (float, shape=(4,)) | 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_attrsdenote the attributecore_attrs.- Parameters:
- deep_copybool, optional
Let
principal_disk_bounding_box_in_uncropped_image_fractional_coordsdenote the attributefakecbed.discretized.CroppedCBEDPattern.principal_disk_bounding_box_in_uncropped_image_fractional_coords.If
deep_copyis set toTrue, then a deep copy ofprincipal_disk_bounding_box_in_uncropped_image_fractional_coordsis returned. Otherwise, a reference toprincipal_disk_bounding_box_in_uncropped_image_fractional_coordsis returned.
- Returns:
- principal_disk_bounding_box_in_uncropped_image_fractional_coordsarray_like (float, shape=(4,)) | 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
signaldenote the attributefakecbed.discretized.CroppedCBEDPattern.signal.If
deep_copyis set toTrue, then a deep copy ofsignalis returned. Otherwise, a reference tosignalis returned.
- Returns:
- signal
hyperspy._signals.signal2d.Signal2D The attribute
fakecbed.discretized.CroppedCBEDPattern.signal.
- 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.signalfor additional context.Let
signal, anddevicedenote the attributesfakecbed.discretized.CroppedCBEDPattern.signal, andfakecbed.discretized.CroppedCBEDPattern.devicerespectively.illumination_supportis 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_supportshould 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.signalfor additional context.Let
signal,device, andcore_attrsdenote the attributesfakecbed.discretized.CroppedCBEDPattern.signal,fakecbed.discretized.CroppedCBEDPattern.device, andcore_attrsrespectively.imageis 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
imageshould be considered read-only.
- property image_has_been_overridden
bool: Equals
Trueif the image of the fake cropped CBED pattern has been overridden.See the summary documentation for the classes
fakecbed.discretized.CBEDPatternandfakecbed.discretized.CroppedCBEDPatternfor additional context, as well as the documentation for the attributefakecbed.discretized.CBEDPattern.image_has_been_overridden.Let
core_attrsdenote the attributecore_attrs.image_has_been_overriddenis calculated effectively by:cbed_pattern = core_attrs["cbed_pattern"] image_has_been_overridden = cbed_pattern.image_has_been_overridden
Note that
image_has_been_overriddenshould 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.
filenameis expected to be such thatjson.load(open(filename, "r"))does not raise an exception.Let
serializable_rep=json.load(open(filename, "r")).Let
validation_and_conversion_funcsandde_pre_serialization_funcsdenote the attributesvalidation_and_conversion_funcsde_pre_serialization_funcsrespectively, both of which being dict objects as well.filenameis also expected to be such thatde_pre_serialization_funcs[key](serializable_rep[key])does not raise an exception for each dict keykeyinde_pre_serialization_funcs.Let
core_attrs_candidatebe a dict object that has the same keys asde_pre_serialization_funcs, where for each dict keykeyinserializable_rep,core_attrs_candidate[key]is set to de_pre_serialization_funcs[key](serializable_rep[key])``.filenameis also expected to be such thatvalidation_and_conversion_funcs[key](core_attrs_candidate)does not raise an exception for each dict keykeyinserializable_rep.- skip_validation_and_conversionbool, optional
Let
core_attrsdenote the attributecore_attrs, which is a dict object.Let
core_attrs_candidatebe as defined in the above description offilename.If
skip_validation_and_conversionis set toFalse, then for each keykeyincore_attrs_candidate,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate), , withvalidation_and_conversion_funcsandcore_attrs_candidatebeing introduced in the above description offilename.Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set tocore_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 ofcore_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_repis expected to be such thatjson.loads(serialized_rep)does not raise an exception.Let
serializable_rep=json.loads(serialized_rep).Let
validation_and_conversion_funcsandde_pre_serialization_funcsdenote the attributesvalidation_and_conversion_funcsde_pre_serialization_funcsrespectively, both of which being dict objects as well.serialized_repis also expected to be such thatde_pre_serialization_funcs[key](serializable_rep[key])does not raise an exception for each dict keykeyinde_pre_serialization_funcs.Let
core_attrs_candidatebe a dict object that has the same keys asserializable_rep, where for each dict keykeyinde_pre_serialization_funcs,core_attrs_candidate[key]is set to de_pre_serialization_funcs[key](serializable_rep[key])``.serialized_repis also expected to be such thatvalidation_and_conversion_funcs[key](core_attrs_candidate)does not raise an exception for each dict keykeyinserializable_rep.- skip_validation_and_conversionbool, optional
Let
core_attrsdenote the attributecore_attrs, which is a dict object.If
skip_validation_and_conversionis set toFalse, then for each keykeyincore_attrs_candidate,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate), withvalidation_and_conversion_funcsandcore_attrs_candidate_1being introduced in the above description ofserialized_rep.Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set tocore_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 ofcore_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.CBEDPatternfor additional context.Let
core_attrsdenote the attributecore_attrs.num_disksis equal tocore_attrs["cbed_pattern"].num_disks.Note that
num_disksshould be considered read-only.
- property pre_serialization_funcs
dict: The pre-serialization functions.
pre_serialization_funcshas the same keys as the attributevalidation_and_conversion_funcs, which is also a dict object.Let
validation_and_conversion_funcsandcore_attrsdenote the attributesvalidation_and_conversion_funcsandcore_attrsrespectively, the last of which being a dict object as well.For each dict key
keyincore_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 functionjson.dumpswithout raising an exception.Note that
pre_serialization_funcsshould 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_coordsfor additional context.Let
core_attrs,principal_disk_boundary_pts_in_uncropped_image_fractional_coords, andsignal, denote the attributescore_attrsfakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords, andfakecbed.discretized.CroppedCBEDPattern.signalrespectively.principal_disk_boundary_pts_in_cropped_image_fractional_coordsis 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_coordsshould 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.CBEDPatternandfakecbed.discretized.CroppedCBEDPatternfor additional context.Let
core_attrsdenote the attributecore_attrs. Furthermore, letcbed_pattern,disk_boundary_sample_size, andprincipal_disk_idxdenotecore_attrs["cbed_pattern"],core_attrs["disk_boundary_sample_size"], andcore_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. Ifprincipal_disk_idx < len(cbed_pattern.core_attrs["undistorted_disks"]), thenprincipal_disk_idxspecifies the CBED disk constructed from the undistorted intensity pattern stored incbed_pattern.core_attrs["undistorted_disks"][prinicpal_disk_idx]. Ifprincipal_disk_idx >= len(cbed_pattern.core_attrs["undistorted_disks"]), thenprincipal_disk_idxspecifies a nonexistent CBED disk.If
principal_disk_idxspecifies a nonexistent CBED disk, thenprincipal_disk_boundary_pts_in_uncropped_image_fractional_coordsis set toNone.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 infakecbedare given implictly in the documentation for the classfakecbed.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_patternspecifies a distortion model, which can be accessed viacbed_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]andprincipal_disk_boundary_pts_in_uncropped_image_fractional_coords[l, 1]respectively, where``principal_disk_boundary_pts_in_uncropped_image_fractional_coordsis the current attribute, andlis equal to the value of \(l\). The current attribute is calculated effectively by executing the following steps:Calculate
(2.1.2.2)\[X_{1} \leftarrow \left\{ l^{\prime}\right\}_{l^{\prime}=0}^{N_{\text{SS}}-1}.\]Calculate
(2.1.2.3)\[X_{2} \leftarrow \left\{ l^{\prime}\right\}_{l^{\prime}=0}^{N_{\text{SS}}-2}\]Calculate
(2.1.2.4)\[m \leftarrow 0.\]Calculate
(2.1.2.5)\[N_{\text{iter}} \leftarrow 0.\]Calculate
(2.1.2.6)\[\phi_{l}\leftarrow\frac{2\pi l}{N_{\text{SS}}} \text{ for }l\in X_{1}.\]Calculate
(2.1.2.7)\[j\leftarrow\min\left(\left\{ N_{\text{iter}}+1,1\right\} \right).\]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}.\]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}.\]If \(m=0\), then go to step 10, otherwise go to step 21.
Calculate
(2.1.2.12)\[n\leftarrow\text{argmax}_{l\in X_{1}}\left(u_{x;l}\right).\]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.
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}}}.\]Go to step 16.
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)}.\]If \(\phi_{\vdash}>\phi_{\dashv}\), then calculate
(2.1.2.18)\[\phi_{\dashv}\leftarrow\phi_{\dashv}+2\pi.\]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.\]Calculate
(2.1.2.23)\[N_{\text{iter}}\leftarrow N_{\text{iter}}+1.\]Go to step 6.
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_coordsshould 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_coordsfor additional context.Let
principal_disk_boundary_pts_in_cropped_image_fractional_coordsdenote the attributefakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_cropped_image_fractional_coords.principal_disk_bounding_box_in_cropped_image_fractional_coordsis 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_coordsshould 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_coordsfor additional context.Let
principal_disk_boundary_pts_in_uncropped_image_fractional_coordsdenote the attributefakecbed.discretized.CroppedCBEDPattern.principal_disk_boundary_pts_in_uncropped_image_fractional_coords.principal_disk_bounding_box_in_uncropped_image_fractional_coordsis 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_coordsshould be considered read-only.
- property principal_disk_is_absent
bool: Equals
Trueif 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.CroppedCBEDPatternfor additional context, as well as the documentation for the attributefakecbed.discretized.CroppedCBEDPattern.disk_absence_registry.Let
core_attrs,num_disks, anddisk_absence_registrydenote the attributescore_attrs,fakecbed.discretized.CroppedCBEDPattern.num_disks, andfakecbed.discretized.CroppedCBEDPattern.disk_absence_registryrespectively.principal_disk_is_absentis 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_absentshould be considered read-only.
- property principal_disk_is_clipped
bool: Equals
Trueif 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.CroppedCBEDPatternfor additional context, as well as the documentation for the attributefakecbed.discretized.CroppedCBEDPattern.disk_clipping_registry.Let
core_attrs,num_disks, anddisk_clipping_registrydenote the attributescore_attrs,fakecbed.discretized.CroppedCBEDPattern.num_disks, andfakecbed.discretized.CroppedCBEDPattern.disk_clipping_registryrespectively.principal_disk_is_clippedis 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_clippedshould be considered read-only.
- property principal_disk_is_overlapping
bool: Equals
Trueif 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.CroppedCBEDPatternfor additional context, as well as the documentation for the attributefakecbed.discretized.CroppedCBEDPattern.disk_overlap_map.Let
core_attrs,num_disks,disk_supports, anddisk_overlap_mapdenote the attributescore_attrs,fakecbed.discretized.CroppedCBEDPattern.num_disks,fakecbed.discretized.CroppedCBEDPattern.disk_supports, andfakecbed.discretized.CroppedCBEDPattern.disk_overlap_maprespectively.principal_disk_is_overlappingis 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_overlappingshould 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.CBEDPatternandfakecbed.discretized.CroppedCBEDPatternfor 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, andcore_attrsdenote the attributesfakecbed.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, andcore_attrsrespectively. Furthermore, letpre_serializedenote the methodpre_serialize().signalis 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
signalshould 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_funcsandcore_attrsdenote the attributesvalidation_and_conversion_funcsandcore_attrsrespectively, both of which being dict objects.If
skip_validation_and_conversionis set toFalse, then for each keykeyincore_attrsthat is also innew_core_attr_subset_candidate,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (new_core_attr_subset_candidate).Otherwise, if
skip_validation_and_conversionis set toTrue, then for each keykeyincore_attrsthat is also innew_core_attr_subset_candidate,core_attrs[key]is set tonew_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 ofnew_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_funcsare the names of the constructor parameters, excludingskip_validation_and_conversionif it exists as a construction parameter.Let
core_attrsdenote the attributecore_attrs, which is also a dict object.For each dict key
keyincore_attrs,validation_and_conversion_funcs[key](core_attrs)is expected to not raise an exception.Note that
validation_and_conversion_funcsshould be considered read-only.