diff --git a/src/eurad_plot.py b/src/eurad_plot.py index 9cae7a70b053e7b74049bf7080387eb5145d23b6..ac385f60ccae46922387021e29dbc4db57e4a183 100644 --- a/src/eurad_plot.py +++ b/src/eurad_plot.py @@ -1,11 +1,23 @@ import os import eurad.eurad_vis as ev from eurad.eurad_netcdf import EURAD_netCDF -from eurad.info import generate_time_series_plot +from eurad.info import generate_time_series_plot, get_available_stations +from eurad.stations import Stations # just to make it run from pathlib import Path +def get_station_coordinates(station_code): + # search correct station lat/lon + station = Stations() + station.read_stations("german_stations.csv", country="", state="") + poi = station.get_station(station_code) + poi["lat"] = poi.pop("coordinates_lat") + poi["lon"] = poi.pop("coordinates_lng") + poi.pop("coordinates_alt") + return poi + + def get_euradim_plot(language_id, jobnr, timestep, species, station, ldiff, ltarget): # regarding target_plots: value can be given by user (later) # for now use default values @@ -37,28 +49,28 @@ def get_euradim_plot(language_id, jobnr, timestep, species, station, ldiff, ltar infile = str(DATA_PATH.joinpath(f'{jobnr}.nc')) if station: - station = station.split(',')[0] # extract station code - # path relative to mlworkflowinterface + station_code = station.split(',')[0] # extract station code + station = get_station_coordinates(station_code) filename = infile nc_file = EURAD_netCDF(infile) if ltarget: - output_file = "job_{}_time_{}_species_{}_station_{}_target_{}.png".format(jobnr, timestep, species, station, language_id) + output_file = "job_{}_time_{}_species_{}_station_{}_target_{}.png".format(jobnr, timestep, species, station_code, language_id) output_path = str(ASSETS_PATH.joinpath(output_file)) if not os.path.isfile(output_path): - ev.plot_area_target(nc_file, species, timestep, output_path, t_values[species], unit=unit, lang=lang) + ev.plot_area_target(nc_file, species, timestep, output_path, t_values[species], unit=unit, station=station, lang=lang) elif ldiff: - output_file = "job_{}_time_{}_species_{}_station_{}_diff_{}.png".format(jobnr, timestep, species, station, language_id) + output_file = "job_{}_time_{}_species_{}_station_{}_diff_{}.png".format(jobnr, timestep, species, station_code, language_id) output_path = str(ASSETS_PATH.joinpath(output_file)) base_file = str(DATA_PATH.joinpath(f'base_{jobnr}.nc')) base_nc_file = EURAD_netCDF(base_file) if not os.path.isfile(output_path): - ev.plot_area_diff(nc_file, base_nc_file, species, timestep, output_path, unit=unit, lang=lang) + ev.plot_area_diff(nc_file, base_nc_file, species, timestep, output_path, unit=unit, station=station, lang=lang) else: - output_file = "job_{}_time_{}_species_{}_station_{}_{}.png".format(jobnr, timestep, species, station, language_id) + output_file = "job_{}_time_{}_species_{}_station_{}_{}.png".format(jobnr, timestep, species, station_code, language_id) output_path = str(ASSETS_PATH.joinpath(output_file)) if not os.path.isfile(output_path): - ev.plot_area(nc_file, species, timestep, output_path, unit=unit, lang=lang) + ev.plot_area(nc_file, species, timestep, output_path, unit=unit, station=station, lang=lang) return os.path.join("assets", "generated_plots", "eurad", output_file) # path relative to website root (src) diff --git a/src/pages/dashboard.py b/src/pages/dashboard.py index 8684ed1535bf154236692054ae411c553248f7c5..32adddbfaa8f94540f5389e41b31dd2bf728b77f 100644 --- a/src/pages/dashboard.py +++ b/src/pages/dashboard.py @@ -406,6 +406,9 @@ def update_image(selected_time_step, selected_variable, selected_station, ltarge plotinfo_dict["time_step"] = selected_time_step plotinfo_dict["variable"] = selected_variable plotinfo_dict["station"] = selected_station.split(',')[0] + plotinfo_dict["language_id"] = language_id + plotinfo_dict["ldiff"] = lldiff + plotinfo_dict["ltarget"] = lltarget plotinfo_json = json.dumps(plotinfo_dict) return first_image, second_image, plotinfo_json @@ -583,9 +586,9 @@ def generate_eurad_scen_output_body(language_id, context, jobnr): class_name="fzj_style_btn"), dcc.Download(id="eurad_scen_download_result")]), dbc.Col(html.Br()), - html.Div([dbc.Button(f"{guitr.im_download_label[language_id]}", id="eurad_scen_plots_download", + html.Div([dbc.Button(f"{guitr.im_download_label[language_id]}", id="eurad_im_plots_download", class_name="fzj_style_btn"), - dcc.Download(id="eurad_scen_download_plots")])], width=6), + dcc.Download(id="eurad_im_download_plots")])], width=6), ], class_name="row mt-3"), dbc.Row([ dbc.Col(html.Br(), width=12), @@ -1266,10 +1269,18 @@ def eurad_im_plots_download(download_button, job_dict, plot_dict): station = json.loads(plot_dict)["station"] species = json.loads(plot_dict)["variable"] timestamp = json.loads(plot_dict)["time_step"] + language_id = json.loads(plot_dict)["language_id"] + ldiff = json.loads(plot_dict)["ldiff"] + ltarget = json.loads(plot_dict)["ltarget"] # file names according to users selection - infile1 = f'job_{jobid}_station_{station}_species_{species}_time_{timestamp}.png' - infile2 = f'job_{jobid}_time_{timestamp}_species_{species}_station_{station}.png' + infile1 = f'job_{jobid}_station_{station}_species_{species}_time_{timestamp}_{language_id}.png' + if ltarget: + infile2 = "job_{}_time_{}_species_{}_station_{}_target_{}.png".format(jobid, timestamp, species, station, language_id) + elif ldiff: + infile2 = "job_{}_time_{}_species_{}_station_{}_diff_{}.png".format(jobid, timestamp, species, station, language_id) + else: + infile2 = "job_{}_time_{}_species_{}_station_{}_{}.png".format(jobid, timestamp, species, station, language_id) files = [infile1, infile2] zipname = str(ASSETS_PATH.joinpath('eurad', f'job_{jobid}_time_{timestamp}_species_{species}_station_{station}.zip'))