routines

Note

The routines in this module are either documented elsewhere (by the class that inherits them) or they are lower-level tools that are only documented here for the developers.

Advanced pre- and postprocessing routines.

Module for generating common plots with ASCOT5.

This module should be imported everywhere where plotting is done instead of using matplotlib directly. The reason is that on some platforms matplotlib is not available and even there we want to able to use all functionality that doesn’t require plotting.

So either import this module or use try-except when importing matplotlib.

a5py.routines.plotting.arrows2d()

Plot vector field on 2D plane.

a5py.routines.plotting.cameracontrols(plotter)

Set FPS camera controls vor interactive plotting.

Parameters:
plotterPlotter

The active plotter.

a5py.routines.plotting.contour2d(x, y, z, contours, xlabel=None, ylabel=None, axesequal=False, colors=None, linestyles=None, linewidths=None, axes=None)

Plot contour on 2D plane.

a5py.routines.plotting.defaultcamera(wallmesh)

Get default camera (helper function for the 3D plots).

Default camera is located at R = (Rmax + Rmin) / 2, phi = 0 deg, z = (zmax, zmin) / 2, where the min/max values are taken from the bounding box of the wall mesh. The focal point is at same (R, z) coordinates but phi = 10 deg. The camera angle parameters are all set to zero.

Parameters:
wallmeshPolydata

The wall mesh.

Returns:
cposarray_like

Camera position coordinates [x, y, z].

cfocarray_like

Camera focal point coordinates [x, y, z].

cangarray_like

Camera angle [azimuth, elevation, roll].

a5py.routines.plotting.figuredoublecolumn(aspectratio=1.5)

Return figure that has a size suitable for printing in A4 double-column width (when the paper has a double-column format).

a5py.routines.plotting.figuresinglecolumn(aspectratio=1.5)

Return figure that has a size suitable for printing in A4 single-column width (when the paper has a double-column format).

Parameters:
aspectratiofloat

Width / height ratio of the returned figure.

Returns:
a5py.routines.plotting.getmathtextsciformatter(format)

Returns a label tick formatter that shows numbers in format “a x 10^b”.

Credit: https://stackoverflow.com/a/49330649

Examples

>>> plt.gca().yaxis.set_major_formatter(getmathtextsciformatter("%1.2e"))
a5py.routines.plotting.hist1d(x, xbins=None, weights=None, xlog='linear', logscale=False, xlabel=None, legend=None, axes=None)

Plot (stacked) marker histogram in 1D.

Parameters:
xarray_like or list [array_like]

Array or a list of arrays to be binned and plotted.

If list is given, the resulting histogram is stacked with each array in the list corresponding to one layer in the stacked histogram.

xbinsint or array_like, optional

Number of bins or array storing bin edges for the x coordinate.

weightsarray_like or list [array_like], optional

Values the datapoints are weighted with.

Same format as for x.

xlog{“linear”, “log”}, optional

x-axis scaling.

logscalebool, optional

Show histogram in logarithmic scale.

xlabelstr, optional

Label for the x-axis.

legendstr, array_like

List of strings to label the data with.

The length of the list must be same as the number of data arrays provided.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

a5py.routines.plotting.hist2d(x, y, xbins=None, ybins=None, weights=None, xlog='linear', ylog='linear', logscale=False, xlabel=None, ylabel=None, axesequal=False, axes=None, cax=None)

Plot marker histogram in 2D.

Parameters:
xarray_like, (n,)

x-coordinates of the data to be binned and plotted.

yarray_like, (n,)

y-coordinates of the data to be binned and plotted.

xbinsint or array_like, optional

Number of bins or array storing bin edges for the x coordinate.

ybinsint or array_like, optional

Number of bins or array storing bin edges for the y coordinate.

weightsarray_like, (n,), optional

Values the datapoints are weighted with.

If weights are included, the colorbar label changes from “Markers” to “Particles”.

xlog{“linear”, “log”}, optional

x-axis scaling.

ylog{“linear”, “log”}, optional

y-axis scaling.

logscalebool, optional

Show histogram in logarithmic scale.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

axesequalbool, optional

Flag to set the aspect ratio equal.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.interactive(wallmesh, *args, points=None, orbit=None, data=None, log=False, clim=None, cpos=None, cfoc=None, cang=None, **kwargs)

Open VTK window to display interactive view of the wall mesh.

Parameters:
wallmeshPolydata

Mesh representing the wall.

*argstuple (str, method), optional

Key (str) method pairs. When key is pressed when the plot is displayed, the associated method is called. The method should take Plotter instance as an argument.

pointsarray_like, optional

Array Npoint x 3 defining points (markers) to be shown. For each point [x, y, z] coordinates are given.

orbitarray_like, (n,3), optional

Cartesian coordinates for an orbit to be plotted.

datastr, optional

Name of the cell data in the wall mesh that is shown in color.

logbool, optional

Color range is logarithmic if True.

clim[float, float], optional

Color [min, max] limits.

cposarray_like, optional

Camera position coordinates [x, y, z].

cfocarray_like, optional

Camera focal point coordinates [x, y, z].

cangarray_like, optional

Camera angle [azimuth, elevation, roll].

**kwargs

Keyword arguments passed to Plotter.

a5py.routines.plotting.line2d(x, y, c=None, xlog='linear', ylog='linear', clog='linear', xlabel=None, ylabel=None, clabel=None, bbox=None, cmap=None, axesequal=False, axes=None, cax=None)

Plot line segments in 2D.

xarray_like

Marker x-coordinates.

yarray_like

Marker y-coordinates.

cstr or array_like, optional

Color data or string indicating the color.

xlog{“linear”, “log”, “symlog”}, optional

x-axis scaling.

ylog{“linear”, “log”, “symlog”}, optional

y-axis scaling.

clog{“linear”, “log”, “symlog”}, optional

color-axis scaling.

cmapstr, optional

Name of the colormap.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

clabelstr, optional

Label for the color axis.

axesequalbool, optional

Flag to set aspect ratio of [x,y] axes equal.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.line3d(x, y, z, c=None, xlog='linear', ylog='linear', zlog='linear', clog='linear', xlabel=None, ylabel=None, zlabel=None, clabel=None, bbox=None, cmap=None, axesequal=False, axes=None, cax=None)

Plot line segments in 3D.

Parameters:
xarray_like

Marker x-coordinates.

yarray_like

Marker y-coordinates.

zarray_like

Marker z-coordinates.

cstr or array_like, optional

Color data or string indicating the color.

xlog{“linear”, “log”, “symlog”}, optional

x-axis scaling.

ylog{“linear”, “log”, “symlog”}, optional

y-axis scaling.

zlog{“linear”, “log”, “symlog”}, optional

z-axis scaling.

clog{“linear”, “log”, “symlog”}, optional

color-axis scaling.

cmapstr, optional

Name of the colormap.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

zlabelstr, optional

Label for the z-axis.

clabelstr, optional

Label for the color axis.

axesequalbool, optional

Flag to set aspect ratio of [x,y,z] axes equal.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.loadvsarea(wetted, loads, axes=None)

Plot histogram showing minimum load vs area.

a5py.routines.plotting.mesh1d(x, y, log=False, xlabel=None, ylabel=None, axes=False, logscale=False)

Plot 1D distribution.

Parameters:
xarray_like (nx,)

Abscissa edges for the x-axis.

zarray_like (nx-1,)

Data to be plotted.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

logscale: bool, optional

Whether the plot is in logarithmic scale.

a5py.routines.plotting.mesh2d(x, y, z, logscale=False, diverging=False, xlabel=None, ylabel=None, clabel=None, clim=None, cmap=None, axesequal=False, axes=None, cax=None)

Make a mesh (surface) plot in 2D.

Parameters:
xarray_like (nx,) or (nx+1,)

Abscissa or abscissa edges for the x-axis.

yarray_like (ny,) or (ny+1,)

Abscissa or abscissa edges for the y-axis.

zarray_like (nx,ny)

Data to be plotted.

logscalebool, optional

Make color axis logarithmic.

divergingbool, optional

Use diverging colormapping which is centered at zero.

Works with logarithmic scale as well.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

clabelstr, optional

Label for the color-axis.

clim[float, float], optional

Color [min, max] limits.

cmapstr, optional

Colormap.

axesequalbool, optional

Flag to set the aspect ratio equal.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.momentumpolargrid(pnorm_edges, pitch_edges, axes=None)

Plot momentum space polar coordinate grid in Cartesian basis.

Parameters:
pnorm_edgesarray_like

Momentum abscissa edges.

pitch_edgesarray_like

Pitch abscissa edges.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

a5py.routines.plotting.momentumpolarplot(pnorm_edges, pitch_edges, dist, axes=None, cax=None)

Plot momentum space distribution in polar coordinates.

Parameters:
pnorm_edgesarray_like

Momentum abscissa edges.

pitch_edgesarray_like

Pitch abscissa edges.

distarray_like

Values of the distribution.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.openfigureifnoaxes(projection='rectilinear')

Decorator for creating and displaying a new figure if axes are not provided.

Parameters:
projectionstr, {None, ‘3d’, ‘aitoff’, ‘hammer’, ‘lambert’, ‘mollweide’,
‘polar’, ‘rectilinear’}, optional

The axes projection type, see Matplotlib documentation for details.

a5py.routines.plotting.poincare(x, y, ids, connlen=None, xlim=None, ylim=None, xlabel=None, ylabel=None, clabel=None, axesequal=False, markersize=2, axes=None, cax=None)

Poincaré plot where color separates markers or shows the connection length.

For better performance this function uses matplotlib’s plot function instead of the scatter function. The only practical difference is that the marker color can’t be continuous.

Parameters:
xarray_like

Orbit x-coordinates.

yarray_like

Orbit y-coordinates.

idsarray_like

Array of marker IDs showing to which marker the points in x and y arrays correspond to.

connlenarray_like, optional

Connection length at the position (x,y).

Negative if the marker is confined. If given, the color scale shows connection length instead of marker ID. The confined markers are still shown with shades of red.

xlimtuple(float, float), optional

Min and max values for the x-axis.

ylimtuple(float, float), optional

Min and max values for the y-axis.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

clabelstr, optional

Label for the color axis.

axesequalbool, optional

If True, x and y axis have equal aspect ratio.

markersizeint, optional

Marker size on plot.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.radialprofile(x, y1, y2=None, xlim=None, y1lim=None, y2lim=None, xlabel=None, y1label=None, y2label=None, y1legends=None, y2legends=None, axes=None)

Plot 1D profiles on axes that can have two y-axes and the y-axis combines both linear and logarithmic scale.

Parameters:
xarray_like, (n,)

The x grid where y1 (and y2) values are provided.

y1array_like or [array_like]

The values (or a list of values in which case they are separated by colour) plotted on the left y-axis.

y2array_like or [array_like], optional

The values (or a list of values) plotted on the right y-axis.

xlim[float, float], optional

Limits on x-axis.

y1lim[float, float, float], optional

Limits on the first y axis where the middle value is when the scale changes from logarithmic to linear.

y2lim[float, float, float], optional

Limits on the second y axis where the middle value is when the scale changes from logarithmic to linear.

xlabelstr, optional

Label on the x-axis.

y1labelstr, optional

Label on the first y-axis.

y2labelstr, optional

Label on the second y-axis.

y1legends: [str], optional

Legends for the values plotted on the first y-axis.

Number of legend values must be the same as the number of y1.

y2legends: [str], optional

Legends for the values plotted on the second y-axis.

Number of legend values must be the same as the number of y2.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

a5py.routines.plotting.scatter2d(x, y, c=None, xlog='linear', ylog='linear', clog='linear', xlabel=None, ylabel=None, clabel=None, cint=9, cmap=None, axesequal=False, axes=None, cax=None)

Make a scatter plot in 2D+1 where color can be one dimension.

For better performance this function uses matplotlib’s plot function instead of the scatter function. The only practical difference is that the marker size can’t vary and the color can’t be continuous.

Parameters:
xarray_like

Marker x-coordinates.

yarray_like

Marker y-coordinates.

cstr or array_like, optional

Color data or string indicating the color.

xlog{“linear”, “log”, “symlog”}, optional

x-axis scaling.

ylog{“linear”, “log”, “symlog”}, optional

y-axis scaling.

clog{“linear”, “log”, “symlog”}, optional

color-axis scaling.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

clabelstr, optional

Label for the color axis.

cintint, optional

Number of colors used if c contains data. Since we are using plot instead of data, the color scale can’t be continuous.

cmapstr, optional

Name of the colormap where nc colors are picked if c contains data.

axesequalbool, optional

Flag to set aspect ratio of [x,y] axes equal.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.scatter3d(x, y, z, c=None, xlog='linear', ylog='linear', zlog='linear', clog='linear', xlabel=None, ylabel=None, zlabel=None, clabel=None, cint=None, cmap=None, axesequal=False, axes=None, cax=None)

Make a scatter plot in 3D+1 where color can be one dimension.

For better performance this function uses matplotlib’s plot function instead of the scatter function. The only practical difference is that the marker size can’t vary and the color can’t be continuous.

Parameters:
xarray_like

Marker x-coordinates.

yarray_like

Marker y-coordinates.

zarray_like

Marker z-coordinates.

cstr or array_like, optional

Color data or string indicating the color.

xlog{“linear”, “log”, “symlog”}, optional

x-axis scaling.

ylog{“linear”, “log”, “symlog”}, optional

y-axis scaling.

zlog{“linear”, “log”, “symlog”}, optional

z-axis scaling.

clog{“linear”, “log”, “symlog”}, optional

color-axis scaling.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

zlabelstr, optional

Label for the z-axis.

clabelstr, optional

Label for the color axis.

cintint, optional

Number of colors used if c contains data. Since we are using plot instead of data, the color scale can’t be continuous.

cmapstr, optional

Name of the colormap where nc colors are picked if c contains data.

axesequalbool, optional

Flag to set aspect ratio of [x,y] axes equal.

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

a5py.routines.plotting.setguistyle(latex=True)

Set default figure settings (label sizes etc.) so that the figure is suitable for GUI and presentations (large labels).

This function modifies the matplotlib style settings so one call is changes the style for the entire session.

Parameters:
latexbool, optional

Use LaTex interpreter.

a5py.routines.plotting.setpaperstyle(latex=True)

Set default figure settings (label sizes etc.) so that the figure is suitable for publications (looks nice on A4).

This function modifies the matplotlib style settings so one call is changes the style for the entire session.

Parameters:
latexbool, optional

Use LaTex interpreter.

a5py.routines.plotting.still(wallmesh, points=None, orbit=None, data=None, log=False, clim=None, cpos=None, cfoc=None, cang=None, axes=None, cax=None, **kwargs)

Take a still shot of the mesh and display it using matplotlib backend.

The rendering is done using vtk but the vtk (interactive) window is not displayed. It is recommended to use the interactive plot to find desired camera position and produce the actual plot using this method. The plot is shown using imshow and acts as a regular matplotlib plot.

Parameters:
wallmeshPolydata

Mesh representing the wall.

pointsarray_like, optional

Array Npoint x 3 defining points (markers) to be shown. For each point [x, y, z] coordinates are given.

orbitarray_like, (n,3), optional

Cartesian coordinates for an orbit to be plotted.

datastr, optional

Name of the cell data in the wall mesh that is shown in color.

logbool, optional

Color range is logarithmic if True.

clim[float, float], optional

Color [min, max] limits.

cposarray_like, optional

Camera position coordinates [x, y, z].

cfocarray_like, optional

Camera focal point coordinates [x, y, z].

cangarray_like, optional

Camera angle [azimuth, elevation, roll].

axesAxes, optional

The axes where figure is plotted or otherwise new figure is created.

caxAxes, optional

The color bar axes or otherwise taken from the main axes.

**kwargs

Keyword arguments passed to Plotter.

a5py.routines.plotting.triangularpatch(patches, color, log=False, xlim=None, ylim=None, clim=None, xlabel=None, ylabel=None, clabel=None, cmap=None, axes=None, cax=None)

Plot triangular patches.