From 544692d94672ec470fe12983aff633470f82ab2b Mon Sep 17 00:00:00 2001 From: Frederik Kratzert Date: Thu, 2 Jun 2022 14:16:51 +0200 Subject: [PATCH] Add name check for basin id field (#8) * Add name check for basin id field * Update code/Caravan_part1_Earth_Engine.ipynb Co-authored-by: Martin Gauch <15731649+gauchm@users.noreply.github.com> Co-authored-by: Martin Gauch <15731649+gauchm@users.noreply.github.com> --- code/Caravan_part1_Earth_Engine.ipynb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/code/Caravan_part1_Earth_Engine.ipynb b/code/Caravan_part1_Earth_Engine.ipynb index 94c61b3..7ab40e9 100644 --- a/code/Caravan_part1_Earth_Engine.ipynb +++ b/code/Caravan_part1_Earth_Engine.ipynb @@ -75,7 +75,7 @@ "\n", "- `OUTPUT_FOLDER_NAME`: The name of the folder (in Google Drive) that is used to store the resulting data. For example, `OUTPUT_FOLDER_NAME = 'my_caravan_extension'` will create a folder called `my_caravan_extension` in the main directory of your Google Drive.\n", "\n", - "- `BASIN_ID_FIELD`: Name of the attribute field in the shapefile that contains the basin id.\n", + "- `BASIN_ID_FIELD`: Name of the attribute field in the shapefile that contains the basin id. Make sure that this name does not conflict with any of the field names of HydroATLAS. For example, you could use something like `'gauge_id'` or `'basin_id'` but _not_ `'HYBAS_ID'`, `'PFAF_ID'`, or `'MAIN_BAS'`, which are all existing field names in HydroATLAS/HydroSHEDS.\n", "\n", "- `BASIN_PREFIX`: A short descriptive string that is prepended to each basin id and that should be unique within the Caravan data space. For example, we use `camels` for basins from the CAMELS (US) dataset and `camelsgb` from the CAMELS-GB dataset. The final name for each basin within the attribute table will be `{BASIN_PREFIX}_{GAUGE_ID}`. Note, if you already included such a prefix in the basin id field of your shapefile, leave this field as an empty string. Please also read the README in the Caravan dataset folder on details about the folder structure of the dataset.\n", "\n", @@ -332,6 +332,13 @@ "# get list list of all available hydroatlas feature properties\n", "property_names = hydro_atlas.first().propertyNames().getInfo()\n", "\n", + "# Make sure that BASIN_ID_FIELD is not a field name of HydroATLAS\n", + "if BASIN_ID_FIELD in property_names:\n", + " msg = (f\"BASIN_ID_FIELD {BASIN_ID_FIELD} has the same name as one of the \"\n", + " \"HydroATLAS fields, which is not allowed. Please rename the basin \"\n", + " \"id field in your shapefile and reingest the shapefile in Earth Engine\")\n", + " raise ValueError(\"\".join(msg))\n", + "\n", "print(f\"Found {len(property_names)} features initially\")\n", "\n", "# List of features for which we take the area-weighted majority vote\n",