-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_util.py
More file actions
41 lines (32 loc) · 992 Bytes
/
app_util.py
File metadata and controls
41 lines (32 loc) · 992 Bytes
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
import numpy as np
import pandas as pd
from matplotlib.colors import LinearSegmentedColormap
def refl_snapshot_to_df(ss):
return pd.DataFrame(
{
"lat": ss.lat,
"lon": ss.lon,
"alt": ss.alt,
"dBZ": ss.dBZ,
}
)
cmap = LinearSegmentedColormap.from_list(
"ice",
[
(0.0, (1.0, 1.0, 1.0)), # Pure white
(0.5, (0.8, 0.9, 1.0)), # Very light blue
(1.0, (0.2, 0.5, 1.0)), # Light blue
],
)
def get_reflectivity_rgba(dBZ: np.float16, threshold_dBZ: float):
norm_dBZ = np.clip((dBZ - threshold_dBZ) / (80 - threshold_dBZ), 0, 1)
rgba = cmap(norm_dBZ)
min_opacity = 0.02
max_opacity = 0.2
norm_dBZ = norm_dBZ = np.clip((dBZ - threshold_dBZ) / (80 - threshold_dBZ), 0, 1)
return [
int(rgba[0] * 255),
int(rgba[1] * 255),
int(rgba[2] * 255),
int((min_opacity + (max_opacity - min_opacity) * np.clip(norm_dBZ, 0, 1)) * 255),
]