-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvisualization.py
104 lines (86 loc) · 3.37 KB
/
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
from economy_model import Economy
import plotly.graph_objects as go
import datetime
def make_datetime(arr, start_year=2005):
x = []
for i in range(len(arr)):
x.append(datetime.datetime(year=start_year + (5 * i), month=1, day=1))
return x
def plot_attr(
arr, title="Evolution of the factor in the model", desc="Model Parameter"
):
model = Economy()
fig = go.Figure(
data=go.Scatter(x=make_datetime(arr, start_year=model.start_year), y=arr),
layout=go.Layout(title=title,),
)
fig.update_xaxes(title_text="Time in Years")
fig.update_yaxes(title_text=desc)
fig.update_layout(template="none")
# fig = go.Figure(data=[go.Scatter(x=make_datetime(model.T_at), y=model.T_at)])
# Use datetime objects to set xaxis range
fig.update_layout(
xaxis_range=[datetime.datetime(2001, 1, 1), make_datetime(arr)[-1]]
)
fig.show()
def plot_temp_change(decades=10, tipping_damage=False, carbon_tax=(0, 0, 0)):
model = Economy()
model.loop(t=decades, tipping_damage=tipping_damage, carbon_tax=carbon_tax)
fig = go.Figure(
data=go.Scatter(
x=make_datetime(model.T_at, start_year=model.start_year), y=model.T_at
),
layout=go.Layout(title="Average Temperature Rise",),
)
fig.update_xaxes(title_text="Time in Years")
fig.update_yaxes(title_text="Rise in Average Temperature since 1900")
fig.update_layout(template="none")
# fig = go.Figure(data=[go.Scatter(x=make_datetime(model.T_at), y=model.T_at)])
# Use datetime objects to set xaxis range
fig.update_layout(
xaxis_range=[datetime.datetime(2001, 1, 1), make_datetime(model.T_at)[-1]]
)
fig.show()
def plot_multiple_attr(main_arr):
"""
Input an array in the format of [(arr_1,name_1),(arr_2,name_2),(arr_3,name_3),...,(arr_n,name_n)]
Please ensure the sizes of all the arrays are same
"""
fig = go.Figure()
for tup in main_arr:
arr, name = tup
this_attr = go.Scatter(x=make_datetime(arr), y=arr, name=str(name))
fig.add_trace(this_attr)
fig.update_xaxes(title_text="Time in Years")
fig.update_layout(template="none")
fig.show()
def give_temperature(decades, tipping_damage=False, carbon_tax=(0, 0, 0)):
model = Economy()
model.loop(decades, tipping_damage=tipping_damage, carbon_tax=carbon_tax)
return model.T_at
def plot_impact_of_carbon_tax(
decades, tipping_damage=False, tax_arr=[], show_default=True
):
"""
To see the impact of diffrent climate policies and represent them in one plot.
Input : decades,tipping_damage,tax_arr
Here tax_arr is an array of tuples with three values each : the amount of tax per topn of CO2 in 2050,2100
and 2150.
"""
fig = go.Figure()
if show_default:
default_arr = give_temperature(decades, tipping_damage=tipping_damage)
fig.add_trace(
go.Scatter(
x=make_datetime(default_arr), y=default_arr, name="No Carbon Tax"
)
)
# In the loop for the carbon tax senarios
for carbon_tax_tup in tax_arr:
arr = give_temperature(
decades, tipping_damage=tipping_damage, carbon_tax=carbon_tax_tup
)
fig.add_trace(go.Scatter(x=make_datetime(arr), y=arr, name=str(carbon_tax_tup)))
fig.update_xaxes(title_text="Time in Years")
fig.update_layout(template="none")
fig.show()