Rx and Ry distances for sources in source modelling#58
Rx and Ry distances for sources in source modelling#58lispandfound wants to merge 6 commits intomainfrom
Conversation
Summary of ChangesHello, 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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
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_distancesmodule implementing segment, fault, and multi-trace GC2 Rx/Ry computations. - Extended
PlaneandFaultwithrx_ry_distance(plusrx_distance/ry_distanceforPlane) and addedmulti_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() |
| 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() |
| 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" |
| from numba import float64, int64, njit, uint64 | ||
|
|
||
|
|
| 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). |
| 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] |
| trace_direction_start_indices = np.cumulative_sum( | ||
| directions_per_trace, include_initial=True | ||
| ) |
Calculates:
I have introduced a new
gc2_distancesmodule 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.
I will dogfood this for my own hazard calculations and make any further fixes.