-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
93 lines (76 loc) · 2.89 KB
/
test.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
# %%
from utils import read_climate, climate_shift, read_data, kriging_predict
import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
def intensity_plot(precip, temp):
xy = np.vstack([precip, temp])
z = gaussian_kde(xy)(xy)
with plt.style.context(['science', 'no-latex']):
plt.scatter(precip,
temp, c=z)
plt.title('Intensity')
plt.xlabel('Mean precipitation')
plt.ylabel('Mean temperature')
plt.tight_layout()
plt.show()
# %%
if __name__ == '__main__':
climate_model = 'CanESM'
ssp = 'ssp585'
city = 'Cleveland'
material = 'Cast Iron'
future_climate = read_climate(model=climate_model, ssp=ssp, city=city)
intensity_plot(future_climate['Pr'].values, future_climate['Temp'].values)
# %%
_, min_temp, precip, _ = read_data()
shift_time = 29
min_temp = climate_shift(
min_temp, shift_day=shift_time + 1, variable='Temp', variation='Mean')
# add precipitation data
shift_time = 29
precip = climate_shift(
precip, shift_day=shift_time + 1, variable='Pr', variation='Mean')
min_temp = min_temp[(min_temp.index.year >= 2010) &
(min_temp.index.year <= 2019)]
precip = precip[(precip.index.year >= 2010) & (precip.index.year <= 2019)]
intensity_plot(precip.used_value.values, min_temp.used_value.values)
# %%
age = 25
label = r'../results/MonthlyPrediction/2DKriging{}{}'.format(material, age)
FR_list, _ = kriging_predict(
precip=precip.used_value.values, temp=min_temp.used_value.values, label=label, style='points')
print(np.sum(FR_list))
# %%
age = 75
label = r'../results/MonthlyPrediction/2DKriging{}{}'.format(material, age)
FR_list_2, _ = kriging_predict(
precip=precip.used_value.values, temp=min_temp.used_value.values, label=label, style='points')
print(np.sum(FR_list_2))
# %%
precip_low = 0
precip_up = 5
temp_low = -6
temp_up = 20
new_precip = np.linspace(0.9*precip_low, precip_up, 50)
new_temp = np.linspace(0.9*temp_low, temp_up, 50)
label_1 = r'../results/MonthlyPrediction/2DKriging{}{}'.format(
material, 25)
label_2 = r'../results/MonthlyPrediction/2DKriging{}{}'.format(
material, 75)
high_res_1, ss = kriging_predict(
new_precip, new_temp, label_1, style='grid')
high_res_2, ss = kriging_predict(
new_precip, new_temp, label_2, style='grid')
with plt.style.context(['science', 'no-latex']):
plt.imshow(high_res_1-high_res_2, origin='lower', extent=[
precip_low, precip_up, temp_low, temp_up], aspect='auto')
cbar = plt.colorbar()
cbar.ax.set_ylabel('Failure rate')
plt.title('Failure rate with kriging')
plt.xlabel('Mean precipitation')
plt.ylabel('Mean temperature')
plt.tight_layout()
plt.show()
# %%