Documentation
model.py
- class temgymbasic.model.Model(components, beam_z=1, num_rays=256, beam_type='point', beam_semi_angle=0.7853981633974483, beam_tilt_x=0, beam_tilt_y=0, beam_width=0.2, detector_size=0.5, detector_pixels=128)[source]
Generates a model electron microscope. This class generates performs the matrix multiplication and function updates to calculate their positions throughout the column.
- __init__(components, beam_z=1, num_rays=256, beam_type='point', beam_semi_angle=0.7853981633974483, beam_tilt_x=0, beam_tilt_y=0, beam_width=0.2, detector_size=0.5, detector_pixels=128)[source]
- Parameters
components (list) – List of components to electron microscope component to input into the model
beam_z (int, optional) – Sets the initial height of the beam, by default 1
num_rays (int, optional) – Sets the number of rays generated at the beam_z position. A large number of rays will in general slow down the programme quite a lot. , by default 256
beam_type (str, optional) –
- Choose the type of beam:
- -‘point’ beam creates a set of rays that start from a single point and
spread out like a cone.
-‘paralell’ beam creates a set of rays that start from the same position, but each have the same angle. - ‘axial’ creates a beam which is only visible on the x and y axis. - ‘x_axial’ creates a beam which is only visible on the x-axis. This is only used for matplotlib diagrams, by default ‘point’
beam_semi_angle (float, optional) – Set the semi angle of the beam in radians., by default np.pi/4
beam_tilt_x (int, optional) – Set the tilt of the beam in the x direction, by default 0
beam_tilt_y (int, optional) – Set the tilt of the beam in the y direction, by default 0
beam_width (float, optional) – Set the width of the beam - only matters if “paralell” beam type is selected
detector_size (float, optional) – Set the size of the detector, by default 0.5
detector_pixels (int, optional) – Set the number of pixels in the detector. A large number of pixels will probably considerably hinder performance, by default 128
- propagate(z)[source]
Propagation matrix
- Parameters
z (float) – Distance to propagate rays
- Returns
Propagation matrix
- Return type
ndarray
components.py
- class temgymbasic.components.Aperture(z, name='Aperture', aperture_radius_inner=0.005, aperture_radius_outer=0.25, label_radius=0.3, num_points=50, x=0, y=0)[source]
Creates an aperture component and handles calls to GUI creation, updates to GUI and stores the component parameters. Important to note that the transfer matrix of the aperture only propagates rays. The logic of blocking rays is handled inside the “model” function.
- __init__(z, name='Aperture', aperture_radius_inner=0.005, aperture_radius_outer=0.25, label_radius=0.3, num_points=50, x=0, y=0)[source]
- Parameters
z (float) – Position of component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘Aperture’
aperture_radius_inner (float, optional) – Inner radius of the aperture, by default 0.005
aperture_radius_outer (float, optional) – Outer radius of the aperture, by default 0.25
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
x (int, optional) – X position of the centre of the aperture, by default 0
y (int, optional) – Y position of the centre of the aperture, by default 0
- class temgymbasic.components.AstigmaticLens(z, name='', fx=- 0.5, fy=- 0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
Creates an Astigmatic lens component and handles calls to GUI creation, updates to GUI and stores the component matrix.
- __init__(z, name='', fx=- 0.5, fy=- 0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
- Parameters
z (float) – Position of component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘’
fx (float, optional,) – Focal length of this lens in x, by default -0.5
fx – Focal length of this lens in y, by default -0.5
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
radius (float, optional) – Radius of the 3D model of this component, by default 0.25
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
- class temgymbasic.components.Biprism(z, name='', deflection=0.5, theta=0, label_radius=0.3, radius=0.25, width=0.01, num_points=50)[source]
Creates a biprism component and handles calls to GUI creation, updates to GUI and stores the component parameters. Important to note that the transfer matrix of the biprism is only cosmetic: It still need to be multiplied by the sign of the position of the ray to perform like a biprism.
- __init__(z, name='', deflection=0.5, theta=0, label_radius=0.3, radius=0.25, width=0.01, num_points=50)[source]
- Parameters
z (float) – Position of component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘’
deflection (float, optional) – Biprism deflection kick in slope units to the incoming ray angle, by default 0.5
theta (int, optional) – Angle of the biprism - Two options - 0 or 1. 0 for 0 degree rotation, 1 for 90 degree rotation, by default 0
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
radius (float, optional) – Radius of the 3D model of this component, by default 0.25
width (float, optional) – Width of the biprism model, by default 0.01
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
- class temgymbasic.components.Deflector(z, name='', defx=0.5, defy=0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
Creates a single deflector component and handles calls to GUI creation, updates to GUI and stores the component matrix. See Double Deflector component for a more useful version
- __init__(z, name='', defx=0.5, defy=0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
_summary_
- Parameters
z (float) – Position of component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘’
defx (float, optional) – deflection kick in slope units to the incoming ray x angle, by default 0.5
defy (float, optional) – deflection kick in slope units to the incoming ray y angle, by default 0.5
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
radius (float, optional) – Radius of the 3D model of this component, by default 0.25
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
- class temgymbasic.components.DoubleDeflector(z_up, z_low, name='', updefx=0.0, updefy=0.0, lowdefx=0.0, lowdefy=0.0, label_radius=0.3, radius=0.25, num_points=50)[source]
Creates a double deflector component and handles calls to GUI creation, updates to GUI and stores the component matrix. Primarily used in the Beam Tilt/Shift alignment.
- __init__(z_up, z_low, name='', updefx=0.0, updefy=0.0, lowdefx=0.0, lowdefy=0.0, label_radius=0.3, radius=0.25, num_points=50)[source]
- Parameters
z_up (float) – Position of the upper deflection component in optic axis
z_low (float) – Position of the lower deflection component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘’
updefx (float, optional) – deflection kick of upper deflector in slope units to the incoming ray x angle, by default 0.0
updefy (float, optional) – deflection kick of upper deflector in slope units to the incoming ray y angle, by default 0.0
lowdefx (float, optional) – deflection kick of lower deflector in slope units to the incoming ray x angle, by default 0.0
lowdefy (float, optional) – deflection kick of lower deflector in slope units to the incoming ray y angle, by default 0.0
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
radius (float, optional) – Radius of the 3D model of this component, by default 0.25
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
- class temgymbasic.components.Lens(z, name='', f=0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
Creates a lens component and handles calls to GUI creation, updates to GUI and stores the component matrix.
- __init__(z, name='', f=0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
- Parameters
z (float) – Position of component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘’
f (float, optional,) – Focal length of this lens, by default 0.5
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
radius (float, optional) – Radius of the 3D model of this component, by default 0.25
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
- class temgymbasic.components.Quadrupole(z, name='', fx=- 0.5, fy=- 0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
Creates a quadrupole component and handles calls to GUI creation, updates to GUI and stores the component matrix. Almost exactly the same as astigmatic lens component
- __init__(z, name='', fx=- 0.5, fy=- 0.5, label_radius=0.3, radius=0.25, num_points=50)[source]
- Parameters
z (float) – Position of component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘’
fx (float, optional,) – Focal length of this quadrupole in x, by default -0.5
fx – Focal length of this quadrupole in y, by default -0.5
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
radius (float, optional) – Radius of the 3D model of this component, by default 0.25
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
- class temgymbasic.components.Sample(z, name='', label_radius=0.3, width=0.25, num_points=50, x=0.0, y=0.0)[source]
Creates a sample component which serves only as a visualisation on the 3D model.
- __init__(z, name='', label_radius=0.3, width=0.25, num_points=50, x=0.0, y=0.0)[source]
- Parameters
z (float) – Position of component in optic axis
name (str, optional) – Name of this component which will be displayed by GUI, by default ‘’
label_radius (float, optional) – Location to place the label in the 3D GUI, by default 0.3
radius (float, optional) – Radius of the 3D model of this component, by default 0.25
num_points (int, optional) – Number of points to use to make the 3D model, by default 50
x (float, optional) – X position of sample model, by default 0
y (int, optional) – Y position of sample model, by default 0
run.py
- class temgymbasic.run.LinearTEMCtrl(model, view)[source]
Control code which links the model and 3D viewer
- class temgymbasic.run.LinearTEMUi(model)[source]
Create the UI Window
- Parameters
QMainWindow (class) – Pyqt5’s Main window Class
- temgymbasic.run.run_pyqt(model)[source]
Main code to run a pyqt model
- Parameters
model (class) – Microscope Model
- temgymbasic.run.show_matplotlib(model, name='model.svg', component_lw=4, edge_lw=1, label_fontsize=20)[source]
Code to show a matplotlib model
- Parameters
model (class) – Microscope Model
name (str, optional) – Name of file, by default ‘model.svg’
component_lw (int, optional) – Linewidth of component outline, by default 4
edge_lw (int, optional) – Linewidth of highlight to edges, by default 1
label_fontsize (int, optional) – Fontsize of labels, by default 20
- Returns
fig (class) – Matplotlib figure object
ax (class) – Matplotlib axis object of the figure
shapes.py
- temgymbasic.shapes.aperture(r_i, r_o, n_i, n_o, x, y, z)[source]
3D vertices model of an aperture
- Parameters
r_i (float) – Radius of inner aperture model
r_o (float) – Radius of outer aperture model
n_i (int) – Number of points used to represent inner aperture model
n_o (int) – Number of points used to represent outer aperture model
x (float) – X position of aperture
y (float) – Y position of aperture
z (float) – Z position of aperture
- Returns
verts3D – 3D array of vertices that represent the aperture model
- Return type
ndarray
- temgymbasic.shapes.biprism(r, z, theta)[source]
Wire model geometry for biprism
- Parameters
r (float) – Radius of wire
z (float) – Z position of wire
theta (float) – Angle of wire - Two options, 0 or np.pi/2
- Returns
points – Points array of wire geometry
- Return type
ndarray
- temgymbasic.shapes.deflector(r, phi, z, n_arc)[source]
Wire model geometry of deflector
- Parameters
r (float) – Radius of deflector geometry
phi (float) – Angular width of deflector mode
z (float) – Z position of deflector geometry
n_arc (int) – Number of arcs to use to make up the model
- Returns
points_arc_1 (ndarray) – Points of a circle to represent the lens geometry
points_arc_2 (ndarray) – Points of a circle to represent the lens geometry
- temgymbasic.shapes.lens(r, z, n_arc)[source]
Wire model geometry of lens
- Parameters
r (float) – Radius of lens geometry
z (float) – Z position of lens geometry
n_arc (int) – Number of arcs to use to make up the model
- Returns
points_circle – Points of a circle to represent the lens geometry
- Return type
ndarray
- temgymbasic.shapes.quadrupole(r, phi, z, n_arc)[source]
Wire model geometry of deflector
- Parameters
r (float) – Radius of quadrupole geometry
phi (float) – Angular width of quadrupole mode
z (float) – Z position of quadrupole geometry
n_arc (int) – Number of arcs to use to make up the model
- Returns
points_arc_1 (ndarray) – Points of first semi circle that represent the quadrupole geometry
points_arc_2 (ndarray) – Points of second semi circle that represent the quadrupole geometry
points_arc_3 (ndarray) – Points of third semi circle that represent the quadrupole geometry
points_arc_4 (ndarray) – Points of fourth semi circle that represent the quadrupole geometry
- temgymbasic.shapes.square(w, x, y, z)[source]
Generates vertices for a square 3D model. Used to represent the detector
- Parameters
w (float) – Width of the square wire model
x (float) – X position of the square wire model
y (float) – Wire position of the square wire model
z (float) – Wire position of the square wire model
- Returns
verts3D – vertices to draw a 3D model
- Return type
ndarray
functions.py
- temgymbasic.functions.axial_point_beam(r, beam_semi_angle)[source]
Generates a cross shaped initial beam on the x and y axis that spreads out with semi angle ‘beam_semi_angle’
- Parameters
r (ndarray) – Ray position and slope matrix
beam_semi_angle (float) – Beam semi angle in radians
- Returns
r – Updated ray position & slope matrix which create a circular beam
- Return type
ndarray
- temgymbasic.functions.circular_beam(r, outer_radius)[source]
Generates a circular paralell initial beam
- Parameters
r (ndarray) – Ray position and slope matrix
outer_radius (float) – Outer radius of the circular beam
- Returns
r (ndarray) – Updated ray position & slope matrix which create a circular beam
num_points_kth_ring (ndarray) – Array of the number of points on each ring of our circular beam
- temgymbasic.functions.get_image_from_rays(rays_x, rays_y, detector_size, detector_pixels)[source]
From an image of rays that hit the detector at the base of the TEM
- Parameters
rays_x (ndarray) – X position of rays that hit the detector
rays_y (ndarray) – X position of rays that hit the detector
detector_size (float) – Real size of the detector in the model. Single value that describes it’s edge length. Note that the detector is always square
detector_pixels (int) – Resolution of the detector.
- Returns
detector_image (ndarray) – Image of where rays have hit the detector
image_pixel_coords (ndarray) – Coordinates of where reach ray has hit the detector
- temgymbasic.functions.point_beam(r, beam_semi_angle)[source]
Generates a point initial beam that spreads out with semi angle ‘beam_semi_angle’
- Parameters
r (ndarray) – Ray position and slope matrix
beam_semi_angle (float) – Beam semi angle in radians
- Returns
r (ndarray) – Updated ray position & slope matrix which create a circular beam
num_points_kth_ring (ndarray) – Array of the number of points on each ring of our circular beam
- temgymbasic.functions.x_axial_point_beam(r, beam_semi_angle)[source]
Generates a cross shaped initial beam on the x axis that spreads out with semi angle ‘beam_semi_angle’
- Parameters
r (ndarray) – Ray position and slope matrix
beam_semi_angle (float) – Beam semi angle in radians
- Returns
r – Updated ray position & slope matrix which create a circular beam
- Return type
ndarray
gui.py
- class temgymbasic.gui.ApertureGui(name, min_radius, max_radius, inner_radius, x, y)[source]
GUI for the aperture component
- __init__(name, min_radius, max_radius, inner_radius, x, y)[source]
- Parameters
name (str) – Name of component
min_radius (float) – Minimum radius of the aperture
max_radius (float) – Max radius of the aperture
inner_radius (float) – Initial inner radius of the aperture
x (float) – X position of component
y (float) – y position of component
- class temgymbasic.gui.AstigmaticLensGui(name, gui_label, fx, fy)[source]
Gui for the Astigmatic Lens component
- class temgymbasic.gui.BiprismGui(name, deflection, theta)[source]
GUI for the biprism component
- __init__(name, deflection, theta)[source]
- Parameters
name (str) – Name of component
deflection (float) – Deflection angle in Slope units
theta (int) – Angle of biprism. Determines if the biprism creates deflects in the x or y direction. Two options: 0 or 1. 0 for 0 degrees, 1 for 90 degree rotation.
- class temgymbasic.gui.DoubleDeflectorGui(name, updefx, updefy, lowdefx, lowdefy)[source]
GUI for the double deflector component
- __init__(name, updefx, updefy, lowdefx, lowdefy)[source]
- Parameters
name (str) – Name of component
updefx (float) – Initial X deflection of upper deflector
updefy (float) – Initial Y deflection of upper deflector
lowdefx (float) – Initial X deflection of lower deflector
lowdefy (float) – Initial Y deflection of lower deflector
- class temgymbasic.gui.ModelGui(num_rays, beam_type, beam_semi_angle, beam_tilt_x, beam_tilt_y)[source]
Overall GUI of the model
- __init__(num_rays, beam_type, beam_semi_angle, beam_tilt_x, beam_tilt_y)[source]
- Parameters
num_rays (int) – Number of rays in the model
beam_type (str) – Type of initial beam: Axial, paralell of point.
beam_semi_angle (float) – Semi angle of the beam
beam_tilt_x (float) – Initial x tilt of the beam in radians
beam_tilt_y (float) – Initial y tilt of the beam in radians