Fastest way to mirror the auto-generation of fields for gas particles?
yt generates many fields from the few that are saved on the disk. I am doing something weird with TNG data where I basically have 'PartType0' and 'PartType0_78', where 'PartType0_78' holds data on the gas particles at a different snapshot (namely, 78). I basically want yt to act like I have two different names for gas particles and generate the temperature, cylindrical coordinates, entropy, magnetic field, etc for 'PartType0_78' just as it does for 'PartType0'. The fields on disk are named the same. I tracked the fields down to yt/frontends/gadget/fields and/or yt/frontends/gadget/fields, and the setup_gas_particle_fields function. I tried doing it all from the plugins file, but the more I look, the more I feel like there's just a few lines where I'd need to change
if ptype=='PartType0':
to
if ptype in ('PartType0', 'PartType0_78'):
in the fields-related scripts and most of my work would be done automatically. Does anyone know where those few places might be?
Sorry for the bad formatting! I guess another issue would be that gas is referred to as 'PartType0' on disk, but some properties (I think fluid properties?) are generated/saved under "gas". Then I would need these to be saved under something like "gas_78", but I'm not sure how to do that.
Hi Jacob, Oh, dang, this is a great idea! I really like this. So what I'm thinking is that there may be a way to do this without touching too many places. Since it's TNG data I think it should be subclassing the gadget HDF5 dataset class. Can you try, before loading any of your datasets, doing this? import yt yt.frontends.gadget.data_structures.GadgetHDF5Dataset._sph_ptypes += ('PartType0_78',) and see if that helps? On Thu, Mar 14, 2024 at 6:11 PM Jacob Morgan <jmorgan15@crimson.ua.edu> wrote:
yt generates many fields from the few that are saved on the disk. I am doing something weird with TNG data where I basically have 'PartType0' and 'PartType0_78', where 'PartType0_78' holds data on the gas particles at a different snapshot (namely, 78). I basically want yt to act like I have two different names for gas particles and generate the temperature, cylindrical coordinates, entropy, magnetic field, etc for 'PartType0_78' just as it does for 'PartType0'. The fields on disk are named the same. I tracked the fields down to yt/frontends/gadget/fields and/or yt/frontends/gadget/fields, and the setup_gas_particle_fields function.
I tried doing it all from the plugins file, but the more I look, the more I feel like there's just a few lines where I'd need to change
if ptype=='PartType0':
to
if ptype in ('PartType0', 'PartType0_78'):
in the fields-related scripts and most of my work would be done automatically. Does anyone know where those few places might be? _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: matthewturk@gmail.com
Hey! Sorry I have been so long in replying. My current installation of yt is a mess, I had to make another thread about some issues I have to fix before I can test this: https://mail.python.org/archives/list/yt-users@python.org/thread/GM75POP42EH...
I’m also throwing some ideas in the pot, but you may be interested in using the particle trajectories functionality (although this isn’t exactly covering what you’re interested into). Otherwise, I’ve had some chance with a pseudo-code as follows (to be adapted to your use case) |ds1 = yt.load("/path/to/output_78") ds2 = yt.load("/path/to/other/output") old_ids = ds1.r["PartType0", "particle_identifier"] old_order = np.argsort(old_ids) def _old_density(field, data): ids = data["PartType0", "particle_identifier"] # find ids in old_ids inds = old_order[np.searchsorted(old_ids, ids, sorter=old_order)] # this is just to make sure I haven't messed up the ids matching np.testing.assert_allclose(ids, old_ids[inds]) # Return the value of the density for those matched indices return ds1.r["density"][inds] ds2.add_field(("PartType0", "old_density"), function=_old_density, sampling_type="cell", units=…) | On 04/04/2024 18:41, Jacob Morgan wrote:
Hey! Sorry I have been so long in replying. My current installation of yt is a mess, I had to make another thread about some issues I have to fix before I can test this:
https://mail.python.org/archives/list/yt-users@python.org/thread/GM75POP42EH... _______________________________________________ yt-users mailing list --yt-users@python.org To unsubscribe send an email toyt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address:contact@cphyc.me
participants (3)
-
Corentin Cadiou -
Jacob Morgan -
Matthew Turk