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

more SPH field improvements #4584

Merged
merged 14 commits into from
Sep 14, 2023
Merged

more SPH field improvements #4584

merged 14 commits into from
Sep 14, 2023

Conversation

jzuhone
Copy link
Contributor

@jzuhone jzuhone commented Jul 19, 2023

PR Summary

Continuing to find improvements to be made to detection of SPH fields:

  • Supporting Gadget fields such as "ColdFraction", "CloudFraction", and "HotPhaseTemperature" with yt-like aliases.
  • Support AREPO/TNG fields "cooling_rate" and "cooling_time".
  • Metal fields can be of "local" sampling_type or "particle" sampling_type depending on if they are star or gas particles.
  • The core of the PR is to make detection of metal fields much more flexible for Gadget and its derivatives, accounting for the (somewhat unfortunate) variety of naming schemes for how these fields are stored in files.

Tests, and probably a bit of documentation about how metal fields are detected, are incoming.

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 changed the title Sph fields more SPH field improvements Jul 19, 2023
@jzuhone jzuhone added the enhancement Making something better label Jul 19, 2023
matthewturk
matthewturk previously approved these changes Jul 20, 2023
units=self.ds.unit_system["density"],
)

return metal_names

def _setup_eleven_metal_masses(self, ptype):
def _make_fraction_functions(self, ptype, fname):
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible at all to reuse the code in periodic_table.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try, but I actually don't think it works

ret = mass / data[(ptype, "particle_mass")]
return ret

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.

Just to clarify, this is done this way because it doesn't track H specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right

@matthewturk
Copy link
Member

What else are you thinking before moving to ready-to-review?

@jzuhone
Copy link
Contributor Author

jzuhone commented Aug 22, 2023

@matthewturk tests and docs, sorry, got sidetracked

@jzuhone
Copy link
Contributor Author

jzuhone commented Aug 22, 2023

This PR now depends on yt-project/website#122 and the corresponding file (already on dickenson) needs to be put on Jenkins (@Xarthisius)

@jzuhone jzuhone marked this pull request as ready for review September 4, 2023 21:14
@neutrinoceros
Copy link
Member

@yt-fido test this please

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 5, 2023

Jenkins still needs the file, I believe, and then I will add the new answer test. Ping @Xarthisius for https://yt-project.org/data/magneticum_camels.tar.gz

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 8, 2023

@Xarthisius just wanted to ping you again on the above ^^ (sorry for being a nuisance)

@Xarthisius
Copy link
Member

@Xarthisius just wanted to ping you again on the above ^^ (sorry for being a nuisance)

Sorry I missed it! It's up now.

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 9, 2023

Let's see if the new test passes here (it did on my laptop). If it does, we're ready to go here.

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 9, 2023

@yt-fido test this please

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 9, 2023

@Xarthisius Jenkins failures appear unrelated?

@neutrinoceros
Copy link
Member

@jzuhone regular tests are a bit flaky since we switch to Python 3.10, which is what we're seeing here. And from what I understand, doc builds are unstable until #4663 is done.

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 10, 2023

@yt-fido test this please

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 11, 2023

@yt-fido test this please

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 12, 2023

This is ready to go.

munkm
munkm previously approved these changes Sep 12, 2023
Copy link
Member

@munkm munkm left a comment

Choose a reason for hiding this comment

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

This looks good! I have a few minor comments/questions.

Comment on lines 100 to 129
n_elem = len(
[
fd
for fd in self.ds.field_list
if fd[0] == ptype and fd[1].startswith("MetalMasses")
]
)
elem_names = {
7: ["C", "N", "O", "Mg", "Si", "Fe", "Ej"],
8: ["He", "C", "O", "Mg", "S", "Si", "Fe", "Ej"],
11: ["He", "C", "Ca", "O", "N", "Ne", "Mg", "S", "Si", "Fe", "Ej"],
15: [
"He",
"C",
"Ca",
"O",
"N",
"Ne",
"Mg",
"S",
"Si",
"Fe",
"Na",
"Al",
"Ar",
"Ni",
"Ej",
],
}[n_elem]
no_He = "He" not in elem_names
Copy link
Member

Choose a reason for hiding this comment

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

I found the logic of this part a little bit confusing. But I don't have a good alternative suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you--I can add some comments to explain what's going on.

Copy link
Member

Choose a reason for hiding this comment

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

The new comments are helpful! Thank you for adding them.

elem_names = {
7: ["C", "N", "O", "Mg", "Si", "Fe", "Ej"],
8: ["He", "C", "O", "Mg", "S", "Si", "Fe", "Ej"],
11: ["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.

Out of curiosity, is there a possibility that an output will have both MetalMasses and ElevenMetalMasses fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really--both are in fact somewhat arbitrary. ElevenMetalMasses is a translation field name for Gadget binary datasets defined here. MetalMasses is a convention I've seen used in Gadget HDF5, and (even worse) Mass of Metals is one I saw used in another similar dataset.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, cool! Thanks for the clarification.

if fd[0] == ptype and fd[1].startswith("MetalMasses")
]
)
elem_names = {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe moving the elem_names dict outside of both field defs and using the same list of elements elem_names[11] for both ElevenMetalMasses and MetalMasses fields would reduce some of the redundancy in your code?

Comment on lines +171 to +185
elems = [
"He",
"C",
"Ca",
"O",
"N",
"Ne",
"Mg",
"S",
"Si",
"Fe",
"Na",
"Al",
"Ar",
"Ni",
Copy link
Member

Choose a reason for hiding this comment

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

I noticed your MetalMasses_ definition didn't include a definition for 14. Did you want to add that too since that's the use case for your test?

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 14 has to be treated differently. It's not a real element, it's basically just the mass of the rest of the elements not specified in the list, and in the codes that use it it's called Ej for "ejecta" (because it comes from supernovae explosions). We define an Ej_fraction field, but the reason I can't stick it in the elem list is that list the Ej_mass field doesn't exist, as it's not a real element and it doesn't get passed through yt's species machinery (though maybe it should be defined on its own).

Copy link
Member

Choose a reason for hiding this comment

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

Ok so your new commits do define it on its own now, is my understanding of that commit correct?

Comment on lines 111 to 127
15: [
"He",
"C",
"Ca",
"O",
"N",
"Ne",
"Mg",
"S",
"Si",
"Fe",
"Na",
"Al",
"Ar",
"Ni",
"Ej",
],
Copy link
Member

Choose a reason for hiding this comment

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

feels like a good place to use # fmt: skip

@neutrinoceros
Copy link
Member

I meant to fill in as a reviewer but I'm happy to get behind @munkm's approval.

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 12, 2023

@munkm @neutrinoceros see c8f4604 and 5156e29, thanks for the helpful suggestions that influenced these.

@jzuhone
Copy link
Contributor Author

jzuhone commented Sep 13, 2023

This is ready.

Copy link
Member

@munkm munkm left a comment

Choose a reason for hiding this comment

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

I like the improvements you made. Thank you for the changes.

One thing I thought about overnight -- is there any possibility a file would have more than one grouping of n_elem? (that is, that more than one option could be triggered by your logic) I can't think of a situation where that would happen, but if it does it it something we should add handling for?

Comment on lines +171 to +185
elems = [
"He",
"C",
"Ca",
"O",
"N",
"Ne",
"Mg",
"S",
"Si",
"Fe",
"Na",
"Al",
"Ar",
"Ni",
Copy link
Member

Choose a reason for hiding this comment

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

Ok so your new commits do define it on its own now, is my understanding of that commit correct?

elem_names = {
7: ["C", "N", "O", "Mg", "Si", "Fe", "Ej"],
8: ["He", "C", "O", "Mg", "S", "Si", "Fe", "Ej"],
11: ["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.

Ok, cool! Thanks for the clarification.

Comment on lines 100 to 129
n_elem = len(
[
fd
for fd in self.ds.field_list
if fd[0] == ptype and fd[1].startswith("MetalMasses")
]
)
elem_names = {
7: ["C", "N", "O", "Mg", "Si", "Fe", "Ej"],
8: ["He", "C", "O", "Mg", "S", "Si", "Fe", "Ej"],
11: ["He", "C", "Ca", "O", "N", "Ne", "Mg", "S", "Si", "Fe", "Ej"],
15: [
"He",
"C",
"Ca",
"O",
"N",
"Ne",
"Mg",
"S",
"Si",
"Fe",
"Na",
"Al",
"Ar",
"Ni",
"Ej",
],
}[n_elem]
no_He = "He" not in elem_names
Copy link
Member

Choose a reason for hiding this comment

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

The new comments are helpful! Thank you for adding them.

@neutrinoceros neutrinoceros added this to the 4.3.0 milestone Sep 14, 2023
@neutrinoceros neutrinoceros merged commit 8ef1569 into yt-project:main Sep 14, 2023
13 checks passed
@jzuhone jzuhone deleted the sph_fields branch January 22, 2024 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making something better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants