5.1. Geometry

Handles geometry of the inversion task. This includes definition of reconstruction grid, creating artificial geometry and computation of geometry (sensitivity/contribution) matrices. Currently only algorithms using single line of sight approximation are implemented.

5.1.1. Geometry matrix

Module with numeric generators of geometry matrix.

tomotok.core.geometry.generators.calcam_sparse_line_3d(pupil, dirs, grid, step=0.001, rmin=None, elong=1.0, steps=None)

Computes geometry matrix from calcam input using sparse_line_3d algorithm.

Assumes that pupil and dirs coordinates are (x, y, z) = (horizontal, horizontal, vertical)

Parameters:

pupil : np.ndarray

(x, y, z) coordinates of pupil position

dirs : np.ndarray

(#rows, #columns, 3) line of sight direction vector coordinates

grid : tomotok.core.geometry.RegularGrid

reconstruction grid

step : float, optional

Integration step in meters.

rmin : float, optional

cut lines of sight if they intersect cylinder with radius of rmin, by default 0.3

elong : float, optional

multiplier for direction vectors elongation

Returns:

sparse.csr_matrix

tomotok.core.geometry.generators.sparse_line(starts, ends, grid, step=0.001, rmin=-1)

Computes geometry matrix using simple numerical integration algorithm.

Uses lines of sight start and end points in 3D Cartesian coordinates as input.

Parameters:

starts, ends : ndarray

Contains lines of sight start/end points, with shape (…, 3)

grid : RegularGrid

Reconstruction grid

step : float, optional

Integration step, by default 1e-3

rmin : int, optional

Stops the lines of sight if they intersect cylinder with radius of rmin, by default -1

Returns:

sparse.csr_matrix

tomotok.core.geometry.generators.sparse_line_3d(rchord, vchord, grid, ychord=None, step=0.001, rmin=None)

Computes geometry matrix using simple numerical integration algorithm.

Assumes toroidally symmetric reconstruction nodes. Optimized version working with sparse matrices.

Parameters:

rchord : array-like

radial coordinates of chord start and end points

vchord : array-like

vertical coordinates of chord start and end points

grid : RegularGrid

ychord : array_like, optional

if specified, 3D Cartesian coordinates are assumed and rchord represents coordinates of x axis

step : float, optional

Integration step in meters.

rmin : float, optional

Stop iteration if r is lower. Useful when chords may go through central column.

Returns:

sparse.csr_matrix

5.1.2. Reconstruction grids

class tomotok.core.geometry.RegularGrid(nr: int, nz: int, rlims: typing.Tuple[float, float], zlims: typing.Tuple[float, float]) → None

Rectangular grid of regularly spaced rectangles of same size

Describes rectangular reconstruction grid consisting of regularly spaced toroidally symmetric nodes that have rectangular projection to reconstruction plane.

Attributes

nr (int) number of nodes along r (radial) axis
nz (int) number of nodes along z (vertical) axis
nodes_num (int) total number of nodes
rmin, rmax (float) limits of r axis
zmin, zmax (float) limits of z axis
rlims, zlims (Tuple[float, float]) grid limits along respective axis
dr, dz (float) dimension of node in r or z axis
r_border, z_border (numpy.ndarray) arrays containing r resp. z coordinates of node borders
r_center, z_center (numpy.ndarray) arrays containing r resp. z coordinates of node centers

Methods

centre

Returns the mean of rmin, rmax and zmin, zmax

corners(mask: numpy.ndarray = None) → numpy.ndarray

Creates an array with r, z coordinates of node corners.

Corners are in clockwise order starting with top left corner.

Parameters:

mask : numpy.ndarray

2D bool matrix for selecting nodes, shape (#z, #r)

Returns:

numpy.ndarray

corner coordinates for each node in reconstruction plane, shape (#z, #r, 4, 2)

extent

Grid extent in format for use in matplotlib

Returns:

tuple of floats

rmin, rmax, zmin, zmax

is_inside(r: numpy.ndarray, z: numpy.ndarray) → numpy.ndarray

Selects nodes with centers inside given polygon.

Parameters:

r, z : numpy.ndarray

Coordinate vectors of polygon

Returns:

numpy.ndarray

Mask matrix for pixgrid with True values for nodes inside polygon

is_inside_any(r: numpy.ndarray, z: numpy.ndarray) → numpy.ndarray

Selects nodes with at least one corner inside given polygon.

Parameters:

r, z : numpy.ndarray

Coordinate vectors of polygon

Returns:

numpy.ndarray

Mask matrix for pixgrid with True values for nodes inside polygon

nodevol

Volumes of individual nodes

Returns:

numpy.ndarray

matrix with volume values for each node with shape (nz, nr)

5.1.3. Lines of sight

Routines for generation of line of sight start and end points.

Creates the lines of sights in x axis direction and then rotates them about the other horizontal axis, then about vertical axis.

tomotok.core.geometry.los.generate_directions(num=(10, 1), fov=(45, 0), axis=(1, 0, 0), elong=1.0)

Creates direction vectors for lines of sight using camera like convention.

The first line of sight is top left, then the numbering follows a row, the last one is bottom right.

Parameters:

num : int or (int,int), optional

number of generated chords (vertical, horizontal)

fov : float, or tuple of two float, optional

vertical or (vertical, horizontal) field of view in degrees

axis : tuple of three floats, optional

direction of symmetry axis

elong : float, optional

vector length multiplier

Returns:

dirs : numpy.ndarray

contains direction vectors cartesian coordinates, shape (#los, 3)

tomotok.core.geometry.los.generate_los(pinhole=(0, 0, 0), num=(10, 1), fov=(45, 0), axis=(1, 0, 0), elong=1.0)

Creates line of sight endpoints with uniform distribution.

Parameters:

num : int or (int,int), optional

number of generated chords (vertical, horizontal)

pinhole : tuple of three floats, optional

r and z coordinates of pinhole

fov : float, or tuple of two float, optional

vertical and horizontal field of view in degrees

axis : tuple of three floats, optional

direction of chordal axis

elong : float, optional

chord length multiplier

Returns:

start : numpy.ndarray

array with line of sight start points coordinates, shape (#los, 3)

end : numpy.ndarray

array with line of sight end points coordinates, shape (#los, 3)

tomotok.core.geometry.los.rot_h(points, angle)

Rotates given points in horizontal direction, that is about vertical axis z.

Parameters:

points : numpy.ndarray

3D coordinates of points to be rotated with shape (#points, 3)

angle : float

angle of rotation in radians

Returns:

numpy.ndarray

array of rotated points

tomotok.core.geometry.los.rot_v(points, angle)

Rotates given points in vertical direction, that is about horizontal y axis perpendicular to r/x.

Should be done before horizontal rotation.

Parameters:

points : numpy.ndarray

3D coordinates of points to be rotated with shape (#points, 3)

angle : float

angle of rotation in radians

Returns:

numpy.ndarray

array of rotated points