Skip to content

New compasUtils file#1467

Open
reinhold-willcox wants to merge 1 commit intodevfrom
compas_post_processing_utils
Open

New compasUtils file#1467
reinhold-willcox wants to merge 1 commit intodevfrom
compas_post_processing_utils

Conversation

@reinhold-willcox
Copy link
Copy Markdown
Collaborator

Added my own compasUtils file, which I use for lots of post-processing and testing. It was previously in misc/unsupported_utils, so I am hoping to get it elevated to the level of the other utils.

This contains two major functions that help a lot with inspecting COMPAS data.

  • printCompasDetails: takes the hdf5 output (optionally with specific seeds or masks) and prints a pandas df of the whole output (including units). Makes it visually much easier to analyze the output from a jupyter notebook.
  • getEventStrings: takes the hdf5 output and generates a string per seed that summarizes the events in the binary. Events include SMT, CEE, SNe, and mergers, and these are listed chronologically with a funny but simple syntax (described in the function). Combined with np.unique(), this is a great way to quickly see which binary channels dominate and which are rare.

I expect that there will be changes requested, so it is probably not yet ready to be merged in, but happy to hear feedback on how to improve / align these scripts with the other python utilities.

@github-actions
Copy link
Copy Markdown

✅ COMPAS Build Successful!

Item Value
Commit 98df732
Logs View workflow

Detailed Evolution Plot

Click to view evolution plot


Generated by COMPAS CI

Copy link
Copy Markdown
Collaborator

@ilyamandel ilyamandel left a comment

Choose a reason for hiding this comment

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

I leave the review to folks who use python (@SimonStevenson ? @avigna ? ).

Consider including supported python tools in the documentation in https://compas.readthedocs.io/en/latest/pages/User%20guide/Post-processing/post-processing.html

@avivajpeyi
Copy link
Copy Markdown
Collaborator

avivajpeyi commented Apr 3, 2026

Looks cool! I would suggest adding some more doctrings at the top, adding some pytests to ensure that this is maintained/doesn't break in the future.

Also, how is this different from h5view?

Can they be merged together?

Finally, if you can add it to the setup.py entry points, its quite easy to get the auto-documentation tools to build docs like so

https://compas.readthedocs.io/en/latest/pages/User%20guide/Post-processing/hdf5/post-processing-h5view.html

I have some time, im happy to help with this if youd like :)

@nrsegovia
Copy link
Copy Markdown
Collaborator

As I suggested in @ilyamandel's post on Slack, I think it might be useful to add type hinting and docstring styling (similar to numpy) to bring the python code style closer to what we have for C++ files.

Perhaps we can start here by just adding type hints?

########################################################################
# ## Function to print the data from a given COMPAS HDF5 group in a readable pandas template

def printCompasDetails(data, *seeds, mask=()):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do I understand correctly that this function name might be a bit misleading? Outside the jupyter environment it would just return the data frame, not print it.

I also wonder if *seeds could be replaced for an input list, it might be more readable for large sets of seeds.

mask = np.ones_like(allSeeds).astype(bool)
mask &= seedsMask

df = pd.DataFrame.from_dict({param: data[param][()][mask] for param in list(data.keys())}).set_index(seedVariableName).T
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are a couple of values being repeated, e.g., ('SEED' in list_of_keys) and list(data.keys())

else: # No seed parameter, so do custom print for Run Details

# Get just the keys without the -Derivation suffix - those will be a second column
keys_not_derivations = []
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can be swapped for a one line definition without affecting readability, e.g., keys_not_derivations = [x for x in key_list if "-Derivation" not in x] or similar

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 this pull request may close these issues.

4 participants