emout.core.data package¶
Submodules¶
emout.core.data.data module¶
Dimensioned ndarray subclasses for EMSES grid data.
Re-exports all Data classes from their respective submodules for
backward compatibility. New code should import from the submodules
directly (e.g. from emout.core.data._data3d import Data3d).
- class emout.core.data.data.Data(input_array, filename=None, name=None, xslice=None, yslice=None, zslice=None, tslice=None, slice_axes=None, axisunits=None, valunit=None)[source]¶
Bases:
ndarrayDimensioned ndarray subclass for EMSES grid data.
- datafile¶
Data file metadata.
- Type:
- slice_axes¶
Mapping from array dimensions to original axes (0: t, 1: z, 2: y, 3: x).
- axisunits¶
Per-axis unit translators.
- Type:
list of UnitTranslator or None
- valunit¶
Value unit translator.
- Type:
UnitTranslator or None
- axis(ax)[source]¶
Return the coordinate array for the given array dimension.
- Parameters:
ax (int) – Array dimension index
- Returns:
1-D coordinate array for the requested axis.
- Return type:
np.ndarray
- build_frame_updater(axis=0, title=None, notitle=False, offsets=None, use_si=True, vmin=None, vmax=None, **kwargs)[source]¶
Build a frame updater for animation.
- Parameters:
axis (int, optional) – Axis along which to animate, by default 0
title (str, optional) – Plot title (uses the field name when None), by default None
notitle (bool, optional) – If True, suppress the automatic title, by default False
offsets (tuple of (float or str), optional) – Axis offsets for x, y, z (‘left’: start at 0, ‘center’: centre at 0, ‘right’: end at 0, float: shift by value), by default None
use_si (bool) – If True, use SI units; otherwise use EMSES grid units, by default False
vmin (float, optional) – Colour-map minimum, by default None
vmax (float, optional) – Colour-map maximum, by default None
- Return type:
- property directory: Path¶
Return the parent directory of the source file.
- Returns:
Parent directory path.
- Return type:
Path
- property filename: Path¶
Return the source file path.
- Returns:
Path to the originating HDF5 file.
- Return type:
Path
- flip(axis=0)[source]¶
Reverse the data along the specified axis.
Coordinates are kept unchanged, so
plot()shows the values in reversed order against the original grid.- Parameters:
axis (int or str) – Array dimension index, or axis name (
'x','y','z','t').- Returns:
Reversed copy (same subclass).
- Return type:
Examples
>>> data.phisp[-1, :, ny//2, :].flip('z').plot()
- gifplot(fig=None, axis=0, mode=None, action='to_html', filename=None, show=False, savefilename=None, interval=200, repeat=True, title=None, notitle=False, offsets=None, use_si=True, vmin=None, vmax=None, to_html=False, return_updater=False, **kwargs)[source]¶
Create and run an animation over one axis.
- Parameters:
fig (plt.Figure or None, optional) – Target figure
axis (int, optional) – Axis to animate along
mode (str, optional) – Plot mode forwarded to the frame updater
action (ANIMATER_PLOT_MODE, optional) – Output action type
filename (path-like, optional) – Destination file path for saving the animation
show (bool, optional) – If True, display the animation interactively
savefilename (path-like, optional) – Destination file name (deprecated alias for filename)
interval (int, optional) – Frame interval in milliseconds
repeat (bool, optional) – If True, loop the animation
title (str or None, optional) – Plot title
notitle (bool, optional) – If True, suppress the automatic frame-number title
offsets (tuple of (float or str) or None, optional) – Per-axis offsets for x, y, z
use_si (bool, optional) – If True, use SI units
vmin (float, optional) – Colour-map minimum
vmax (float, optional) – Colour-map maximum
to_html (bool, optional) – Deprecated. Equivalent to
action='to_html'.return_updater (bool, optional) – Deprecated. Equivalent to
action='frames'.**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Animation object, HTML string, or FrameUpdater depending on action.
- Return type:
- masked(mask)[source]¶
Return a copy with masked elements set to NaN.
- Parameters:
mask (numpy.ndarray or callable) – Boolean mask array, or a callable that returns one
- Returns:
Copy of the data with masked elements replaced by NaN.
- Return type:
- mirror(axis=0)[source]¶
Append a reflected copy along the specified axis.
Simulates a reflection (Neumann / symmetry) boundary by concatenating the array with its reverse along axis. The boundary point is not duplicated, so the length changes from n to 2n - 1.
- Parameters:
axis (int or str) – Array dimension index, or axis name (
'x','y','z','t').- Returns:
New Data object with reflected data appended.
- Return type:
Examples
>>> d = data.phisp[-1, :, ny//2, :] >>> d.mirror('z').plot() # 2x domain with reflection
- negate()[source]¶
Return a copy with all values sign-flipped.
Equivalent to
-selfbut chainable withmirror(),tile(), andplot().- Returns:
Negated copy (same subclass).
- Return type:
Examples
>>> data.ex[-1, :, ny//2, :].negate().mirror('z').plot()
- scale(factor)[source]¶
Return a copy with all values multiplied by factor.
- Parameters:
factor (float) – Multiplicative factor.
- Returns:
Scaled copy (same subclass).
- Return type:
Examples
>>> data.phisp[-1].scale(1e3).plot()
- property t: ndarray¶
Time-axis coordinate array in grid units.
- Returns:
Time-axis coordinates.
- Return type:
np.ndarray
- property t_si: ndarray¶
Time-axis coordinate array in SI units.
- Returns:
Time-axis coordinates in SI units.
- Return type:
np.ndarray
- tile(n=1, axis=0, *, include_edge=False)[source]¶
Tile (repeat) the data along the specified axis.
Simulates a periodic boundary by concatenating n additional copies. By default the first element of each appended copy is dropped (
include_edge=False), giving[d0, ..., dn, d1, ..., dn, d1, ..., dn].- Parameters:
- Returns:
New Data object with tiled data.
- Return type:
Examples
>>> d = data.phisp[-1, :, ny//2, :] >>> d.tile(1, 'z').plot() # 2x periodic domain >>> d.mirror('z').tile(1, 'z').plot() # 4x (reflect + periodic)
- property tslice: slice¶
Return the sub-range along the time axis.
- Returns:
Sub-range along the time axis.
- Return type:
- property val_si: Data¶
Field values converted to SI units.
- Returns:
Field values in SI units.
- Return type:
- property x: ndarray¶
X-axis coordinate array in grid units.
- Returns:
X-axis coordinates.
- Return type:
np.ndarray
- property x_si: ndarray¶
X-axis coordinate array in SI units.
- Returns:
X-axis coordinates in SI units.
- Return type:
np.ndarray
- property xslice: slice¶
Return the sub-range along the x axis.
- Returns:
Sub-range along the x axis.
- Return type:
- property y: ndarray¶
Y-axis coordinate array in grid units.
- Returns:
Y-axis coordinates.
- Return type:
np.ndarray
- property y_si: ndarray¶
Y-axis coordinate array in SI units.
- Returns:
Y-axis coordinates in SI units.
- Return type:
np.ndarray
- property yslice: slice¶
Return the sub-range along the y axis.
- Returns:
Sub-range along the y axis.
- Return type:
- property z: ndarray¶
Z-axis coordinate array in grid units.
- Returns:
Z-axis coordinates.
- Return type:
np.ndarray
- class emout.core.data.data.Data1d(input_array, **kwargs)[source]¶
Bases:
DataOne-dimensional line data container.
- plot(show=False, use_si=True, offsets=None, **kwargs)[source]¶
Plot one-dimensional data as a line.
- Parameters:
show (bool) – If True, display the plot (suppresses return value), by default False
use_si (bool) – If True, use SI units; otherwise use EMSES grid units, by default True
offsets (tuple of (float or str), optional) – Offsets for the x and y axes (‘left’: start at 0, ‘center’: centre at 0, ‘right’: end at 0, float: shift by value), by default None
savefilename (str, optional) – Output file name, by default None
vmin (float, optional) – Minimum value, by default None
vmax (float, optional) – Maximum value, by default None
figsize (tuple of float, optional) – Figure size, by default None
xlabel (str, optional) – Horizontal axis label, by default None
ylabel (str, optional) – Vertical axis label, by default None
label (str, optional) – Series label, by default None
title (str, optional) – Title, by default None
- Returns:
Line object (None when saved or shown)
- Return type:
Line2D or None
- Raises:
ValueError – If the data is not one-dimensional.
- class emout.core.data.data.Data2d(input_array, **kwargs)[source]¶
Bases:
DataTwo-dimensional grid data container.
- cmap(**kwargs)[source]¶
Plot two-dimensional data as a colour map.
Shortcut equivalent to
plot(mode='cm'). Accepts the same arguments asplot()exceptmode(raisesTypeErrorif supplied).- Returns:
Same as
plot().- Return type:
matplotlib.image.AxesImage or list or None
- contour(**kwargs)[source]¶
Plot two-dimensional data as contour lines.
Shortcut equivalent to
plot(mode='cont'). Accepts the same arguments asplot()exceptmode(raisesTypeErrorif supplied).- Returns:
Same as
plot().- Return type:
matplotlib.contour.QuadContourSet or list or None
- plot(axes='auto', show=False, use_si=True, offsets=None, mode='cm', **kwargs)[source]¶
Plot two-dimensional data.
- Parameters:
axes (str, optional) – Axis pair to plot (‘xy’, ‘zx’, etc.), by default ‘auto’
show (bool) – If True, display the plot (suppresses file output), by default False
use_si (bool) – If True, use SI units; otherwise use EMSES grid units, by default True
offsets (tuple of (float or str), optional) – Per-axis offsets for x, y, z (‘left’: start at 0, ‘center’: centre at 0, ‘right’: end at 0, float: shift by value), by default None
mode (str) – Plot type (‘cm’: colour map, ‘cont’: contour, ‘surf’: surface)
**kwargs (dict) – Additional arguments forwarded to the low-level plot function (
plot_2dmapfor ‘cm’/’cm+cont’,plot_2d_contourfor ‘cont’,plot_surfacefor ‘surf’).mesh (tuple of numpy.ndarray, optional) – Mesh grid, by default None
savefilename (str, optional) – Output file name (None to skip saving), by default None
cmap (matplotlib.Colormap or str or None, optional) – Colour map, by default cm.coolwarm
vmin (float, optional) – Minimum value, by default None
vmax (float, optional) – Maximum value, by default None
figsize (tuple of float, optional) – Figure size, by default None
xlabel (str, optional) – X-axis label, by default None
ylabel (str, optional) – Y-axis label, by default None
title (str, optional) – Title, by default None
interpolation (str, optional) – Interpolation method, by default ‘bilinear’
dpi (int, optional) – Resolution (ignored when figsize is set), by default 10
- Returns:
Plot image data (None when saved or shown)
- Return type:
AxesImage or None
- Raises:
ValueError – If the axes parameter is invalid.
ValueError – If the requested axis does not exist in the data.
ValueError – If the data is not two-dimensional.
- plot3d(*args, **kwargs)[source]¶
Alias for
plot_pyvista().
- class emout.core.data.data.Data3d(input_array, **kwargs)[source]¶
Bases:
DataThree-dimensional (z, y, x) grid data container.
- plot(mode='auto', use_si=True, offsets=None, *args, **kwargs)[source]¶
Plot three-dimensional data.
Currently only
mode='cont'is implemented, which delegates toemout.plot.contour3d.contour3d().- Parameters:
mode ({'auto', 'cont'}, optional) – Plot mode.
'auto'selects'cont'.use_si (bool, optional) – If True, convert to SI units before plotting.
offsets (tuple of (float or str) or None, optional) – Origin offsets
(x, y, z). Strings'left','center','right'are also accepted.*args (tuple) – Positional arguments forwarded to
contour3d. Typically the first element islevels(a sequence of iso-surface values).**kwargs (dict) – Keyword arguments forwarded to
contour3d, includingax,bounds_xyz,roi_zyx,opacity,step,title,save,show,xlabel,ylabel,zlabel,clabel, etc.
- Returns:
(fig, ax)formode='cont';Nonefor unsupported modes.- Return type:
tuple of (Figure, Axes) or None
- plot3d(*args, **kwargs)[source]¶
Alias for
plot_pyvista().
- plot_pyvista(mode='box', use_si=True, offsets=None, show=False, plotter=None, cmap='viridis', clim=None, opacity='sigmoid', contour_levels=8, add_outline=True, outline_color='white', add_scalar_bar=True, **kwargs)[source]¶
Render three-dimensional data with PyVista.
- plot_surfaces(surfaces, *, ax=None, use_si=True, vmin=None, vmax=None, **kwargs)[source]¶
Overlay explicit mesh boundaries on a 3-D scalar field.
Wraps
selfas aField3Dand passes it toemout.plot.surface_cut.plot_surfaces(). Designed for one-line calls such asdata.phisp[-1].plot_surfaces(data.boundaries.mesh().render(), vmin=0, vmax=10).- Parameters:
surfaces – A
RenderItem,MeshSurface3D,Boundary,BoundaryCollection, or a sequence thereof. A bareMeshSurface3Dis wrapped with default render style. ABoundary/BoundaryCollectionis converted viamesh(use_si=use_si)thenrender(), sodata.phisp[-1].plot_surfaces(data.boundaries)works directly.ax (matplotlib.axes.Axes, optional) – Target 3-D axes. Created automatically if not supplied.
use_si (bool, optional) – If True (default), convert data and grid spacing to SI units before plotting. Also propagated to boundary mesh generation. Falls back to False when no unit conversion key is available.
vmin (float, optional) – Colour-map range.
vmax (float, optional) – Colour-map range.
**kwargs (dict) – Additional keyword arguments forwarded to
plot_surfaces()(e.g.bounds,cmap_name,contour_levels).
- Returns:
(cmap, norm)returned byplot_surfaces.- Return type:
emout.core.data.griddata_series module¶
Lazy time-series loader for EMSES grid HDF5 files.
GridDataSeries memory-maps a sequence of {name}00_0000.h5
files and produces Data slices on demand.
- class emout.core.data.griddata_series.GridDataSelection(series, selectors=None)[source]¶
Bases:
NDArrayOperatorsMixinLazy staged selector for a
GridDataSeries.Instances keep the selected
(t, z, y, x)ranges as metadata and only materialise arrays once the result has at most three dimensions or the caller asks for functionality that requires a realData4d.- build_frame_updater(axis=0, title=None, notitle=False, offsets=None, use_si=True, vmin=None, vmax=None, **kwargs)[source]¶
Build a frame updater for lazy 4-D selections.
- Return type:
- gifplot(fig=None, axis=0, mode=None, action='to_html', filename=None, show=False, savefilename=None, interval=200, repeat=True, title=None, notitle=False, offsets=None, use_si=True, vmin=None, vmax=None, to_html=False, return_updater=False, **kwargs)[source]¶
Create an animation without materialising the full 4-D array.
- select_space(*item)[source]¶
Select only spatial axes while preserving the current time range.
Examples
data.phisp.lazy[:].select_space(1, 1, 1)is equivalent todata.phisp.lazy[:][:, 1, 1, 1].
- property shape¶
- property slice_axes¶
- property slices¶
- property use_axes¶
- class emout.core.data.griddata_series.GridDataSeries(filename, name, tunit=None, axisunit=None, valunit=None)[source]¶
Bases:
objectManage 3-D time-series grid data.
- datafile¶
Data file metadata.
- Type:
- h5¶
HDF5 file handle.
- Type:
h5py.File
- group¶
HDF5 dataset group.
- Type:
h5py.Datasets
- chain(other_series)[source]¶
Chain this series with another.
- Parameters:
other_series (GridDataSeries) – Series to append.
- Returns:
Concatenated series.
- Return type:
- property lazy: GridDataSelection¶
Return a lazy 4-D selector for staged indexing.
series[:]also returns this selector. Useseries.lazywhen you want to make the lazy intent explicit before additional spatial slicing, e.g.data.phisp.lazy[:][:, 1, 1, 1]ordata.phisp.lazy[:].select_space(1, 1, 1).
- class emout.core.data.griddata_series.MultiGridDataSeries(*series)[source]¶
Bases:
GridDataSeriesManage multiple concatenated 3-D time-series datasets.
- datafile¶
Data file metadata.
- Type:
- tunit¶
Time unit translator.
- Type:
- axisunit¶
Spatial axis unit translator.
- Type:
- valunit¶
Value unit translator.
- Type:
- property directories: List[Path]¶
Return the list of directories.
- Returns:
Directory paths.
- Return type:
list of Path
- property directory: Path¶
Return the directory of the first series.
- Returns:
Directory path.
- Return type:
Path
- property filename: Path¶
Return the file name of the first series.
- Returns:
File name.
- Return type:
Path
- property filenames: List[Path]¶
Return the list of file names.
- Returns:
File names.
- Return type:
list of Path
emout.core.data.vector_data module¶
Multi-component vector field wrappers.
VectorData bundles two or three Data
components and provides unified plotting for 2-D quiver / streamline and
3-D PyVista visualisation.
- class emout.core.data.vector_data.VectorData(objs, name=None, attrs=None)[source]¶
Bases:
GroupMulti-component vector field container.
Wraps 2 or 3
Dataarrays (x, y[, z]) and delegates axis metadata, slicing, and plotting to the underlying components.- Parameters:
- property axisunits: UnitTranslator¶
Return per-axis unit translators.
- Returns:
Per-axis unit translators
[-1]=x, [-2]=y, [-3]=z.- Return type:
- build_frame_updater(axis=0, title=None, notitle=False, offsets=None, use_si=True, **kwargs)[source]¶
Build a frame updater for animation.
- Parameters:
axis (int, optional) – Axis along which to animate, by default 0
title (str, optional) – Plot title (uses the field name when None), by default None
notitle (bool, optional) – If True, suppress the automatic title, by default False
offsets (tuple of (float or str), optional) – Axis offsets for x, y, z (‘left’: start at 0, ‘center’: centre at 0, ‘right’: end at 0, float: shift by value), by default None
use_si (bool) – If True, use SI units; otherwise use EMSES grid units, by default False
- gifplot(fig=None, axis=0, action='to_html', filename=None, interval=200, repeat=True, title=None, notitle=False, offsets=None, use_si=True, show=False, savefilename=None, to_html=False, return_updater=False, **kwargs)[source]¶
Create and run an animation over one axis.
- Parameters:
fig (plt.Figure or None, optional) – Target figure
axis (int, optional) – Axis to animate along
action (ANIMATER_PLOT_MODE, optional) – Output action type
filename (path-like, optional) – Destination file path for saving the animation
interval (int, optional) – Frame interval in milliseconds
repeat (bool, optional) – If True, loop the animation
title (str or None, optional) – Plot title
notitle (bool, optional) – If True, suppress the automatic frame-number title
offsets (tuple of (float or str) or None, optional) – Per-axis offsets for x, y, z
use_si (bool, optional) – If True, use SI units
show (bool, optional) – If True, display the animation interactively
savefilename (path-like, optional) – Destination file name (deprecated alias for filename)
to_html (bool, optional) – Deprecated. Equivalent to
action='to_html'.return_updater (bool, optional) – Deprecated. Equivalent to
action='frames'.**kwargs (dict) – Additional keyword arguments forwarded to the underlying function.
- Returns:
Animation object, HTML string, or FrameUpdater depending on action.
- Return type:
- property name: str¶
Return the human-readable name of this vector field.
- Returns:
Human-readable name of this vector field.
- Return type:
- negate()[source]¶
Return a new VectorData with all components sign-flipped.
- Returns:
Negated copy.
- Return type:
Examples
>>> data.bxyz[-1].negate().plot()
- plot(*args, **kwargs)[source]¶
Plot vector data.
Delegates to
plot2d()for 2-D data andplot3d()for 3-D data.- Parameters:
*args (tuple) – Positional arguments forwarded to
plot2d(). Common arguments: mode, axes, show, use_si, offsets.**kwargs (dict) – Keyword arguments forwarded to
plot2d(), which in turn delegates toplot_2d_vectororplot_2d_streamline. Acceptsmesh,savefilename,scale,scaler,skip,easy_to_read,color,cmap,norm,vmin,vmax,density,figsize,xlabel,ylabel,title,dpi, etc.
- Returns:
Return value of the delegated plotting method.
- Return type:
- plot2d(mode='stream', axes='auto', show=False, use_si=True, offsets=None, **kwargs)[source]¶
Plot two-dimensional vector data.
- Parameters:
mode (str) – Plot type (‘vec’: quiver, ‘stream’: streamline), by default ‘stream’
axes (str, optional) – Axis pair to plot (‘xy’, ‘zx’, etc.), by default ‘auto’
show (bool) – If True, display the plot, by default False
use_si (bool) – If True, use SI units; otherwise use EMSES grid units, by default False
offsets (tuple of (float or str), optional) – Per-axis offsets (‘left’, ‘center’, ‘right’, or float), by default None
mesh (tuple of numpy.ndarray, optional) – Mesh grid, by default None
savefilename (str, optional) – Output file name (None to skip saving), by default None
cmap (matplotlib.Colormap or str or None, optional) – Colour map, by default cm.coolwarm
vmin (float, optional) – Minimum value, by default None
vmax (float, optional) – Maximum value, by default None
figsize (tuple of float, optional) – Figure size, by default None
xlabel (str, optional) – X-axis label, by default None
ylabel (str, optional) – Y-axis label, by default None
title (str, optional) – Title, by default None
interpolation (str, optional) – Interpolation method, by default ‘bilinear’
dpi (int, optional) – Resolution (ignored when figsize is set), by default 10
- Returns:
Plot image data (None when saved or shown)
- Return type:
AxesImage or None
- Raises:
ValueError – If the axes parameter is invalid.
ValueError – If the requested axis does not exist in the data.
ValueError – If the data is not two-dimensional.
- plot3d(mode='stream', backend='mpl', **kwargs)[source]¶
Plot a 3-D vector field.
- Parameters:
mode ({'stream', 'streamline', 'vec', 'quiver'}) – Plot type.
backend ({'mpl', 'pyvista'}, default 'mpl') –
'mpl'uses matplotlib 3-D axes;'pyvista'uses the PyVista renderer.**kwargs – Forwarded to
plot3d_mpl()orplot_pyvista().
- Return type:
- plot3d_mpl(mode='stream', use_si=True, offsets=None, ax=None, **kwargs)[source]¶
Plot a 3-D vector field with matplotlib.
For
mode='stream'(default), field lines are traced usingscipy.integrate.solve_ivp()and drawn on ampl_toolkits.mplot3d.Axes3D.- Parameters:
mode ({'stream', 'streamline', 'vec', 'quiver'}) – Plot type.
use_si (bool, default True) – Convert to SI units when available.
offsets (tuple of (float or str), optional) – Per-axis offsets.
ax (Axes3D, optional) – Target axes.
**kwargs – Forwarded to the underlying plot function (e.g.
n_seeds,seed_points,max_length,step_size,color,cmap,linewidth).
- Return type:
Axes3D
- plot_pyvista(mode='stream', show=False, use_si=True, offsets=None, plotter=None, **kwargs)[source]¶
Render three-dimensional vector field with PyVista.
- scale(factor)[source]¶
Return a new VectorData with all components scaled.
- Parameters:
factor (float) – Multiplicative factor.
- Returns:
Scaled copy.
- Return type:
- property shape: tuple¶
Return the shape of the underlying component arrays.
- Returns:
Shape tuple of the underlying component arrays.
- Return type:
- property slice_axes: ndarray¶
Return the mapping from current array axes to original data axes.
- Returns:
Integer array mapping current array axes to original data axes.
- Return type:
np.ndarray
- property slices: ndarray¶
Return the slice objects describing the current sub-range on each axis.
- Returns:
Slice objects describing the current sub-range on each axis.
- Return type:
np.ndarray
- property valunit: UnitTranslator¶
Return the unit translator for the field values.
- Returns:
Unit translator for the field values.
- Return type:
- emout.core.data.vector_data.VectorData2d¶
alias of
VectorData
- emout.core.data.vector_data.VectorData3d¶
alias of
VectorData
Module contents¶
Data classes for EMSES grid and particle output.
Re-exports¶
- Data, Data1d, Data2d, Data3d, Data4d
Dimensioned numpy-subclass wrappers for grid data.
- VectorData, VectorData2d, VectorData3d
Multi-component vector field wrappers.
- GridDataSeries, GridDataSelection
Lazy time-series loader for grid HDF5 files.
- ParticleData, ParticleDataSeries, MultiParticleDataSeries
Particle output wrappers.