1.1.3. tomotok.core.io package¶
Contains classes and functions used for creating database interfaces.
- base class Dsystem for a general diagnostic system
- sublcass with magnetics handling typical for tokamaks
- simple hdf interface using h5py
1.1.3.1. Submodules¶
1.1.3.2. tomotok.core.io.diag module¶
Template class for general tomographic diagnostic system.
-
class
tomotok.core.io.diag.
Dsystem
(shot, geometry_path=”, **kw)¶ Bases:
object
Contains basic information about diagnostic system
Attributes
chnl_index (dict) dict maping channel to detector geometry_path (pathlib.Path) path to location with saved geometrical data name (str) name of diagnostic system n_dets (int) number of cameras with separate calibration files, (to be removed) Methods
-
compute_bd_mat
(grid, loc=None)¶ Simple generation of boundary matrix 1 inside rec area, 0 outside
Deprecated since version 1.3.0.
Parameters: grid : RegularGrid
Returns: boundary_matrix : numpy.ndarray of bool
matrix with true inside border, false otherwise, with shape (grid.nz, grid.nr)
-
data_name
¶ Template data file name
-
download_data
(**kwargs)¶ Downloads data from network/database using source method or database.
Returns: dict
-
fetch_data
(data_path=”, source=None, save=False, force_dl=False)¶ Loads data from data storage specified by data_path or downloads data from network storage.
Parameters: data_path : str or Path, optional
default is working directory
source :
string
, optionalspecifies method for data download
save : bool, optional
switches saving to local storage
force_dl : bool, optional
forces download of data
Returns: dict
-
get_calb
()¶ Loads preset calibrations for detectors, if not specified returns array of ones with length n_dets.
-
get_chord_geometry
()¶ Loads chord geometry from geometry_path.
Expected names of detectors are detector_[num]_[x,y].txt. Data for x and y coordinates are in separate files. Each row represents one detector. Number of rows and columns should be same in all files containing coordinates
Returns: xchords, ychords : numpy.ndarray
arrays with coordinates of chord points with shape (#chords, #points)
-
get_chord_widening
()¶ Tries to load widening coefficients from file. Returns None if IOError
Returns: array-like or None
Contains widening coefficients for each channel
-
get_pinholes
()¶ Loads pinhole coordinates for each chord from pinholes.txt located in geometry folder.
Returns: ph : numpy.ndarray
matrix containing pinhole x,y coordinates with shape (#chords, 2)
-
load_border
(loc=None)¶ Load border coordinates from geometry path or from tokamak module. Sets boundary_coord attribute to loaded coords.
Parameters: loc : str or Path
Returns: numpy.ndarray
contains (R, z) coordinates of vacuum vessel cross section, shape (#points, 2)
-
load_boundary_coord
()¶ Load border coordinates from geometry path or from tokamak module. Sets boundary_coord attribute to loaded coords.
Returns: numpy.ndarray
contains (R, z) coordinates of vacuum vessel cross section points, should have shape (#points, 2)
-
load_data
(loc)¶ Loads hdf file containing data.
If loc is path to a directory, default data file name from property data_name is assumed.
Parameters: loc : str or Path
Path to file with signal data. Can be full path or path to folder if default name is used.
Returns: dict
keys values, chnl, time
-
load_los
(loc=None)¶ Loads line of sights geometry from hdf file.
Parameters: loc : str or Path, optional
location of los file, by default geometry path is used
Returns: dict
with coordinates of los start and end points with shape (2, #chords, 3)
-
static
save_data
(loc, data)¶ Saves downloaded detector data to data_path
Parameters: loc : str or pathlib.Path
saving path with file name
data : dict
contains signal values, channel numbers and time stamps
-
1.1.3.3. tomotok.core.io.support module¶
Simple hdf saving and loading functions
-
tomotok.core.io.support.
from_hdf
(floc)¶
-
tomotok.core.io.support.
to_hdf
(dct, floc, attrs={})¶ Saves provided dict into a hdf file
Parameters: dct : dict
[description]
floc : str
path to file with name
attrs : dict
metadata to be saved to attributes
1.1.3.4. tomotok.core.io.tokamaks module¶
Universal tokamak template class for creating machine specific subclasses
-
class
tomotok.core.io.tokamaks.
Tokamak
(shot, **kwargs)¶ Bases:
tomotok.core.io.diag.Dsystem
Handles magnetic field and divertor
Attributes
name (str) Name of tokamak params (dict) Keyword arguments provided to initialization divertor_coord (tuple of float) Contains bounds for divertor area. (x1, x2, y1, y2) Methods
-
compute_weight_matrix
(grid, diw=0.4, smooth_boundary=None, bdr=None)¶ Computes weight matrix. Supports different weight for pixels located in divertor area or those that are outside vacuum vessel.
Parameters: grid : RegularGrid
diw : float, 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.
smooth_boundary : float, optional
Specifies weight for pixels outside of vacuum vessel, that is used for smoothing the boundary. Vacuum vessel coordinates are defined by bdr parameter. Recommended value is 0.1
bdr : tuple of numpy.ndarray
Contains coordinates of vacuum vessel border. Must be provided if smooth_boundary is requested.
Returns: numpy.ndarray dtype float64
matrix with pixel weights with same shape as grid (#y pixels, #x pixels)
-
download_mag_field
(shot, tvec=None, source=None)¶ Dowloads magnetic field data from network.
Parameters: shot : int
tvec : list-like, optional
specifies timeslices to be loaded
source : string, optional
specifies source for loading magnetics data
Returns: dict
Psi normalized stored in dict with keys (values, time, z, r)
-
fetch_mag_field
(shot, mag_path, grid=None, tvec=None, save=False, force_dl=False)¶ Loads magnetic field from local storage or database and interpolates it if grid is provided.
Parameters: shot : int
mag_path : str or Path
grid : RegularGrid, optional
Returned values are interpolated to this grid if provided.
tvec : numpy.ndarray, optional
Time vector of requested magnetic field for download
save : bool, optional
force_dl : bool, optional
forces download from remote database
-
get_divertor_area
(grid, boundary=None)¶ Returns mask matrix with True for indexes representing pixels inside predefined divertor area. Size and shape is obtained from
grid
.Parameters: grid : RegularGrid
boundary : numpy.ndarray, optional
Boundary matrix with same shape as grid
Returns: numpy.ndarray
Bool mask matrix for determining divertor pixels with shape ny, nx
-
get_divertor_chnls
(gmat, grid, boundary=None)¶ Finds channels of geometry matrix that have contributions in divertor area. Uses dot product of geometry and divertor area matrices.
Parameters: gmat : csr_matrix
grid : RegularGrid
boundary : numpy.ndarray, optional
Boundary matrix with same shape as grid
Returns: mask : numpy.ndarray of bool
mask array with True on channels interfering with predefined divertor area
-
static
interpolate_mag_field
(magfield, grid, tvec=None)¶ Interpolates given magnetic field to provided grid using rectangular bivariate spline.
If tvec is provided, only one nearest time slice of magnetic field is interpolated for each value in tvec.
Parameters: magfield : dict
grid : RegularGrid
tvec : int, float, list, tuple, np.ndarray, optional
Returns: dict
-
load_mag_field
(loc)¶ Loads magnetic field from hdf file saved at loc
If loc is path to a directory, default data file name from property mag_name is assumed.
Parameters: loc : str or Path
location of hdf file containing magnetic field
Returns: dict
Psi normalized stored in dict with keys (values, time, z, R)
-
mag_name
¶
-
static
save_mag_field
(loc, mag_field)¶ Saves magnetic field into hdf file.
Expects to have name included to mag_loc if magname is omitted.
Parameters: loc : str or pathlib.Path
Path to file
mag_field : dict, optional
DataArray with magnetic field
-