4. tomotok.tools package#
- class tomotok.tools.Diagnostic#
Bases:
objectBase class for diagnostics. Should be subclassed for specific diagnostics.
Methods
load_data(shot[, tvec])Loads diagnostic data from database specified by source.
- load_data(shot: int, tvec: ArrayLike | None = None) Signals#
Loads diagnostic data from database specified by source.
- Parameters:
- shotint
Shot number for which the diagnostic data is loaded.
- tvecArrayLike, optional
specifies timeslices to be loaded, if not provided, all available timeslices are loaded
- sourcestr, optional
specifies source for loading diagnostic data
- Returns:
- Signals
Loaded diagnostics signal stored in Signals container
- class tomotok.tools.Tokamak(divertor_area_r: ArrayLike | None = None, divertor_area_z: ArrayLike | None = None)#
Bases:
objectA Template class that should be subclassed for specific tokamaks.
Currently only defines a template method for loading magnetic field data for subclasses and stores divertor area.
- Attributes:
- divertor_area_rarray-like, optional
radial coordinates of divertor area boundary polygon
- divertor_area_zarray-like, optional
vertical coordinates of divertor area boundary polygon
Methods
load_magnetic_field(shot[, tvec])Loads magnetic field data from database for given shot and time slices.
- load_magnetic_field(shot: int, tvec: ArrayLike = None) Magnetics#
Loads magnetic field data from database for given shot and time slices.
Specific implementation should be provided in subclass.
- Parameters:
- shotint
Shot number for which the magnetic field is loaded.
- tvecarray-like, optional
specifies vector of time slices to be loaded, if not provided, all available time slices are loaded
- Returns:
- Magnetics
Psi normalized stored in Magnetics dataclass container
4.1. Subpackages#
4.2. Submodules#
4.3. tomotok.tools.checkers module#
Contains classes and functions for user checks of selected inputs for tomographic inversion
4.3.1. Examples#
Checking anisotropic derivative matrix
>>> from tomotok.geometry import RegularGrid
>>> from tomotok.regularisations import anisotropic_derivative_matrix
>>>
>>> grid = RegularGrid(50, 100, (0.5, 1), (-0.5, 0.5))
>>> checker = AnisotropicDerivativeChecker(grid)
>>> dmat_par = anisotropic_derivative_matrix(grid, flux, 'parallel')
>>> dmat_per = anisotropic_derivative_matrix(grid, flux, 'perpendicular')
>>> checker(flux, dmat_par, dmat_per)
- class tomotok.tools.checkers.AnisotropicDerivativeChecker(grid: RegularGrid, flux: ndarray, dmat1: spmatrix, dmat2: spmatrix, contour_colors='k', contour_levels=10, dmat_cmap='RdBu')#
Bases:
objectComputes anisotropic matrix for a time slice from provided magnetic flux and plots its components. Supports interactive selection of matrix element using mouse.
- Attributes:
- figmatplotlib.figure
contains color mesh and countour plot of magnetic surfaces
- fig2matplotlib.figure
contains two subplots with parallel and perpendicular parts of derivative matrix
Methods
onclick(event)Gets coordinate from the click on the main flux plot
update(x, y)Updates plots for current pixel coordinate
- update(x, y)#
Updates plots for current pixel coordinate
- onclick(event)#
Gets coordinate from the click on the main flux plot
4.4. tomotok.tools.containers module#
- class tomotok.tools.containers.Signals(time_axis: ndarray, channel_numbers: ndarray, values: ndarray)#
Bases:
objectContainer for signals.
- class tomotok.tools.containers.Magnetics(time_axis: ndarray, vertical: ndarray, radial: ndarray, flux: ndarray)#
Bases:
objectContainer for magnetics data.
Methods
interpolate(grid[, tvec, unique])Interpolates given magnetic field to provided grid using rectangular bivariate spline.
- interpolate(grid: RegularGrid, tvec: ArrayLike | None = None, unique: bool = False) Magnetics#
Interpolates given magnetic field to provided grid using rectangular bivariate spline.
If tvec is provided, only given time slices are interpolated. If unique is set to True, only unique time slices specified in tvec are interpolated.
- Parameters:
- gridRegularGrid
- tvecarray-like, optional
- uniquebool, optional
If False, the same time slice can be interpolated multiple times to provide field for each value in tvec. If True, only unique time slices specified in tvec are interpolated. Default value is False.
- Returns:
- Magnetics
- class tomotok.tools.containers.Reconstruction(time_axis: ndarray, grid: Grid, values: ndarray)#
Bases:
objectContainer for reconstruction results.
- class tomotok.tools.containers.Sightlines(start_points: ndarray, end_points: ndarray)#
Bases:
objectContainer for sight line coordinates.
- Attributes:
- start_pointsnumpy.ndarray
Array with sight line start points coordinates, with shape (…, 3). Last dimension contains Cartesian coordinates.
- end_pointsnumpy.ndarray
Array with sight line end points coordinates, with shape (…, 3). Last dimension contains Cartesian coordinates.
Methods
coords_r([number])Returns given number of radial coordinates along the sight lines.
coords_z([number])Returns given number of vertical coordinates along the sight lines.
cylindrical_coords([number])Returns given number of cylindrical coordinates along the sight lines.
- coords_r(number: int = 3) ndarray#
Returns given number of radial coordinates along the sight lines.
- Parameters:
- numberint, optional
Number of points to interpolate along the sight line. Default is 3 which is minimum not to overlook tangential sight lines.
4.5. tomotok.tools.divertor module#
- tomotok.tools.divertor.get_divertor_channels(grid: RegularGrid, divertor_area_r: ArrayLike, divertor_area_z: ArrayLike, gmat: ndarray | sparray, method: str = 'any') NDArray[bool]#
Finds channels of geometry matrix that have contributions in the divertor area.
Uses dot product of geometry matrix with divertor area mask matrix obtained from
divertor_area_mask().- Parameters:
- gridRegularGrid
- divertor_area_rArrayLike
radial coordinates of divertor area boundary polygon
- divertor_area_zArrayLike
vertical coordinates of divertor area boundary polygon
- gmatnumpy.ndarray or scipy.sparse.sparray
geometry matrix with shape (# channels, # nodes)
- methodstr, optional
Method for defining divertor area mask. Supported values are ‘any’ and ‘centers’. Default value is ‘any’.
- Returns:
- numpy.ndarray of bool
mask array with True on channels interfering with predefined divertor area
See also
grid.is_inside(),grid.is_inside_any()
- tomotok.tools.divertor.divertor_weighted_matrix(grid: RegularGrid, divertor_area_r: ArrayLike, divertor_area_z: ArrayLike, divertor_weight=0.4, border_matrix: tuple[ndarray, ndarray] | None = None, outside_weight: float = 0.1, outside_weight_sigma: float = 3, method: str = 'any') ndarray#
Computes weight matrix. Supports different weight for pixels located in divertor area or those that are outside vacuum vessel.
This matrix is useful for regularization of inverse problem, where the emission from divertor area is expected to differ from the rest of plasma.
- Parameters:
- gridRegularGrid
- divertor_area_rArrayLike
Radial coordinates of divertor area boundary polygon.
- divertor_area_zArrayLike
Vertical coordinates of divertor area boundary polygon.
- divertor_weightfloat, optional
Specifies divertor pixels’ weight. Default value for divertor is 0.4 and standard weight of pixel is 1. If standard weight is used, the divertor area will not have any preference.
- border_matrixtuple of numpy.ndarray, optional
Coordinates of vacuum vessel border outline in (r, z). If provided, the pixels outside of vacuum vessel will be assigned with outside_weight.
- outside_weightfloat, optional
Specifies weight for pixels outside of vacuum vessel, that is used for smoothing the boundary. Inside nodes are defined by border_matrix parameter. Default value is 0.1
- outside_weight_sigmafloat, optional
Sigma for gaussian filter used for smoothing the boundary between inside and outside of vacuum vessel. Default value is 3.
- methodstr, optional
Method for defining divertor area mask. Supported values are ‘any’ and ‘centers’. Default value is ‘any’.
- Returns:
- numpy.ndarray dtype float64
matrix with pixel weights with same shape as grid (#y pixels, #x pixels)
4.6. tomotok.tools.hdf module#
Handles saving and loading of sparse matrices to/from HDF files.
- Currently supported formats:
scipy.sparse.csc_array
scipy.sparse.csr_array
scipy.sparse.dia_array
- tomotok.tools.hdf.sparse_to_hdf(matrix: csc_array | csr_array | dia_array, group: Group)#
Saves scipy.sparse matrix of formats (csc, csr, dia) into hdf file group.
- tomotok.tools.hdf.hdf_to_sparse(group: Group) spmatrix#
Loads scipy.sparse matrix of formats (csc, csr, dia) from hdf file group.
4.7. tomotok.tools.phantoms module#
Contains utility functions for creation of emissivity phantoms.
The phantoms are based on a gaussian profile as a function of magnetic flux coordinates. A function for creation of a simple flux map with elliptical shape is also provided. Additionally, a function for creation of a polar phase matrix is provided, which can be used to create magnetic island-like structures in the emissivity phantom.
- tomotok.tools.phantoms.regular_elliptical_flux(grid: RegularGrid, span: float | tuple[float, float] = 1.5) ndarray#
Creates a matrix of artificial flux surfaces with elliptical shape based on provided grid.
- tomotok.tools.phantoms.elliptical_flux(radial_num: int, vertical_num: int, span: float | tuple[float, float] = 1.5) ndarray#
Creates a matrix of artificial flux surfaces with elliptical shape.
Minimum values at the border are determined by the span parameter.
- Parameters:
- radial_numint
number of nodes along radial axis
- vertical_numint
number of nodes along vertical axis
- spanfloat or tuple of two floats, optional
flux value at the center of grid edge if tuple, first value is for radial axis, second for vertical
- Returns:
- numpy.ndarray
Matrix with generated fluxes
- tomotok.tools.phantoms.gaussian_on_flux(flux: ndarray, amplitude: float = 1, center: float = 0, width: float = 0.1, limit: float = 1, limit_width: float = 0.2, limit_power: int = 2) ndarray#
Creates gaussian artificial emissivity profile by transforming provided flux values
\[f = a \mathrm{e}^{-(f - c)^2 / w }\]The limit width parameter allows to create a smooth transition from gaussian profile to zero at the limit value of flux. This is done by multiplying the gaussian profile with a polynomial function that goes from 1 to 0 in the range of limit - limit_width to limit.
- Parameters:
- fluxnp.ndarray
Flux values for transformation, any shape is supported
- amplitudefloat, optional
maximum of gaussian profile,
- centerfloat, optional
center of gaussian profile allows hollow profile generation when mapped on psi
- widthfloat, optional
width of gaussian profile
- limitfloat, optional
flux value where emissivity is forced to reach zero if flux > limit emissivity is set to zero
- limit_widthfloat, optional
width of transition from gaussian profile to zero at limit value of flux
- limit_powerfloat, optional
power of polynomial transition from gaussian profile to zero at limit value of flux
- Returns:
- numpy.ndarray
Transformed values of x with same dimensions
- tomotok.tools.phantoms.polar_phase_matrix(grid: RegularGrid, num: int = 3, shift: float = 0.0, center: tuple[float, float] | None = None) ndarray#
Creates a matrix with sine phase in poloidal direction relative to provided center.
The intended use is to modify an emissivity pattern by multiplying it with the returned matrix. This could be used to create island-like radiating structures in the phantom. The phase is applied in the positive angle direction (counterclockwise). If center is not provided, the grid centre is used.
- Parameters:
- gridRegularGrid
grid for which the phase matrix is generated
- numint, optional
number of periods per one rotation
- shiftfloat, optional
initial phase shift in degrees
- centertuple of two floats, optional
center of polar phase, if None, grid centre is used
- tomotok.tools.phantoms.iso_psi(nx: int, ny: int, span: float = 1.5) ndarray#
Creates matrix of artificial isotropic psi profile with border values for each axis equal to span.
Deprecated since version 2.0: Use
elliptical_flux()instead.- Parameters:
- nxint
Number of pixels on x axis
- nyint
Number of pixels on y axis
- spanfloat, optional
Value of result on the center of border
- Returns:
- numpy.ndarray
Matrix with generated profile
- tomotok.tools.phantoms.gauss(x: ndarray, w: float = 0.1, lim: float = 1, amp: float = 1, cen: float = 0.0) ndarray#
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)\]Deprecated since version 2.0: Use
gaussian_on_flux()instead.Can be used on np.ndarray. Lim should be greater than cen.
- Parameters:
- xfloat, array, np.ndarray
Contains values to be transformed, usually psi
- wfloat, optional
width of gaussian profile
- limfloat, optional
minimal value of x where transform gives zero if x > lim emissivity is set to zero
- ampfloat, optional
amplitude of gaussian profile,
- cenfloat, optional
center of gaussian profile allows hollow profile generation when mapped on psi
- Returns:
- numpy.ndarray
Transformed values of x with same dimensions
- tomotok.tools.phantoms.gauss_iso(nx: int, ny: int, span: float = 1.2, w: float = 0.1, lim: float = 1, amp: float = 1, cen: float = 0.0) ndarray#
Creates isotropic gaussian distribution. See references for iso_psi and gauss
Deprecated since version 2.0: Use
gaussian_on_flux()instead.
- tomotok.tools.phantoms.polar_phase(x: ndarray, num: int = 3, shift: float = 0) ndarray#
Applies sine phase in radial angle direction to given profile x.
Assumes equal dimension of grid elements in both axes.
Deprecated since version 2.0: Use
polar_phase_matrix()instead.- Parameters:
- xnumpy.ndarray
Profile for application of polar phase.
- numint, optional
number of periods per one rotation
- shiftfloat, optional
initial phase shift
- Returns:
- numpy.ndarray
Matrix with applied polar phase
- tomotok.tools.phantoms.islands(psi: ndarray, w: float = 0.01, lim: float = 1, amp: float = 1, cen: float = 0.4, num: int = 3, shift: float = 0.0) ndarray#
Creates island like phantom from given psi profile. See references for gauss and polar_phase.
Deprecated since version 2.0: Use
gaussian_on_flux()andpolar_phase_matrix()insteadSee also