-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLWC.py
64 lines (49 loc) · 2.05 KB
/
LWC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: spirrobe -> github.com/spirrobe/
"""
def LWC(inputdata, # needs to be in # / m^3
data_is_conc=True,
binsizes=[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20,
22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50],
windspeed=[1], # in m/s
samplearea=0.298, # as area in square millimeters
samplefrequency=10,
combined=True,
quiet=True,
):
import numpy as np
inputdata = inputdata.copy()
# binsizes are NOT the treshold values that are sent via setup cmd
if not data_is_conc:
from ConcPerCCM import ConcPerCCM
_lwc = ConcPerCCM(inputdata,
windspeed=windspeed,
samplearea=samplearea,
samplefrequency=samplefrequency,
combined=False,
)
# if you have given bins directly, ConcPerCCM will give you back #/cm^3
# which we need to scale for the LWC
# convert the concentration from cm^3 (default) to m^3
# as we get per cm^3 from ConcPerCCM (as the name implies)
_lwc *= 10**6
else:
_lwc = np.asarray(inputdata, np.float)
if len(binsizes) < _lwc.shape[1]:
print('binsizes length must be one longer than length of bins')
return False
# midpoints are in micrometers
midpoints = [sum(_)/2 for _ in zip(binsizes[1:], binsizes[:-1])]
dropsize = [(midpoint)**3 * np.pi/6 * 10**-12 for midpoint in midpoints]
dropsize = np.asarray(dropsize)
if np.nanmax(_lwc) > 200000 and not quiet:
print('Warning from LWC():')
print('Are you sure the concentration is in # / m^3?')
print('It seems somewhat high with a max of', np.nanmax(_lwc))
if type(_lwc) != np.ndarray:
_lwc = np.asarray(_lwc, dtype=np.float)
_lwc = (_lwc * dropsize)
# choose either the sum of bins for a record or the single bins
return np.nansum(_lwc, axis=1) if combined else _lwc