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.

Parameters:
  • 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.

Examples

>>> 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_fields(fields)[source]

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.

Examples

>>> trajs = ParticleTrajectories(my_fns, indices)
>>> trajs.add_fields(["particle_mass", "particle_gpot"])
has_key(key)[source]
keys()[source]
trajectory_from_index(index)[source]

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.
Returns:
  • A dictionary corresponding to the particle’s trajectory and the
  • fields along that trajectory

Examples

>>> 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(filename_base)[source]

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.

Examples

>>> trajs = ParticleTrajectories(my_fns, indices)
>>> trajs.write_out("orbit_trajectory")
write_out_h5(filename)[source]

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

Examples

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