1. tomotok.core package¶
1.1. Subpackages¶
1.2. Submodules¶
1.3. tomotok.core.derivative module¶
Contains functions for derivative matrix computation.
- new functions (isotropic) derivative_matrix and laplace_matrix
- compute_aniso_dmats and compute_iso_dmats takes care of obtaining flux dependent or flux independent derivative matrices,
- prepare_mag_data is an auxiliary function to calculate magnetic flux gradients and
- px_norm is a simple auxiliary function to calculate norms for coefficients
-
tomotok.core.derivative.
compute_aniso_dmats
(grid, magflux, derivative=4, mask=None)¶ Prepares matrix of finite differences, magnetic configuration dependent or fixed simple differences. First or second derivative can be used
Parameters: grid : RegularGrid
A reconstruction grid
magflux : numpy.ndarray
values of psi normalized mapped to grid
mask : numpy.ndarray, optional
bool mask
derivative : int in {1,2,3,4}
specifies type of derivative scheme, default is 4
Returns: tuple of scipy.sparse.csrmatrix pairs
derivative matrix
-
tomotok.core.derivative.
compute_iso_dmats
(grid, derivatives=[1, 2], mask=None)¶ Computes isotropic derivative matrix pairs for given differential schemes.
Parameters: grid : RegularGrid
mask : np.ndarray, optional
derivatives : list of int/str, optional
Returns: list of dmat pairs
-
tomotok.core.derivative.
derivative_matrix
(grid: tomotok.core.geometry.grids.RegularGrid, direction: str, scheme: str = ‘forward’, mask: numpy.ndarray = None, compensate_edges=False)¶ Creates a derivative matrix using numerical differences
Parameters: grid : RegularGrid
direction : str
Determines one of the 8 possible directions that can be used. Specified using the over edge neighbor ‘right’, ‘top’, ‘left’, ‘bottom’ or combination over corner directions like ‘top-left’
scheme : str, optional
Selects numerical scheme to be used. Can be ‘forward’, ‘backward’, ‘central’, ‘second’. The default value is ‘forward’.
mask : numpy.ndarray, optional
A bool mask determining nodes of regular grid to keep, by default None. Rows and columns representing False nodes are removed from derivative matrix. If mask is None, all rows and columns are returned.
compensate_edges : bool, optional
Subtracts from diagonal so that sum of each row is zero, by default False.
Returns: scipy.sparse.csc_matrix
-
tomotok.core.derivative.
generate_anizo_matrix
(grid, atan2, derivative)¶ Write prepared directions atan2 into the derivative matrix. Main magic of this algorithm. Rewrite arctan into the directions and decompose directions to parallel and oblique direction.
Parameters: grid : RegularGrid
Object with pixel grid gridinates
atan2 : numpy.ndarray
3D array of arcus tangents of Psi(R,z) evolution
derivative : int
derivative type identificator
Returns: bper : scipy.sparse
sparse matrix with perpendicular derivatives
bpar : scipy.sparse
sparse matrix with parallel derivatives
bpar_tmp: numpy.array
(optional) dense matrix with parallel derivatives
bper_tmp: numpy.array
(optional) dense matrix with perpendicular derivatives
-
tomotok.core.derivative.
generate_iso_dmat
(grid: tomotok.core.geometry.grids.RegularGrid, derivative=4)¶ Computes isotropic derivative matrix.
Parameters: grid : RegularGrid
derivative : list of int
Returns: scipy.sparse.csc_matrix, scipy.sparse.csc_matrix
-
tomotok.core.derivative.
get_index_shift
(col_num: int, direction: str, distance: int = 1) → int¶ Computes the index difference of a node neighbor on a flatten grid.
Parameters: col_num : int
number of columns in reconstruction grid
direction : str
Determines one of the 8 possible directions that can be used. Specified using the over edge neighbor ‘right’, ‘top’, ‘left’, ‘bottom’ or combination over corner directions like ‘top-left’
distance : int, optional
expressed in number of nodes, by default 1
Returns: int
relative index of neighbor in flattened grid
-
tomotok.core.derivative.
laplace_matrix
(grid: tomotok.core.geometry.grids.RegularGrid, mask=None, compensate_edge=False, diagonals=True)¶ Creates sparse laplace matrix.
Parameters: grid : RegularGrid
mask : numpy.ndarray, optional
A bool mask determining nodes of regular grid to keep, by default None. Rows and columns representing False nodes are removed from derivative matrix. If mask is None, all rows and columns are returned.
compensate_edges : bool, optional
Subtracts from diagonal so that sum of each row is zero, by default False.
diagonals : bool, optional
Selects whether to use diagonal neighbors in matrix, by default True.
Returns: scipy.sparse.csc_matrix
-
tomotok.core.derivative.
prepare_mag_data
(flux)¶ Calculates gradient map of magnetic flux function Psi(R,z) and returns arcus tangens of dPsi_y/-dPsi_x that is a suitable funciton for anizotropic diffusion matrix calculation
Parameters: flux : numpy.ndarray
array of Psi(R,z) evolution, with axes (z, R, t)
Returns
——
numpy.ndarray
arcus tangens of Psi gradient
-
tomotok.core.derivative.
px_norm
(direc)¶ Computed (normalised?) distance between centers of nodes.
-
tomotok.core.derivative.
reduce_dmats
(dmats, idx)¶ Creates reduced derivative matrices by cutting out rows and columns representing unwanted nodes.
Parameters: dmats : tuples of scipy.sparse.csr_matrix
tuple containing full derivative matrices
idx : numpy.ndarray of bool
array or mask array to select desired nodes
Returns: list of scipy.sparse.csr_matrix pairs
derivative matrices with removed rows and columns representing nodes outside the bdr polygon (vacuum vessel)
1.4. tomotok.core.phantoms module¶
Contains functions that can create emissivity phantoms.
Both isotropic one or based on the shape of flux surfaces.
-
tomotok.core.phantoms.
gauss
(x, w=0.1, lim=1, amp=1, cen=0.0)¶ Creates anisotropic gaussian artificial emissivity by 1D transform of x
\[f = amp \left( \mathrm{e}^{-(x-cen)^2 / w } - \mathrm{e}^{-(lim-cen)^2 / w)} \right)\]Can be used on np.ndarray. Lim should be greater than cen.
Parameters: x : float, array, np.ndarray
Contains values to be transformed, usually psi
w : float, optional
width of gaussian profile
lim : float, optional
minimal value of x where transform gives zero if x > lim emissivity is set to zero
amp : float, optional
amplitude of gaussian profile,
cen : float, optional
center of gaussian profile allows hollow profile generation when mapped on psi
Returns: numpy.ndarray
Transformed values of x with same dimensions
-
tomotok.core.phantoms.
gauss_iso
(nx, ny, span=1.2, w=0.1, lim=1, amp=1, cen=0)¶ Creates isotropic gaussian distribution. See references for iso_psi and gauss
-
tomotok.core.phantoms.
islands
(psi, w=0.01, lim=1, amp=1, cen=0.4, num=3, shift=0)¶ Creates island like phantom from given psi profile. See references for gauss and polar_phase.
-
tomotok.core.phantoms.
iso_psi
(nx, ny, span=1.5)¶ Creates matrix of artificial isotropic psi profile with border values for each axis equal to span.
Parameters: nx : int
Number of pixels on x axis
ny : int
Number of pixels on y axis
span : float, optional
Value of result on the center of border
Returns: numpy.ndarray
Matrix with generated profile
-
tomotok.core.phantoms.
polar_phase
(x, num=3, shift=0)¶ Applies sine phase in radial angle direction to given profile x.
Parameters: x : numpy.ndarray
Profile for application of polar phase.
num : int, optional
number of periods per one rotation
shift : float, optional
initial phase shift
Returns: numpy.ndarray
Matrix with applied polar phase