Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keurfonluu committed Dec 8, 2022
1 parent fea376e commit 168a8f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
18 changes: 4 additions & 14 deletions bruces/stats/_sample_magnitude.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import numpy as np

from .._common import jitted

__all__ = [
"sample_magnitude",
]


@jitted
def grmag(low=0.0, high=None, b=1.0, size=1):
"""Draw magnitude samples."""
beta = 2.30258509 * b # np.log(10**b)
u = np.random.rand(size)
u *= 1.0 - np.exp(-beta * (high - low)) if high is not None else 1.0

return low - np.log(1.0 - u) / beta


def sample_magnitude(low=0.0, high=None, b=1.0, size=1):
"""
Draw magnitude samples following Gutenberg-Richter law.
Expand All @@ -38,6 +26,8 @@ def sample_magnitude(low=0.0, high=None, b=1.0, size=1):
Sampled magnitudes.
"""
m = grmag(low, high, b, size)
beta = 2.30258509 * b # np.log(10**b)
u = np.random.rand(size) if size > 1 else np.random.rand()
u *= 1.0 - np.exp(-beta * (high - low)) if high is not None else 1.0

return m[0] if size == 1 else m
return low - np.log(1.0 - u) / beta
3 changes: 2 additions & 1 deletion tests/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def test_etas():
K=0.5,
b=1.4,
d=0.1,
seed=42,
)

assert len(cat) == 18
assert len(cat) == 23


def test_seismicity_rate():
Expand Down

0 comments on commit 168a8f7

Please sign in to comment.