yt.data_objects.particle_trajectories module¶
- 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 = [ ... ("all", "particle_position_x"), ... ("all", "particle_position_y"), ... ("all", "particle_position_z"), ... ("all", "particle_velocity_x"), ... ("all", "particle_velocity_y"), ... ("all", "particle_velocity_z"), ... ] >>> ds = load(my_fns[0]) >>> init_sphere = ds.sphere(ds.domain_center, (0.5, "unitary")) >>> indices = init_sphere["all", "particle_index"].astype("int64") >>> ts = DatasetSeries(my_fns) >>> trajs = ts.particle_trajectories(indices, fields=fields) >>> for t in trajs: ... print( ... t["all", "particle_velocity_x"].max(), ... t["all", "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([("all", "particle_mass"), ("all", "particle_gpot")])
- 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
>>> import matplotlib.pyplot as plt >>> trajs = ParticleTrajectories(my_fns, indices) >>> traj = trajs.trajectory_from_index(indices[0]) >>> plt.plot( ... traj["all", "particle_time"], ... traj["all", "particle_position_x"], ... "-x", ... ) >>> plt.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")