2.4.1.2. prismatique.hrtem.image.Params

class Params(postprocessing_seq=(), avg_num_electrons_per_postprocessed_image=1, apply_shot_noise=False, save_wavefunctions=False, save_final_intensity=False, skip_validation_and_conversion=False)[source]

Bases: PreSerializableAndUpdatable

The simulation parameters related to HRTEM image wavefunctions and intensities.

As discussed in the documentation for the class prismatique.thermal.Params, the intensity image for a given probe collected by the TEM detector measures the diagonal elements of the state operator \(\hat{\rho}_{t}\) of a transmitted beam electron, in the electron’s transverse position basis. See Eq. (2.9.1.2) for a mathematical expression of the above. We model \(\hat{\rho}_{t}\) by Eq. (2.9.1.3), wherein \(\hat{\rho}_{t}\) is expressed as mixed state. Specifically, it is expressed as an incoherent average of pure (i.e. coherent) states \(\left|\psi_{t}\left(\delta_{f};\mathbf{u}_{1},\ldots,\mathbf{u}_{N}; \boldsymbol{\delta}_{\beta}\right)\right\rangle\) over a range of defocii, beam tils, and a set of frozen phonon configurations. See the documentation for the class prismatique.thermal.Params for further discussion on \(\hat{\rho}_{t}\). To approximate the average, prismatic calculates the \(\left|\psi_{t}\left(\delta_{f};\mathbf{u}_{1},\ldots,\mathbf{u}_{N}; \boldsymbol{\delta}_{\beta}\right)\right\rangle\) for a discrete set of defocii, beam tilts, and randomly sampled frozen phonon configurations.

Prior to any postprocessing, the pixel size of any HRTEM image wavefunction or image intensity is given by:

(2.4.1.2.1)\[\Delta \tilde{x}=2 \Delta x,\quad\Delta \tilde{y}=2 \Delta y,\]

where \(\Delta x\) and \(\Delta y\) are the potential slice or sample supercell pixel sizes along the \(x\)- and \(y\)-directions respectively [see the documentation for the class prismatique.discretization.Params for a discussion on potential slices and sample supercells]. The \(x\)- and \(y\)-dimensions of any HRTEM image wavefunction or image intensity in units of pixels is given by respectively:

(2.4.1.2.2)\[n_x=\frac{N_x}{2},\quad n_y=\frac{N_y}{2},\]

where \(N_x\) and \(N_y\) are the \(x\)- and \(y\)-dimensions of the sample’s supercell in units of sample supercell pixels respectively. The factors of 2 in Eqs. (2.4.1.2.1) and (2.4.1.2.2) are the result of an anti-aliasing operation performed in prismatic.

Parameters:
postprocessing_seqarray_like (empix.OptionalCroppingParams | empix.OptionalDownsamplingParams | empix.OptionalResamplingParams, ndim=1), optional

Each item in postprocessing_seq specifies a postprocessing step to be applied to the HRTEM intensity image. Each item must be an instance of one of the following classes: empix.OptionalCroppingParams; empix.OptionalDownsamplingParams; or empix.OptionalResamplingParams. If for example the \(i^{\text{th}}\) item is an instance of the class empix.OptionalCroppingParams, then said item specifies that at the \(i^{\text{th}}\) postprocessing step, the output from the previous step is converted to a hyperspy signal, and passed as the first parameter to the function empix.crop(), with the item being passed as the second parameter, i.e. the optional parameters to the function. If the item is an instance of the class empix.OptionalDownsamplingParams, then the function used is empix.downsample(). If the item is an instance of the class empix.OptionalResamplingParams, then the function used is empix.resample(). Of course, for postprocessing_seq[0], the unprocessed HRTEM intensity image generated by the simulation is used as the first parameter to the implied postprocessing function, after being converted to a hyperspy signal. The convention used in prismatique is that, when converted to a hyperspy signal, the HRTEM intensity image or image wavefunction is visualized with the \(x\)-axis being the horizontal axis, increasing from left to right, and the \(y\)-axis being the vertical axis, increasing from bottom to top, both expressed in units of \(Å\).

Blank [i.e. zeroed] unprocessed HRTEM intensity images can be generated as hyperspy signals using the function prismatique.hrtem.image.blank_unprocessed_image_signal(). This function may help users determine what postprocessing sequence they require to obtain postprocessed HRTEM intensity images with the desired pixel sizes, number of pixels, etc.

Note that the parameter postprocessing_seq[idx].core_attrs["title"] is effectively ignored for all integers idx satisfying 0<=idx<len(postprocessing_seq). Moreover, if postprocessing_seq[idx] is an instance of the class empix.OptionalDownsamplingParams, then said object must satisfy postprocessing_seq[idx].core_attrs["downsample_mode"]=="mean, otherwise an exception will be raised.

avg_num_electrons_per_postprocessed_imagefloat, optional

The average number of electrons per postprocessed HRTEM intensity image.

apply_shot_noisebool, optional

If apply_shot_noise is set to True and save is set to "intensity", then simulated shot noise is applied to each HRTEM intensity image as a final postprocessing step, i.e. after all the postprocessing steps, specified by postprocessing_seq, have been applied. Otherwise, no simulated shot noise is applied.

Shot noise is simulated as follows: for each pixel in each HRTEM intensity image, the numerical value stored therein is used as the variance of a Poisson distribution, from which to sample a new value of said pixel.

save_wavefunctionsbool, optional

If save_wavefunctions is set to True, then the unprocessed \(\left|\psi_{t}\left(\delta_{f};\mathbf{u}_{1}, \ldots,\mathbf{u}_{N}; \boldsymbol{\delta}_{\beta}\right)\right\rangle\), represented in the electron’s transverse position basis, are saved, where the wavefunction data corresponding to the i th frozen phonon configuration subset is saved to a file with the basename "hrtem_sim_wavefunction_output_of_subset_"+str(i)+".h5". Otherwise, no wavefunction data is saved.

save_final_intensitybool, optional

If save_final_intensity is set to True, then the postprocessed HRTEM intensity image, obtained by performing the incoherent average described further above, is saved to a file with basename "hrtem_sim_intensity_output.h5". Otherwise, it is not saved.

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.

pre_serialization_funcs

dict: The pre-serialization functions.

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_pre_serialization_funcs()

Return the pre-serialization functions.

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.

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.

get_core_attrs

Return the core attributes.

get_de_pre_serialization_funcs

Return the de-pre-serialization functions.

get_pre_serialization_funcs

Return the pre-serialization functions.

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.

pre_serialization_funcs

dict: The pre-serialization functions.

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.

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.

classmethod get_pre_serialization_funcs()[source]

Return the pre-serialization functions.

Returns:
pre_serialization_funcsdict

The attribute pre_serialization_funcs.

classmethod get_validation_and_conversion_funcs()[source]

Return the validation and conversion functions.

Returns:
validation_and_conversion_funcsdict

The attribute validation_and_conversion_funcs.

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 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.

update(new_core_attr_subset_candidate={}, skip_validation_and_conversion=False)

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.