2.1.1.1.1.6. emicroml.modelling.cbed.distortion.estimation.ml_data_dict_to_signals
- ml_data_dict_to_signals(ml_data_dict, sampling_grid_dims_in_pixels=(512, 512), device_name=None, least_squares_alg_params=None)[source]
Convert a dictionary representation of ML data instances to a sequence of Hyperspy signals.
See the documentation for the classes
fakecbed.discretized.CBEDPattern
,distoptica.DistortionModel
, andhyperspy._signals.signal2d.Signal2D
for discussions on “fake” CBED patterns, distortion models, and Hyperspy signals respectively.The current function converts a dictionary representation
ml_data_dict
of complete or incomplete machine learning (ML) data instances to a sequence of Hyperspy signals. If incomplete, the ML data instances can, at the very least be used to evaluate ML models represented by the classemicroml.modelling.cbed.distortion.estimation.MLModel
, and if complete, the ML data instances can be used to train such ML models as well.Each dict key in
ml_data_dict
is the name of a feature of the ML data instances. The only required dict key is"cbed_pattern_images"
. If additional valid dict items are present inml_data_dict
, then more data and metadata can be stored potentially in the Hyperspy representations of the ML data instances. A complete dictionary representation is identical in structure to a dictionary returned by the methodemicroml.modelling.cbed.distortion.estimation.MLDataset.get_ml_data_instances()
of the classemicroml.modelling.cbed.distortion.estimation.MLDataset
. See the documentation for said method for more details. An incomplete dictionary representation is identical in structure to a complete dictionary representation, except that at least one dict item is missing.For each ML data instance, an instance
distortion_model
of the classdistoptica.DistortionModel
is constructed according to the ML data instance’s features. The objectdistortion_model
is a distortion model that describes the distortion field of the imaged CBED pattern of the ML data instance. If no distortion information is present inml_data_dict
, thendistortion_model.is_trivial
yieldsTrue
, i.e. the distortion model is assumed to be trivial. After constructingdistortion_model
, an instance of the classfakecbed.discretized.CBEDPattern
is constructed according to the ML data instance’s features anddistortion_model
.fake_cbed_pattern
is a fake CBED pattern representation of the CBED pattern of the ML data instance. Next, a Hyperspy signalfake_cbed_pattern_signal
is obtained fromfake_cbed_pattern.signal
. The Hyperspy signal representation of the ML data instance is obtained by modifying in placefake_cbed_pattern_signal.data[1:3]
according to the ML data instance’s features. Note that the illumination support of the fake CBED pattern representation of the CBED pattern of the ML data instance is inferred from the features of the ML data instance, and is stored infake_cbed_pattern_signal.data[1]
. Moreover, the illumination suport implied by the signal’s metadata should be ignored.- Parameters:
- ml_data_dictdict
The dictionary representation of the ML data instances to be converted. The current function assumes that all normalizable features of the ML data instances are unnormalized. If the normalizable features of the ML data instances are not normalized, they can be unnormalized using the function
emicroml.modelling.cbed.distortion.estimation.unnormalize_normalizable_elems_in_ml_data_dict()
prior to using the current function.- sampling_grid_dims_in_pixelsarray_like (int, shape=(2,)), optional
The dimensions of the sampling grid, in units of pixels, used for all distortion models.
- least_squares_alg_params
distoptica.LeastSquaresAlgParams
| None, optional least_squares_alg_params
specifies the parameters of the least-squares algorithm to be used to calculate the mappings of fractional Cartesian coordinates of distorted images to those of the corresponding undistorted images.least_squares_alg_params
is used to calculate the interim distortion models mentioned above in the summary documentation. Ifleast_squares_alg_params
is set toNone
, then the parameter will be reassigned to the valuedistoptica.LeastSquaresAlgParams()
. See the documentation for the classdistoptica.LeastSquaresAlgParams
for details on the parameters of the least-squares algorithm.- device_namestr | None, optional
This parameter specifies the device to be used to perform computationally intensive calls to PyTorch functions and to store intermediate arrays of the type
torch.Tensor
. Ifdevice_name
is a string, then it is the name of the device to be used, e.g.”cuda”
or”cpu”
. Ifdevice_name
is set toNone
and a GPU device is available, then a GPU device is to be used. Otherwise, the CPU is used.
- Returns:
- signalsarray_like (
hyperspy._signals.signal2d.Signal2D
, ndim=1) The ML data instances, represented as a sequence of Hyperspy signals, where each Hyperspy signal represents a ML data instance.
- signalsarray_like (