# Measurement¶

Module to describe the detection of scattered electron waves.

class abtem.measure.Calibration(offset, sampling, units, name='', endpoint=True, adjustable=True)[source]

Calibration object

The calibration object represents the sampling of a uniformly sampled Measurement.

Parameters
• offset (float) – The lower bound of the sampling points.

• sampling (float) – The distance between sampling points.

• units (str) – The units of the calibration shown in plots.

• name (str) – The name of this calibration to be shown in plots.

copy()[source]

Make a copy.

class abtem.measure.Measurement(array, calibrations=None, units='', name='')[source]

Measurement object.

The measurement object is used for representing the output of a TEM simulation. For example a line profile, an image or a collection of diffraction patterns.

Parameters
• array (ndarray) – The array representing the measurements. The array can be any dimension.

• calibrations (list of Calibration objects) – The calibration for each dimension of the measurement array.

• units (str) – The units of the array values to be displayed in plots.

• name (str) – The name of the array values to be displayed in plots.

property array

Array of measurements.

Return type

ndarray

property calibrations

The measurement calibrations.

Return type

List[Optional[Calibration]]

copy()[source]

Make a copy.

Return type

Measurement

diffractograms(axes=None)[source]

Calculate the diffractograms of this measurement.

Parameters

axes (list of int) – The axes to Fourier transform.

Returns

Return type

Measurement

property dimensions

The measurement dimensions.

Return type

int

gaussian_filter(sigma, padding_mode='wrap')[source]

Apply gaussian filter to measurement.

Parameters
• sigma (float or sequence of float) – Standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes.

• padding_mode (str) – The padding_mode parameter determines how the input array is padded at the border. Different modes can be specified along each axis. Default value is ‘wrap’.

Returns

Blurred measurement.

Return type

Measurement

integrate(start, end, axis=- 1, interactive=False)[source]

Perform 1d integration measurement from e.g. the FlexibleAnnularDetector

Parameters
• start (float) – Lower limit of integral in units of the calibration of the given axis.

• end (float) – Upper limit of integral in units of the calibration of the given axis.

• axis (int) – The

Returns

Integrated measurement.

Return type

Measurement

interpolate(new_sampling=None, new_gpts=None, padding='wrap', kind=None, axes=None)[source]

Interpolate a 2d measurement.

Parameters
• new_sampling (one or two float, optional) – Target measurement sampling. Same units as measurement calibrations.

• new_gpts (one or two int, optional) – Target measurement gpts.

• kind (str, optional) – The kind of spline interpolation to use. Default is ‘quintic’.

Returns

Interpolated measurement

Return type

Measurement object

interpolate_line(start, end=None, angle=0.0, gpts=None, sampling=None, width=None, margin=0.0, interpolation_method='splinef2d')[source]

Interpolate 2d measurement along a line.

Parameters
• start (two float, Atom) – Start point on line [Å].

• end (two float, Atom, optional) – End point on line [Å].

• angle (float, optional) – The angle of the line. This is only used when an “end” is not give.

• gpts (int) – Number of grid points along line.

• sampling (float) – Sampling rate of grid points along line [1 / Å].

• width (float, optional) – The interpolation will be averaged across line of this width.

• margin (float, optional) – The line will be extended by this amount at both ends.

• interpolation_method (str, optional) – The interpolation method.

Returns

Line profile measurement.

Return type

Measurement

mean(axis)[source]

Mean of measurement elements over a given axis.

Parameters

axis (int or tuple of ints) – Axis or axes along which a sum is performed. If axis is negative it counts from the last to the first axis.

Returns

A measurement with the same shape, but with the specified axis removed.

Return type

Measurement object

property name

The name of the array values to be displayed in plots.

Return type

str

classmethod read(path)[source]

Read measurement from a hdf5 file.

path: str

The path to read the file.

Return type

Measurement

save_as_image(path)[source]

Write the measurement array to an image file. The array will be normalized and converted to 16-bit integers.

path: str

The path to write the file.

property shape

The shape of the measurement array.

Return type

Tuple[int]

show(ax=None, interact=False, **kwargs)[source]

Show the measurement.

Parameters

kwargs – Additional keyword arguments for the abtem.plot.show_image function.

squeeze()[source]

Remove dimensions of length one from measurement.

Returns

Return type

Measurement

sum(axis)[source]

Sum of measurement elements over a given axis.

Parameters

axis (int or tuple of ints) – Axis or axes along which a sum is performed. If axis is negative it counts from the last to the first axis.

Returns

A measurement with the same shape, but with the specified axis removed.

Return type

Measurement

tile(multiples)[source]

Construct a measurement by repeating the measurement number of times given by multiples.

Parameters

multiples (sequence of int) – The number of repetitions of the measurement along each axis.

Returns

The tiled potential.

Return type

Measurement object

property units

The units of the array values to be displayed in plots.

Return type

str

write(path, mode='w')[source]

Write measurement to a hdf5 file.

path: str

The path to write the file.

abtem.measure.bandlimit(measurement, cutoff, taper=0.1, band_type='lowpass')[source]

Bandlimit a collection of diffraction patterns.

Parameters
• measurement (Measurement) – Collection of diffraction patterns.

• taper (float) – Taper the bandlimiting window to avoid a sharp cutoff.

Returns

Bandlimited measurement.

Return type

Measurement

abtem.measure.block_zeroth_order_spot(diffraction_pattern, angular_radius=1)[source]

Set the zero’th order spot of a diffraction pattern to zero.

Parameters
• diffraction_pattern (Measurement) – Measurement representing one or more diffraction patterns.

• angular_radius (float) – The radius of the disk-shaped region set to zero.

Returns

Return type

Measurement

abtem.measure.calculate_fwhm(probe_profile)[source]

Calculate the full width at half maximum of a 1d measurement, typically a probe profile.

Parameters

probe_profile (Measurement) – Probe profile measurement.

Returns

Return type

float

abtem.measure.calibrations_from_grid(gpts, sampling, names=None, units=None, fourier_space=False, scale_factor=1.0)[source]

Returns the spatial calibrations for a given computational grid and sampling.

Parameters
• gpts (list of int) – Number of grid points in the x and y directions.

• sampling (list of float) – Sampling of the potential in Å.

• names (list of str, optional) – The name of this calibration.

• units (str, optional) – Units for the calibration.

• fourier_space (bool, optional) – Setting for calibrating either in the reciprocal or real space. Default is False.

• scale_factor (float, optional) – Scaling factor for the calibration. Default is 1.0.

Returns

calibrations

Return type

Tuple of Calibrations

abtem.measure.center_of_mass(measurement, return_magnitude=False, return_icom=False)[source]

Calculate the center of mass of a measurement.

Parameters
• measurement (Measurement) – A collection of diffraction patterns.

• return_icom (bool) – If true, return the integrated center of mass.

Returns

Return type

Measurement

abtem.measure.fourier_space_offset(n, d)[source]

Calculate the calibration offset of a Fourier space measurement.

Parameters
• n (int) – Number of sampling points.

• d (float) – Real space sampling density.

abtem.measure.integrate_disc(image, position, radius, return_mean=True, border='wrap', interpolate=0.01)[source]

Integrate the values of a 2d measurement on a disc-shaped region.

Parameters
• position (two floats) – Center of disc-shaped integration region

• measurement (2d measurement) – The measurement to integrate

• return_mean (bool) – If true return the mean, otherwise return the sum.

• border (str) –

Specify how to treat integration regions that cross the image border. The valid values and their behaviour is: ‘wrap’

The measurement is extended by wrapping around to the opposite edge.

’raise’

Raise an error if the integration region crosses the measurement border.

• interpolate (float or False) – The image will be interpolated to this sampling. Units of Angstrom.

Returns

Integral value

Return type

float

abtem.measure.intgrad2d(gradient, sampling=None)[source]

Parameters
• gradient (two np.ndarrays) – The x- and y-components of the gradient.

• sampling (two float) – Lateral sampling of the gradients. Default is 1.0.

Returns

Integrated center of mass measurement

Return type

np.ndarray

abtem.measure.probe_profile(probe_measurement, angle=0.0)[source]

Return the profile of a probe given a 2d measurement of that probe.

Parameters
• probe_measurement (Measurement) – 2d measurement of the centered intensity of an electron probe.

• angle (float) – The angle at which to interpolate the profile.

Returns

1d measurement of the probe profile.

Return type

Measurement

abtem.measure.rotational_average(measurement)[source]

Calculate the rotational average of a measurement.

Parameters

measurement (Measurement) – 2d measurement of calculate the rotational average from.

Returns

1d rotational average of a 2d measurement.

Return type

Measurement