Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions nshmdb/nshmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

from nshmdb import query
from qcore import coordinates
from source_modelling.moment import BoldM

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.

medium

Import Mapping and Union from typing to support a more flexible type signature for parent_fault_magnitudes that accepts both standard float and BoldM values.

Suggested change
from source_modelling.moment import BoldM
from typing import Mapping, Union
from source_modelling.moment import BoldM

from source_modelling.sources import Fault, Plane


Expand Down Expand Up @@ -153,7 +154,7 @@ def add_rupture(
)

def most_likely_fault(
self, rupture_id: int, parent_fault_magnitudes: dict[str, float]
self, rupture_id: int, parent_fault_magnitudes: dict[str, BoldM]
) -> dict[str, float]:
Comment on lines 156 to 158

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.

medium

By changing the type annotation of parent_fault_magnitudes from dict[str, float] to dict[str, BoldM], any existing or future callers passing a standard dict[str, float] will trigger static type-checking errors (since dict is invariant in Python).

To allow both float and BoldM (or other magnitude conventions) without type-checking issues, use Mapping[str, Union[float, BoldM]]. Since Mapping is covariant in its value type, this will seamlessly accept both dict[str, float] and dict[str, BoldM] without requiring any # type: ignore comments.

    def most_likely_fault(
        self,
        rupture_id: int,
        parent_fault_magnitudes: Mapping[str, Union[float, BoldM]],
    ) -> dict[str, float]:

"""
Calculate the cumulative activity rate for each fault involved in a specified rupture.
Expand All @@ -174,9 +175,10 @@ def most_likely_fault(
----------
rupture_id : int
The unique identifier of the rupture to query.
parent_fault_magnitudes : dict[str, float]
A mapping of parent fault names to their expected magnitudes. These magnitudes
define the target values for querying activity rates in the MFD table.
parent_fault_magnitudes : dict[str, BoldM]
A mapping of parent fault names to their expected magnitudes (in the
`BoldM` convention). These magnitudes define the target values for
querying activity rates in the MFD table.
Comment on lines +178 to +181

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.

medium

Update the docstring to reflect that parent_fault_magnitudes can accept either standard float values or BoldM convention objects.

Suggested change
parent_fault_magnitudes : dict[str, BoldM]
A mapping of parent fault names to their expected magnitudes (in the
`BoldM` convention). These magnitudes define the target values for
querying activity rates in the MFD table.
parent_fault_magnitudes : Mapping[str, Union[float, BoldM]]
A mapping of parent fault names to their expected magnitudes (either as
floats or in the `BoldM` convention). These magnitudes define the target
values for querying activity rates in the MFD table.


Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pygmt-helper
pytest
qcore-utils
shapely
source-modelling
source-modelling>=2026.6.2
typer
3 changes: 2 additions & 1 deletion tests/test_nshmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from nshmdb.nshmdb import NSHMDB, FaultInfo, Rupture
from source_modelling.moment import BoldM


@pytest.fixture
Expand Down Expand Up @@ -140,7 +141,7 @@ def test_query(alpine_fault_nshmdb: NSHMDB):


def test_rates(alpine_fault_nshmdb: NSHMDB):
assert alpine_fault_nshmdb.most_likely_fault(1, {"Alpine Fault": 6.5}) == {
assert alpine_fault_nshmdb.most_likely_fault(1, {"Alpine Fault": BoldM(6.5)}) == {
"Alpine Fault": 0.01
}

Expand Down
Loading