From 130a85188d017f1cb051fdca2bc8b2a68d1924fd Mon Sep 17 00:00:00 2001 From: roeldegoede Date: Fri, 11 Oct 2024 14:51:15 +0200 Subject: [PATCH] added vertical datum to metadata --- .../modelmaker_sfincs_hmt/bathymetry.py | 24 +++++++++++++++++++ .../modelmaker_sfincs_hmt.py | 7 ++++++ 2 files changed, 31 insertions(+) diff --git a/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/bathymetry.py b/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/bathymetry.py index 950dd055..7d339508 100644 --- a/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/bathymetry.py +++ b/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/bathymetry.py @@ -134,17 +134,30 @@ def add_dataset(*args): if not src.nodata: app.gui.window.dialog_warning("File does not have a nodata value") return + if not src.crs: app.gui.window.dialog_warning("File does not have a valid CRS") return else: epsg = src.crs.to_epsg() + # Check if the vertical datum is explicitly mentioned in the files metadata + if src.tags().get('VERTICAL_CS'): + vdatum = src.tags()['VERTICAL_CS'] + else: + vdatum, okay = app.gui.window.dialog_string("Provide a vertical datum for the dataset", "MSL") + if not okay: + # Cancel was clicked + return + # ask for a name for the dataset name, okay = app.gui.window.dialog_string("Provide a name for the dataset", "New dataset") if not okay: # Cancel was clicked return + + #TODO add nodata, crs, vertical_datum and name to single pop-up, where everything that is already known is filled in + # check whether the name already exists in the data catalog while name in app.data_catalog.sources.keys(): name, okay = app.gui.window.dialog_string("Dataset name already exists. Provide a different name", "New dataset") @@ -162,6 +175,7 @@ def add_dataset(*args): meta: category: topography source: User + vertical_datum: {vdatum} """ # check if my_data_catalog.yml exists @@ -316,6 +330,15 @@ def update(): app.gui.setvar(group, "selected_bathymetry_dataset_zmin", dataset["zmin"]) app.gui.setvar(group, "selected_bathymetry_dataset_zmax", dataset["zmax"]) app.gui.setvar(group, "selected_bathymetry_dataset_offset", dataset["offset"]) + + # set vdatum of the model + name = selected_names[0] + meta = app.data_catalog[name].meta + + # check if vertical datum is defined in the metadata + if "vertical_datum" in meta: + value = meta["vertical_datum"] + app.gui.setvar(group, "selected_bathymetry_vdatum", value) else: app.gui.setvar(group, "selected_bathymetry_dataset_names", []) app.gui.setvar(group, "selected_bathymetry_dataset_index", 0) @@ -325,5 +348,6 @@ def update(): app.gui.setvar(group, "nr_selected_bathymetry_datasets", nrd) + def generate_bathymetry(*args): app.toolbox["modelmaker_sfincs_hmt"].generate_bathymetry() diff --git a/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/modelmaker_sfincs_hmt.py b/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/modelmaker_sfincs_hmt.py index 72d58f56..32008bfe 100644 --- a/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/modelmaker_sfincs_hmt.py +++ b/src/delftdashboard/toolboxes/modelmaker_sfincs_hmt/modelmaker_sfincs_hmt.py @@ -42,6 +42,9 @@ def __init__(self, name): self.setup_dict = {} + # create "meta" entry in the setup_dict, this is not used in the model but can be used to store additional information + self.setup_dict["meta"] = {} + # Set GUI variable group = "modelmaker_sfincs_hmt" @@ -128,6 +131,7 @@ def __init__(self, name): app.gui.setvar(group, "bathymetry_dataset_names", dataset_names) app.gui.setvar(group, "bathymetry_dataset_index", 0) app.gui.setvar(group, "selected_bathymetry_dataset_names", []) + app.gui.setvar(group, "selected_bathymetry_vdatum", "MSL") app.gui.setvar(group, "selected_bathymetry_dataset_index", 0) app.gui.setvar(group, "selected_bathymetry_dataset_meta", "") app.gui.setvar(group, "selected_bathymetry_dataset_zmin", -99999.0) @@ -448,6 +452,9 @@ def generate_bathymetry(self): return self.setup_dict.update({"setup_dep": setup_dep}) + # add the vdatum to the metadata + self.setup_dict["meta"]["vertical_datum"] = app.gui.getvar(group, "selected_bathymetry_vdatum") + # show merged bathymetry on map app.map.layer["sfincs_hmt"].layer["bed_levels"].update()