1.1.1. tomotok.core.geometry package

Contains functions and classes required for geometry matrix computation using single line of sight approximation.

  • Functions computing contributions of nodes to gmat
  • reconstruction grid definition
  • line of sight generators for artificial diagnostics
  • gmat handler prototype

1.1.1.1. Submodules

1.1.1.2. tomotok.core.geometry.analytical module

Contains analytical geometry matrix generators. Requires shapely library.

Shapely module is imported after the function is called so that it is not a hard dependence. These are significantly slower than numerical ones, but can use polygons instead of line of sights.

tomotok.core.geometry.analytical.distance_mat(grid, ph)

Computes distances of pixels centers from pinhole and returns them in a matrix form. Indexing starts with bottom row.

Parameters:

grid : RegularGrid

class describing reconstruction area

ph : numpy.ndarray

contains pinhole coordinates

Returns:

numpy.ndarray

matrix with pixel center distances from pinhole

tomotok.core.geometry.analytical.lines_len(lines, grid)

Computes lengths of chords inside whole pixel grid

Parameters:

lines : array of shapely.geometry.LineString

Contains central lines from polygon chord

grid : RegularGrid

Returns:

numpy.ndarray

array with lengths of chords in pixel grid

tomotok.core.geometry.analytical.shapely_line_mat(xchord, ychord, grid)

Generates geometry matrix using shapely module

Parameters:

xchord, ychord : numpy.ndarray

chord coordinates with shape (#chords, 2)

grid : RegularGrid

class of tomotok module describing reconstruction area

Returns:

gmat : dict

holds geometry matrix and grid coordinates

tomotok.core.geometry.analytical.shapely_poly_mat(xchord, ychord, grid, ph=None, w=None)

Generates geometry matrix using polygon object from shapely module.

Parameters:

xchord, ychord : numpy.ndarray

chord coordinates with shape (#chords, #2) or (#chords, #curve_points)

grid : RegularGrid

class of tomotok module describing reconstruction area

ph : numpy.ndarray, optional

matrix with pinholes coords with shape (#chords, 2) If no values are supplied, start points of chords are used.

w : numpy.ndarray, optional

contains widening coefficients for chords with shape (#chords,). If no values are supplied, locally predefined value is used.

Returns:

dict

geometry matrix and parameters

1.1.1.3. tomotok.core.geometry.generators module

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

1.1.1.4. tomotok.core.geometry.grids module

Contains class describing regularly spaced node grid

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

Bases: object

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

center_mesh
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)

rlims
shape
size
zlims

1.1.1.5. tomotok.core.geometry.handler module

Tool for easier handling of geometry matrices. Work in progress.

class tomotok.core.geometry.handler.GmatHandler(diag, grid, gmat=None)

Bases: object

[summary]

Attributes

diag  
grid  
gmat (dict)

Methods

compute_sparse_lines(**kw)

Computes geometry matrix using single line of sight approx. with numerical algorithm.

fetch(gmat_path=”, gtype=’line’, save=False, force_comp=False)

Tries to load geometry matrix for specified grid from gmat path. Computes new matrix if appropriate matrix is not available.

Parameters:

gmat_path : str or Path, optional

gtype : str, optional

Specifies type of geometry matrix to be used. {‘line’, ‘poly’} are supported for computation.

save : bool, optional

force_comp : bool, optional

Forces computation of geometry matrix

load_dense(gpath, filename=None)

Loads geometry matrix.

Assumes that gpath is full path to gmat file if filename is omitted.

Parameters:

gpath : str or Path

filename : str, optional

name of file containing geometry matrix

Returns:

dict

save_dense(gmat_path, grid=None, filename=None)

Saves geometry matrix to gmat_path. Either grid or filename must be specified.

If filename is not specified, the default filename is generated using grid properties.

Parameters:

gmat_path : str or Path

saving folder

grid : Pixgrid, optional

filename : str, optional

1.1.1.6. tomotok.core.geometry.io module

Saving and loading functions for geometry matrices in sparse format using h5py module.

tomotok.core.geometry.io.load_sparse_gmat(floc: str) → typing.Tuple[scipy.sparse.csr.csr_matrix, tomotok.core.geometry.grids.RegularGrid]

Loads hdf file and creates sparse csr_matrix and RegularGrid class

Parameters:

floc : str

hdf file location

Returns:

gmat : sparse.csr_matrix

grid : geometry.RegularGrid

tomotok.core.geometry.io.save_sparse_gmat(floc, gmat: scipy.sparse.csr.csr_matrix, grid: tomotok.core.geometry.grids.RegularGrid, attrs_dct: dict = None) → None

Saves geometry matrix together with description of the grid.

Currently suports only sparse CSR matrices and regular rectangular grids.

Parameters:

floc : str

file location

gmat : csr_matrix

with shape (#chanels, #nodes)

grid : RegularGrid

class describing regular grid the gmat was computed for

attrs_dict : dict, optional

additional attributes to be saved in hdf file

1.1.1.7. tomotok.core.geometry.los module

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