yt.data_objects.particle_trajectories module

Particle trajectories

class yt.data_objects.particle_trajectories.ParticleTrajectories(outputs, indices, fields=None, suppress_logging=False, ptype=None)[source]

Bases: object

A collection of particle trajectories in time over a series of datasets.

  • outputs (DatasetSeries) – DatasetSeries object from which to draw the particles.
  • indices (array_like) – An integer array of particle indices whose trajectories we want to track. If they are not sorted they will be sorted.
  • fields (list of strings, optional) – A set of fields that is retrieved when the trajectory collection is instantiated. Default: None (will default to the fields ‘particle_position_x’, ‘particle_position_y’, ‘particle_position_z’)
  • suppress_logging (boolean) – Suppress yt’s logging when iterating over the simulation time series. Default: False
  • ptype (str, optional) – Only use this particle type. Default: None, which uses all particle type.


>>> my_fns = glob.glob("orbit_hdf5_chk_00[0-9][0-9]")
>>> my_fns.sort()
>>> fields = ["particle_position_x", "particle_position_y",
>>>           "particle_position_z", "particle_velocity_x",
>>>           "particle_velocity_y", "particle_velocity_z"]
>>> ds = load(my_fns[0])
>>> init_sphere = ds.sphere(ds.domain_center, (.5, "unitary"))
>>> indices = init_sphere["particle_index"].astype("int")
>>> ts = DatasetSeries(my_fns)
>>> trajs = ts.particle_trajectories(indices, fields=fields)
>>> for t in trajs :
>>>     print t["particle_velocity_x"].max(), t["particle_velocity_x"].min()

Add a list of fields to an existing trajectory

Parameters:fields (list of strings) – A list of fields to be added to the current trajectory collection.


>>> trajs = ParticleTrajectories(my_fns, indices)
>>> trajs.add_fields(["particle_mass", "particle_gpot"])

Retrieve a single trajectory corresponding to a specific particle index

Parameters:index (int) – This defines which particle trajectory from the ParticleTrajectories object will be returned.
  • A dictionary corresponding to the particle’s trajectory and the
  • fields along that trajectory


>>> from yt.mods import *
>>> import matplotlib.pylab as pl
>>> trajs = ParticleTrajectories(my_fns, indices)
>>> traj = trajs.trajectory_from_index(indices[0])
>>> pl.plot(traj["particle_time"], traj["particle_position_x"], "-x")
>>> pl.savefig("orbit")

Write out particle trajectories to tab-separated ASCII files (one for each trajectory) with the field names in the file header. Each file is named with a basename and the index number.

Parameters:filename_base (string) – The prefix for the outputted ASCII files.


>>> trajs = ParticleTrajectories(my_fns, indices)
>>> trajs.write_out("orbit_trajectory")

Write out all the particle trajectories to a single HDF5 file that contains the indices, the times, and the 2D array for each field individually

Parameters:filename (string) – The output filename for the HDF5 file


>>> trajs = ParticleTrajectories(my_fns, indices)
>>> trajs.write_out_h5("orbit_trajectories")