Skip to content

Refactor generate velocity model parameters#83

Merged
lispandfound merged 33 commits intopegasusfrom
generate_domain_refactor
Jan 19, 2026
Merged

Refactor generate velocity model parameters#83
lispandfound merged 33 commits intopegasusfrom
generate_domain_refactor

Conversation

@lispandfound
Copy link
Contributor

@lispandfound lispandfound commented Jan 6, 2026

  1. It removes the dict_zip function and moves it to utils. Doing this allowed proper testing of the function. I also added better type hinting in the two and three argument case.
  2. Fixed the rake calculation to use a moment-weighted circular mean instead of unweighted arithmetic mean for GMM inputs.
  3. Depth calculation is now always at least as deep as the deepest source plus a buffer.
  4. R-surface is used instead of rrup, and is estimated directly from magnitude instead of PGV. This reflects changes in our thinking on domain estimation in the last year or so.

I also added some unit and integration tests to the generate_domain module, which test some key properties:

  1. That the simulation domain contains the sources,
  2. That the simulation duration scales with magnitude and produces sensible outputs and,
  3. That a simple E2E test of the generate domain stage works.

Finally, in response to @claudio525, I have extracted the domain generation logic into a function that does not require a realisation file. There is now generate_domain.generate_domain which takes realisation objects and returns domain parameters, and generate_domain.generate_domain_from_realisation that takes a path to a realisation file and reads the relevant parameters from the file, and writes them back.

…ion logic to pure function

- Move domain and duration computation into new generate_domain function
- Add generate_domain_from_realisation as CLI entrypoint for file-based workflow
- Improve separation of concerns and enable easier testing of domain logic
Copilot AI review requested due to automatic review settings January 6, 2026 00:50
@gemini-code-assist
Copy link

Summary of Changes

Hello @lispandfound, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring of the simulation domain parameter generation process. The core functionality has been extracted into a new, dedicated module, enhancing modularity and maintainability. These changes improve the accuracy of seismic calculations, bolster test coverage, and provide more flexible interfaces for integrating domain generation into the workflow.

Highlights

  • Refactored Domain Generation: The generate_velocity_model_parameters stage has been refactored into a new, modular generate_domain module, improving code organization and testability.
  • Improved dict_zip Utility: The dict_zip function was moved to workflow/utils.py, given better type hinting for two and three argument cases, and now has dedicated unit tests.
  • Enhanced Rake Calculation: Rake calculation now uses a moment-weighted circular mean instead of an unweighted arithmetic mean for GMM inputs, leading to more accurate results.
  • Robust Depth Calculation: The depth calculation ensures the simulation domain is always at least as deep as the deepest source plus an additional buffer.
  • New Unit and Integration Tests: Added comprehensive unit and integration tests for the generate_domain module, verifying that the simulation domain contains sources, duration scales with magnitude, and end-to-end functionality works as expected.
  • Flexible Domain Generation Interface: The domain generation logic has been extracted into two functions: generate_domain.generate_domain (which takes realisation objects) and generate_domain.generate_domain_from_realisation (which takes a path to a realisation file).

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant and well-executed refactoring of the domain generation logic, moving it from generate_velocity_model_parameters.py to a new, more modular generate_domain.py script. The introduction of generate_domain and generate_domain_from_realisation functions is a great improvement for testability and reusability. Moving dict_zip to utils and adding comprehensive tests for it is also a positive change. The fixes to the rake and depth calculations are valuable improvements.

My review focuses on the new generate_domain.py script, where I've identified several opportunities for minor improvements, mainly around code clarity, removing redundancies, and handling edge cases. These include simplifying some data conversions, removing unnecessary type casts, and addressing a potential ValueError in average_rake. Overall, this is a high-quality contribution that significantly improves the codebase.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the generate_velocity_model_parameters stage by:

  • Extracting and improving the dict_zip utility function with enhanced type hints
  • Implementing moment-weighted circular mean for rake calculations
  • Improving depth calculation logic to ensure it's at least as deep as the deepest source plus buffer
  • Separating domain generation logic into reusable functions that don't require realisation files

Key changes:

  • The dict_zip function is moved to workflow/utils.py with comprehensive type overloads for better type inference
  • A new generate_domain.py module replaces generate_velocity_model_parameters.py with refactored functions
  • Unit tests added for dict_zip and integration properties for domain generation

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
workflow/utils.py Adds dict_zip function with type overloads for better type inference in 2 and 3 argument cases
workflow/scripts/generate_velocity_model_parameters.py Entire file removed as functionality moved to generate_domain.py
workflow/scripts/generate_domain.py New file containing refactored domain generation logic with separation of concerns between file I/O and domain calculations
tests/test_utils.py Adds comprehensive test coverage for dict_zip function with various edge cases
pyproject.toml Updates CLI command name from generate-velocity-model-parameters to generate-domain and adds test dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

lispandfound and others added 7 commits January 6, 2026 14:02
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lispandfound lispandfound changed the title This PR addresses a long overdue refactor of the generate_velocity_model_parameters stage: Refactor generate velocity model parameters for testing Jan 6, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lispandfound lispandfound changed the title Refactor generate velocity model parameters for testing Refactor generate velocity model parameters Jan 6, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

@claudio525 claudio525 left a comment

Choose a reason for hiding this comment

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

Nice one, just one minor comment.


Environment
-----------
Can be run in the cybershake container. Can also be run from your own computer using the `generate-domain` command which is installed after running `pip install workflow@git+https://github.com/ucgmsim/workflow`.

Choose a reason for hiding this comment

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

Nitpick, but maybe this should use pypi package instead of pulling it from github? Would need to do a release after this commit, but seems like the nicer option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At some point yes I will do this.

@lispandfound lispandfound merged commit 8d958cf into pegasus Jan 19, 2026
14 checks passed
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.

5 participants