Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#134 integrate roads script in code base #186

Merged
merged 15 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/api_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Build components
fiat.FiatModel.setup_basemaps
fiat.FiatModel.setup_vulnerability
fiat.FiatModel.setup_vulnerability_from_csv
fiat.FiatModel.setup_exposure_vector
fiat.FiatModel.setup_exposure_buildings
fiat.FiatModel.setup_hazard
fiat.FiatModel.setup_social_vulnerability_index

Expand Down
2 changes: 1 addition & 1 deletion docs/data/hazus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ by providing the following values in the configuration file::
vulnerability_identifiers_and_linking_fn = "default_hazus_iwr_linking"
unit = "ft"

[setup_exposure_vector]
[setup_exposure_buildings]
max_potential_damage = "hazus_max_potential_damages"
unit = "m"

Expand Down
2 changes: 1 addition & 1 deletion docs/data/jrc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ by providing the following values in the configuration file::
vulnerability_identifiers_and_linking_fn = "jrc_vulnerability_curves_linking"
unit = "m"

[setup_exposure_vector]
[setup_exposure_buildings]
max_potential_damage = "jrc_damage_values"
unit = "m"

Expand Down
2 changes: 1 addition & 1 deletion docs/data/national_structure_inventory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For projects in the United States, users of **HydroMT-FIAT** can directly and ea
of the `National Structure Inventory <https://www.hec.usace.army.mil/confluence/nsi>`_ (NSI). The
user can access the data through providing 'NSI' in the configuration file as such::

[setup_exposure_vector]
[setup_exposure_buildings]
asset_locations = "NSI"
occupancy_type = "NSI"
max_potential_damage = "NSI"
Expand Down
2 changes: 1 addition & 1 deletion docs/data/openstreetmap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ OpenStreetMap Building Footprints and Land Use
Users of **HydroMT-FIAT** can directly and easily make use of the `OpenStreetMap <https://www.openstreetmap.org/about>`_
(OSM) initiative. The user can access the data through providing 'OSM' in the configuration file as such::

[setup_exposure_vector]
[setup_exposure_buildings]
asset_locations = "OSM"
occupancy_type = "OSM"

Expand Down
6 changes: 3 additions & 3 deletions docs/user_guide/user_guide_overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ to local data on the user's machine. The `asset_locations`, `occupancy_type`, an
data should be provided as a vector file (e.g. *.shp* or *.gpkg*). The `ground_floor_height` can currently
only be set to a single value (this will be updated soon!). The `damage_types` should be provided as a
list of strings (e.g. ["structure", "content"]). The `unit` should be provided as a string (e.g. "m").
See below how the `setup_exposure_vector` method can be used to build or update the exposure data::
See below how the `setup_exposure_buildings` method can be used to build or update the exposure data::

[setup_exposure_vector]
[setup_exposure_buildings]
asset_locations = <Key in the Data Catalog, data API key, or path to local data>
occupancy_type = <Key in the Data Catalog, data API key, or path to local data>
damage_types = <List of damage types, e.g. ["structure", "content"]>
Expand All @@ -45,7 +45,7 @@ See below how the `setup_exposure_vector` method can be used to build or update
The following method is used to build or update the **exposure** data:

.. autosummary::
FiatModel.setup_exposure_vector
FiatModel.setup_exposure_buildings

For more information, see the :ref:`exposure_vector`.

Expand Down
2 changes: 1 addition & 1 deletion examples/global_OSM_JRC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
" \"continent\": continent,\n",
" \"unit\": unit,\n",
" },\n",
" \"setup_exposure_vector\": {\n",
" \"setup_exposure_buildings\": {\n",
" \"asset_locations\": asset_locations,\n",
" \"occupancy_type\": occupancy_type,\n",
" \"max_potential_damage\": max_potential_damage,\n",
Expand Down
2 changes: 1 addition & 1 deletion hydromt_fiat/api/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ class ConfigIni(BaseModel):
setup_config: ModelIni
setup_hazard: HazardIni
setup_vulnerability: VulnerabilityIni
setup_exposure_vector: ExposureVectorIni
setup_exposure_buildings: ExposureVectorIni
2 changes: 1 addition & 1 deletion hydromt_fiat/api/hydromt_fiat_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def build_config_ini(self):
setup_config=self.model_vm.config_model,
setup_hazard=self.hazard_vm.hazard_model,
setup_vulnerability=self.vulnerability_vm.vulnerability_model,
setup_exposure_vector=self.exposure_vm.exposure_model,
setup_exposure_buildings=self.exposure_vm.exposure_model,
)

database_path = self.__class__.database.drive
Expand Down
70 changes: 41 additions & 29 deletions hydromt_fiat/data/hydromt_fiat_catalog_USA.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@

NSI:
path: "https://nsi.sec.usace.army.mil/nsiapi/structures?fmt=fc"
data_type: GeoDataFrame
driver: vector
crs: 4326
translation_fn: "attribute_linking/NSI_attributes_to_FIAT.json"
meta:
category: exposure
path: "https://nsi.sec.usace.army.mil/nsiapi/structures?fmt=fc"
data_type: GeoDataFrame
driver: vector
crs: 4326
translation_fn: "attribute_linking/NSI_attributes_to_FIAT.json"
meta:
category: exposure

default_vulnerability_curves:
path: damage_functions/flooding/Hazus_IWR_curves.csv
data_type: DataFrame
driver: csv
meta:
category: vulnerability
source: HAZUS SQL database, USACE-IWR and FEMA expert elicitation curves. The source of these curves is the Draft Report Nonresidential Flood Depth-Damage Functions Derived from Expert Elicitation, April 2009, Revised 2013. FEMA Contract Number HSFEHQ-06-D-0162. Task Order HSFEHQ-08-J-0014. Not for distribution, but data shared by USACE.
path: damage_functions/flooding/Hazus_IWR_curves.csv
data_type: DataFrame
driver: csv
meta:
unit: ft
category: vulnerability
source: HAZUS SQL database, USACE-IWR and FEMA expert elicitation curves. The source of these curves is the Draft Report Nonresidential Flood Depth-Damage Functions Derived from Expert Elicitation, April 2009, Revised 2013. FEMA Contract Number HSFEHQ-06-D-0162. Task Order HSFEHQ-08-J-0014. Not for distribution, but data shared by USACE.

jrc_vulnerability_curves:
path: damage_functions/flooding/JRC_damage_functions.xlsx
data_type: DataFrame
driver: xlsx
meta:
category: vulnerability
path: damage_functions/flooding/JRC_damage_functions.xlsx
data_type: DataFrame
driver: xlsx
meta:
unit: m
category: vulnerability

hazus_max_potential_damages:
path: max_potential_damages/damage_values_fema_hazus-inventory-technical-manual-4.2.3.xlsx
data_type: DataFrame
driver: xlsx
meta:
category: vulnerability
path: max_potential_damages/damage_values_fema_hazus-inventory-technical-manual-4.2.3.xlsx
data_type: DataFrame
driver: xlsx
meta:
unit: ft
category: vulnerability

social_vulnerability:
path: social_vulnerability/census_vulnerability_data_codebook.xlsx
data_type: DataFrame
driver: xlsx
meta:
category: social_vulnerability
path: social_vulnerability/census_vulnerability_data_codebook.xlsx
data_type: DataFrame
driver: xlsx
meta:
category: social_vulnerability

default_hazus_iwr_linking:
path: vulnerability_linking/default_hazus_iwr_curve_linking.csv
data_type: DataFrame
driver: csv
meta:
category: vulnerability
category: vulnerability

default_road_max_potential_damages:
path: max_potential_damages/us_road_damage.csv
data_type: DataFrame
driver: csv
meta:
unit: ft
category: exposure
source: Bouwer, Laurens & Haasnoot, Marjolijn & Wagenaar, Dennis & Roscoe, Kathryn. (2018). Assessment of alternative flood mitigation strategies for the C-7 Basin in Miami, Florida.
7 changes: 7 additions & 0 deletions hydromt_fiat/data/max_potential_damages/us_road_damage.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lanes,cost [USD/ft]
1,240
2,240
3,360
4,480
5,600
6,720
50 changes: 35 additions & 15 deletions hydromt_fiat/data_apis/open_street_maps.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import osmnx as ox
import logging
from shapely.geometry import Polygon
import geopandas as gpd
from typing import Union, List


def get_assets_from_osm(polygon: Polygon):
def get_assets_from_osm(polygon: Polygon) -> gpd.GeoDataFrame:
tags = {"building": True} # this is the tag we use to find the correct OSM data
footprints = ox.features.features_from_polygon(
polygon, tags
) # then we query the data

if footprints.empty:
logging.warning("No buildings found from OSM")
return None

logging.info(f"Total number of buildings found from OSM: {len(footprints)}")
Expand All @@ -25,7 +26,38 @@ def get_assets_from_osm(polygon: Polygon):
return footprints


def get_landuse_from_osm(polygon: Polygon):
def get_roads_from_osm(
polygon: Polygon,
road_types: Union[str, List[str], bool] = True,
) -> gpd.GeoDataFrame:
if isinstance(road_types, str):
road_types = [road_types]

tag = {
"highway": road_types
} # this is the tag we use to find the correct OSM data

roads = ox.features.features_from_polygon(
polygon, tags=tag
) # then we query the data

if roads.empty:
return None

logging.info(f"Total number of roads found from OSM: {len(roads)}")

# Not sure if this is needed here and maybe filter for the columns that we need
roads = roads.loc[
(roads.geometry.type == "LineString")
| (roads.geometry.type == "MultiLineString")
]
roads = roads.reset_index(drop=True)
roads = roads.loc[:, ["highway", "name", "lanes", "geometry"]]

return roads


def get_landuse_from_osm(polygon: Polygon) -> gpd.GeoDataFrame:
tags = {"landuse": True} # this is the tag we use to find the correct OSM data
landuse = ox.features.features_from_polygon(polygon, tags) # then we query the data

Expand All @@ -45,18 +77,6 @@ def get_landuse_from_osm(polygon: Polygon):
return landuse


if __name__ == "__main__":
_polygon = Polygon(
[
[-80.21997289327112, 25.83897611793664],
[-80.21997289327112, 25.86427542636784],
[-80.24609330530801, 25.86427542636784],
[-80.24609330530801, 25.83897611793664],
[-80.21997289327112, 25.83897611793664],
]
)
get_landuse_from_osm(_polygon)

# # Do a spatial join to connect the buildings with the classes
# # (here we use a buffer area of 100 m around the classes in case there buildings falling completely out of the classes)
# # a more comprehensive spatial join to account for overlapping area can be used as well
Expand Down
60 changes: 53 additions & 7 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,35 @@ def setup_vulnerability_from_csv(self, csv_fn: Union[str, Path], unit: str) -> N
(e.g. meter).
"""
# Process the vulnerability data
self.vulnerability = Vulnerability(
unit,
self.logger,
)
if not self.vulnerability:
self.vulnerability = Vulnerability(
unit,
self.logger,
)
self.vulnerability.from_csv(csv_fn)

def setup_exposure_vector(
def setup_road_vulnerability(
self,
vertical_unit: str,
threshold_value: float = 0.6,
min_hazard_value: float = 0,
max_hazard_value: float = 10,
step_hazard_value: float = 1.0,
):
if not self.vulnerability:
self.vulnerability = Vulnerability(
vertical_unit,
self.logger,
)
self.vulnerability.create_step_function(
"roads",
threshold_value,
min_hazard_value,
max_hazard_value,
step_hazard_value,
)

def setup_exposure_buildings(
self,
asset_locations: Union[str, Path],
occupancy_type: Union[str, Path],
Expand All @@ -262,7 +284,7 @@ def setup_exposure_vector(
damage_types: Union[List[str], None] = ["structure", "content"],
country: Union[str, None] = None,
) -> None:
"""Setup vector exposure data for Delft-FIAT.
"""Setup building exposure (vector) data for Delft-FIAT.

Parameters
----------
Expand Down Expand Up @@ -322,7 +344,7 @@ def setup_exposure_vector(
except AssertionError:
logging.error(
"Please call the 'setup_vulnerability' function before "
"the 'setup_exposure_vector' function. Error message: {e}"
"the 'setup_exposure_buildings' function. Error message: {e}"
)
self.exposure.link_exposure_vulnerability(
self.vf_ids_and_linking_df, damage_types
Expand All @@ -334,6 +356,30 @@ def setup_exposure_vector(
self.set_config("exposure.geom.crs", self.exposure.crs)
self.set_config("exposure.geom.unit", unit)

def setup_exposure_roads(
self,
roads_fn: Union[str, Path],
road_damage: Union[str, Path],
road_types: Union[str, List[str], bool] = True,
unit: str = "m",
):
"""Setup road exposure data for Delft-FIAT.

Parameters
----------
roads_fn : Union[str, Path]
Path to the road network source (e.g., OSM) or file.
road_types : Union[str, List[str], bool], optional
List of road types to include in the exposure data, by default True
"""
if not self.exposure:
self.exposure = ExposureVector(self.data_catalog, self.logger, self.region, unit=unit)
self.exposure.setup_roads(roads_fn, road_damage, road_types)

# Link to vulnerability curves

# Combine the exposure database with pre-existing exposure data if available

def setup_exposure_raster(self):
"""Setup raster exposure data for Delft-FIAT.
This function will be implemented at a later stage.
Expand Down
Loading
Loading