-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from thpap/main
implemented Weichert (1980) method for estimation of GR-parameters
- Loading branch information
Showing
3 changed files
with
288 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import numpy as np | ||
from scipy import stats | ||
from typing import Optional, Tuple, Union | ||
|
||
|
||
def simulate_magnitudes(n: int, beta: float, mc: float) -> np.ndarray: | ||
def simulate_magnitudes(n: int, beta: float, mc: float, | ||
mag_max: Optional[float] = None) -> np.ndarray: | ||
""" Generates a vector of n elements drawn from an exponential distribution | ||
exp(-beta*M) | ||
Args: | ||
n: number of sample magnitudes | ||
beta: scale factor of the exponential distribution | ||
mc: completeness magnitude | ||
mc: cut-off magnitude | ||
mag_max: maximum magnitude. If it is not None, the exponential | ||
distribution is truncated at mag_max. | ||
Returns: | ||
mags: vector of length n of magnitudes drawn from an exponential | ||
distribution | ||
""" | ||
|
||
mags = np.random.exponential(1 / beta, n) + mc | ||
if mag_max: | ||
quantile1 = stats.expon.cdf(mc, loc=0, scale=1 / beta) | ||
quantile2 = stats.expon.cdf(mag_max, loc=0, scale=1 / beta) | ||
mags = stats.expon.ppf( | ||
np.random.uniform(quantile1, quantile2, size=n), | ||
loc=0, | ||
scale=1 / beta, | ||
) | ||
else: | ||
mags = np.random.exponential(1 / beta, n) + mc | ||
|
||
return mags |