-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·189 lines (160 loc) · 4.62 KB
/
app.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
"""dsfds."""
import dash
from dash.dependencies import Input, Output
import dash_bootstrap_components as dbc
import plotly.express as px
import pynch.mass_table as mt
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.CYBORG])
server = app.server
df = mt.MassTable().full_data
table_years = df.index.unique()
variables = df.columns
segre_colours = {
'stable': 'black',
'B-': 'red',
'B+': 'blue',
'A': 'yellow',
'n': 'limegreen',
'2n': 'darkgreen',
'p': 'magenta',
'2p': 'purple',
'EC': 'orange',
'SF': 'cyan'
}
@app.callback(
[
Output("graph-title", "children"),
Output("a-graph", "figure"),
Output("z-graph", "figure"),
Output("n-graph", "figure"),
Output("xval_slider", "min"),
Output("xval_slider", "max"),
Output("xval_slider", "marks"),
],
[
Input("yaxis_dropdown", "value"),
Input("xval_slider", "value"),
Input("year_slider", "value"),
],
)
def update_graph(y_var, x_value, year):
"""The actions to do when the selected data is changed."""
df_f = df.loc[table_years[year]][["Symbol", "Decay", "A", "Z", "N", y_var]]
df_ff = df_f.loc[(df_f["A"] == x_value)]
logit = (
True
if y_var in ["HalfLife", "NubaseRelativeError", "AMERelativeError"]
else False
)
a_fig = px.scatter(
data_frame=df_f,
x="N",
y="Z",
hover_name="Symbol",
color="Decay",
color_discrete_map=segre_colours,
template="plotly_dark",
)
z_fig = px.scatter(
data_frame=df_ff,
x="Z",
y=y_var,
hover_name="Symbol",
hover_data=[y_var],
log_y=logit,
template="plotly_dark",
)
n_fig = px.scatter(
data_frame=df_ff,
x="N",
y=y_var,
hover_name="Symbol",
hover_data=[y_var],
log_y=logit,
template="plotly_dark",
)
title = dash.html.H2(f"A = {x_value}")
min_a = df_f["A"].min()
max_a = df_f["A"].max()
marks_a = {i: f"{i}" for i in range(20, max_a, 20)}
return (
title,
a_fig,
z_fig.update_traces(mode="lines+markers"),
n_fig.update_traces(mode="lines+markers"),
min_a,
max_a,
marks_a,
)
year_and_variable = dbc.Row(
[
dbc.Col(
dash.html.Div(
[
dash.html.H3("Year"),
dash.dcc.Slider(
id="year_slider",
min=0,
max=len(table_years) - 1,
marks={i: f"{table_years[i]}" for i in range(len(table_years))},
value=0,
),
],
)
),
dbc.Col(
dash.html.Div(
[
dash.html.H3("Value to plot"),
dash.dcc.Dropdown(
id="yaxis_dropdown",
options=[{"label": i, "value": i} for i in variables],
value=variables[7],
),
],
)
),
]
)
a_slider = dbc.Row(
dbc.Col(
[
dash.html.Div(id="graph-title", children=[]),
dash.html.Div(dash.dcc.Slider(id="xval_slider", value=50)),
]
)
)
graphs = dbc.Row(
[
dbc.Col(dash.dcc.Graph(id="n-graph", figure={}), width=3),
dbc.Col(dash.dcc.Graph(id="a-graph", figure={}), width=6),
dbc.Col(dash.dcc.Graph(id="z-graph", figure={}), width=3),
]
)
app.layout = dbc.Container(children=[year_and_variable, graphs, a_slider], fluid=True)
def main():
"""For testing."""
# df = MassData().full_data
# print(df)
# print(df.index.unique())
# print(df.columns)
# print(df.loc['2003', ['A', 'Symbol']])
# print(df.loc[(df['Z'] == 2) & (df['A'] == 3) & (df['TableYear'] == '2003')])
# print(df.loc['2003'][['A', 'Z']])
# df_f = df.loc["2003"][["A", "Z", "N", "NubaseRelativeError"]]
# df_ff = df_f.loc[(df_f["A"] == 12)]
# print(df_ff)
# print(df_ff["Z"].max())
# print(df_ff["Z"].min())
# print(df_f.loc[(df_f['A'] == 20)])
# filtered = df[df["TableYear"] == "2003"]
# print(filtered)
# print(type(filtered))
# print(df.loc[(25), :]['2012']['NubaseMassExcess'].index.get_level_values('N'))
# print("~~~~~~~~~~~~~~~~~~~~~~")
# print(df[df.index.get_level_values('A') == 40]['2016']['NubaseMassExcess'])
# print("~~~~~~~~~~~~~~~~~~~~~~")
# print(df.loc[(40), :]["2016"]["NubaseMassExcess"])
if __name__ == "__main__":
# main()
app.run_server(debug=True)