-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f61d33d
commit cb431e0
Showing
15 changed files
with
305 additions
and
214 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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import numpy as np | ||
from numpy import exp, log | ||
from scipy.signal import find_peaks | ||
|
||
|
||
def geometric(dp: np.ndarray, | ||
dist: np.ndarray | ||
) -> tuple[float, float]: | ||
""" Calculate the geometric mean and standard deviation. """ | ||
|
||
_gmd = (((dist * log(dp)).sum()) / dist.sum()) | ||
|
||
logdp_mesh, gmd_mesh = np.meshgrid(log(dp), _gmd) | ||
_gsd = ((((logdp_mesh - gmd_mesh) ** 2) * dist).sum() / dist.sum()) ** .5 | ||
|
||
return exp(_gmd), exp(_gsd) | ||
|
||
|
||
def contribution(dp: np.ndarray, | ||
dist: np.ndarray | ||
) -> tuple[float, float, float]: | ||
""" Calculate the relative contribution of each mode. """ | ||
|
||
ultra = dist[(dp >= 11.8) & (dp < 100)].sum() / dist.sum() | ||
accum = dist[(dp >= 100) & (dp < 1000)].sum() / dist.sum() | ||
coars = dist[(dp >= 1000) & (dp < 2500)].sum() / dist.sum() | ||
|
||
return ultra, accum, coars | ||
|
||
|
||
def mode(dp: np.ndarray, | ||
dist: np.ndarray | ||
) -> np.ndarray: | ||
""" Find three peak mode in distribution. """ | ||
|
||
min_value = np.array([dist.min()]) | ||
mode, _ = find_peaks(np.concatenate([min_value, dist, min_value]), distance=len(dist) - 1) | ||
|
||
return dp[mode - 1] | ||
|
||
|
||
def properties(dist, | ||
dp: np.ndarray, | ||
dlogdp: np.ndarray, | ||
weighting: str | ||
) -> dict: | ||
""" for apply """ | ||
dist = np.array(dist) | ||
|
||
gmd, gsd = geometric(dp, dist) | ||
ultra, accum, coarse = contribution(dp, dist) | ||
peak = mode(dp, dist) | ||
|
||
return {key: round(value, 3) for key, value in | ||
{f'total_{weighting}': (dist * dlogdp).sum(), | ||
f'GMD_{weighting}': gmd, | ||
f'GSD_{weighting}': gsd, | ||
f'mode_{weighting}': peak[0], | ||
f'ultra_{weighting}': ultra, | ||
f'accum_{weighting}': accum, | ||
f'coarse_{weighting}': coarse} | ||
.items()} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.