Skip to content
Snippets Groups Projects
Commit 94b871cb authored by Florian Obersteiner's avatar Florian Obersteiner :octopus:
Browse files

separate callbacks for updating the info fields

parent 9cbeb7af
No related branches found
No related tags found
1 merge request!7revise callbacks
......@@ -19,13 +19,27 @@ from src.data import load_from_disk, load_from_thredds
from src.layout import create_layout
from src.thredds import get_datasets
appconfig = DotDict.from_toml_file("./config/env.toml")
# BEGIN state structures
appconfig: DotDict = DotDict.from_toml_file("./config/env.toml")
appconfig.VERSION = get_latest_semantic_version_tag() or appconfig.VERSION
varconfig = pd.read_csv("./config/parms_units.csv", sep=";")
varconfig: pd.DataFrame = pd.read_csv("./config/parms_units.csv", sep=";")
varconfig = varconfig.set_index("VNAME")
airportsconfig = pd.read_csv("./config/CARIBIC2_Airports.csv", sep=";")
airportsconfig: pd.DataFrame = pd.read_csv("./config/CARIBIC2_Airports.csv", sep=";")
airportsconfig = airportsconfig.set_index("IATA")
# using separate variable declaration here to have a type annotation:
data: pd.DataFrame = pd.DataFrame()
ap_info: dict[int, str] = {}
data, ap_info = (
load_from_thredds(get_datasets(appconfig), appconfig, airportsconfig, True) # type: ignore
if appconfig.USE_THREDDS
else load_from_disk(Path("./testdata").glob("MS_*.nc"), appconfig, airportsconfig, True) # type: ignore
)
log.debug(f"Data loaded. Used THREDDS: {appconfig.USE_THREDDS}")
# END state structures
# fmt: off
app = Dash(
appconfig.TITLE,
......@@ -38,25 +52,32 @@ app.title = appconfig.TITLE
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
data, ap_info = (
load_from_thredds(get_datasets(appconfig), appconfig, airportsconfig, True) # type: ignore
if appconfig.USE_THREDDS
else load_from_disk(Path("./testdata").glob("MS_*.nc"), appconfig, airportsconfig, True) # type: ignore
)
log.debug(f"Data loaded. Used THREDDS: {appconfig.USE_THREDDS}")
# log.debug(f"Data size: {data.info()}")
app.layout = create_layout(data, appconfig)
server = app.server # for deployment via gunicorn / WSGI server
@app.callback(Output("var-info", "children"), Input("variable-dropdown", "value"))
def set_var_info(selected_variable: str) -> str:
return varconfig.loc[selected_variable, :].Long_Name
@app.callback(Output("second-var-info", "children"), Input("second-variable-dropdown", "value"))
def set_second_var_info(secondary_variable: str) -> str:
return (
varconfig.loc[secondary_variable, :].Long_Name
if secondary_variable in varconfig.index
else ""
)
@app.callback(Output("flight-dep-dest", "children"), Input("flight-dropdown", "value"))
def set_flight_dep_dest(selected_flight: int) -> str:
return ap_info.get(selected_flight, "?!")
@app.callback(
[
Output("fig-map", "figure"),
Output("fig-ts", "figure"),
Output("flight-dep-dest", "children"),
Output("var-info", "children"),
Output("second-var-info", "children"),
],
[
Input("flight-dropdown", "value"),
......@@ -68,15 +89,9 @@ def update_plots(selected_flight: int, primary_variable: str, secondary_variable
filtered_df = data[data["flight_number"] == selected_flight]
valid_indices = filtered_df[primary_variable].notna()
unit_primary = varconfig.loc[primary_variable, :].Unit
lname_primary = (varconfig.loc[primary_variable, :].Long_Name,)
unit_secondary = (
varconfig.loc[secondary_variable, :].Unit if secondary_variable in varconfig.index else "-"
)
lname_secondary = (
varconfig.loc[secondary_variable, :].Long_Name
if secondary_variable in varconfig.index
else ""
)
fig_map = go.Figure(
go.Scattermap(
......@@ -193,12 +208,13 @@ def update_plots(selected_flight: int, primary_variable: str, secondary_variable
fig_ts.update_yaxes(title=f"{primary_variable} {unit_primary}")
fig_ts.update_yaxes(title=f"{secondary_variable} {unit_secondary}", secondary_y=True)
set_var_info(primary_variable)
set_second_var_info(secondary_variable)
set_flight_dep_dest(selected_flight)
return [
fig_map,
fig_ts,
ap_info[selected_flight],
lname_primary,
lname_secondary,
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment