-
Notifications
You must be signed in to change notification settings - Fork 0
/
06PlotFutureClimate
69 lines (55 loc) · 2.29 KB
/
06PlotFutureClimate
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
# %%
import numpy as np
import matplotlib.pyplot as plt
from utils import read_climate, line_styles
plt.style.use(['science', 'no-latex'])
plt.rcParams.update({
"figure.figsize": (4, 3)})
def plot_future_climate(city):
temp = []
precip = []
line_style, _ = line_styles()
for count, ssp in enumerate(['ssp126', 'ssp370', 'ssp585']):
for model in ['MIROC6', 'CanESM', 'CESM2']:
future_climate = read_climate(model, ssp, city)
future_climate['year'] = future_climate.index.year
grouped = future_climate.groupby('year').mean()
temp.append(grouped['Temp'].values.tolist())
Total_temp = np.array(temp)
temp_upper = np.max(Total_temp, axis=0)
temp_lower = np.min(Total_temp, axis=0)
temp_mean = np.mean(Total_temp, axis=0)
plt.fill_between(np.arange(2020, 2101),
temp_lower, temp_upper, alpha=0.2)
plt.plot(np.arange(2020, 2101), temp_mean, lw=2,
label=ssp, linestyle=line_style[count])
plt.xlabel('Year')
plt.ylabel("Temperature")
plt.legend()
plt.tight_layout()
plt.savefig(
f'../results/MonthlyPrediction/Temperature{city}.tiff', dpi=300, bbox_inches='tight')
plt.show()
for count, ssp in enumerate(['ssp126', 'ssp370', 'ssp585']):
for model in ['MIROC6', 'CanESM', 'CESM2']:
future_climate = read_climate(model, ssp, city)
future_climate['year'] = future_climate.index.year
grouped = future_climate.groupby('year').mean()
precip.append(grouped['Pr'].values.tolist())
Total_pr = np.array(precip)
pr_upper = np.max(Total_pr, axis=0)
pr_lower = np.min(Total_pr, axis=0)
pr_mean = np.mean(Total_pr, axis=0)
plt.fill_between(np.arange(2020, 2101), pr_lower, pr_upper, alpha=0.2)
plt.plot(np.arange(2020, 2101), pr_mean, lw=2,
label=ssp, linestyle=line_style[count])
plt.xlabel('Year')
plt.ylabel("Precipitation")
plt.legend()
plt.tight_layout()
plt.savefig(
f'../results/MonthlyPrediction/Precipitation{city}.tiff', dpi=300, bbox_inches='tight')
plt.show()
if __name__ == '__main__':
for city in ['Miami', 'Cleveland', 'Phoenix', 'Salt Lake']:
plot_future_climate(city)