forked from nblettner/eSALpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAL_visualization.py
134 lines (112 loc) · 3.18 KB
/
SAL_visualization.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import numpy as np
import matplotlib.pyplot as plt
import proplot as pplt
def maps_with_bars(fields, sal_out, cMap=None, cLevels=None, outname=None):
mapsz = 7
x_strech = 1.4
fontsz = 14
c_markers = "r"
cmap_binary_wb = ["#FFFFFF", "#000000"]
cmap_binary_wo = ["#FFFFFF", c_markers]
plot_array = [
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, 1, 2, 2, 2],
[3, 3, 3, 3, 3, 3],
]
fig, axs = pplt.subplots(
plot_array,
figsize=(mapsz * x_strech, mapsz),
space=0.1,
sharey=3,
sharex=3,
)
# map plots -----------------
title = ["Prediction", "Reference"]
name = ["sim", "ref"]
cLevels = np.linspace(0, np.max(fields), 20)
# loop over fields
for i_field, field in enumerate(fields):
# rainfall
axs[i_field].pcolormesh(field, cmap=cMap, levels=cLevels)
# # contour for threshold
# axs[i_field].contour(
# field,
# levels=np.array([-1, sal_out["thld_%s" % name[i_field]]]),
# lw=50,
# colors=cmap_binary_wo,
# zorder=4
# )
# center of mass
axs[i_field].scatter(
sal_out["tcm_x_%s" % name[i_field]],
sal_out["tcm_y_%s" % name[i_field]],
marker="X",
color=c_markers,
ec="white",
s=200,
label=""
)
# format
axs[i_field].set_title(title[i_field], fontsize=fontsz)
axs[:2].format(
ylim=[0, field.shape[0]], xlim=[0, field.shape[1]], yticks=[], xticks=[],
ylabel="", xlabel=""
)
# axs[0].plot([], [], c_markers, label="Threshold Value")
axs[0].scatter(
[], [], marker="X", color=c_markers, ec="white", s=200, label="Center of Mass"
)
axs[0].legend(loc="lr") # , fontsize=14)
# SAL Plot -------------------
axs[2].scatter(
sal_out["S"].values,
3,
c="r",
marker="D",
s=100,
zorder=4
)
axs[2].scatter(
sal_out["A"].values,
2,
c="r",
marker="D",
s=100,
zorder=4
)
axs[2].scatter(
sal_out["L"].values,
1,
c="r",
marker="D",
s=100,
zorder=4
)
axs[2].axvline(0, c="k", linewidth=5, zorder=3)
# axs[2].set_title('SAL', fontsize=14)
# horizontal bars
axs[2].axhline(3, c="gray")
axs[2].axhline(2, c="gray")
axs[2].axhline(1, xmin=0.5, c="gray")
# formatting
axs[2].set_ylim((0.5, 3.5))
axs[2].set_yticks([1, 2, 3])
axs[2].set_yticklabels(["L", "A", "S"], fontsize=fontsz)
axs[2].set_xlim((-2, 2))
axs[2].set_xticks([-2, -1, 0, 1, 2])
axs[2].set_xticklabels([-2, -1, 0, 1, 2], fontsize=fontsz)
axs[2].format(
ygrid=False,
ytickminor=False,
)
if outname is not None:
fig.savefig(outname, dpi=150)
def gauss2D(y, x, ymu, xmu, sig):
yp = (1 / (sig * (2 * np.pi) ** (1 / 2))) * np.exp(
(-1 / 2) * ((y - ymu) / sig) ** 2
)
xp = (1 / (sig * (2 * np.pi) ** (1 / 2))) * np.exp(
(-1 / 2) * ((x - xmu) / sig) ** 2
)
return yp * xp