Skip to content

Conversation

cphyc
Copy link
Member

@cphyc cphyc commented Sep 20, 2024

PR Summary

Rockstar catalogs unfortunately are not self-descriptive. This PR is an attempt to automatically detect the format into which a catalog is written by simply trying all the formats until one is found that looks alright.

@cphyc
Copy link
Member Author

cphyc commented Sep 20, 2024

Note: this should only be merged after #4661 is merged

@cphyc cphyc marked this pull request as ready for review August 7, 2025 11:28
@cphyc cphyc requested a review from brittonsmith August 7, 2025 11:29
@cphyc cphyc added enhancement Making something better domain: astro labels Aug 7, 2025
brittonsmith
brittonsmith previously approved these changes Aug 15, 2025
Copy link
Member

@brittonsmith brittonsmith left a comment

Choose a reason for hiding this comment

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

I'm really sorry for never seeing this. It looks good to me, although I'm having trouble finding any data I can test it on. I remember that if you guess the format revision wrong the particle masses are nonsensical, but I can't remember if they are negative. I'm willing to take this PR's word for it since it provides a nice way to make additional tweaks.

@cphyc cphyc dismissed brittonsmith’s stale review August 15, 2025 14:36

The merge-base changed after approval.

@brittonsmith
Copy link
Member

@cphyc, is it too late to merge this? Maybe you just need to merge the PR branch with upstream changes.

@cphyc
Copy link
Member Author

cphyc commented Aug 16, 2025

Duh, I have no idea how your approval got dismissed but it is not too late to merge :)

@mtryan83
Copy link
Contributor

mtryan83 commented Aug 26, 2025

What's the expected/intended procedure for adding revisions that aren't strict upgrades?

For example, I primarily use a fork of Rockstar from Andrew Wetzel (here), which follows revision 2, but has two additional fields (m_hires and m_lowres). So the path would be straightforward: add a revision 3, version-gate the two additional fields, and go from there. E.g:

KNOWN_REVISIONS: list[int] = [0, 1, 2, 3] # Added version 3
...
    ("av_density", np.float32, (2, 100)),
    ("m_hires", np.float32, (3, 100)), # New
    ("m_lowres", np.float32, (3, 100)), # New
]

But Andrew also has another fork (alt fork) which is based off of revision 1, with an additional field, halfmass_radius, between m_pe_d and num_p. Obviously, I could add halfmass_radii with the version gate (1, 1) or similar, but then there'd be problems if I use, say, Behroozi's original version for something. I wouldn't want to define it as revision 3 or 4 (assuming the above version is 3). Would the expectation be it comes as revision 1.5 or similar? (But then what if there's another fork based on revision 1 with a different added field...)

This is directly related to the version issues I mentioned in #5031. (And for an example of that, the Wetzel revision 2-based version defines HALO_FORMAT_REVISION as 1, while the revision-1 based version defines it as 2 🤣 )

@cphyc
Copy link
Member Author

cphyc commented Aug 29, 2025

Hey @mtryan83,

So long as your alternative format has a different number of bytes in the header or in the members of the halos, what you wrote above should work (assuming m_hires and m_lowres are indeed located at the end of the halo definition).

If this works, would you mind opening a PR (on top of this one)?

As a side note, it would make the code much more readable if the syntax was:

halo_dt: list[HaloDataType] = [
    ("particle_identifier", np.int64),
    ("particle_position_x", np.float32),
    ("particle_position_y", np.float32),
    ("particle_position_z", np.float32),
    ("particle_mposition_x", np.float32, {0}),
    ("particle_mposition_y", np.float32, {0}),
    ("particle_mposition_z", np.float32, {0}),
    [...]
    ("m_pe_d", np.float32, {1, 2}),
    [...]
]

At the moment, the third (optional) argument gives a lower and upper boundary for the format revisions that should include the corresponding entry; using a set would be more explicit IMO.

brittonsmith
brittonsmith previously approved these changes Aug 29, 2025
@cphyc cphyc dismissed brittonsmith’s stale review August 29, 2025 10:30

The merge-base changed after approval.

brittonsmith
brittonsmith previously approved these changes Aug 29, 2025
@cphyc cphyc dismissed brittonsmith’s stale review August 29, 2025 12:00

The merge-base changed after approval.

@mtryan83
Copy link
Contributor

My bad, my comment should probably have been a new issue (#5278), it's only tangentially related to this PR.

brittonsmith
brittonsmith previously approved these changes Sep 1, 2025
@cphyc cphyc dismissed brittonsmith’s stale review September 1, 2025 12:26

The merge-base changed after approval.

brittonsmith
brittonsmith previously approved these changes Sep 1, 2025
@cphyc cphyc dismissed brittonsmith’s stale review September 1, 2025 12:34

The merge-base changed after approval.

@cphyc cphyc force-pushed the autodetect-rockstar-format branch from a7755ca to 945f008 Compare September 1, 2025 13:53
@brittonsmith brittonsmith merged commit 62a722c into yt-project:main Sep 1, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: astro enhancement Making something better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants