Visualize data (nsfds3.graphics)

The graphics package provides some helper classes and functions to represent meshes graphically.

The main viewer used in nsfds3 is nsfds3.graphics.MPLViewer.

Example

from nsfds3.graphics import MPLViewer
from nsfds3.utils import CfgSetup

filename = 'reference.conf'
cfg = CfgSetup(filename)
with MPLViewer(cfg) as viewer:
    viewer.movie(view='p', buffer=False, probes=True)  # Make movie
    viewer.probes()                                    # figure with probe evolutions
    viewer.spectrogram()                               # figure with spectrogram
class nsfds3.graphics.CPViewer(cpdomain)[source]

MeshViewer specialization adapted to ComputationDomains.

Parameters:

cpdomain (ComputationalDomain) – Computational domain object

Methods

grid(ax, axes, indices, N, **kwargs)

Plot grid on ax.

objects(ax, axes, indices, obj, **kwargs)

Plot objects on ax.

show

class nsfds3.graphics.MPLViewer(cfg, data=None)[source]

MeshViewer specialization adapted to exploit libfds.Fields isntances or hdf5 files.

Parameters:
  • cfg (nsfds3.solver.CfgSetup) – Configuration of the simulation

  • data (libfds.fields.Fields2d, libfds.fields.Fields3d, pathlib.Path, str, optional) – Data can be provided as Fields2d/Fields3d or with the path to a hdf5 file. If data is not provided, the file pointed to by the cfg.files.data_path attribute is used if it exists.

Note

Until the MPLViewer instance is not closed with the close method, it keeps the hdf5 file open. This can cause problems when opening it in another process. It is strongly recommanded to use MPLViewer as a context manager :

with MPLViewer(path_to_config_file.conf) as viewer:
    viewer.show(view='p', iteration=100)

Methods

close()

Close hdf5 file if one is open.

grid(ax, axes, indices, N, **kwargs)

Plot grid on ax.

movie([view, nt, ref, xlim, ylim, zlim, codec])

Make movie for a given view.

objects(ax, axes, indices, obj, **kwargs)

Plot objects on ax.

probes([figsize])

Plot acoustic pressure at probe locations.

show([view, vmin, vmax, iteration])

Show view at a given iteration.

spectrogram([M, figsize])

Plot spectograms at probe locations.

close()[source]

Close hdf5 file if one is open.

movie(view='p', nt=None, ref=None, xlim=None, ylim=None, zlim=None, codec='libx264', **kwargs)[source]

Make movie for a given view.

probes(figsize=(9, 4))[source]

Plot acoustic pressure at probe locations.

show(view='p', vmin=None, vmax=None, iteration=0, **kwargs)[source]

Show view at a given iteration.

spectrogram(M=None, figsize=(9, 4))[source]

Plot spectograms at probe locations.

Parameters:

M (int) – Length of each segment

class nsfds3.graphics.MeshViewer(msh)[source]

Graphical tool to visualize Mesh instances graphically.

Parameters:
  • mesh (CartesianGrid or CurvilinearGrid) – Mesh object

  • figsize (tuple, optional) – Size of the figure

  • dpi (int, optional) – Resolution of the figure

  • grid (bool, optional) – If True, display the grid.

  • buffer (bool, optional) – If True, display the buffer zones.

  • obstacles (bool, optional) – If True, display the obstacles

  • domains (bool, optional) – If True, diplay the computation domains

  • N (int, optional) – Grid step

  • slice (tuple, (x0, y0[, z0])) – Position of the cross sections for 3d views

Methods

grid(ax, axes, indices, N, **kwargs)

Plot grid on ax.

objects(ax, axes, indices, obj, **kwargs)

Plot objects on ax.

show

static grid(ax, axes, indices, N, **kwargs)[source]

Plot grid on ax.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis where to draw the grid

  • axes (tuple of np.ndarray) – Grid axes (x, y [, z])

  • indices (tuple of int) – Indices of the axes to use

  • N (int) – Plot a grid line every N points

  • **kwargs (dict) – Keyword Arguments of ax.vlines/ax.hlines

static objects(ax, axes, indices, obj, **kwargs)[source]

Plot objects on ax.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis where to draw the grid

  • axes (tuple of np.ndarray) – Grid axes (x, y [, z])

  • indices (tuple of int) – Indices of the axes to use

  • obj (sequence) – Sequence of objects that must be drawn

  • **kwargs (dict) – Keyword Arguments of matplotlib.patches.Rectangle