tofu.data package

Provide data handling class and methods (storing, processing, plotting…)

Submodules

tofu.data._comp module

tofu.data._comp.calc_svd(data, lapack_driver='gesdd')[source]
tofu.data._comp.filter_bandpass_fourier(t, data, method='stft', detrend='linear', df=None, harm=True, df_out=None, harm_out=True)[source]

Return bandpass FFT-filtered signal (and the rest)

Optionnally include all higher harmonics Can also exclude a frequency interval and its higher harmonics

Parameters
  • t (np.ndarray) – 1D array, monotonously increasing time vector with regular spacing

  • data (np.ndarray) – 1 or 2D array, with shape[0]=t.size, the data to be filtered

  • method (str) –

    Flag indicating which method to use:
    • ’rfft’: scipy.fftpack.rfft

    • ’stft’: scipy.signal.stft

  • df (None / list) – List or tuple of len()=2, containing the bandpass lower / upper bounds

  • harm (bool) – If True all the higher harmonics of df will also be included

  • df_out (None / list) – List or tuple of len()=2, containing the bandpass lower / upper bounds to be excluded from filtering (if it overlaps with high harmonics of df)

  • harm_out (bool) – If True, the higher harmonics of the interval df_out are also excluded

  • Test (bool) – If True tests all the input arguments for any mistake

Returns

  • In (np.ndarray) – Array with shape=data.shape, filtered signal retrieved from inverse FFT

  • Out (np.ndarray) – Array with shape=data.shape, excluded signal from filtering

tofu.data._comp.filter_svd(data, lapack_driver='gesdd', modes=[])[source]

Return the svd-filtered signal using only the selected mode

Provide the indices of the modes desired

tofu.data._comp.get_finterp_ani(plasma, idq2dR, idq2dPhi, idq2dZ, interp_t='nearest', interp_space=None, fill_value=None, mpltri=None, idmesh=None, vq2dR=None, vq2dPhi=None, vq2dZ=None, tall=None, tbinall=None, ntall=None, indtq=None, trifind=None, Type=None)[source]
tofu.data._comp.get_finterp_isotropic(plasma, idquant, idref1d, idref2d, interp_t='nearest', interp_space=None, fill_value=None, idmesh=None, mpltri=None, vquant=None, tall=None, tbinall=None, ntall=None, indtq=None, indtr1=None, indtr2=None, trifind=None)[source]
tofu.data._comp.spectrogram(data, t, fmin=None, method='scipy-fourier', deg=False, window='hann', detrend='linear', nperseg=None, noverlap=None, boundary='constant', padded=True, wave='morlet', warn=True)[source]

tofu.data._core module

class tofu.data._core.DataCam1D(data=None, t=None, X=None, lamb=None, dchans=None, dlabels=None, dX12='geom', Id=None, Name=None, Exp=None, shot=None, Diag=None, dextra=None, lCam=None, config=None, fromdict=None, sep=None, SavePath='/home/lasofivec/tofu/doc/source', SavePath_Include=['Mod', 'Cls', 'Type', 'Exp', 'Deg', 'Diag', 'Name', 'shot'])[source]

Bases: tofu.data._core.DataAbstract

Data object used for 1D cameras or list of 1D cameras

class tofu.data._core.DataCam2D(data=None, t=None, X=None, lamb=None, dchans=None, dlabels=None, dX12='geom', Id=None, Name=None, Exp=None, shot=None, Diag=None, dextra=None, lCam=None, config=None, fromdict=None, sep=None, SavePath='/home/lasofivec/tofu/doc/source', SavePath_Include=['Mod', 'Cls', 'Type', 'Exp', 'Deg', 'Diag', 'Name', 'shot'])[source]

Bases: tofu.data._core.DataAbstract

Data object used for 2D cameras or list of 2D cameras

property dX12
get_X12plot(plot='imshow')[source]
set_dX12(dX12=None)[source]
class tofu.data._core.DataCam1DSpectral(data=None, t=None, X=None, lamb=None, dchans=None, dlabels=None, dX12='geom', Id=None, Name=None, Exp=None, shot=None, Diag=None, dextra=None, lCam=None, config=None, fromdict=None, sep=None, SavePath='/home/lasofivec/tofu/doc/source', SavePath_Include=['Mod', 'Cls', 'Type', 'Exp', 'Deg', 'Diag', 'Name', 'shot'])[source]

Bases: tofu.data._core.DataCam1D

Data object used for 1D cameras or list of 1D cameras

property lamb
property nlamb
class tofu.data._core.DataCam2DSpectral(data=None, t=None, X=None, lamb=None, dchans=None, dlabels=None, dX12='geom', Id=None, Name=None, Exp=None, shot=None, Diag=None, dextra=None, lCam=None, config=None, fromdict=None, sep=None, SavePath='/home/lasofivec/tofu/doc/source', SavePath_Include=['Mod', 'Cls', 'Type', 'Exp', 'Deg', 'Diag', 'Name', 'shot'])[source]

Bases: tofu.data._core.DataCam2D

Data object used for 1D cameras or list of 1D cameras

property lamb
property nlamb
class tofu.data._core.Plasma2D(dtime=None, dradius=None, d0d=None, d1d=None, d2d=None, dmesh=None, config=None, Id=None, Name=None, Exp=None, shot=None, fromdict=None, sep=None, SavePath='/home/lasofivec/tofu/doc/source', SavePath_Include=['Mod', 'Cls', 'Type', 'Exp', 'Deg', 'Diag', 'Name', 'shot'])[source]

Bases: tofu.utils.ToFuObject

A generic class for handling 2D (and 1D) plasma profiles

Provides:
  • equilibrium-related quantities

  • any 1d profile (can be remapped on 2D equilibrium)

  • spatial interpolation methods

add_quantity(key=None, data=None, depend=None, dim=None, quant=None, units=None, origin=None, name=None)[source]

Add a quantity

add_ref(key=None, data=None, group=None, dim=None, quant=None, units=None, origin=None, name=None)[source]

Add a reference

calc_signal_from_Cam(cam, t=None, quant=None, ref1d=None, ref2d=None, q2dR=None, q2dPhi=None, q2dZ=None, Brightness=True, interp_t=None, interp_space=None, fill_value=None, res=0.005, DL=None, resMode='abs', method='sum', ind=None, out=<class 'object'>, plot=True, dataname=None, fs=None, dmargin=None, wintit=None, invert=True, units=None, draw=True, connect=True)[source]
compute_bremzeff(Te=None, ne=None, zeff=None, lamb=None, tTe=None, tne=None, tzeff=None, t=None, interp_t=None)[source]

Return the bremsstrahlung spectral radiance at lamb

The plasma conditions are set by:
  • Te (eV)

  • ne (/m3)

  • zeff (adim.)

The wavelength is set by the diagnostics
  • lamb (m)

The vol. spectral emis. is returned in ph / (s.m3.sr.m)

The computation requires an intermediate : gff(Te, zeff)

compute_fanglev(BR=None, BPhi=None, BZ=None, ne=None, lamb=None, t=None, interp_t=None, tBR=None, tBPhi=None, tBZ=None, tne=None)[source]

Return the vector faraday angle at lamb

The plasma conditions are set by:
  • BR (T) , array of R component of B

  • BRPhi (T) , array of phi component of B

  • BZ (T) , array of Z component of B

  • ne (/m3)

The wavelength is set by the diagnostics
  • lamb (m)

The vector faraday angle is returned in T / m

property config
property ddata
property dgroup
property dindref
property dmesh
property dradius
property dtime
get_Data(lquant, X=None, ref1d=None, ref2d=None, remap=False, res=0.01, interp_space=None, dextra=None)[source]
get_dextra(dextra=None)[source]
get_finterp2d(quant=None, ref1d=None, ref2d=None, q2dR=None, q2dPhi=None, q2dZ=None, interp_t=None, interp_space=None, fill_value=None, Type=None)[source]

Return the function interpolating (X,Y,Z) pts on a 1d/2d profile

Can be used as input for tf.geom.CamLOS1D/2D.calc_signal()

get_summary(sep=' ', line='-', just='l', table_sep=None, verb=True, return_=False)[source]

Summary description of the object content

get_tcommon(lq, prefer='finer')[source]

Check if common t, else choose according to prefer

By default, prefer the finer time resolution

get_time(key)[source]

Return the time vector associated to a chosen quantity (identified by its key)

get_time_common(lkeys, choose=None)[source]

Return the common time vector to several quantities

If they do not have a common time vector, a reference one is choosen according to criterion choose

interp_pts2profile(pts=None, vect=None, t=None, quant=None, ref1d=None, ref2d=None, q2dR=None, q2dPhi=None, q2dZ=None, interp_t=None, interp_space=None, fill_value=None, Type=None)[source]

Return the value of the desired profiles_1d quantity

For the desired inputs points (pts):
  • pts are in (X,Y,Z) coordinates

  • space interpolation is linear on the 1d profiles

At the desired input times (t):
  • using a nearest-neighbourg approach for time

interp_t(dkeys, choose='min', interp_t=None, t=None, fill_value=nan)[source]
plot(lquant, X=None, ref1d=None, ref2d=None, remap=False, res=0.01, interp_space=None, sharex=False, bck=True)[source]
plot_combine(lquant, lData=None, X=None, ref1d=None, ref2d=None, remap=False, res=0.01, interp_space=None, sharex=False, bck=True)[source]

plot combining several quantities from the Plasma2D itself and optional extra list of Data instances

set_dgeom(config=None)[source]
strip(strip=0, verb=True)[source]

Remove non-essential attributes to save memory / disk usage

Useful to save a very compressed version of the object The higher strip => the more stripped the object Use strip=0 to recover all atributes

See the difference by doing:

> self.get_nbytes() > self.strip(-1) > self.get_nbytes()

Parameters

strip (int) –

Flag indicating how much to strip from the object

0: Make complete (retrieve all attributes) 1: dgeom pathfiles

-1: Equivalent to strip=1

tofu.data._core_new module

class tofu.data._core_new.DataHolder(dref=None, ddata=None, Id=None, Name=None, fromdict=None, SavePath='/home/lasofivec/tofu/doc/source', SavePath_Include=['Mod', 'Cls', 'Type', 'Exp', 'Deg', 'Diag', 'Name', 'shot'])[source]

Bases: tofu.utils.ToFuObject

A generic class for handling data

Provides methods for:
  • introspection

  • plateaux finding

  • visualization

add_data(key, data=None, ref=None, **kwdargs)[source]

Add a data (all associated ref must be added first))

add_param(param, values=None)[source]
add_ref(key, data=None, group=None, **kwdargs)[source]

Add a reference

property dconfig

The dict of configs

property ddata

the dict of data

property dgroup

The dict of groups

property dref

the dict of references

get_param(param=None, returnas=<class 'numpy.ndarray'>)[source]
get_summary(show=None, show_core=None, sep=' ', line='-', just='l', table_sep=None, verb=True, return_=False)[source]

Summary description of the object content

get_tcommon(lq, prefer='finer')[source]

Check if common t, else choose according to prefer

By default, prefer the finer time resolution

get_time_common(lkeys, choose=None)[source]

Return the common time vector to several quantities

If they do not have a common time vector, a reference one is choosen according to criterion choose

interp_t(dkeys, choose='min', interp_t=None, t=None, fill_value=nan)[source]
property ldata

the dict of data

property lgroup

The dict of groups

property lparam

the dict of data

property lref

the dict of references

plot(lquant, X=None, ref1d=None, ref2d=None, remap=False, res=0.01, interp_space=None, sharex=False, bck=True)[source]
plot_combine(lquant, lData=None, X=None, ref1d=None, ref2d=None, remap=False, res=0.01, interp_space=None, sharex=False, bck=True)[source]

plot combining several quantities from the Plasma2D itself and optional extra list of Data instances

remove_data(key, propagate=True)[source]

Remove a data

Any associated ref reated to this data only is removed too (useless)

remove_param(param=None)[source]
remove_ref(key)[source]

Remove a reference (all data depending on it are removed too)

select(group=None, ref=None, log='all', return_key=True, **kwdargs)[source]

Return the indices / keys of data matching criteria

The selection is done comparing the value of all provided parameters The result is a boolean indices array, optionally with the keys list It can include:

  • log = ‘all’: only the data matching all criteria

  • log = ‘any’: the data matching any criterion

If log = ‘raw’, a dict of indices arrays is returned, showing the details for each criterion

set_param(param=None, values=None, ind=None, key=None)[source]
strip(strip=0, verb=True)[source]

Remove non-essential attributes to save memory / disk usage

Useful to save a very compressed version of the object The higher strip => the more stripped the object Use strip=0 to recover all atributes

See the difference by doing:

> self.get_nbytes() > self.strip(-1) > self.get_nbytes()

Parameters

strip (int) –

Flag indicating how much to strip from the object

0: Make complete (retrieve all attributes) 1: None

-1: Equivalent to strip=1

tofu.data._def module

tofu.data._plot module

tofu.data._plot.Data_plot(lData, key=None, bck=True, indref=0, cmap=None, ms=4, vmin=None, vmax=None, vmin_map=None, vmax_map=None, cmap_map=None, normt_map=False, ntMax=None, nchMax=None, nlbdMax=None, inct=[1, 10], incX=[1, 5], inclbd=[1, 10], lls=None, lct=None, lcch=None, lclbd=None, cbck=None, fmt_t='06.3f', fmt_X='01.0f', fmt_l='07.3f', invert=True, Lplot='In', dmarker=None, sharey=True, sharelamb=True, fs=None, dmargin=None, wintit=None, tit=None, fontsize=None, labelpad=None, draw=True, connect=True)[source]
tofu.data._plot.Data_plot_combine(lData, key=None, bck=True, indref=0, cmap=None, ms=4, vmin=None, vmax=None, vmin_map=None, vmax_map=None, cmap_map=None, normt_map=False, ntMax=None, nchMax=None, nlbdMax=3, inct=[1, 10], incX=[1, 5], inclbd=[1, 10], lls=None, lct=None, lcch=None, lclbd=None, cbck=None, fmt_t='06.3f', fmt_X='01.0f', sharex=False, invert=True, Lplot='In', dmarker=None, fs=None, dmargin=None, wintit=None, tit=None, fontsize=None, labelpad=None, draw=True, connect=True)[source]
tofu.data._plot.Data_plot_spectrogram(Data, tf, f, lpsd, lang, fmax=None, key=None, bck=True, indref=0, cmap_f=None, cmap_img=None, ms=4, vmin=None, vmax=None, normt=False, ntMax=None, nfMax=3, lls=['-', '--', '-.', ':'], lct=[(0.12156862745098039, 0.4666666666666667, 0.7058823529411765), (1.0, 0.4980392156862745, 0.054901960784313725), (0.17254901960784313, 0.6274509803921569, 0.17254901960784313), (0.6823529411764706, 0.7803921568627451, 0.9098039215686274), (1.0, 0.7333333333333333, 0.47058823529411764), (0.596078431372549, 0.8745098039215686, 0.5411764705882353)], lcch=[(0.8392156862745098, 0.15294117647058825, 0.1568627450980392), (0.5803921568627451, 0.403921568627451, 0.7411764705882353), (0.5490196078431373, 0.33725490196078434, 0.29411764705882354), (1.0, 0.596078431372549, 0.5882352941176471), (0.7725490196078432, 0.6901960784313725, 0.8352941176470589), (0.7686274509803922, 0.611764705882353, 0.5803921568627451)], plotmethod='imshow', invert=False, fs=None, dmargin=None, wintit='tofu-1.4.6-2-g7a0d42d4 report issues / requests at https://github.com/ToFuProject/tofu/issues', tit=None, fontsize=None, draw=True, connect=True)[source]

tofu.data._spectrafit2d module

tofu.data._spectrafit2d.fit_spectra2d_x0_per_row()[source]
tofu.data._spectrafit2d.fit_spectra_2d(data2d, indt=None, nbin_init=None, nmax=None, bck=None, nbsplines=None)[source]

Return fitted spectra

Can handle unique or multiple time Takes already formatted 2d data:

  • (nx, ny)

  • (nt, nx, ny)

x being the horizontal / spectral direction (lambda)

tofu.data._spectrafit2d.get_2dspectralfit_func(lamb0, forcelamb=False, deg=None, knots=None)[source]
tofu.data._spectrafit2d.get_dindx(bckdeg=None, dlines=None, nbs=None)[source]
tofu.data._spectrafit2d.get_func1d_all(n=5, lamb0=None)[source]
tofu.data._spectrafit2d.get_func1d_lamb0fix(n=5, lamb0=None)[source]
tofu.data._spectrafit2d.get_func2d(y0, y1, x0_y, bspl_n, bspl_deg)[source]
tofu.data._spectrafit2d.get_funccostjac()[source]
tofu.data._spectrafit2d.get_knots_nbs_for_bsplines(knots_unique, deg)[source]
tofu.data._spectrafit2d.get_lamb0_from_dlines(dlines)[source]
tofu.data._spectrafit2d.get_multigaussianfit2d_costfunc(lamb=None, phi=None, data=None, std=None, lamb0=None, forcelamb=None, deg=None, knots=None, nlamb0=None, nkperbs=None, nbs=None, nc=None, debug=None)[source]
tofu.data._spectrafit2d.get_p0bounds_all(x, y, nmax=None, lamb0=None)[source]
tofu.data._spectrafit2d.get_p0bounds_lambfix(x, y, nmax=None, lamb0=None)[source]
tofu.data._spectrafit2d.get_peaks(x, y, nmax=None)[source]
tofu.data._spectrafit2d.get_x0_bounds(x01d=None, dlines=None, dindx=None, lamb=None, data=None)[source]
tofu.data._spectrafit2d.multigaussianfit2d(lamb, phi, data, std=None, lamb0=None, forcelamb=None, knots=None, deg=None, nbsplines=None, x0=None, bounds=None, method=None, max_nfev=None, xtol=None, ftol=None, gtol=None, loss=None, verbose=0, debug=None)[source]
tofu.data._spectrafit2d.multiplegaussianfit1d(x, spectra, nmax=None, lamb0=None, forcelamb=None, p0=None, bounds=None, max_nfev=None, xtol=None, verbose=0, percent=None, plot_debug=False)[source]
tofu.data._spectrafit2d.remove_bck(x, y)[source]