Commit c6795f49 authored by Samuël Weber's avatar Samuël Weber
Browse files

work on OP contribution

parent 59ee76ef
......@@ -438,15 +438,6 @@ def get_op_contribution_component():
],
value='daily',
),
dcc.RadioItems(
id='op-contribution-estimator',
className='options-items',
options=[
{'label': 'Mean', 'value': 'mean'},
{'label': 'Median', 'value': 'median'},
],
value='median',
),
dcc.Loading(
dcc.Graph(
id="op-contribution-graph",
......
......@@ -1387,9 +1387,8 @@ def update_betacoeff_graph(sources, stations, species):
Input('station-dropdown', 'value'),
Input('OP-dropdown', 'value'),
Input('op-contribution-plottype', 'value'),
Input('op-contribution-estimator', 'value')
])
def update_op_contribution_graph(stations, species, plot_type, estimator):
def update_op_contribution_graph(stations, species, plot_type):
"""TODO: Docstring for update_op_contribution_graph.
:returns: TODO
......@@ -1437,34 +1436,42 @@ def update_op_contribution_graph(stations, species, plot_type, estimator):
contrib = contrib.dropna(how="all", axis=1)
print(plot_type)
contrib = ac.add_season(contrib)
contrib = contrib.reset_index().melt(id_vars=["station", "Date", "season", "month"],
var_name="factor", value_name="OP")
if plot_type == "daily":
if estimator == "median":
contrib = contrib.groupby(["factor"]).median().reset_index()
elif estimator == "mean":
contrib = contrib.groupby(["factor"]).mean().reset_index()
if plot_type == "daily":
data = contrib.groupby(["factor"])\
.describe()["OP"][["mean", "50%"]]\
.reset_index()\
.melt(id_vars=["factor"], value_name="OP",
var_name="estimator")
fig = px.bar(
contrib, x="OP", y="factor", color="factor",
data, x="OP", y="factor", color="factor",
orientation='h',
facet_row="estimator",
color_discrete_map=colors,
height=500
category_orders={"estimator": ["50%", "mean"]},
height=1000
)
fig.update_yaxes(title_text="Median value<br>OP {} (nmol.min⁻¹.m⁻³)".format(species[0]), row=1)
fig.update_yaxes(title_text="Mean value<br>OP {} (nmol.min⁻¹.m⁻³)".format(species[0]), row=2)
elif plot_type == "seasonal":
if estimator == "median":
contrib = contrib.groupby(["season", "station", "factor"]).median().reset_index()
elif estimator == "mean":
contrib = contrib.groupby(["season", "station", "factor"]).mean().reset_index()
data = contrib.groupby(["season", "factor"])\
.describe()["OP"][["mean", "50%"]]\
.reset_index()\
.melt(id_vars=["season", "factor"], value_name="OP",
var_name="estimator")
fig = px.bar(
contrib, x="season", y="OP", color="factor",
data, x="season", y="OP", color="factor",
color_discrete_map=colors,
facet_row="station",
height=500*len(stations)
barmode="group",
facet_row="estimator",
category_orders={"season": ["Winter", "Spring", "Summer", "Fall"]},
height=1000, #*len(stations),
)
fig.update_yaxes(title_text="Median value<br>OP {} (nmol.min⁻¹.m⁻³)".format(species[0]), row=1)
fig.update_yaxes(title_text="Mean value<br>OP {} (nmol.min⁻¹.m⁻³)".format(species[0]), row=2)
elif plot_type == "ts":
fig = px.area(
contrib, x="Date", y="OP", color="factor",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment