desc.plotting.plot_field_lines

desc.plotting.plot_field_lines(field, R0, Z0, phi0=0, ntransit=1, nphi_per_transit=50, endpoint=True, fig=None, return_data=False, **kwargs)Source

Field line plot from external magnetic field.

Parameters:
  • field (MagneticField) – External field, coilset, current potential etc to plot from.

  • R0 (array-like) – Starting points for field line tracing.

  • Z0 (array-like) – Starting points for field line tracing.

  • phi0 (float) – Starting value of phi for field line tracing in radians. Defaults to 0.

  • ntransit (int, float) – Number of transits to trace field lines for. Defaults to 1. To trace the field in negative toroidal direction, use a negative value.

  • nphi_per_transit (int) – Number of equidistant toroidal points to plot for each field line per transit. Must be positive integer. Defaults to 50.

  • endpoint (bool) – If True, the point phi0+2*pi*ntransit is included, else the last point is phi0 + 2*np.pi*(ntransit - 1/nphi_per_transit). Defaults to True.

  • fig (plotly.graph_objs._figure.Figure, optional) – Figure to plot on.

  • return_data (bool) – If True, return the data plotted as well as fig

  • **kwargs (dict, optional) –

    Specify properties of the figure, axis, and plot appearance e.g.:

    plot_X(figsize=(4,6),)
    

    Valid keyword arguments are:

    • color: color to use for field lines, default is black.

    • figsize: tuple of length 2, the size of the figure in inches

    • lw: float, linewidth of plotted field lines

    • ls: str, linestyle of plotted field lines

    • showgrid: Bool, whether or not to show the coordinate grid lines. True by default.

    • showticklabels: Bool, whether or not to show the coordinate tick labels. True by default.

    • showaxislabels: Bool, whether or not to show the coordinate axis labels. True by default.

    • zeroline: Bool, whether or not to show the zero coordinate axis lines. True by default.

    Additionally, any other keyword arguments will be passed on to desc.magnetic_fields.field_line_integrate (except return_aux).

Returns:

  • fig (plotly.graph_objs._figure.Figure) – Figure being plotted to.

  • plot_data (dict) – Dictionary of the data plotted, only returned if return_data=True Contains keys ["X","Y","Z","R","phi"], each entry in the dict is a list of length R0.size corresponding to the number of field lines, and each element of that list is an array of size phis.size corresponding to the coordinate values along that field line.

Examples

import desc
from desc.plotting import plot_field_lines

field = desc.io.load("../tests/inputs/precise_QA_helical_coils.h5")
eq = desc.examples.get("precise_QA")
grid_trace = desc.grid.LinearGrid(rho=[1])
r0 = eq.compute("R", grid=grid_trace)["R"]
z0 = eq.compute("Z", grid=grid_trace)["Z"]

fig = plot_field_lines(field, r0, z0, nphi_per_transit=100, ntransit=10)