Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with the particle_trajectories documentation/module (2/2) #4766

Closed
mtryan83 opened this issue Dec 21, 2023 · 2 comments · Fixed by #4768
Closed

Problems with the particle_trajectories documentation/module (2/2) #4766

mtryan83 opened this issue Dec 21, 2023 · 2 comments · Fixed by #4768

Comments

@mtryan83
Copy link
Contributor

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 strs and tuples 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?).

@neutrinoceros
Copy link
Member

This should to and be mentioned in #4590

@mtryan83
Copy link
Contributor Author

I'm not positive, but I don't think this is related to #4590 (mostly because I originally ran into this problem with GIZMO data). I suspect it's an artifact from the 4.0 transition?

I think I have a possible fix actually, I'll post a pr in a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants