1.1.4. tomotok.core.tools package

Contains various tools to ease using the package.

  • DataHandler class prototype
  • projection space plot of a system

1.1.4.1. Submodules

1.1.4.2. tomotok.core.tools.checkers module

Contains classes and functions for user checking of some tomography algorithm parts

1.1.4.2.1. Examples

Checking anisotropic derivative matrix computed from DataArray with magnetic flux surfaces magnetic_flux

>>> from tomotok.core.io import Pixgrid, Tokamak
>>> time = 1.2
>>> shot = 19925
>>> coord = Pixgrid(50, 100, (0.5, 1), (-0.5, 0.5))
>>> magf = Tokamak.interpolate_mag_field(magnetic_flux, coord)
>>> checker = DerivMatChecker(coord, magf)
>>> checker(time)

# TODO Plotting geometry matrix stored at local drive

>>> from tomotok.utils.gmat import load_function  # not implemented yet
>>> gmat = load_function('path/to/gmat/file')
>>> fig = check_gmat(gmat)
class tomotok.core.tools.checkers.DerivMatChecker(coord, magfield)

Bases: object

Computes anisotropic matrix for a time slice from provided magnetic flux and plots its components. Supports interactive selection of matrix element using mouse.

Parameters:

coord : Pixgrid

magfield : dict

Attributes

fig (matplotlib.figure) contains color mesh and countour plot of magnetic surfaces
fig2 ( matplotlib.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

tomotok.core.tools.checkers.check_gmat(gmat)

Checks geometry matrix by summing all channels and plotting.

Parameters:gmat : dict
Returns:fig : matplotlib.pyplot.figure

1.1.4.3. tomotok.core.tools.data module

WIP

Contains class that does data filtering and stuff. It can also handle error estimation.

class tomotok.core.tools.data.DataHandler(data, min_error=0)

Bases: object

Does filtering and stuff

Attributes

chnls (np.ndarray)
time (np.ndarray)
data (np.ndarray)
errors (np.ndarray)

Methods

add_errors(err)
Parameters:err :
average(avg_num, tvec)
butter_bandpass_filter(lowcut, highcut, fs, order=5)
crop_data(tlim, extend_num=None)

Cuts data to requested interval

Parameters:

tlim : tuple

contains limits of requested time axis

extend_num : int, optional

contains number of points outside tlim for filtering methods (default value is calculated to fit chosen filtering method) <- should be determined by user

downsample(n, average=False)

Keeps only each n-th time slice of data.

Parameters:

n : int

average : bool, optional

not implemented yet

errors_scalar_multiply(scalar)
fourier(freqs)

Transforms data to frequency domain using fourier transform

Parameters:

freqs : list

values of frequencies used for new time vector

Returns:

DataHandler

new instance of DataHandler with transformed data and errors

interpolate(tvec)

Interpolates both data and errors to given time vector.

Parameters:tvec : int, float, np.ndarray
Returns:data, err : ndarray
median_filter(kernel_size=1, error_type=’sem’)
plot_chnls(chnls=None)
plot_time(time=0)
remove_below(threshold)

Removes channels with average signal bellow given threshold

Parameters:threshold : float
remove_chnls(chnls)

Removes specified channels from data

Parameters:chnls : iterable of ints
remove_nan_chnls()

Removes channels that contain at least one Nan value.

remove_zero_chnls()
reset(min_error=0)

1.1.4.4. tomotok.core.tools.gifmaker module

1.1.4.5. tomotok.core.tools.hdf module

Handles saving and loading of sparse matrices to/from HDF files.

Currently supported formats:
  • scipy.sparse.csc_matrix
  • scipy.sparse.csr_matrix
  • scipy.sparse.dia_matrix
tomotok.core.tools.hdf.cs_to_hdf(matrix: typing.Union[scipy.sparse.csc.csc_matrix, scipy.sparse.csr.csr_matrix], group: h5py._hl.group.Group)

Saves compressed sparse matrix to hdf group.

tomotok.core.tools.hdf.dia_to_hdf(matrix: scipy.sparse.dia.dia_matrix, group: h5py._hl.group.Group)

Saves dia matrix to hdf group.

tomotok.core.tools.hdf.hdf_to_cs(group: h5py._hl.group.Group) → typing.Union[scipy.sparse.csc.csc_matrix, scipy.sparse.csr.csr_matrix]

Loads compressed sparse matrix from hdf group.

tomotok.core.tools.hdf.hdf_to_dia(group: h5py._hl.group.Group) → scipy.sparse.dia.dia_matrix

Loads dia matrix from hdf group.

tomotok.core.tools.hdf.hdf_to_sparse(group: h5py._hl.group.Group) → scipy.sparse.base.spmatrix

Loads scipy.sparse matrix of formats (csc, csr, dia) from hdf file group.

tomotok.core.tools.hdf.sparse_to_hdf(matrix: typing.Union[scipy.sparse.dia.dia_matrix, scipy.sparse.csc.csc_matrix, scipy.sparse.csr.csr_matrix], group: h5py._hl.group.Group)

Saves scipy.sparse matrix of formats (csc, csr, dia) into hdf file group.

1.1.4.6. tomotok.core.tools.postproc module

tomotok.core.tools.postproc.compute_power(recs, grid)

Computes total radiated power from whole reconstruction area.

Parameters:

grid : RegularGrid

Returns:

numpy.ndarray

Contains values of total radiated power for all time slices

tomotok.core.tools.postproc.plot(recs, ts=0)

Moved from BaseMfr class

1.1.4.7. tomotok.core.tools.projection module

tomotok.core.tools.projection.projection_space(chords, centre=(0, 0), magnetics=None, maglvl=1)
Parameters:

chords : tuple

centre : tuple of float

magnetics : dict

maglvl : float, list of float

Returns:

fig : matplotlib.figure