Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Deltares/hydromt_fiat into …
Browse files Browse the repository at this point in the history
…bugfixs
  • Loading branch information
Santonia27 committed Nov 26, 2024
2 parents ab4c530 + 3ed996e commit 8166437
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/data/hazus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ by providing the following values in the configuration file::

[setup_exposure_buildings]
max_potential_damage = "hazus_max_potential_damages"
length_unit = "meters"
unit = "meters"


The HAZUS flood depth-damage functions and replacement values are processed into an easy-to-use format
Expand Down
2 changes: 1 addition & 1 deletion docs/data/jrc.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::

[setup_exposure_buildings]
max_potential_damage = "jrc_damage_values"
length_unit = "meters"
unit = "meters"


The JRC Global flood depth-damage functions and replacement values are processed into an easy-to-use format
Expand Down
4 changes: 2 additions & 2 deletions docs/user_guide/user_guide_overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Exposure data can be build from a data_catalog_, a data API key, or by supplying
to local data on the user's machine. The `asset_locations`, `occupancy_type`, and `max_potential_damage`
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 `length_unit` should be provided as a string (e.g. "meters").
list of strings (e.g. ["structure", "content"]). The `unit` should be provided as a string (e.g. "meters").
See below how the `setup_exposure_buildings` method can be used to build or update the exposure data::

[setup_exposure_buildings]
Expand All @@ -40,7 +40,7 @@ See below how the `setup_exposure_buildings` method can be used to build or upda
damage_types = <List of damage types, e.g. ["structure", "content"]>
max_potential_damage = <Key in the Data Catalog, data API key, or path to local data>
ground_floor_height = <For now only a number can be entered here for uniform ground floor heights>
length_unit = <The unit of the values in the exposure data inputs, e.g. if the ground floor height in meters, "meters">
unit = <The unit of the values in the exposure data inputs, e.g. if the ground floor height in meters, "meters">

The following method is used to build or update the **exposure** data:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ step_size = 0.1
[exposure.geom]
csv = "./exposure/exposure.csv"
crs = "EPSG:4326"
length_unit = "feet"
unit = "feet"
file1 = "./exposure/buildings.gpkg"
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ step_size = 0.1
[exposure.geom]
csv = "./exposure/exposure.csv"
crs = "EPSG:4326"
length_unit = "feet"
unit = "feet"
file1 = "./exposure/buildings.gpkg"
2 changes: 1 addition & 1 deletion examples/data/aggregation_zones/fiat_model/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv"

[exposure.geom]
crs = "EPSG:4326"
length_unit = "feet"
unit = "feet"
file1 = "./exposure/buildings.gpkg"
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv"

[exposure.geom]
crs = "EPSG:4326"
length_unit = "feet"
unit = "feet"
file1 = "./exposure/buildings.gpkg"
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv"

[exposure.geom]
crs = "EPSG:4326"
length_unit = "feet"
unit = "feet"
file1 = "./exposure/buildings.gpkg"
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv"

[exposure.geom]
crs = "EPSG:4326"
length_unit = "feet"
unit = "feet"
file1 = "./exposure/buildings.gpkg"
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv"

[exposure.geom]
crs = "EPSG:4326"
length_unit = "feet"
unit = "feet"
file1 = "./exposure/buildings.gpkg"
4 changes: 2 additions & 2 deletions examples/global_OSM_JRC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"max_potential_damage = \"jrc_damage_values\"\n",
"ground_floor_height = 0\n",
"damage_types = [\"total\"]\n",
"length_unit = \"meters\"\n",
"unit = \"meters\"\n",
"\n",
"### Setup output parameters ###\n",
"output_dir = \"output\"\n",
Expand Down Expand Up @@ -251,7 +251,7 @@
" \"occupancy_type\": occupancy_type,\n",
" \"max_potential_damage\": max_potential_damage,\n",
" \"ground_floor_height\": ground_floor_height,\n",
" \"length_unit\": unit,\n",
" \"unit\": unit,\n",
" \"damage_types\": damage_types,\n",
" \"country\": country,\n",
" },\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 @@ -81,7 +81,7 @@ class ExposureBuildingsSettings(BaseModel):
max_potential_damage: str
ground_floor_height: Union[str, float]
gfh_unit: Units = None
length_unit: Units
unit: Units
extraction_method: ExtractionMethod
damage_types: Optional[List[str]] = None
damage_unit: str
Expand Down
8 changes: 4 additions & 4 deletions hydromt_fiat/api/exposure_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def set_asset_locations_source_and_get_data(
logger=self.logger,
region=region,
crs=crs,
length_unit=Units.feet.value,
unit=Units.feet.value,
)

self.exposure.setup_buildings_from_single_source(
Expand Down Expand Up @@ -120,7 +120,7 @@ def set_asset_locations_source_and_get_data(
logger=self.logger,
region=region,
crs=crs,
length_unit=Units.meters.value,
unit=Units.meters.value,
)

self.exposure.setup_buildings_from_multiple_sources(
Expand Down Expand Up @@ -167,7 +167,7 @@ def set_asset_locations_source(
occupancy_type=source,
max_potential_damage=source,
ground_floor_height=ground_floor_height,
length_unit=Units.feet.value,
unit=Units.feet.value,
extraction_method=ExtractionMethod.centroid.value,
damage_types=["structure", "content"],
damage_unit=Currency.dollar.value,
Expand Down Expand Up @@ -198,7 +198,7 @@ def set_asset_locations_source(
keep_unclassified=keep_unclassified,
max_potential_damage=max_potential_damage,
ground_floor_height=ground_floor_height,
length_unit=Units.meters.value,
unit=Units.meters.value,
extraction_method=ExtractionMethod.centroid.value,
damage_types=["structure", "content"],
damage_unit=Currency.euro.value,
Expand Down
18 changes: 9 additions & 9 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def setup_exposure_buildings(
occupancy_type: Union[str, Path],
max_potential_damage: Union[str, Path],
ground_floor_height: Union[int, float, str, Path, None],
length_unit: Units = None,
unit: Units = None,
gfh_unit: Units = None,
gfh_attribute_name: str = None,
occupancy_attr: Union[str, None] = None,
Expand Down Expand Up @@ -342,7 +342,7 @@ def setup_exposure_buildings(
Either a number (int or float), to give all assets the same ground floor
height or a path to the data that can be used to add the ground floor
height to the assets.
length_unit : Units
unit : Units
The unit of the model
gfh_unit : Units
The unit of the ground_floor_height
Expand Down Expand Up @@ -380,14 +380,14 @@ def setup_exposure_buildings(
The path to the translation function that can be used to relate user damage curves with user damages.
"""
# In case the unit is passed as a pydantic value get the string
if hasattr(length_unit, "value"):
length_unit = length_unit.value
if hasattr(unit, "value"):
unit = unit.value

self.exposure = ExposureVector(
self.data_catalog,
self.logger,
self.region,
length_unit=length_unit,
unit=unit,
damage_unit=damage_unit,
)

Expand Down Expand Up @@ -478,7 +478,7 @@ def setup_exposure_buildings(
# Update the other config settings
self.set_config("exposure.csv.file", "exposure/exposure.csv")
self.set_config("exposure.geom.crs", self.exposure.crs)
self.set_config("exposure.geom.length_unit", length_unit)
self.set_config("exposure.geom.unit", unit)
self.set_config("exposure.damage_unit", damage_unit)

def setup_exposure_roads(
Expand All @@ -502,7 +502,7 @@ def setup_exposure_roads(
self.data_catalog,
self.logger,
self.region,
length_unit=unit,
unit=unit,
)
self.exposure.setup_roads(roads_fn, road_damage, road_types)

Expand Down Expand Up @@ -647,7 +647,7 @@ def setup_hazard(
# Convert to units of the exposure data if required
if self.exposure: # change to be sure that the unit information is available from the exposure dataset
if hasattr(da, "units"):
if self.exposure.length_unit != da.units:
if self.exposure.unit != da.units:
da = da * unit_conversion_factor

# convert to gdal compliant
Expand Down Expand Up @@ -1260,7 +1260,7 @@ def read_tables(self):
self.exposure = ExposureVector(
crs=self.get_config("exposure.geom.crs"),
logger=self.logger,
length_unit=self.get_config("exposure.geom.length_unit"),
unit=self.get_config("exposure.geom.unit"),
damage_unit=self.get_config("exposure.damage_unit"),
data_catalog=self.data_catalog, # TODO: See if this works also when no data catalog is provided
)
Expand Down
2 changes: 1 addition & 1 deletion hydromt_fiat/interface/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ExposureGeomModel(BaseModel):
crs: str
file1: str
file2: str
length_unit: str
unit: str
damage_unit: str


Expand Down
24 changes: 12 additions & 12 deletions hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
logger: logging.Logger = None,
region: gpd.GeoDataFrame = None,
crs: str = None,
length_unit: Units = Units.feet.value,
unit: Units = Units.feet.value,
damage_unit=Currency.dollar.value,
) -> None:
"""Transforms data into Vector Exposure data for Delft-FIAT.
Expand All @@ -94,8 +94,8 @@ def __init__(
The region of interest, by default None
crs : str, optional
The CRS of the Exposure data, by default None
length_unit : Units, optional
The length_unit of the model, by default feet
unit : Units, optional
The unit of the model, by default feet
damage_unit : str, optional
The unit/currency of the (potential) damages, by default USD$
"""
Expand All @@ -104,7 +104,7 @@ def __init__(
)
self.exposure_db = pd.DataFrame()
self.exposure_geoms = list() # A list of GeoDataFrames
self.length_unit = length_unit
self.unit = unit
self._geom_names = list() # A list of (original) names of the geometry (files)
self.damage_unit = damage_unit
self.building_footprints = gpd.GeoDataFrame
Expand Down Expand Up @@ -285,7 +285,7 @@ def setup_roads(

# Convert OSM road from meters to feet (if model unit is feet)
road_length = get_road_lengths(roads)
if self.length_unit == Units.feet.value and str(source).upper() == "OSM":
if self.unit == Units.feet.value and str(source).upper() == "OSM":
road_length = road_length * Conversion.meters_to_feet.value
road_length = road_length.apply(lambda x: f"{x:.2f}")

Expand Down Expand Up @@ -1469,12 +1469,12 @@ def setup_new_composite_areas(
axis=1
)
self.logger.info(
f"The elevation of the new development area is {new_area['height'].values} {self.length_unit}"
f"The elevation of the new development area is {new_area['height'].values} {self.unit}"
" relative to datum." # TODO: make unit flexible
)
elif elevation_reference == "geom":
self.logger.info(
f"The elevation of the new development area is {new_area['height'].values} {self.length_unit}"
f"The elevation of the new development area is {new_area['height'].values} {self.unit}"
f" relative to {Path(path_ref).stem}. The height of the floodmap is"
f" identified with column {attr_ref}." # TODO: make unit flexible
)
Expand Down Expand Up @@ -2023,15 +2023,15 @@ def get_continent_name(self, continent_code: str) -> str:
}
return continent_dict[continent_code]

def unit_conversion(self, parameter: str, unit:Units) -> None:
# Unit conversion
if unit != self.length_unit:
if (unit == Units.meters.value) and (self.length_unit == Units.feet.value):
def unit_conversion(self, parameter: str,unit: Union[str, Units]) -> Union[str, Units]:
# Unit conversion
if unit != self.unit:
if (unit == Units.meters.value) and (self.unit == Units.feet.value):
self.exposure_db[parameter] = self.exposure_db[
parameter
].apply(lambda x: x * Conversion.meters_to_feet.value)

elif (unit == Units.feet.value) and (self.length_unit == Units.meters.value):
elif (unit == Units.feet.value) and (self.unit == Units.meters.value):
self.exposure_db[parameter] = self.exposure_db[
parameter
].apply(lambda x: x * Conversion.feet_to_meters.value)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_SVI_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"occupancy_type": "NSI",
"max_potential_damage": "NSI",
"ground_floor_height": "NSI",
"length_unit": "feet",
"unit": "feet",
},
"setup_social_vulnerability_index": {
"census_key": "495a349ce22bdb1294b378fb199e4f27e57471a9",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_equity_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"occupancy_type": "NSI",
"max_potential_damage": "NSI",
"ground_floor_height": "NSI",
"length_unit": "feet",
"unit": "feet",
},
"setup_equity_data": {
"census_key": "495a349ce22bdb1294b378fb199e4f27e57471a9",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"occupancy_type": "NSI",
"max_potential_damage": "NSI",
"ground_floor_height": "NSI",
"length_unit": "feet",
"unit": "feet",
},
"setup_hazard": {
"map_fn": [
Expand Down Expand Up @@ -96,7 +96,7 @@
"occupancy_type": "NSI",
"max_potential_damage": "NSI",
"ground_floor_height": "NSI",
"length_unit": "feet",
"unit": "feet",
},
"setup_hazard": {
"map_fn": [
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vulnerability_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"max_potential_damage": "NSI",
"damage_types": ["structure", "content"],
"ground_floor_height": "NSI",
"length_unit": "feet",
"unit": "feet",
},
},
"region": _region,
Expand Down Expand Up @@ -86,7 +86,7 @@
"max_potential_damage": "NSI",
"damage_types": ["structure", "content"],
"ground_floor_height": "NSI",
"length_unit": "feet",
"unit": "feet",
},
"setup_social_vulnerability_index": {
"census_key": "495a349ce22bdb1294b378fb199e4f27e57471a9",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vulnerability_exposure_add_to_data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"occupancy_attr": "DESCR",
"max_potential_damage": "hazus_max_potential_damages",
"ground_floor_height": 1,
"length_unit": "feet",
"unit": "feet",
"damage_types": ["structure", "content"],
},
},
Expand All @@ -83,7 +83,7 @@
"occupancy_attr": "DESCR",
"max_potential_damage": "hazus_max_potential_damages",
"ground_floor_height": 1,
"length_unit": "feet",
"unit": "feet",
"damage_types": ["structure", "content"],
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vulnerability_exposure_global_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"max_potential_damage": "jrc_damage_values",
"ground_floor_height": 0,
"damage_types": ["structure", "content"],
"length_unit": "meters",
"unit": "meters",
"country": "United Kingdom",
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vulnerability_expousure_with_user_dem_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"damage_types": ["structure", "content"],
"ground_floor_height": "NSI",
"ground_elevation": DATADIRDEM / "charleston_14m.tif",
"length_unit": "feet",
"unit": "feet",
},
},
"region": _region,
Expand Down

0 comments on commit 8166437

Please sign in to comment.