Streamlines, as implemented in yt, are defined as being parallel to a vector field at all points. While commonly used to follow the velocity flow or magnetic field lines, they can be defined to follow any three-dimensional vector field. Once an initial condition and total length of the streamline are specified, the streamline is uniquely defined. Relatedly, yt also has the ability to follow Particle Trajectories.
Streamlining through a volume is useful for a variety of analysis
tasks. By specifying a set of starting positions, the user is
returned a set of 3D positions that can, in turn, be used to visualize
the 3D path of the streamlines. Additionally, individual streamlines
can be converted into
and queried for all the available fields along the streamline.
The implementation of streamlining in yt is described below.
import yt import numpy as np import matplotlib.pylab as pl from yt.visualization.api import Streamlines from yt.units import Mpc from mpl_toolkits.mplot3d import Axes3D # Load the dataset ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030') # Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.domain_center N = 100 scale = ds.domain_width pos_dx = np.random.random((N,3))*scale-scale/2. pos = c+pos_dx # Create streamlines of the 3D vector velocity and integrate them through # the box defined above streamlines = Streamlines(ds, pos, 'velocity_x', 'velocity_y', 'velocity_z', length=1.0*Mpc, get_magnitude=True) streamlines.integrate_through_volume() # Create a 3D plot, trace the streamlines throught the 3D volume of the plot fig=pl.figure() ax = Axes3D(fig) for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] ax.plot3D(stream[:,0], stream[:,1], stream[:,2], alpha=0.1) # Save the plot to disk. pl.savefig('streamlines.png')
This functionality has not been implemented yet in in the 3.x series of yt. If you are interested in working on this and have questions, please let us know on the yt-dev mailing list.
Once the streamlines are found, a
YTStreamline object can
be created using the
path() function, which
takes as input the index of the streamline requested. This conversion
is done by creating a mask that defines where the streamline is, and
creating ‘t’ and ‘dts’ fields that define the dimensionless streamline
integration coordinate and integration step size. Once defined, fields
can be accessed in the standard manner.
import yt from yt.visualization.api import Streamlines ds = yt.load('DD1701') # Load ds streamlines = Streamlines(ds, ds.domain_center) streamlines.integrate_through_volume() stream = streamlines.path(0) matplotlib.pylab.semilogy(stream['t'], stream['density'], '-x')
The integration of the streamline paths is “embarrassingly” parallelized by splitting the streamlines up between the processors. Upon completion, each processor has access to all of the streamlines through the use of a reduction operation.
For more information on enabling parallelism in yt, see Parallel Computation With yt.