Diagnostic tools#
Diagnostics are a vital part for interpreting simulation results. Sometimes these tools just facilitate a proper visualization of the results. Struphy aims to provide a wide range of diagnostic tools that have general applicability.
Plotting and video#
- struphy.diagnostics.diagn_tools.power_spectrum_2d(values: dict, name: str, grids: tuple, grids_mapped: tuple | None = None, component: int = 0, slice_at: tuple = (None, 0, 0), do_plot: bool = False, disp_name: str | None = None, disp_params: dict = {}, fit_branches: int = 0, noise_level: float = 0.1, extr_order: int = 10, fit_degree: tuple = (1,), save_plot: bool = False, save_name: str | None = None, file_format: str = 'png')[source]#
Perform fft in space-time, (t, x) -> (omega, k), where x can be a logical or physical coordinate. Returns values if plot=False.
- Parameters:
values (dict) – Dictionary holding values of a B-spline FemField on the grid as 3d xp.arrays: values[n] contains the values at time step n, where n = 0:Nt-1:step with 0<step.
name (str) – Name of the FemField.
grids (3-tuple) – 1d logical grids in each eta-direction with Nel[i]*npts_per_cell[i] + 1 entries in each direction.
grids_mapped (3-tuple) – Mapped grids obtained by domain(). If None, the fft is performed on the logical grids.
component (int) – Which component of a FemField to consider; is 0 for 0-and 3-forms, is in {0, 1, 2} for 1- and 2-forms.
slice_at (3-tuple) – At which indices i, j the 1d slice data (t, eta)_(i, j) should be obtained. One entry must be “None”; this is the direction of the fft. Default: [None, 0, 0] performs the eta1-fft at (eta2[0], eta3[0]).
do_plot (boolean) – Plot result if True, otherwise return things.
disp_name (str) – The name of the dispersion relation class in struphy.dispersion_relations.analytic to be used for analytic comparison.
disp_params (dict) – Parameters needed for analytical dispersion relation, see struphy.dispersion_relations.analytic.
fit_branches (int) – How many branches to fit in the dispersion relation. Default=0 means no fits are made.
noise_level (float) – Sets the threshold above which local maxima in the power spectrum are taken into account. Computed as threshold = max(spectrum) * noise_level.
extr_oder (int) – Order given to argrelextrema.
fit_degree (tuple[int]) – Degree of fitting polynomial for each branch (fit_branches) of power spectrum.
save_plot (boolean) – Save figure if True. Then a path has to be given.
save_name (str) – Name under which the plot of the result should be saved.
file_format (str) – Type of file which the plot of the result should be saved.
- Returns:
omega (xp.array) – 1d array of angular frequency.
kvec (xp.array) – 1d array of wave vector.
dispersion (xp.array) – 2d array of shape (omega.size, kvec.size) holding the fft.
coeffs (list[list]) – List of fitting coefficients (lenght is fit_branches).
- struphy.diagnostics.diagn_tools.plot_scalars(time, scalar_quantities, scalars_plot=None, do_log=False, do_fit=False, fit_minima=False, order=4, no_extrema=4, start_extremum=0, degree=1, show_plot=False, save_plot=False, savedir=None, file_format='png')[source]#
Plot the scalar quantities and the relative error in the total energy for a simulation.
- Parameters:
scalar_quantities (dict) – HDF5 dictionary dataset containing the scalar quantities that were saved during the simulation
scalars_plot (list | tuple) – list of names of scalars that should be plotted. If empty then all are plotted
do_log (boolean) – Do a logarithmic plot in the y-axis if True.
do_fit (boolean) – Do a fit to maxima if True.
fit_minima (boolean) – Do a fit to minima if True. Will set do_fit to False if True.
order (int) – How many neighbouring points should be used for finding extrema.
no_extrema (int) – How many extrema should be used for the fit.
start_extremum (int) – Which extremum should be used first for the fit.
show_plot (boolean) – Display the figure if True.
save_plot (boolean) – Save the figure if True. Then a path has to be given.
savedir (str) – Name of the folder in which the plot of the result should be saved.
file_format (str) – Type of file which the plot of the result should be saved.
- struphy.diagnostics.diagn_tools.plot_distr_fun(path, time_idx, grid_slices, save_plot=False, savepath=None, file_format='png')[source]#
Plot the binned distribution function at given slices of the phase space.
- Parameters:
path (str) – Path to the kinetic data of the species.
time (float) – at which point in time to plot
grid_slices (dict) – dictionary with keys e and v that hold dictionaries with directions and values that indicate which slices of the data should be plotted
save_plot (boolean) – Save figure if True. Then a path has to be given.
savepath (str) – Path under which the plot of the result should be saved.
file_format (str) – Type of file which the plot of the result should be saved.
- struphy.diagnostics.diagn_tools.plots_videos_2d(t_grid, grid_slices, slice_name, plot_full_f, species, path, model_name, output: str = 'overview', background_params=None, n_times=6, show_plot=False, save_plot=True, polar_params={})[source]#
TODO
- struphy.diagnostics.diagn_tools.video_2d(slc, diagn_path, images_path)[source]#
Create a video of all 2D slices of the distribution function over time.
- Parameters:
t_grid (xp.ndarray) – 1D-array containing all the times
grid_slices (dict) – holds the names of the directions as keys and the values at where the function should be evaluated as values
slice_name (str) – The name of the slicing, e.g. e2_v1_v2
plot_full_f (bool) – whether to plot full-f instead of delta-f data
species (str) – the name of the species
path (str) – the path to the data of which the videos should be created
model_name (str) – name of the model that was run
background_params (dict [optional]) – parameters of the maxwellian background type if a full_f method was used
- struphy.diagnostics.diagn_tools.plots_2d_video(t_grid, grid_1_mesh, grid_2_mesh, df_binned, model_name, label_1=None, label_2=None, do_polar=False, images_path=None)[source]#
- struphy.diagnostics.diagn_tools.plots_2d_overview(t_grid, grid_1_mesh, grid_2_mesh, slc, df_binned, save_path, model_name, label_1=None, label_2=None, do_polar=False, n_times=1, show_plot=False, save_plot=True)[source]#
- struphy.diagnostics.diagn_tools.get_slices_grids_directions_and_df_data(plot_full_f, grid_slices, data_path, slice_name, background_params=None)[source]#
Prepare the lists of slices, grids, and directions from the given data and extract the delta-f data.
- Parameters:
plot_full_f (bool) – whether to plot full-f instead of delta-f data
grid_slices (dict) – holds the names of the directions as keys and the values at where the function should be evaluated as values
data_path (str) – the path to the data which should be prepared
slice_name (str) – The name of the slicing, e.g. e2_v1_v2
background_params (dict [optional]) – parameters of the maxwellian background type if a full_f method was used
- Returns:
slices_2d (list[string]) – A list of all the slicings
grids (list[xp.ndarray]) – A list of all grids according to the slices
directions (list[string]) – A list of the directions that appear in all slices
df_data (xp.ndarray) – The data of delta-f (in case of full-f: distribution function minus background)
Continuous spectra#
- struphy.diagnostics.continuous_spectra.get_mhd_continua_2d(space, domain, omega2, U_eig, m_range, omega_A, div_tol, comp_sound)[source]#
Get the eigenfrequencies omega^2/omega_A^2 in the range (0, 1) sorted by shear Alfvén modes and slow sound modes.
- Parameters:
space (struphy.eigenvalue_solvers.spline_space.Tensor_spline_space) – 2d finite element B-spline space.
domain (struphy.geometry.base.Domain) – The domain in which the eigenvalue problem has been solved.
omega2 (array-like) – Eigenfrequencies obtained from eigenvalue solver.
U_eig (array-like) – Eigenvectors obtained from eigenvalue solver.
m_range (list) – Range of poloidal mode numbers that shall be identified.
omega_A (float) – On-axis Alfvén frequency B0/R0.
div_tol (float) – Threshold for the maximum divergence of an eigenmode below which it is considered to be an Alfvénic mode.
comp_sound (int) – The component that is used for the slow sound mode analysis (2 : 2nd component or 3 : third component).
- Returns:
a_spec (list of 2d numpy arrays) – the radial location a_spec[m][0], squared eigenfrequencis a_spec[m][1] and global mode index a_spec[m][2] corresponding to shear Alfvén modes for each poloidal mode number m in m_range.
s_spec (list of 2d numpy arrays) – the radial location s_spec[m][0], squared eigenfrequencis s_spec[m][1] and global mode index s_spec[m][2] corresponding to slow sound modes for each poloidal mode number m in m_range.