-
Notifications
You must be signed in to change notification settings - Fork 293
Description
Bug report
Bug summary
Assuming we successfully run the example code for the particle_trajectories module (e.g. using the workaround mentioned in #4765, ie ("all","particle_position_x")
--> ("io","particle_position_x")
), getting a trajectory by index fails due to mixing str
s and tuple
s in a call to sorted(self.field_data.keys())
Code for reproduction
import yt
fields = [ ("all", "particle_position_x"),] # simplified for brevity
ts = yt.load("orbit_hdf5_chk_000?")
ds = ts[0]
init_sphere = ds.sphere(ds.domain_center, (0.5, "unitary"))
indices = init_sphere[("all", "particle_index")].astype("int64")
trajs = ts.particle_trajectories(indices, fields=fields, suppress_logging=True)
trajs.trajectory_from_index(1)
Actual outcome
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.conda/envs/test_yt/lib/python3.11/site-packages/yt/data_objects/particle_trajectories.py", line 340, in trajectory_from_index
fields = sorted(self.field_data.keys())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'tuple' and 'str'
Expected outcome
A dictionary with particle trajectory information. Something like
{'particle_time': unyt_array([ 0., 100., 200., 300., 400., 500., 600., 700., 800., 900.], 'code_time'), 'particle_index': 1, 'particle_position_x': unyt_array([0.25 , 0.25131274, 0.25524942, 0.26175659, 0.27075597,
0.28215068, 0.2958247 , 0.31164457, 0.32945507, 0.3491025 ], 'code_length'), 'particle_position_y': unyt_array([0.5 , 0.47421621, 0.44873755, 0.42384795, 0.39982133,
0.37690862, 0.35532256, 0.3353068 , 0.31707255, 0.30078343], 'code_length'), 'particle_position_z': unyt_array([0.5 , 0.5 , 0.5 , 0.5 , 0.50000001,
0.50000001, 0.50000002, 0.50000003, 0.50000004, 0.50000005], 'code_length'), ('io','particle_position_x'):unyt_array([0.25 , 0.25131274, 0.25524942, 0.26175659, 0.27075597,
0.28215068, 0.2958247 , 0.31164457, 0.32945507, 0.3491025 ], 'code_length') }
Version Information
- Operating System: Fedora 38
- Python Version: 3.11
- yt version: 4.2.1, 4.3
- Other Libraries (if applicable):
yt is installed through the conda-forge channel.
Additional Comments
I'm guessing this is occurring because the ParticleTrajectories constructor is adding the default fields particle_position_x/y/z
, particle_index
, and particle_time
to the field_data
parameter instead of tupleizing them (as e.g. ('all','particle_index')
or (ptype,'particle_index')
maybe?).