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

clean + add obs OP

parent 39411b0c
......@@ -9,27 +9,12 @@ from dash.exceptions import PreventUpdate
import os
import itertools
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import plotly.express as px
import numpy as np
import pandas as pd
import sqlite3
import copy
from app_main import app
import apps.app_components as ac
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.exceptions import PreventUpdate
import itertools
import plotly.graph_objs as go
import numpy as np
import pandas as pd
import sqlite3
import copy
import collections
from app_main import app
import apps.app_components as ac
......@@ -39,22 +24,6 @@ import settings
# RELATIVE TO index !!!
DBPATH = os.path.abspath("./data/deconvolOP.db")
print(os.path.abspath("./"))
print(DBPATH)
conn = sqlite3.connect(DBPATH)
SID = pd.read_sql(
"SELECT * FROM SID;",
con=conn,
)
PD = pd.read_sql(
"SELECT * FROM PD;",
con=conn,
)
conn.close()
# DBPATH = "./testDB.db"
conn = sqlite3.connect(DBPATH)
OPi = pd.read_sql(
"SELECT * FROM OPi;", con=conn, index_col=["station", "factor"]
......@@ -62,13 +31,6 @@ OPi = pd.read_sql(
conn.close()
# =============================================================================
SID.set_index(["profile", "station"], inplace=True)
PD.set_index(["profile", "station"], inplace=True)
if "index" in SID.columns:
SID.drop("index", axis=1, inplace=True)
if "index" in PD.columns:
PD.drop("index", axis=1, inplace=True)
STATIONS = OPi.index.get_level_values("station").unique()
BASE_VAR_SP = ["date", "station"]
......@@ -91,7 +53,6 @@ SPECIES_ORDER_WO_OP = ["PM10"] + carboneous + ions + organics + metals
SPECIES_ORDER = ["PM10"] + carboneous + ions + organics + metals + ops
BUTTONS = ["rd_ts", "rd_monthly", "rd_seasonal", "pmf_profiles", "pmf_deltatool", "pmf_unc", "pmf_sr", "op_beta", "op_contrib"]
BUTTONS_VALUES = {button: 0 for button in BUTTONS}
COMPONENTS = {
"rd_ts": ac.get_rawdata_timeserie_component(),
"rd_monthly": ac.get_rawdata_monthly_component(),
......@@ -400,15 +361,15 @@ def update_map_station_selected(stations, figure):
Output('item-op-contribution', 'active')
],
[
Input('item-rawdata-timeserie', 'n_clicks'),
Input('item-rawdata-monthly', 'n_clicks'),
Input('item-rawdata-seasonal', 'n_clicks'),
Input('item-pmf-profiles', 'n_clicks'),
Input('item-pmf-deltatool', 'n_clicks'),
Input('item-pmf-uncertainties', 'n_clicks'),
Input('item-pmf-speciesrepartition', 'n_clicks'),
Input('item-op-betacoefficient', 'n_clicks'),
Input('item-op-contribution', 'n_clicks')
Input('item-rawdata-timeserie', 'n_clicks_timestamp'),
Input('item-rawdata-monthly', 'n_clicks_timestamp'),
Input('item-rawdata-seasonal', 'n_clicks_timestamp'),
Input('item-pmf-profiles', 'n_clicks_timestamp'),
Input('item-pmf-deltatool', 'n_clicks_timestamp'),
Input('item-pmf-uncertainties', 'n_clicks_timestamp'),
Input('item-pmf-speciesrepartition', 'n_clicks_timestamp'),
Input('item-op-betacoefficient', 'n_clicks_timestamp'),
Input('item-op-contribution', 'n_clicks_timestamp')
]
)
def get_graph_component(rd_ts, rd_monthly, rd_seasonal, pmf_profiles, pmf_deltatool, pmf_unc, pmf_sr, op_beta, op_contrib):
......@@ -428,50 +389,51 @@ def get_graph_component(rd_ts, rd_monthly, rd_seasonal, pmf_profiles, pmf_deltat
"""
new_button_values = {"rd_ts": rd_ts, "rd_monthly": rd_monthly, "rd_seasonal": rd_seasonal, "pmf_profiles": pmf_profiles, "pmf_deltatool": pmf_deltatool, "pmf_unc": pmf_unc, "pmf_sr": pmf_sr, "op_beta": op_beta, "op_contrib": op_contrib}
active_button = {"rd_ts": False, "rd_monthly": False, "rd_seasonal": False, "pmf_profiles": False, "pmf_deltatool": False, "pmf_unc": False, "pmf_sr": False, "op_beta": False, "op_contrib": False}
update = False
init_val = 0
clicked = "rd_ts"
for nth, button in enumerate(BUTTONS):
if new_button_values[button] > BUTTONS_VALUES[button]:
active_button[button] = True
update = True
break
# force to be rd_ts if no item is clicked
if not update:
button = "rd_ts"
BUTTONS_VALUES[button] = new_button_values[button]
if new_button_values[button] is None:
continue
if new_button_values[button] > init_val:
init_val = new_button_values[button]
clicked = button
active_button[clicked] = True
# ==== Disable drodpown
source_disabled = True
specie_disabled = True
OP_disabled = True
if button in ['rd_ts', 'rd_monthly', 'rd_seasonal', 'pmf_profiles', 'pmf_deltatool', 'pmf_unc', 'op_beta']:
if clicked in ['rd_ts', 'rd_monthly', 'rd_seasonal', 'pmf_profiles', 'pmf_deltatool', 'pmf_unc', 'op_beta']:
source_disabled = False
if button in ['pmf_unc']:
if clicked in ['pmf_unc']:
specie_disabled = False
if button in ['rd_ts', 'rd_monthly', 'rd_seasonal', 'op_beta', 'op_contrib']:
if clicked in ['rd_ts', 'rd_monthly', 'rd_seasonal', 'op_beta', 'op_contrib']:
OP_disabled = False
# ==== Set active button
rd_ts_a = rd_monthly_a = rd_seasonal_a = pmf_profiles_a = pmf_deltatool_a = pmf_unc_a = pmf_sr_a = op_beta_a = op_contrib_a = False
if button == "rd_ts":
if clicked == "rd_ts":
rd_ts_a = True
elif button == "rd_monthly":
elif clicked == "rd_monthly":
rd_monthly_a = True
elif button == "rd_seasonal":
elif clicked == "rd_seasonal":
rd_seasonal_a = True
elif button == "pmf_profiles":
elif clicked == "pmf_profiles":
pmf_profiles_a = True
elif button == "pmf_deltatool":
elif clicked == "pmf_deltatool":
pmf_deltatool_a = True
elif button == "pmf_unc":
elif clicked == "pmf_unc":
pmf_unc_a = True
elif button == "pmf_sr":
elif clicked == "pmf_sr":
pmf_sr_a = True
elif button == "op_beta":
elif clicked == "op_beta":
op_beta_a = True
elif button == "op_contrib":
elif clicked == "op_contrib":
op_contrib_a = True
return (COMPONENTS[button], source_disabled, specie_disabled, OP_disabled, rd_ts_a, rd_monthly_a, rd_seasonal_a, pmf_profiles_a, pmf_deltatool_a, pmf_unc_a, pmf_sr_a, op_beta_a, op_contrib_a)
return (COMPONENTS[clicked], source_disabled, specie_disabled, OP_disabled, rd_ts_a, rd_monthly_a, rd_seasonal_a, pmf_profiles_a, pmf_deltatool_a, pmf_unc_a, pmf_sr_a, op_beta_a, op_contrib_a)
@app.callback(Output('ts-graph', 'figure'),
......@@ -1415,9 +1377,11 @@ def update_op_contribution_graph(stations, species, plot_type):
to_return["layout"]["title"] = "Select at least one OP (DTTv or AAv), and only 1 at a time"
return to_return
queryOPobs = "SELECT * FROM OP;"
queryOPi = "SELECT * FROM OPi;"
querySRC = "SELECT * FROM SRC;"
conn = sqlite3.connect(DBPATH)
OP = pd.read_sql(queryOPobs, con=conn, parse_dates=["date"]).set_index(["station", "date"])
df = pd.read_sql(queryOPi, con=conn).set_index(["station", "factor"]).T
SRC = pd.read_sql(querySRC, con=conn, parse_dates=["date"]).set_index(["station", "date"])
SRC.index.names = ["station", "Date"]
......@@ -1477,12 +1441,45 @@ def update_op_contribution_graph(stations, species, plot_type):
contrib, x="Date", y="OP", color="factor",
color_discrete_map=colors,
facet_row="station",
height=200*len(stations)
category_orders={"station": settings.STATION_ORDER},
height=100+200*len(stations),
)
fig.update_traces({"mode": "none"}, selector={"type": "scatter", "mode": "lines"})#, overwrite=True)
for factor in factors:
fig.update_traces({"fillcolor": colors[factor]}, selector={"type": "scatter", "legendgroup": "factor="+factor}) #, overwrite=True)
i = 0
for station in settings.STATION_ORDER:
if station not in settings.STATION_ORDER:
continue
data = OP.loc[station, ["SD_"+species[0], species[0]]]
fig.add_trace(
go.Scatter(
x=data.index, y=data[species[0]],
error_y=dict(
type="data",
array=data["SD_"+species[0]],
visible=True,
width=0,
thickness=1,
color="purple",
),
name="OP obs. {station}".format(station=station),
showlegend=False,
line=dict(
color="blue",
width=1,
),
marker=dict(
color="purple",
)
),
row=len(stations)-i,
col=1
)
i += 1
fig.update_yaxes(matches=None)
# fig.update_yaxes({"title": species[0]+"<br>nmol/min/m3"})
......
......@@ -50,3 +50,7 @@ p {
/* background-color: #DDD; */
margin: 0px 10px;
}
.list-group-item.active {
z-index: 0 !important;
}
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