desc.plotting.plot_particle_trajectories
- desc.plotting.plot_particle_trajectories(field, model, initializer, ts, end_position=True, return_data=False, fig=None, **kwargs)Source
Plot particle trajectories in a magnetic field.
- Parameters:
field (MagneticField or Equilibrium) – Magnetic field to trace the particle trajectories in. Given field, trajectory model, and initializer must be compatible. Field can be a subclass of MagneticField, such as Coilset, CurrentPotential, or it can be Equilibrium.
model (AbstractTrajectoryModel) – Particle trajectory model to use for tracing the particle trajectories.
initializer (AbstractParticleInitializer) – Particle initializer to use for initializing the particles.
ts (array-like) – Time values to trace the particle trajectories for.
end_position (bool, optional) – If True, the last point in the trajectory is shown with a marker. Defaults to True.
fig (plotly.graph_objs._figure.Figure, optional) – Figure to plot on. Defaults to None, in which case a new figure is created.
return_data (bool, optional) – If True, return the data plotted as well as fig, Defaults to False.
**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 particle trajectories, default is black.figsize: tuple of length 2, the size of the figure in incheslw: float, linewidth of plotted particle trajectoriesls: str, linestyle of plotted particle trajectoriesshowgrid: 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.particles.trace_particles
- Returns:
fig (plotly.graph_objs._figure.Figure) – Figure being plotted to.
plot_data (dict) – Dictionary of the data plotted, only returned if
return_data=TrueContains keys["X","Y","Z","R","phi], each entry in the dict is a list with length corresponding to the number of particles, and each element of that list is an array of size ts.size corresponding to the coordinate values along that particles trajectory.
Examples
import desc from desc.plotting import plot_particle_trajectories from desc.particles import ( ManualParticleInitializerFlux, VacuumGuidingCenterTrajectory, ) eq = desc.examples.get('precise_QA') rhos = [0.7] initializer = ManualParticleInitializerFlux( rho0=rhos, theta0=0, zeta0=0, xi0=0.7, E = 1e-1, m = 4.0, q = 1.0, ) model = VacuumGuidingCenterTrajectory(frame='flux') ts=np.linspace(0, 1e-2, 1000) # For visual purposes, we will plot the LCFS of the equilibrium fig = plot_3d(eq, '|B|', alpha=0.5) # Plot the particle trajectories plot_particle_trajectories( eq, model, initializer, ts=ts, fig=fig )