Skip to content

Commit

Permalink
refactor: minor syntax improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex870521 committed Nov 2, 2024
1 parent f61d33d commit cb431e0
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 214 deletions.
3 changes: 1 addition & 2 deletions AeroViz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from AeroViz import plot
from AeroViz.dataProcess import DataProcess
from AeroViz.rawDataReader import RawDataReader
from AeroViz.tools import DataBase, DataReader, DataClassifier
from AeroViz.tools import DataBase, DataClassifier

__all__ = [
'plot',
'RawDataReader',
'DataProcess',
'DataBase',
'DataReader',
'DataClassifier'
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
from scipy.special import jv, yv


def coerceDType(d):
if type(d) is not np.ndarray:
return np.array(d)
else:
return d


def MieQ(m, wavelength, diameter, nMedium=1.0, asDict=False, asCrossSection=False):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#MieQ
nMedium = nMedium.real
Expand Down Expand Up @@ -271,8 +264,8 @@ def Mie_SD(m, wavelength, dp, ndp, nMedium=1.0, SMPS=True, interpolate=False, as
nMedium = nMedium.real
m /= nMedium
wavelength /= nMedium
dp = coerceDType(dp)
ndp = coerceDType(ndp)
dp = np.array(dp)
ndp = np.array(ndp)
_length = np.size(dp)
Q_ext = np.zeros(_length)
Q_sca = np.zeros(_length)
Expand Down Expand Up @@ -373,8 +366,8 @@ def SF_SD(m, wavelength, dp, ndp, nMedium=1.0, minAngle=0, maxAngle=180, angular
wavelength /= nMedium

_steps = int(1 + (maxAngle - minAngle) / angularResolution)
ndp = coerceDType(ndp)
dp = coerceDType(dp)
ndp = np.array(ndp)
dp = np.array(dp)
SL = np.zeros(_steps)
SR = np.zeros(_steps)
SU = np.zeros(_steps)
Expand Down
File renamed without changes.
62 changes: 62 additions & 0 deletions AeroViz/dataProcess/SizeDistr/prop.py
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()}
1 change: 0 additions & 1 deletion AeroViz/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from . import optical
from .bar import bar
from .box import box
from .hysplit import hysplit
from .pie import pie, donuts
from .radar import radar
from .regression import linear_regression, multiple_linear_regression
Expand Down
1 change: 0 additions & 1 deletion AeroViz/plot/hysplit/__init__.py

This file was deleted.

Loading

0 comments on commit cb431e0

Please sign in to comment.