diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 522378a9..c7e01de4 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -1,6 +1,7 @@
name: Build Documentation
on:
+ workflow_dispatch:
push:
branches: [ main ]
paths:
@@ -39,50 +40,23 @@ jobs:
miniforge-variant: Mambaforge
miniforge-version: latest
channels: conda-forge
- activate-environment: hydromt-fiat-docs
use-mamba: true
- - name: load from cache
- id: cache
- uses: actions/cache/restore@v3
- with:
- path: |
- /usr/share/miniconda3
- ~/pycache
- ./docs/_build
- # the below two settings mean we'll alway srestore the cache
- # but the cache hit output can tell us if we have to update afterwards
- key: docs-${{ hashFiles('envs/hydromt-fiat-docs.yml') }}
- restore-keys: |
- docs
-
- - name: Fail on no cache restore
- if: steps.cache.outputs.cache-matched-key == ''
- run: |
- echo "Failed to restore any cache. exiting..."
- exit 1
-
- # by avoiding the mamba setup stage by loading it from cache instead we save
- # a lot of setup time, but we do have to do our own PATH management
- # hence the exports
- - name: Update environment
- if: steps.cache.outputs.cache-hit != 'true'
+ - name: Install and activate environment
run: |
- export PATH=/usr/share/miniconda3/bin:$PATH
- mamba env update -n hydromt-fiat-docs -f envs/hydromt-fiat-docs.yml
-
- - name: Install hydromt-fiat
- run: pip install .
+ mamba env create -f envs/hydromt-fiat-docs.yml
+ conda activate hydromt-fiat-docs
+ pip install .
- name: Generate docs
- # if: ${{ github.event_name != 'pull_request' && !github.event.act }}
+ if: ${{ github.event_name != 'pull_request' && !github.event.act }}
run: |
export PATH=/usr/share/miniconda3/bin:$PATH
PYTHONPYCACHEPREFIX=~/pycache mamba run -n hydromt-fiat-docs sphinx-build -M html ./docs ./docs/_build
echo "DOC_VERSION=$(mamba run -n hydromt-fiat-docs python -c 'from hydromt_fiat import __version__ as v; print("dev" if "dev" in v else "v"+v.replace(".dev",""))')" >> $GITHUB_ENV
- name: Upload to GitHub Pages
- # if: ${{ github.event_name != 'pull_request' && !github.event.act }}
+ if: ${{ github.event_name != 'pull_request' && !github.event.act }}
uses: peaceiris/actions-gh-pages@v3.9.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.gitignore b/.gitignore
index 143ade5b..7e3a8fb7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -121,7 +121,5 @@ venv.bak/
cache
/examples/FIAT_database
hydromt_fiat/data/damage_functions/flooding/AllDDF_HAZUS_fractions.xlsx
-hydromt_fiat/data/damage_functions/flooding/~$AllDDF_HAZUS_fractions.xlsx
examples/data/building_footprints/fiat_model_bfs
-examples/data/aggregation_zones_example/aggregation_test_1_output
-examples/data/aggregation_zones_example/aggregation_test_2_output
\ No newline at end of file
+examples/data/aggregation_zones/output
\ No newline at end of file
diff --git a/docs/examples/index.rst b/docs/examples/index.rst
index 47354e42..ad9e3d8b 100644
--- a/docs/examples/index.rst
+++ b/docs/examples/index.rst
@@ -12,4 +12,5 @@ Offline example access
Below you can access some of the main examples and go through them in an off-line manner. More examples will be added soon.
1. `Creating a Delft-FIAT model anywhere in the world from OSM and JRC data <../_examples/global_OSM_JRC.ipynb>`_
+2. `Adding aggregation zones to your Delft-FIAT model <../_examples/aggregation_zones_example.ipynb>`_
diff --git a/docs/index.rst b/docs/index.rst
index b346e85e..77a13f2a 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -17,6 +17,10 @@ by configuring the model building process from single *yml* file.
For detailed information on HydroMT itself, you can visit the `core documentation `_.
+::
+
+ Note: This repository is under development, the documentation is not yet complete...
+
Overview
=============
diff --git a/envs/hydromt-fiat-docs.yml b/envs/hydromt-fiat-docs.yml
index 0fff25aa..4c42a90e 100644
--- a/envs/hydromt-fiat-docs.yml
+++ b/envs/hydromt-fiat-docs.yml
@@ -18,6 +18,7 @@ dependencies:
- pip
- pyogrio
- pydata-sphinx-theme
+- python=3.10
- rasterio
- requests
- rioxarray
diff --git a/examples/aggregation_zones_example.ipynb b/examples/aggregation_zones_example.ipynb
index 152d80dc..e965cf44 100644
--- a/examples/aggregation_zones_example.ipynb
+++ b/examples/aggregation_zones_example.ipynb
@@ -14,7 +14,7 @@
"In spatial analysis and urban planning the division of objects into spatial zones is a pivotal tool to facilitate analysis and/or visualization. This jupyter notebook demonstrates how to create a **spatial joint** of the FIAT model data with single or multiple **aggregation zones** in order to link an the zone and objects of interest. \n",
"
The base for this notebook is the DELFT FIAT toolbox.
\n",
"\n",
- "Note: In this notebook the model was already initialized. Unless the user does not wish to use own data, there is `no need` to create a new model and the user can simply continue with the example data found in the / \"example\" / \"data\"/ \"aggregation_zone_example\" - directory."
+ "Note: In this notebook the model was already initialized. Unless the user does not wish to use own data, there is `no need` to create a new model and the user can simply continue with the example data found in the / \"example\" / \"data\"/ \"aggregation_zone\" - directory."
]
},
{
@@ -50,16 +50,422 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "Make this Notebook Trusted to load map: File -> Trust Notebook
"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 1,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"import geopandas as gpd\n",
"from pathlib import Path\n",
"import os \n",
"#Load aggregation zones as GeoDataFrames\n",
- "exposure=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\" / \"exposure\" / \"buildings.gpkg\")\n",
- "base_zone=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\" / \"aggregation_zones\" / \"base_zones.gpkg\")\n",
+ "exposure=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"fiat_model\" / \"exposure\" / \"buildings.gpkg\")\n",
+ "base_zone=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"aggregation_zones\" / \"base_zones.gpkg\")\n",
"\n",
"m = base_zone.explore(column = 'ZONE_BASE')\n",
"m = exposure.explore(m=m, color = '#FFFACD')\n",
@@ -91,21 +497,15 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
- "from typing import Sequence\n",
- "from _pytest.mark.structures import ParameterSet\n",
"from hydromt_fiat.fiat import FiatModel\n",
"from hydromt.log import setuplog\n",
- "import pytest\n",
"import pandas as pd\n",
- "from hydromt_fiat.workflows.aggregation_areas import join_exposure_aggregation_areas\n",
"import yaml\n",
"import json\n",
- "from hydromt_fiat.workflows.exposure_vector import ExposureVector\n",
- "from hydromt_fiat.workflows.vulnerability import Vulnerability\n",
"import shutil"
]
},
@@ -172,14 +572,57 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "{\n",
+ " \"cases\": {\n",
+ " \"test1_single_aggregation\": {\n",
+ " \"new_root\": \"./data/Aggregation_zones/output/aggregation_zones_test1\",\n",
+ " \"configuration\": {\n",
+ " \"setup_aggregation_areas\": {\n",
+ " \"aggregation_area_fn\": \"./data/Aggregation_zones/aggregation_zones/base_zones.gpkg\",\n",
+ " \"attribute_names\": \"ZONE_BASE\",\n",
+ " \"label_names\": \"Base_zones\"\n",
+ " }\n",
+ " }\n",
+ " },\n",
+ " \"test2_multiple_aggregation\": {\n",
+ " \"new_root\": \"./data/Aggregation_zones/output/aggregation_zones_test2\",\n",
+ " \"configuration\": {\n",
+ " \"setup_aggregation_areas\": {\n",
+ " \"aggregation_area_fn\": [\n",
+ " \"./data/Aggregation_zones/aggregation_zones/base_zones.gpkg\",\n",
+ " \"./data/Aggregation_zones/aggregation_zones/land_use.gpkg\",\n",
+ " \"./data/Aggregation_zones/aggregation_zones/accomodation_type.gpkg\"\n",
+ " ],\n",
+ " \"attribute_names\": [\n",
+ " \"ZONE_BASE\",\n",
+ " \"LAND_USE\",\n",
+ " \"ACCOM\"\n",
+ " ],\n",
+ " \"label_names\": [\n",
+ " \"Base_zones\",\n",
+ " \"Land_use\",\n",
+ " \"Accommodation_type\"\n",
+ " ]\n",
+ " }\n",
+ " }\n",
+ " }\n",
+ " }\n",
+ "}\n"
+ ]
+ }
+ ],
"source": [
"#Let's read the yaml file with the required information \n",
"#and set up the FIAT model for the two test cases. \n",
"\n",
- "with open(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\" / \"config_aggregation.yml\", 'r') as file:\n",
+ "with open(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"config_aggregation.yml\", 'r') as file:\n",
" config_aggregation = yaml.safe_load(file)\n",
"\n",
"print(json.dumps(config_aggregation, indent=4, sort_keys=False))"
@@ -203,12 +646,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2023-10-20 09:59:17,072 - hydromt_fiat - log - INFO - HydroMT version: 0.8.0\n"
+ ]
+ }
+ ],
"source": [
"# Set up Fiat Model\n",
- "root = Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\"\n",
+ "root = Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"fiat_model\"\n",
"\n",
"#If case exist\n",
"if Path(config_aggregation[\"cases\"][\"test1_single_aggregation\"][\"new_root\"]).exists():\n",
@@ -235,9 +686,42 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2023-10-20 09:59:18,050 - hydromt_fiat - log - DEBUG - Appending log messages to file c:\\Repositories\\hydromt_fiat\\examples\\data\\aggregation_zones\\fiat_model\\hydromt.log.\n",
+ "2023-10-20 09:59:18,051 - hydromt_fiat - model_api - INFO - Initializing fiat model from hydromt_fiat (v0.2.1.dev0).\n",
+ "2023-10-20 09:59:18,052 - hydromt_fiat - fiat - INFO - Reading model data from c:\\Repositories\\hydromt_fiat\\examples\\data\\aggregation_zones\\fiat_model\n",
+ "2023-10-20 09:59:18,053 - hydromt_fiat - model_api - DEBUG - User defined config read from c:\\Repositories\\hydromt_fiat\\examples\\data\\aggregation_zones\\fiat_model\\settings.toml\n",
+ "2023-10-20 09:59:18,054 - hydromt_fiat - fiat - INFO - Reading model table files.\n",
+ "2023-10-20 09:59:18,055 - hydromt_fiat - fiat - DEBUG - Reading vulnerability table c:\\Repositories\\hydromt_fiat\\examples\\data\\aggregation_zones\\fiat_model\\vulnerability\\vulnerability_curves.csv\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2023-10-20 09:59:18,085 - hydromt_fiat - fiat - DEBUG - Reading exposure table c:\\Repositories\\hydromt_fiat\\examples\\data\\aggregation_zones\\fiat_model\\exposure\\exposure.csv\n",
+ "2023-10-20 09:59:18,092 - hydromt_fiat - fiat - INFO - Reading exposure geometries.\n",
+ "2023-10-20 09:59:18,093 - hydromt_fiat - exposure_vector - INFO - Setting geometry name to buildings...\n",
+ "2023-10-20 09:59:18,181 - hydromt_fiat - exposure_vector - INFO - Setting exposure geometries...\n",
+ "2023-10-20 09:59:18,181 - hydromt_fiat - model_api - INFO - setup_aggregation_areas.aggregation_area_fn: ./data/Aggregation_zones/aggregation_zones/base_zones.gpkg\n",
+ "2023-10-20 09:59:18,182 - hydromt_fiat - model_api - INFO - setup_aggregation_areas.attribute_names: ZONE_BASE\n",
+ "2023-10-20 09:59:18,182 - hydromt_fiat - model_api - INFO - setup_aggregation_areas.label_names: Base_zones\n",
+ "2023-10-20 09:59:18,285 - hydromt_fiat - log - DEBUG - Writing log messages to new file c:\\Repositories\\hydromt_fiat\\examples\\data\\Aggregation_zones\\output\\aggregation_zones_test1\\hydromt.log.\n",
+ "2023-10-20 09:59:18,286 - hydromt_fiat - fiat - INFO - Updating all data objects...\n",
+ "2023-10-20 09:59:18,287 - hydromt_fiat - fiat - INFO - Writing model data to c:\\Repositories\\hydromt_fiat\\examples\\data\\Aggregation_zones\\output\\aggregation_zones_test1\n",
+ "2023-10-20 09:59:18,288 - hydromt_fiat - model_api - INFO - Writing model config to c:\\Repositories\\hydromt_fiat\\examples\\data\\Aggregation_zones\\output\\aggregation_zones_test1\\settings.toml\n",
+ "2023-10-20 09:59:18,289 - hydromt_fiat - model_api - DEBUG - Writing file exposure/buildings.gpkg\n",
+ "2023-10-20 09:59:18,396 - hydromt_fiat - fiat - INFO - Writing model exposure table file to exposure/exposure.csv.\n",
+ "2023-10-20 09:59:18,411 - hydromt_fiat - fiat - INFO - Writing model vulnerability_curves table file to vulnerability/vulnerability_curves.csv.\n"
+ ]
+ }
+ ],
"source": [
"#Start running the new model with the new exposure output \n",
"fm = FiatModel(root=root, mode=\"r\", logger=logger)\n",
@@ -270,7 +754,7 @@
"outputs": [],
"source": [
"#If case exist\n",
- "if Path(config_aggregation[\"cases\"][\"test1_single_aggregation\"][\"new_root\"]).exists():\n",
+ "if Path(config_aggregation[\"cases\"][\"test2_multiple_aggregation\"][\"new_root\"]).exists():\n",
" shutil.rmtree(config_aggregation[\"cases\"][\"test2_multiple_aggregation\"][\"new_root\"])\n",
" \n",
"# Set up the logger\n",
@@ -320,10 +804,10 @@
"outputs": [],
"source": [
"#Load *.csv into dataframe\n",
- "df_single_aggregation = pd.read_csv(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\" / \"output\" / \"aggregation_zones_test1\" / \"exposure\" / \"exposure.csv\")\n",
+ "df_single_aggregation = pd.read_csv(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"output\" / \"aggregation_zones_test1\" / \"exposure\" / \"exposure.csv\")\n",
"\n",
"#Load original exposure geopackage into GeoDataFrame\n",
- "new_exposure=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\" / \"output\" / \"aggregation_zones_test1\" / \"exposure\" / \"buildings.gpkg\")\n",
+ "new_exposure=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"output\" / \"aggregation_zones_test1\" / \"exposure\" / \"buildings.gpkg\")\n",
"\n",
"#Merge dataframe with GeoDataFrame\n",
"merged_gdf = new_exposure.merge(df_single_aggregation, left_on='Object ID', right_on='Object ID', how='inner')\n",
@@ -354,10 +838,10 @@
"outputs": [],
"source": [
"#Load *.csv into dataframe\n",
- "df_multiple_aggregation = pd.read_csv(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\" / \"output\" / \"aggregation_zones_test2\" / \"exposure\" / \"exposure.csv\")\n",
+ "df_multiple_aggregation = pd.read_csv(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"output\" / \"aggregation_zones_test2\" / \"exposure\" / \"exposure.csv\")\n",
"\n",
"#Load original exposure geopackage into GeoDataFrame\n",
- "new_exposure=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones_example\" / \"output\" / \"aggregation_zones_test2\" / \"exposure\" / \"buildings.gpkg\")\n",
+ "new_exposure=gpd.read_file(Path(os.path.abspath(\"\")) / \"data\" / \"aggregation_zones\" / \"output\" / \"aggregation_zones_test2\" / \"exposure\" / \"buildings.gpkg\")\n",
"\n",
"#Merge dataframe with GeoDataFrame\n",
"merged_gdf_multiple = new_exposure.merge(df_multiple_aggregation, left_on='Object ID', right_on='Object ID', how='inner')"
diff --git a/examples/data/aggregation_zones/config_aggregation.yml b/examples/data/aggregation_zones/config_aggregation.yml
index ee763e4d..ae077966 100644
--- a/examples/data/aggregation_zones/config_aggregation.yml
+++ b/examples/data/aggregation_zones/config_aggregation.yml
@@ -1,20 +1,20 @@
cases:
test1_single_aggregation:
- new_root: "./data/Aggregation_zones_example/output/aggregation_zones_test1"
+ new_root: "./data/Aggregation_zones/output/aggregation_zones_test1"
configuration:
setup_aggregation_areas:
- aggregation_area_fn: "./data/Aggregation_zones_example/aggregation_zones/base_zones.gpkg"
+ aggregation_area_fn: "./data/Aggregation_zones/aggregation_zones/base_zones.gpkg"
attribute_names: ZONE_BASE
label_names: Base_zones
test2_multiple_aggregation:
- new_root: "./data/Aggregation_zones_example/output/aggregation_zones_test2"
+ new_root: "./data/Aggregation_zones/output/aggregation_zones_test2"
configuration:
setup_aggregation_areas:
aggregation_area_fn:
- - "./data/Aggregation_zones_example/aggregation_zones/base_zones.gpkg"
- - "./data/Aggregation_zones_example/aggregation_zones/land_use.gpkg"
- - "./data/Aggregation_zones_example/aggregation_zones/accomodation_type.gpkg"
+ - "./data/Aggregation_zones/aggregation_zones/base_zones.gpkg"
+ - "./data/Aggregation_zones/aggregation_zones/land_use.gpkg"
+ - "./data/Aggregation_zones/aggregation_zones/accomodation_type.gpkg"
attribute_names:
- ZONE_BASE
- LAND_USE
diff --git a/examples/data/aggregation_zones/fiat_model/settings.toml b/examples/data/aggregation_zones/fiat_model/settings.toml
index 44b60c5b..3ae7d2ea 100644
--- a/examples/data/aggregation_zones/fiat_model/settings.toml
+++ b/examples/data/aggregation_zones/fiat_model/settings.toml
@@ -15,8 +15,10 @@ file = "./vulnerability/vulnerability_curves.csv"
unit = "feet"
step_size = 0.1
+[exposure.csv]
+file = "./exposure/exposure.csv"
+
[exposure.geom]
-csv = "./exposure/exposure.csv"
crs = "EPSG:4326"
unit = "ft"
file1 = "./exposure/buildings.gpkg"
diff --git a/hydromt_fiat/fiat.py b/hydromt_fiat/fiat.py
index ab7128bd..c1dd90e6 100644
--- a/hydromt_fiat/fiat.py
+++ b/hydromt_fiat/fiat.py
@@ -718,7 +718,7 @@ def read_tables(self):
logging.warning(f"File {vulnerability_fn} does not exist!")
# Now with exposure
- exposure_fn = Path(self.root) / self.get_config("exposure.geom.csv")
+ exposure_fn = Path(self.root) / self.get_config("exposure.csv.file")
if Path(exposure_fn).is_file():
self.logger.debug(f"Reading exposure table {exposure_fn}")
self.exposure = ExposureVector(
diff --git a/pyproject.toml b/pyproject.toml
index 1a871285..117e1efb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -10,6 +10,7 @@ authors = [
{name = "Mario Fuentes Monjaraz", email = "mario.fuentesmonjaraz@deltares.nl"},
{name = "Luis Rodriguez Galvez", email = "luis.rodriguez@deltares.nl"},
{name = "Lieke Meijer", email = "lieke.meijer@deltares.nl"},
+ {name = "Sarah Rautenbach", email = "sarah.rautenbach@deltares.nl"},
]
requires-python = ">=3.8"
dependencies = [