diff --git a/src/mlair/time_series.py b/src/mlair/time_series.py index 149b27684696b6b7fc05fe36c66436246e8958f7..ede43ce74f42e4fc5c5d1191b97b5182c57fa92b 100644 --- a/src/mlair/time_series.py +++ b/src/mlair/time_series.py @@ -56,9 +56,7 @@ def plot(station, language_id=0, ispec=0, start_date = "2018-07-18 00:00", forec ax.errorbar(x=df_ob["ob_time"], y=df_ob["ob_value"], xerr=pd.Timedelta(hours=4), fmt="none", elinewidth=2.0, label=f"{guitr.mlair_legend_obs_label[language_id]} [{statistics}]", color='blue') #plot observations with dma8eu dummy = ax.legend() ax.errorbar(x=df_fc["fc_time"], y=df_fc["value"], xerr=pd.Timedelta(hours=4), fmt="none", elinewidth=2.0, label=f'{guitr.mlair_legend_fc_label[language_id]} [{statistics}]', color='orange') #plot fc - dummy = ax.legend() - logging.error(f'{df_hourly["hourly_time"][0]=}') - logging.error(f'{df_fc["fc_time"]=}') + dummy = ax.legend(loc='lower right') # extend x axis since last forecast is not plotted nticks = 2 * forecast_length + 1 ax.set_xlim(df_hourly["hourly_time"][0], df_fc["fc_time"][forecast_length-1] + pd.Timedelta(hours=12)) diff --git a/src/pages/dashboard.py b/src/pages/dashboard.py index c7338918877e879a4852e8dae3283af57395adae..3e15fe99b713e25ec864d639aec656e3e4579305 100644 --- a/src/pages/dashboard.py +++ b/src/pages/dashboard.py @@ -164,8 +164,6 @@ aai_login = dbc.Row([ def generate_ml_fcast_body(language_id=0): - disabled_days = [ dt.datetime.strptime('2017-01-26','%Y-%m-%d') + dt.timedelta(days=i) for i in range(13) ] - disabled_days += [ dt.datetime.strptime('2017-02-18','%Y-%m-%d') + dt.timedelta(days=i) for i in range(512) ] return [ dbc.Row([ dbc.Col(dbc.Label(guitr.state_label[language_id]), width=3), @@ -180,20 +178,19 @@ def generate_ml_fcast_body(language_id=0): ], class_name="row mt-3"), dbc.Row([ dbc.Col(dbc.Label(guitr.date_label[language_id]), width=3), - dbc.Col(dcc.DatePickerSingle(date=guiconst.min_date_allowed, + dbc.Col(dcc.DatePickerSingle(date=dt.date(2018, 7, 18), display_format=guitr.date_format[language_id], first_day_of_week=guitr.first_day_of_week[language_id], - min_date_allowed=guiconst.min_date_allowed, - max_date_allowed=guiconst.max_date_allowed, - disabled_days=disabled_days, - initial_visible_month=guiconst.initial_visible_month, + min_date_allowed=dt.date(2018, 7, 18), + max_date_allowed=dt.date(2018, 7, 31), + initial_visible_month=dt.date(2018, 7, 1), id="ml_fcast_body_startdate")), dbc.Col(dbc.Label(f"{guitr.forecast_length_label[language_id]}:")), dbc.Col(dcc.Dropdown(value=guitr.forecast_length_options[language_id][0], options=guitr.forecast_length_options[language_id], id="ml_fcast_body_forecast_length")) ], class_name="row mt-3"), dbc.Row([ - dbc.Col(dbc.Label(guitr.species_label[language_id]), width=3), + dbc.Col(dbc.Label(f"{guitr.species_label[language_id]}:"), width=3), dbc.Col( dcc.Dropdown(value=0, options=[{'label': guitr.species_options[language_id][i], @@ -204,7 +201,7 @@ def generate_ml_fcast_body(language_id=0): ) ], class_name="row mt-3"), dbc.Row([ - dbc.Col(dbc.Label(guitr.output_metrics_label[language_id]), width=3), + dbc.Col(dbc.Label(f"{guitr.output_metrics_label[language_id]}:"), width=3), dbc.Col(dcc.Dropdown(value=0, options=[{'label': metrics_info[language_id][' Name'][i], 'value': i, @@ -227,14 +224,34 @@ def generate_ml_fcast_body(language_id=0): ], class_name="row mt-3") ] -def generate_ml_fcast_output_body(language_id): +def generate_ml_fcast_output_body(language_id, jobnr): stations_list = info.get_available_stations(infile="mlair_stations.csv") # stations_list = sorted(stations_list) - + if jobnr and (jobnr != 'bla'): + job_props = get_db_job_entry(jobnr) + start_date = job_props['start_date'] + ireg = job_props['region'] + region = guitr.region_text[language_id][ireg] + ispec = job_props['species'] + species = guitr.species_options[language_id][ispec] + imetric = job_props['metric'] + metric = guitr.metrics_options[language_id][imetric] + fc_length = job_props['forecast_length'] + fc_length_str = "{} {}{}".format(fc_length, guitr.day_label[language_id], guitr.day_plural_label[language_id] if fc_length > 1 else "") + else: + start_date = "2018-07-18" + region = "X" + species = "X" + metric = "X" + fc_length_str = "X" return [ - dbc.Row(dbc.Label(f"{guitr.start_date_label[language_id]}: 18.07.2018, Ozon, Nordrhein Westfalen")), + dbc.Row(dbc.Label(f"""{guitr.region_label[language_id]}: {region}, + {guitr.species_label[language_id]}: {species}, + {guitr.output_metrics_label[language_id]}: {metric}, + {guitr.start_date_label[language_id]}: {start_date}, + {guitr.forecast_length_label[language_id]}: {fc_length_str}""")), dbc.Row([ - dbc.Col(dbc.Label(f"{guitr.station_label[language_id]}"), width=3), + dbc.Col(dbc.Label(f"{guitr.station_label[language_id]}:"), width=3), dbc.Col( dcc.Dropdown(id="station-dropdown-ml-output", value=stations_list[0], @@ -247,8 +264,14 @@ def generate_ml_fcast_output_body(language_id): dbc.Col(dbc.Button(f"{guitr.map_select_label[language_id]}", disabled=True, class_name="fzj_style_btn"), width=2) ], class_name="row mt-3"), dbc.Row([ - dbc.Col(html.Div(id='image-container-ml-output'), width=12), - dbc.Col(dbc.Button(f"{guitr.download_label[language_id]}", class_name="fzj_style_btn"), width=6) + dbc.Col([html.Div(id='image-container-ml-output'), + html.Div([dbc.Button(f"{guitr.download_label[language_id]}", id="mlair_download", + class_name="fzj_style_btn"), + dcc.Download(id="mlair_download_result")]), + dbc.Col(html.Br()), + html.Div([dbc.Button(f"{guitr.im_download_label[language_id]}", id="mlair_plot_download", + class_name="fzj_style_btn"), + dcc.Download(id="mlair_download_plot")])], width=12), ], class_name="row mt-3"), ] @@ -282,7 +305,7 @@ def generate_ml_fcast_output_modal(jobnr=None, lisopen=False, language_id=0): [ dbc.ModalTitle(f"{guitr.run2_label[language_id]} {jobnr}", style={"fontSize": 15}), dbc.ModalHeader(dbc.ModalTitle(guitr.application_text[language_id][1])), - dbc.ModalBody(generate_ml_fcast_output_body(language_id)), + dbc.ModalBody(generate_ml_fcast_output_body(language_id, jobnr)), dbc.ModalFooter([dbc.Button(f"{guitr.close_label[language_id]}", id="ml_fcast_output_close", class_name="fzj_style_btn", n_clicks=0) ]), @@ -299,7 +322,7 @@ def generate_ml_fcast_result_modal(jobnr=None, lisopen=False, language_id=0): [ dbc.ModalTitle(f"{guitr.run2_label[language_id]} {jobnr}", style={"fontSize": 15}), dbc.ModalHeader(dbc.ModalTitle(guitr.application_text[language_id][1])), - dbc.ModalBody(generate_ml_fcast_output_body(language_id)), + dbc.ModalBody(generate_ml_fcast_output_body(language_id, jobnr)), dbc.ModalFooter(dbc.Button(f"{guitr.close_label[language_id]}", id="ml_fcast_result_close", class_name="fzj_style_btn", n_clicks=0)), ], @@ -333,7 +356,7 @@ def generate_eurad_im_body(language_id=0): id="eurad_im_forecast_length")) ], class_name="row mt-3"), dbc.Row([ - dbc.Col(dbc.Label(guitr.region_label[language_id]), width=3), + dbc.Col(dbc.Label(f"{guitr.region_label[language_id]}:"), width=3), dbc.Col(dcc.RadioItems(options={ 0: 'Nordrhein-Westfalen', 1: 'Berlin-Brandenburg'}, @@ -386,6 +409,7 @@ def generate_eurad_im_output_body(language_id, context, jobnr): infile = str(DATA_PATH.joinpath(f'{jobnr}.nc')) job_props = get_db_job_entry(jobnr) start_date = job_props['start_date'] + region = job_props['region'] if not os.path.isfile(infile): trans_filename = transfer_results_from_HPC(jobnr, start_date, 0, DATA_PATH) @@ -393,7 +417,6 @@ def generate_eurad_im_output_body(language_id, context, jobnr): timestep_list = info.get_available_time_stamps(infile) timestep_strings = [np.datetime_as_string(ts, unit="m") for ts in timestep_list] - # TODO: Zeit in Stunden seit Start start_date = pd.to_datetime(timestep_list[0]).strftime(guitr.date_format2[language_id]) fc_length = (len(timestep_list)-1) // 24 @@ -405,12 +428,15 @@ def generate_eurad_im_output_body(language_id, context, jobnr): stations_list = sorted(stations_list) else: start_date = '2018-07-19T00:00' + region = 0 timestep_strings = [ '2018-07-19 00:00' ] fc_length_str = '1' variables_list = [ 'NoneAvailable' ] stations_list = [ "XX, XX" ] return [ - dbc.Row([dbc.Label(f"{guitr.start_date_label[language_id]}: {start_date}, {guitr.forecast_length_label[language_id]}: {fc_length_str}")]), + dbc.Row([dbc.Label(f"""{guitr.region_label[language_id]}: {guitr.region_text[language_id][region]}, + {guitr.start_date_label[language_id]}: {start_date}, + {guitr.forecast_length_label[language_id]}: {fc_length_str}""")]), dbc.Row([ dbc.Col(dbc.Label(f"{guitr.time_step_label[language_id]}:"), width=3), dbc.Col(dcc.Dropdown(value=timestep_strings[0], options=timestep_strings, id='time-step-dropdown-{}'.format(context)), width=3) @@ -435,8 +461,11 @@ def generate_eurad_im_output_body(language_id, context, jobnr): dbc.Row([ dbc.Col(html.Br(), width=12), dbc.Col([ - dbc.Checkbox(label=f"{guitr.show_downscaling_label[language_id]}", value=0) - ], style={"display": "flex"}), + dbc.Checkbox(label=f"{guitr.show_target_plot_label[language_id]}", value=0) + ], width=12), + dbc.Col([ + dbc.Checkbox(label=f"{guitr.show_downscaling_label[language_id]}", value=0, disabled=True) + ], width=12) ], class_name="row mt-3f"), ] @@ -485,6 +514,8 @@ def generate_eurad_scen_output_body(language_id, context, jobnr): job_props = get_db_job_entry(jobnr) start_date = job_props['start_date'] iscen = job_props['emis_scen'] + ireg = job_props['region'] + region = guitr.region_text[language_id][ireg] if not os.path.isfile(infile): trans_filename = transfer_results_from_HPC(jobnr, start_date, iscen, DATA_PATH) @@ -509,10 +540,12 @@ def generate_eurad_scen_output_body(language_id, context, jobnr): variables_list = [ 'NoneAvailable' ] stations_list = [ "XX, XX" ] iscen = 0 + region = "X" return [ - dbc.Row([dbc.Label(f"{guitr.start_date_label[language_id]}: {start_date},\ - {guitr.forecast_length_label[language_id]}: {fc_length_str},\ - {guitr.emis_scen_label[language_id]} {emis_info[language_id][' Name'][iscen]}")]), + dbc.Row([dbc.Label(f"""{guitr.region_label[language_id]}: {region}, + {guitr.start_date_label[language_id]}: {start_date}, + {guitr.forecast_length_label[language_id]}: {fc_length_str}, + {guitr.emis_scen_label[language_id]}: {emis_info[language_id][' Name'][iscen]}""")]), dbc.Row([ dbc.Col(dbc.Label(f"{guitr.time_step_label[language_id]}:"), width=3), dbc.Col(dcc.Dropdown(value=timestep_strings[0], options=timestep_strings, id='time-step-dropdown-{}'.format(context)), width=3) @@ -563,14 +596,14 @@ def generate_eurad_scen_body(language_id): id="eurad_scen_forecast_length")) ], class_name="row mt-3"), dbc.Row([ - dbc.Col(dbc.Label(f"{guitr.region_label[language_id]}"), width=3), + dbc.Col(dbc.Label(f"{guitr.region_label[language_id]}:"), width=3), dbc.Col(dcc.RadioItems(options={ 0: 'Nordrhein-Westfalen', 1: 'Berlin-Brandenburg'}, value=0, id="eurad_scen_region_choice")), ], class_name="row mt-3"), dbc.Row([ - dbc.Col(dbc.Label(f"{guitr.emis_scen_label[language_id]}"), width=3), + dbc.Col(dbc.Label(f"{guitr.emis_scen_label[language_id]}:"), width=3), dbc.Col( dcc.Dropdown(value=0, options=[{'label': emis_info[language_id][" Name"][i], @@ -1143,6 +1176,45 @@ def eurad_scen_job_run(run_button, region, startdate, forecast_length, emi_scen, generate_eurad_scen_output_modal(container_id="eurad_scen_output_modal_container", language_id=language_id)] +@callback( + Output("mlair_download_result", "data"), + Input("mlair_output_download", "n_clicks"), + State("job-info", "data"), + prevent_initial_call=True +) +def mlair_output_download(download_button, job_dict): +# jobid = json.loads(job_dict)["jobnr"] + # infile = str(DATA_PATH.joinpath('MLAIR', f'{jobid}.nc')) + # demonstrator + infile = str(DATA_PATH.joinpath('MLAIR', 'forecasts_DENW067_test.nc')) + return dcc.send_file( + infile + ) + + +@callback( + Output("mlair_download_plot", "data"), + Input("mlair_plot_download", "n_clicks"), + [State("job-info", "data"), + State("plot-info", "data")], + prevent_initial_call=True +) +def mlair_plots_download(download_button, job_dict, plot_dict): +# jobid = json.loads(job_dict)["jobnr"] +# species = json.loads(job_dict)["variable"] +# start_date = json.loads(job_dict)["start_date"] +# station = json.loads(plot_dict)["station"] + + # file name according to users selection +# output_file_name = f"mlair_{ml_species}_{station_code}_{start_date}_{fc_length_str}.png" + # just to test + output_file_name = "mlair_O3_DENW067_2018-07-18_4Tage.png" + infile = str(ASSETS_PATH.joinpath('mlair', output_file_name)) + return dcc.send_file( + infile + ) + + @callback( Output("eurad_im_download_result", "data"), Input("eurad_im_output_download", "n_clicks"), diff --git a/src/pages/dashboard_translations.py b/src/pages/dashboard_translations.py index 5975d77670457a00b0d70646cad1637ecc2c7188..4ef6b89b0ee6001638b61a7a8a1f9ee631a97a45 100644 --- a/src/pages/dashboard_translations.py +++ b/src/pages/dashboard_translations.py @@ -99,20 +99,20 @@ date_format = ["M/D/Y", "D.M.Y"] date_format2 = ['%Y-%m-%d %H:%M', '%d.%m.%Y %H:%M'] first_day_of_week = [0, 1] forecast_length_label = ["forecast length", "Vorhersagedauer"] -region_label = ["region:", "Region:"] +region_label = ["region", "Region"] forecast_length_options = [["4 days", "3 days", "2 days", "1 day"], ["4 Tage", "3 Tage", "2 Tage", "1 Tag"]] output_format_options = [["raw model output", "2D plots", "time series"], ["Rohmodellausgabe", "2D-Diagramme", "Zeitreihen"]] state_label = ["state:", "Bundesland:"] -species_label = ["species:", "Spezies:"] -station_label = ["station:", "Station:"] -output_metrics_label = ["output metrics:", "Ausgabemetrik:"] +species_label = ["species", "Spezies"] +station_label = ["station", "Station"] +output_metrics_label = ["output metrics", "Ausgabemetrik"] species_options = [["ozone", "NO", "NO2", "PM2.5"], ["Ozon", "Stickstoffmonoxid", "Stickstoffdioxid", "Feinstaub (PM2.5)"]] metrics_options = [["dma8eu", "mean"], ["dma8eu", "Mittelwert"]] -emis_scen_label = ["emission scenario:", "Emissionsszenario:"] +emis_scen_label = ["emission scenario", "Emissionsszenario"] help_metrics_label = ["Help on metrics", "Hilfe zu Ausgabemetriken"] help_emissions_label = ["Help on emission scenarios", "Hilfe zu Emissions-Szenarien"] map_select_label = ["Select on map", "auf Karte auswählen"] @@ -125,6 +125,7 @@ download_label = ["Download Data", "Daten herunterladen"] im_download_label = ["Download Plots", "Plots herunterladen"] downscaling_label = ["Postprocessing with ML-Downscaling", "Postprocessing mit ML-Downscaling"] show_downscaling_label = ["Show results with ML downscaling", "Ergebnisse mit ML-Downscaling anzeigen"] +show_target_plot_label = ["Show target plot", "Ergebnisse als Schwellwertplot anzeigen"] out_option_label = ["output option", "Ausgabe-Option"] mlair_legend_obs_label = ["measurements", "Beobachtungen"] mlair_legend_fc_label = ["forecasts", "Vorhersagen"]