Skip to content

Commit

Permalink
Add name check for basin id field (#8)
Browse files Browse the repository at this point in the history
* Add name check for basin id field

* Update code/Caravan_part1_Earth_Engine.ipynb

Co-authored-by: Martin Gauch <[email protected]>

Co-authored-by: Martin Gauch <[email protected]>
  • Loading branch information
kratzert and gauchm authored Jun 2, 2022
1 parent a6c3f09 commit 544692d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion code/Caravan_part1_Earth_Engine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 544692d

Please sign in to comment.