Skip to content

Rx and Ry distances for sources in source modelling#58

Open
lispandfound wants to merge 6 commits intomainfrom
rx_ry
Open

Rx and Ry distances for sources in source modelling#58
lispandfound wants to merge 6 commits intomainfrom
rx_ry

Conversation

@lispandfound
Copy link
Copy Markdown
Contributor

@lispandfound lispandfound commented Mar 19, 2026

Calculates:

  1. Planar rx/ry between one plane and many points,
  2. Fault rx/ry between one fault and many points,
  3. Scenario rx/ry between several faults and many points.

I have introduced a new gc2_distances module for the calculation, and several extensive tests for every part of the process.

Here is "proof by picture" that the calculations appear to work using a dummy pair of faults.

rx_calculations

I will dogfood this for my own hazard calculations and make any further fixes.

@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 significantly enhances the source-modelling library by introducing robust capabilities for calculating Rx and Ry distances, crucial metrics in seismic hazard analysis. It centralizes the core distance logic in a new gc2_distances module and seamlessly integrates these calculations into existing Plane and Fault source types, as well as providing a function for multi-fault scenarios. This update ensures accurate and efficient distance computations for various source geometries.

Highlights

  • New Distance Module: Introduced a new gc2_distances.py module to implement the NGA-West-3 Rx/Ry distance metrics for seismic source modeling.
  • Source Class Integration: Added rx_ry_distance methods to the Plane and Fault classes, allowing direct calculation of Rx and Ry distances for individual sources.
  • Multi-Fault Distance Calculation: Implemented a multi_fault_rx_ry_distance function to handle Rx/Ry calculations for scenarios involving multiple faults or planes.
  • Python Version Compatibility: Broadened the supported Python versions in pyproject.toml to >=3.11.
  • Comprehensive Testing: Included a new test_rx_ry.py file with extensive unit and property-based tests to ensure the accuracy and robustness of the new distance calculations.
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 introduces a new module gc2_distances for calculating Rx and Ry distances as per the NGA-West-3 specification, and integrates it into the existing Plane and Fault source models. The implementation is well-structured and accompanied by an extensive and high-quality test suite, which provides strong confidence in the correctness of the complex geometric calculations. The code is clear and leverages numpy effectively for performance. I've identified a couple of minor areas for improvement regarding code maintainability and robustness, detailed in the specific comments.

lispandfound and others added 2 commits March 19, 2026 16:28
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@lispandfound lispandfound requested a review from Copilot March 19, 2026 03:30
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

This PR introduces GC2-style Rx/Ry distance calculations (per Spudich & Chiou, 2015) into source_modelling, adds Plane/Fault/multi-fault convenience APIs, and provides a comprehensive new test suite to validate the geometry and weighting logic.

Changes:

  • Added new source_modelling.gc2_distances module implementing segment, fault, and multi-trace GC2 Rx/Ry computations.
  • Extended Plane and Fault with rx_ry_distance (plus rx_distance/ry_distance for Plane) and added multi_fault_rx_ry_distance.
  • Added extensive tests covering segment rx/ry, segment weights, antipodal selection, reductions, strike correction, and multi-trace aggregation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.

File Description
source_modelling/gc2_distances.py New GC2 distance implementation (segment + generalised multi-trace logic) with numba-accelerated reductions.
source_modelling/sources.py Adds Plane/Fault rx/ry APIs and multi-fault helper wiring into gc2_distances.
tests/test_rx_ry.py New test suite for segment/fault/multi-trace rx/ry behavior and core helper routines.
pyproject.toml Updates supported Python version constraint.

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

You can also share your feedback on Copilot code review. Take the survey.

trace = self.bounds[:2, :2]
point = coordinates.wgs_depth_to_nztm(point)[..., :2]
rx, ry = gc2_distances.segment_rx_ry(trace, point)
return rx.squeeze(), ry.squeeze()
Comment on lines +1367 to +1369
trace_lengths = np.linalg.norm(p_end - p_start, axis=-1)
origins = np.cumulative_sum(trace_lengths[:-1], include_initial=True)
t, u = gc2_distances.generalised_t_u_coordinates(trace_lengths, rx, ry, origins)
trace_lengths = np.linalg.norm(p_end - p_start, axis=-1)
origins = np.cumulative_sum(trace_lengths[:-1], include_initial=True)
t, u = gc2_distances.generalised_t_u_coordinates(trace_lengths, rx, ry, origins)
return t.squeeze(), u.squeeze()
Comment on lines +1395 to +1397
trace_indices = np.cumulative_sum(
[len(trace) for trace in traces], include_initial=True
)
description = "Source modelling library"
readme = "README.md"
requires-python = ">=3.11,<3.14"
requires-python = ">=3.11"
Comment on lines +17 to +19
from numba import float64, int64, njit, uint64


Comment on lines +242 to +244
The weighted average rx distance, an array of shape (m, n).
u : np.ndarray
The weighted average ry distance, an array of shape (m, n).
Comment on lines +349 to +350
trace_points = np.array([[0.0, 0.0], [5.0, 0.0], [5.0, 0.0], [15.0, 0.0]])
trace_indices = np.array([0, 2, 4], dtype=np.uint64)


def test_diff_reduction_isolates_traces() -> None:
# 5 points, 2 traces: [P0, P1, P2] and [P3, P4]
Comment on lines +379 to +381
trace_direction_start_indices = np.cumulative_sum(
directions_per_trace, include_initial=True
)
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.

2 participants