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

New fields for Arepo and Gadget frontends #3258

Merged
merged 25 commits into from
May 20, 2021

Conversation

jzuhone
Copy link
Contributor

@jzuhone jzuhone commented May 13, 2021

PR Summary

This PR adds new fields for both the Arepo and Gadget frontends.

  • For Arepo: adds the "CosmicRaySpecificEnergy" field and "PassiveScalars"
  • For Gadget: adds specifications to support Magneticum halos (http://www.magneticum.org) and known fields
  • For Gadget: If we already have a temperature field in the dataset, there is no need to create a derived field for it. This was technically a bug.

EDIT: This got more complicated. It turns out that if you naively run sph_answer on the Magneticum dataset that you get an error because you project a sphere at the domain center with no data in it (the data is confined to a small region of the domain). The error will need to be fixed in a separate PR.

It would have been simple to set a bounding box around the data, but when I tried this it took forever to construct the index. So I did a simple (and probably useful in the future thing) and allowed the sphere in sph_answer and nbody_answer to be set to some alternate center.

PR Checklist

  • New features are documented, with docstrings and narrative docs
  • Adds a test for any bugs fixed. Adds tests for new features.

@jzuhone jzuhone added code frontends Things related to specific frontends new feature Something fun and new! labels May 13, 2021
@jzuhone
Copy link
Contributor Author

jzuhone commented May 13, 2021

pre-commit.ci autofix

@jzuhone
Copy link
Contributor Author

jzuhone commented May 14, 2021

I added more doc edits--it turns out we had a number of things in Gadget and Arepo data that needed explaining in the docs.

For the tests to pass this needs the dataset which will be part of https://yt-project.org/data once PR yt-project/website#96 is merged (ping @Xarthisius) and I upload new answers.

@@ -124,3 +125,25 @@ def test_bigendian_field_access():
ds = data_dir_load(BE_Gadget)
data = ds.all_data()
data["Halo", "Velocities"]


mag_fields = OrderedDict(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick note: since Python 3.6, builtin dict objects are also ordered. At the time it was deemed an implementation detail, but it's been embraced as a feature since.
Some minor differences persist (see https://stackoverflow.com/questions/34305003/difference-between-dictionary-and-ordereddict), but it's doubtful we need them here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you look at the top of the file:

# This maps from field names to weight field names to use for projections
iso_fields = OrderedDict(
[
(("gas", "density"), None),
(("gas", "temperature"), None),
(("gas", "temperature"), ("gas", "density")),
(("gas", "velocity_magnitude"), None),
]
)

We have another one of these in there, which I copied to make the new one below. For some reason there are two ("gas","temperature") entries in here--OrderedDict simply replaces the first one with the second one silently without complaining. When I tried to change this to a dict the pre-commit bot complained.

So the real question is if sph_answer is expecting us to try projections with and without the weight field for ("gas","temperature"). Does anyone know (I can look myself, but if anyone knows please comment)? @matthewturk @brittonsmith @chummels

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me taking an unweighted projection of ("gas", "temperature") would be useless and non-sensical, so I don't think sph_answer should do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably is expecting that. A non-weighted temperature projection is generally not useful, but it can also serve as a proxy for testing in situations where the temperature itself is a derived field (rather than intrinsic) and we want to test the machinery of unweighted temperature projections. I don't know that we need to keep it in this instance, but I don't think we should always require that answer tests always map 1:1 to useful quantities.

Copy link
Member

@matthewturk matthewturk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; @jzuhone what is pending still?

@jzuhone
Copy link
Contributor Author

jzuhone commented May 18, 2021

@matthewturk need to fix the pre-commit issue, update test answers

@jzuhone
Copy link
Contributor Author

jzuhone commented May 18, 2021

@Xarthisius it looks like I screwed up the answer testing--can we remove local_gadget_007 on the build box?

@Xarthisius
Copy link
Member

@yt-fido test this please

@jzuhone
Copy link
Contributor Author

jzuhone commented May 18, 2021

@Xarthisius thanks!

@jzuhone
Copy link
Contributor Author

jzuhone commented May 19, 2021

This is finally ready.

@@ -259,6 +259,15 @@
"load_name": "plt00015",
"url": "https://yt-project.org/data/Laser.tar.gz"
},
"MagneticumCluster.tar.gz": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order for this to integrate with yt.load_sample, you'll need to update https://github.com/yt-project/website/blob/master/data/datafiles.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neutrinoceros This was done already (you looked at the PR): yt-project/website#96

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realise it was the same one. In any case I've tested this branch and it currently doesn't work

import yt
yt.load_sample("MagneticumCluster")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a traceback or something for more information?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this is what the traceback looked like (rather cryptic if you ask me) I made it much more informative for next time this kind of accident happens in #3277
Screenshot 2021-05-19 at 14 48 28

Co-authored-by: Clément Robert <cr52@protonmail.com>
Copy link
Member

@chummels chummels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks good; I have just a few comments inline. Thanks for putting some love into the AREPO/Gadget frontends. It's good that they're getting a bit more attention with the yt4 refactor.

and aliased to fields with the naming convention ``"PassiveScalars_XX"`` where
``XX`` is the number of the passive scalar array, e.g. ``"00"``, ``"01"``, etc.

HDF5 snapshots will be detected as Arepo data if they have the ``"GFM_Metals"``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for including this, @jzuhone !

This gets used with the magneticum_box2_hr format
as defined in the gadget_field_specs in frontends/gadget/definitions.py
"""
metal_names = ["He", "C", "Ca", "O", "N", "Ne", "Mg", "S", "Si", "Fe", "Ej"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's Ej? Is that ejected metals or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct--that's the name that the magneticum folks use for it.

)

# hydrogen fraction and density
def _h_fraction(field, data):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is interesting, calculating the H fraction as the remainder when you take away all the other elements. I think this will only work if Ej is distinct from all of the other elements present, though. Can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the way they are defined in magneticum.


def _temperature(field, data):
# Assume cosmic abundances
x_H = _primordial_mass_fraction["H"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to look on disk and see if there is already an H_fraction field and use that instead of assuming primordial?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. we need to think about this one a bit more carefully. I didn't change the field definition--I just moved it within a new if-then block. But I see what you mean. I'll try changing it, but I suspect it will break answer tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jzuhone pointed me to the TNG documentation where they themselves are calculating temperature using this formula, with primordial hydrogen abundances. So we should mimic that behavior and I retract my point above.

@chummels chummels merged commit 7bbaa93 into yt-project:main May 20, 2021
@jzuhone jzuhone deleted the new_arepo_fields branch May 21, 2021 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code frontends Things related to specific frontends new feature Something fun and new!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants