Skip to content

Perform basic sanity check on moment magnitude calculations#63

Merged
lispandfound merged 12 commits into
mainfrom
moment_sensibility
Jun 9, 2026
Merged

Perform basic sanity check on moment magnitude calculations#63
lispandfound merged 12 commits into
mainfrom
moment_sensibility

Conversation

@lispandfound

@lispandfound lispandfound commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Checks if magnitude calculations are too large. If user provides dyne-cm then magnitudes are ~4.5 log-units higher than they should be because the calculation only works with Newton-metres.

Also refactored the magnitude scaling dispatch functions so that they now correctly convert magnitude types between Mw/BoldM where required (mostly, Leonard).

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

Copy link
Copy Markdown
Contributor

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 a validation check to moment_to_magnitude to raise a ValueError if the calculated magnitude exceeds 10.0, preventing issues when input moments are mistakenly provided in dyne-cm instead of Nm. A corresponding unit test is also added. The review feedback suggests adding a check for non-positive moments to avoid runtime warnings and invalid values, and addresses minor PEP 8 formatting issues regarding extra spaces and excessive blank lines.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread source_modelling/moment.py
Comment thread tests/test_moment.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a basic plausibility guard to moment_to_magnitude so obviously mis-scaled seismic moments (notably dyne-cm passed where N·m is expected) fail fast instead of producing unrealistic magnitudes.

Changes:

  • Compute magnitude first, then raise a ValueError when the resulting magnitude exceeds 10.0 (heuristic for “physically implausible”).
  • Add a unit-focused test ensuring dyne-cm-scale inputs trigger the new error.

Reviewed changes

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

File Description
tests/test_moment.py Adds a regression test asserting dyne-cm moments raise a ValueError.
source_modelling/moment.py Introduces a magnitude upper-bound sanity check and returns computed magnitude after validation.

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

Comment thread tests/test_moment.py Outdated
Comment thread source_modelling/moment.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 5 out of 5 changed files in this pull request and generated 10 comments.

Comment thread source_modelling/moment.py
Comment thread source_modelling/moment.py
Comment thread source_modelling/magnitude_scaling.py
Comment thread source_modelling/magnitude_scaling.py Outdated
Comment thread source_modelling/magnitude_scaling.py
Comment thread source_modelling/magnitude_scaling.py
Comment thread tests/test_magnitude_scaling.py
Comment thread tests/test_magnitude_scaling.py
Comment thread source_modelling/magnitude_scaling.py
Comment thread source_modelling/magnitude_scaling.py
lispandfound and others added 6 commits June 9, 2026 14:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@AndrewRidden-Harper AndrewRidden-Harper left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. I explicitly checked the magnitude conversion maths

@lispandfound lispandfound merged commit 4a4f82d into main Jun 9, 2026
6 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.

3 participants