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

rework

parent 5784357d
......@@ -410,6 +410,31 @@ def get_specie_repartition_component():
)
return specie_repartition_component
def get_op_obs_vs_model_component():
component = html.Div(
children=[
dcc.Markdown("""
### Observation vs. model OP
"""),
# dcc.RadioItems(
# id="op-obsvsmodel-options",
# options=[
# {"label": "Trendline", "value": "trendline"},
# {"label": "Add uncertainties", "value": "error_xy"},
# {"label": "None", "value": "nothing"},
# ]
# ),
dcc.Loading(
dcc.Graph(
id="op-obs-vs-model-graph",
figure={"data": [], "layout": {}}
)
)
]
)
return component
def get_op_beta_component():
"""Get the OP model
:returns: TODO
......@@ -484,9 +509,16 @@ def get_op_contribution_ts_component():
{'label': 'Monthly timeserie', 'value': 'monthly'},
{'label': 'Quaterly timeserie', 'value': 'quaterly'},
],
value='monthly',
value='daily',
),
html.Br(),
dcc.Dropdown(
id='op-contribution-ts-station-dropdown',
className='dropdown',
options=[{"label": "CHAM", "value": "CHAM"}],
value=["CHAM"],
multi=False,
),
dcc.RadioItems(
id='op-contribution-ts-estimator',
className='options-items',
......@@ -496,7 +528,17 @@ def get_op_contribution_ts_component():
],
value='median',
),
dcc.Markdown("**Daily** is the daily reconstructed OP from the regression model. **Monthly** (mean or median) are the monthly aggregated mean or median for each station. **Quaterly** is the seasonal (4 seasons: DJF, MAM, JJA, SON) mean or median aggratation per station. This plot may take some time to generate..."),
dcc.Markdown("""
**Daily** is the daily reconstructed OP from the
regression model. You have to chose only one station from
the little dropdown above. The default one is "CHAM".
**Monthly** (mean or median) are the monthly aggregated mean or median for each station. **Quaterly** is the seasonal (4 seasons: DJF, MAM, JJA, SON) mean or median aggratation per station. This plot may take some time to generate...
The bars represent the contribution of each source to
the OP (in nmol.min⁻¹.m⁻³) and the line and dot are the
observed OP.
"""),
dcc.Loading(
dcc.Graph(
id="op-contribution-ts-graph",
......@@ -756,18 +798,18 @@ def plot_ts(df, station, var, groupby):
for groupName, dfgroup in df.groupby(group):
if all(dfgroup.loc[:, v].isnull()):
continue
dfgroup = dfgroup.sort_values(by="date")
dfgroup = dfgroup.sort_values(by="Date")
traces.append(go.Scatter(
x=dfgroup.loc[:, "date"],
x=dfgroup.loc[:, "Date"],
y=dfgroup.loc[:, v],
mode="lines+markers",
name="{}-{}-({})".format(station, v, groupName)
))
else:
for v in var:
dfgroup = df.sort_values(by="date")
dfgroup = df.sort_values(by="Date")
traces.append(go.Scatter(
x=dfgroup.loc[:, "date"],
x=dfgroup.loc[:, "Date"],
y=dfgroup.loc[:, v],
mode="lines+markers",
name="{}-{}".format(station, v)
......@@ -788,7 +830,7 @@ def plot_box(df, trace_name, x_var, y_var, groupby=None, plot_type="box"):
:returns: a list of plotly traces
"""
traces=[]
df = df.sort_values(by="station")
df = df.sort_values(by="Station")
if len(groupby) != 0:
for v in y_var:
for group in groupby:
......@@ -836,26 +878,26 @@ def get_contribution(factors, species, stations):
if len(factors) > 0:
conn = sqlite3.connect(DBPATH)
contrib = pd.read_sql(
"""SELECT "{factors}" FROM SRC WHERE station in ('{stations}');""".format(
factors='", "'.join(factors + ["station", "date"]),
"""SELECT "{factors}" FROM SRC WHERE Station IN ('{stations}');""".format(
factors='", "'.join(factors + ["Station", "Date"]),
stations="', '".join(stations)
),
con=conn,
parse_dates=["date"],
index_col=["station", "date"]
parse_dates=["Date"],
index_col=["Station", "Date"]
)
conn.close()
if len(species) > 0:
conn = sqlite3.connect(DBPATH)
sp = pd.read_sql(
"SELECT {sp} FROM OP WHERE station in ('{stations}');".format(
sp=", ".join(species + ["station", "date"]),
"SELECT {sp} FROM OP WHERE Station IN ('{stations}');".format(
sp=", ".join(species + ["Station", "Date"]),
stations="', '".join(stations)
),
con=conn,
parse_dates=["date"],
index_col=["station", "date"]
parse_dates=["Date"],
index_col=["Station", "Date"]
)
conn.close()
......@@ -866,7 +908,7 @@ def get_contribution(factors, species, stations):
elif (not sp.empty) and contrib.empty:
df = sp
else:
df = contrib.merge(sp, on=["station", "date"], how="outer")
df = contrib.merge(sp, on=["Station", "Date"], how="outer")
return df.reset_index()
def get_SID_PD():
......@@ -879,8 +921,8 @@ def get_SID_PD():
SID = pd.read_sql("SELECT * FROM SID;", con=con)
PD = pd.read_sql("SELECT * FROM PD;", con=con)
con.close()
SID = SID.set_index(["profile", "station"])
PD = PD.set_index(["profile", "station"])
SID = SID.set_index(["Profile", "Station"])
PD = PD.set_index(["Profile", "Station"])
return (SID, PD)
......@@ -994,13 +1036,13 @@ def add_month(df, season=False):
df_tmp = df.copy()
# ensure we have date in index
if 'date' not in df_tmp.columns:
if 'Date' not in df_tmp.columns:
print("No date given")
return
else:
df_tmp.date = pd.to_datetime(df_tmp["date"])
df_tmp["Date"] = pd.to_datetime(df_tmp["Date"])
df_tmp["month_number"] = df_tmp.date.apply(lambda x: x.month)
df_tmp["month_number"] = df_tmp["Date"].apply(lambda x: x.month)
df_tmp["month"] = df_tmp["month_number"].replace(number_to_name)
df_tmp.sort_values(by="month", inplace=True)
if season:
......
This diff is collapsed.
......@@ -14,6 +14,10 @@
color: darkolivegreen;
}
#op-contribution-ts-station-dropdown {
max-width: 150px;
}
.equation {
text-align: center;
}
......
No preview for this file type
Markdown is supported
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