abtem.detectors#
Module for describing the detection of transmitted waves and different detector types.
Module Contents#
Classes#
The annular detector integrates the intensity of the detected wave functions between an inner and outer radial integration limits, i.e. over an annulus. |
|
Base detector class. |
|
The flexible annular detector allows choosing the integration limits after running the simulation by binning the intensity in annular integration regions. |
|
The pixelated detector records the intensity of the Fourier-transformed exit wave function, i.e. the diffraction patterns. This may be used for example for simulating 4D-STEM. |
|
The segmented detector covers an annular angular range, and is partitioned into several integration regions divided to radial and angular segments. This can be used for simulating differential phase contrast (DPC) imaging. |
|
Sweeps an offset circular acceptance region over q to build S(q, E). |
|
A rectangular slit detector in reciprocal (diffraction) space. |
|
Detect the complex wave functions. |
Functions#
Validate that a variable is a list of detectors. |
API#
- class abtem.detectors.AnnularDetector(...)[source]#
Bases:
abtem.detectors._AbstractRadialDetectorThe annular detector integrates the intensity of the detected wave functions between an inner and outer radial integration limits, i.e. over an annulus.
- Parameters:
inner (float) – Inner integration limit [mrad].
outer (float) – Outer integration limit [mrad].
offset (two float, optional) – Center offset of the annular integration region [mrad].
to_cpu (bool, optional) – If True, copy the measurement data from the calculation device to CPU memory after applying the detector, otherwise the data stays on the respective devices. Default is True.
url (str, optional) – If this parameter is set the measurement data is saved at the specified location, typically a path to a local file. A URL can also include a protocol specifier like s3:// for remote data. If not set (default) the data stays in memory.
Initialization
- detect(...) Images | RealSpaceLineProfiles | MeasurementsEnsemble[source]#
Detect the given waves producing images.
- Parameters:
waves (Waves) – The waves to detect.
- Returns:
measurement
- Return type:
- get_detector_region(...)[source]#
Get the annular detector region as a diffraction pattern.
- Parameters:
waves (BaseWaves or DiffractionPatterns) – The waves or diffraction patterns used to derive grid calibration.
fftshift (bool, optional) – If True, the zero-frequency of the detector region is shifted to the centre of the array, otherwise the centre is at (0, 0).
- Returns:
detector_region
- Return type:
- property nbins_azimuthal#
- property nbins_radial#
- class abtem.detectors.BaseDetector(...)[source]#
Bases:
abtem.transform.ArrayObjectTransform[abtem.waves.Waves,abtem.measurements.BaseMeasurements | abtem.waves.Waves]Base detector class.
- Parameters:
to_cpu (bool, optional) – If True, copy the measurement data from the calculation device to CPU memory after applying the detector, otherwise the data stays on the respective devices. Default is True.
url (str, optional) – If this parameter is set the measurement data is saved at the specified location, typically a path to a local file. A URL can also include a protocol specifier like s3:// for remote data. If not set (default) the data stays in memory.
Initialization
- apply(...) BaseMeasurements | Waves[source]#
- detect(...) BaseMeasurements | Waves[source]#
Detect the given waves producing a measurement.
- Parameters:
waves (Waves) – The waves to detect.
- Returns:
measurement
- Return type:
- class abtem.detectors.FlexibleAnnularDetector(...)[source]#
Bases:
abtem.detectors._AbstractRadialDetectorThe flexible annular detector allows choosing the integration limits after running the simulation by binning the intensity in annular integration regions.
- Parameters:
step_size (float, optional) – Radial extent of the bins [mrad] (default is 1).
inner (float, optional) – Inner integration limit of the bins [mrad].
outer (float, optional) – Outer integration limit of the bins [mrad].
to_cpu (bool, optional) – If True, copy the measurement data from the calculation device to CPU memory after applying the detector, otherwise the data stays on the respective devices. Default is True.
url (str, optional) – If this parameter is set the measurement data is saved at the specified location, typically a path to a local file. A URL can also include a protocol specifier like s3:// for remote data. If not set (default) the data stays in memory.
Initialization
- detect(...) PolarMeasurements[source]#
- property nbins_azimuthal#
- property nbins_radial#
- class abtem.detectors.PixelatedDetector(...)[source]#
Bases:
abtem.detectors.BaseDetectorThe pixelated detector records the intensity of the Fourier-transformed exit wave function, i.e. the diffraction patterns. This may be used for example for simulating 4D-STEM.
- Parameters:
max_angle (float or {'cutoff', 'valid', 'full'}) –
The diffraction patterns will be detected up to this angle [mrad]. If str, it must be one of:
cutoffThe maximum scattering angle will be the cutoff of the antialiasing aperture.
validThe maximum scattering angle will be the largest rectangle that fits inside the circular antialiasing aperture (default).
fullDiffraction patterns will not be cropped and will include angles outside the antialiasing aperture.
resample (str or False) – If ‘uniform’, the diffraction patterns from rectangular cells will be downsampled to a uniform angular sampling.
reciprocal_space (bool, optional) – If True (default), the diffraction pattern intensities are detected, otherwise the probe intensities are detected as images.
to_cpu (bool, optional) – If True, copy the measurement data from the calculation device to CPU memory after applying the detector, otherwise the data stays on the respective devices. Default is True.
url (str, optional) – If this parameter is set the measurement data is saved at the specified location, typically a path to a local file. A URL can also include a protocol specifier like s3:// for remote data. If not set (default) the data stays in memory.
Initialization
- detect(...) DiffractionPatterns | Images[source]#
Detect the given waves producing diffraction patterns.
- Parameters:
waves (Waves) – The waves to detect.
- Returns:
measurement
- Return type:
- class abtem.detectors.SegmentedDetector(...)[source]#
Bases:
abtem.detectors._AbstractRadialDetectorThe segmented detector covers an annular angular range, and is partitioned into several integration regions divided to radial and angular segments. This can be used for simulating differential phase contrast (DPC) imaging.
- Parameters:
nbins_radial (int) – Number of radial bins.
nbins_azimuthal (int) – Number of angular bins.
inner (float) – Inner integration limit of the bins [mrad].
outer (float) – Outer integration limit of the bins [mrad].
rotation (float) – Rotation of the bins around the origin [mrad].
offset (two float) – Offset of the bins from the origin in x and y [mrad].
to_cpu (bool, optional) – If True, copy the measurement data from the calculation device to CPU memory after applying the detector, otherwise the data stays on the respective devices. Default is True.
url (str, optional) – If this parameter is set the measurement data is saved at the specified location,typically a path to a local file. A URL can also include a protocol specifier like s3:// for remote data. If not set (default) the data stays in memory.
Initialization
- property azimuthal_sampling#
- property radial_sampling#
- property rotation#
- class abtem.detectors.SpectralAnnularDetector(...)[source]#
Bases:
abtem.detectors.AnnularDetectorSweeps an offset circular acceptance region over q to build S(q, E).
The acceptance disk (radius
outer, inner always 0) is centred at(q·cos(angle), q·sin(angle))for each q in[q_min, q_max). Pass toabtem.momentum_resolved_spectrum()together with energy-resolved diffraction patterns to obtain aMomentumResolvedSpectrum.- Parameters:
outer (float) – Acceptance radius [mrad] of the integration disk at each q-point. The full disk diameter is
2 * outer. The q-axis in the resultingMomentumResolvedSpectrumruns fromq_mintoq_maxin approximatelyouter-sized steps. For equivalent perpendicular acceptance as aSpectralSlitDetectorwithwidth=w, useouter = w / 2.q_min (float, optional) – Start of the q sweep [mrad]. Default is 0.
q_max (float, optional) – End of the q sweep [mrad]. If None (default), the diffraction-pattern cutoff angle is used at call time. To cover the same q-range as a
SpectralSlitDetectorwithq_max=Q, use the sameq_max=Q.angle (float, optional) – Direction of the q sweep [degrees, CCW from kx]. Default is 0.
q_sampling (float, optional) – Step between q-points [mrad]. If None (default) the step equals
outer(one disk-radius per step). Setting a larger value produces fewer q-points and a faster spectrum.to_cpu (bool, optional)
url (str, optional)
Notes
Comparing annular and slit detectors
SpectralAnnularDetector
SpectralSlitDetector
outer— disk radiuswidth/2— half-widthq_max— max qq_max— max qFor equivalent perpendicular acceptance and the same q-range:
SpectralAnnularDetector(outer=r, q_max=Q) SpectralSlitDetector(q_max=Q, width=2*r)
Initialization
- show(...)[source]#
Show all acceptance-disk positions along the q-sweep.
Each disk (radius
outer) is drawn at the q-position it would be centred on when computing a spectrum, so the full sweep fromq_mintoq_maxis visible at once.- Parameters:
waves (BaseWaves or DiffractionPatterns) – Provides grid calibration and, when show_pattern is True, the diffraction data. Must be a
DiffractionPatternswhen show_pattern is True.show_pattern (bool, optional) – Overlay the disks on the summed diffraction pattern shown as a grayscale background.
power (float, optional) – Exponent applied to the pattern before display (default 0.5 → square-root stretch). Ignored when show_pattern is False.
ax (matplotlib Axes, optional)
figsize (tuple, optional)
- class abtem.detectors.SpectralSlitDetector(...)[source]#
Bases:
abtem.detectors.BaseDetectorA rectangular slit detector in reciprocal (diffraction) space.
The slit can be defined in two ways:
Geometry mode — specify size, q-range and orientation:
- Parameters:
width (float) – Full width of the slit perpendicular to its long axis [mrad]. This is the full integration aperture, not the half-width. For equivalent integration coverage perpendicular to the q-scan direction as a
SpectralAnnularDetectorwith acceptance radiusouter=r, usewidth = 2 * r(the disk diameter, not the radius).q_min (float, optional) – Start of the q-axis [mrad]. Default is 0, which includes q=0 (the direct beam direction) as the first point of the spectrum. Set to a positive value to exclude the low-q / direct-beam region, e.g.
q_min=10to start at 10 mrad. Directly comparable to theq_minparameter ofSpectralAnnularDetector.q_max (float) – Maximum scattering vector along the slit’s long axis [mrad]. Directly comparable to the
q_maxparameter ofSpectralAnnularDetector.angle (float, optional) – Rotation of the long axis of the slit [degrees, CCW from kx axis]. Default is 0.
offset (two floats, optional) – Origin of the q-axis sweep
(kx, ky)[mrad]. The q-axis starts here (atq_min) and extends in the direction given byangle. Default is(0, 0), i.e. the sweep starts from the diffraction pattern centre.q_sampling (float, optional) – Desired q-axis bin size [mrad]. If None (default) the native pixel sampling of the diffraction pattern is used. Setting a larger value bins adjacent line samples together, producing fewer q-points and a faster spectrum.
directly (**Corner mode** — specify the four sides)
corners ((kx_min, kx_max, ky_min, ky_max)) – Axis-aligned bounds of the rectangle [mrad], with signs measured from the diffraction-pattern origin. Incompatible with offset, angle, q_min, q_max and width. The q-axis origin is taken as
(kx_min, (ky_min+ky_max)/2), soq=0maps to the left edge of the rectangle.parameters (Common)
-----------------
to_cpu (bool, optional) – Copy result to CPU after detection. Default is True.
url (str, optional) – Save path for the measurement.
Notes
Comparing slit and annular detectors
Both detector types share the same
q_min/q_maxconvention — the same numerical value gives the same scattering-vector range in the output spectrum. The perpendicular acceptance differs: the slit integrates a rectangle of full widthwidth, while the annular detector integrates a disk of radiusouter.SpectralSlitDetector
SpectralAnnularDetector
width— full slit widthouter— acceptance radiusq_min— start q (≥ 0)q_min— start q (≥ 0)q_max— max qq_max— max qangle— sweep directionangle— sweep directionFor equivalent perpendicular acceptance and the same q-range:
SpectralSlitDetector(width=2*r, q_min=Q0, q_max=Q) SpectralAnnularDetector(outer=r, q_min=Q0, q_max=Q)
Note that
width = 2 * outer: the slitwidthis the full aperture diameter, whereasouteris the acceptance radius.Initialization
- angular_limits(...) tuple[float, float][source]#
Radial bounds [mrad] of the acceptance region, for grid-sufficiency checks. The slit has no rotationally-symmetric inner exclusion, so the inner bound is 0; the outer bound is the farthest distance from the origin reached by the bounding rectangle’s corners.
- property corners: tuple[float, float, float, float]#
Axis-aligned bounding rectangle (kx_min, kx_max, ky_min, ky_max) [mrad].
- detect(...) Images | RealSpaceLineProfiles | MeasurementsEnsemble[source]#
Detect the given waves producing images.
- Parameters:
waves (Waves)
- Returns:
measurement
- Return type:
- get_detector_region(...)[source]#
Get the slit detector region as a DiffractionPatterns object.
- Parameters:
waves (BaseWaves or DiffractionPatterns) – The waves or diffraction patterns used to derive grid calibration.
fftshift (bool, optional) – If True, the zero-frequency component is shifted to the centre.
- property offset: tuple[float, float]#
Origin of the q-axis sweep (kx, ky) [mrad]. The q-axis starts here.
- property q_max: float#
Maximum scattering vector along the slit’s long axis [mrad] (= q_min + extent).
- show(...)[source]#
Show the slit detector region as a polygon patch.
- Parameters:
waves (BaseWaves or DiffractionPatterns) – Provides grid calibration. When show_pattern is True, the diffraction pattern (summed over all ensemble axes) is shown as a grayscale background and waves must be a
DiffractionPatterns.show_pattern (bool, optional) – Overlay the patch on the summed diffraction pattern. Requires a
DiffractionPatternsas waves.power (float, optional) – Exponent applied to the pattern before display (default 0.5 → square-root stretch). Ignored when show_pattern is False.
ax (matplotlib Axes, optional)
figsize (tuple, optional)
- class abtem.detectors.WavesDetector(...)[source]#
Bases:
abtem.detectors.BaseDetectorDetect the complex wave functions.
- Parameters:
to_cpu (bool, optional) – If True, copy the measurement data from the calculation device to CPU memory after applying the detector, otherwise the data stays on the respective devices. Default is True.
url (str, optional) – If this parameter is set the measurement data is saved at the specified location, typically a path to a local file. A URL can also include a protocol specifier like s3:// for remote data. If not set (default) the data stays in memory.
Initialization
- abtem.detectors.validate_detectors(...) list[BaseDetector][source]#
Validate that a variable is a list of detectors.
- Parameters:
detectors (BaseDetector or list of BaseDetector) – The detectors to validate.
waves (Waves, optional) – The waves to match the detectors to.
- Returns:
A list of validated detectors.
- Return type:
list of BaseDetector
- Raises:
TypeError – If detectors is not a BaseDetector or a list of BaseDetector.