Skip to content

Write SRF in format SW4 needs#59

Open
AndrewRidden-Harper wants to merge 19 commits intomainfrom
write-for-sw4
Open

Write SRF in format SW4 needs#59
AndrewRidden-Harper wants to merge 19 commits intomainfrom
write-for-sw4

Conversation

@AndrewRidden-Harper
Copy link
Copy Markdown
Contributor

This pull request adds support for writing SRF data in the format needed by SW4.
SW4 provides srf2hdf5.py to convert text-based SRFs to the SW4 format. However, this Python script is much slower than Jake's Rust SRF parser, so we do not simply adopt srf2hdf5.py. However, we do use our own forked version of srf2hdf5.py, which was slightly modified to handle our Version 1 SRF files, to also convert an example Version 1 SRF file provided by SW4, examples/rupture/rtest.srf. You can do this comparison yourself by cloning our fork of SW4 (which was only created for this check), checking out the branch write-v1-srf, and running the script tools/verify_sw4_hdf5.py.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces the capability to export Standard Rupture Format (SRF) data into a specialized HDF5 format tailored for the SW4 seismic simulation software. This enhancement streamlines the workflow for users who need to prepare SRF inputs for SW4, providing a direct and efficient conversion method within the existing SRF handling utilities. The implementation includes precise data structuring and comprehensive testing to ensure data integrity and compatibility with the target software.

Highlights

  • New SW4 HDF5 Export Functionality: A new method, write_sw4_hdf5, has been added to the SRF class in source_modelling/srf.py. This method allows for writing SRF data into the specific HDF5 format required by the SW4 simulation software, including handling of plane and point data structures, shear wave velocity, density, and slip time functions.
  • SW4 Data Type Definitions: Structured NumPy dtypes, SW4_PLANE_DTYPE and SW4_POINTS_DTYPE, were introduced to precisely define the data schema for the SW4 HDF5 format, ensuring compatibility with SW4's expectations for fault plane and rupture point attributes.
  • Comprehensive Testing for SW4 HDF5 Output: A new test case, test_sw4_hdf5_read_write, was added to tests/test_srf.py to validate the correctness and integrity of the data written by the write_sw4_hdf5 method. This test verifies the version, plane attributes, point data, and slip time function data against the original SRF content.
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.

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
Copy Markdown
Contributor

@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 adds functionality to write SRF data into SW4's HDF5 format. The implementation is largely correct and well-tested. However, I've identified a critical bug in handling array inputs for shear wave velocity and density which would cause a runtime error. Additionally, the new test case has a potential cross-platform compatibility issue and a minor maintainability concern. I have provided specific suggestions to address these points.

Copy link
Copy Markdown
Contributor

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

Adds an SW4-compatible SRF→HDF5 writer so SRF content can be consumed by SW4 without relying on the slower Python srf2hdf5.py conversion path.

Changes:

  • Introduces SrfFile.write_sw4_hdf5() to emit SW4’s expected HDF5 structure (VERSION, PLANE, POINTS, and optional SR1).
  • Adds SW4-specific NumPy structured dtypes (SW4_PLANE_DTYPE, SW4_POINTS_DTYPE) used for binary-compatible layout.
  • Adds a unit test validating round-trip preservation of header/points and slip-time-function data when writing SW4 HDF5.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
source_modelling/srf.py Adds SW4 HDF5 writer + SW4 structured dtypes; imports h5py.
tests/test_srf.py Adds coverage for write_sw4_hdf5() output structure and values.

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

AndrewRidden-Harper and others added 2 commits March 23, 2026 16:55
np.float32() fails on arrays, but the docstring allows np.ndarray.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@AndrewRidden-Harper
Copy link
Copy Markdown
Contributor Author

AndrewRidden-Harper commented Mar 23, 2026

ty type checker is finding 38 issues related to existing code not changed in this PR. Should they be fixed in a separate PR?

@sungeunbae
Copy link
Copy Markdown
Member

Do we have a format specification of SW4 HDF5?

joelridden
joelridden previously approved these changes Mar 24, 2026
@AndrewRidden-Harper
Copy link
Copy Markdown
Contributor Author

@sungeunbae The format is specified in the SW4 User Guide (Section 12.7, page 105). Do you think we should add the PDF to the repo?

AndrewRidden-Harper and others added 4 commits March 28, 2026 16:17
Co-authored-by: Jake Faulkner <jake.faulkner@canterbury.ac.nz>
Co-authored-by: Jake Faulkner <jake.faulkner@canterbury.ac.nz>
Co-authored-by: Jake Faulkner <jake.faulkner@canterbury.ac.nz>
Co-authored-by: Jake Faulkner <jake.faulkner@canterbury.ac.nz>
AndrewRidden-Harper and others added 5 commits March 28, 2026 16:21
Co-authored-by: Jake Faulkner <jake.faulkner@canterbury.ac.nz>
Co-authored-by: Jake Faulkner <jake.faulkner@canterbury.ac.nz>
@AndrewRidden-Harper
Copy link
Copy Markdown
Contributor Author

Thanks for the PR comments. I've addressed them all as you suggested

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