Skip to content

Commit

Permalink
Currency conversion jrc (#434)
Browse files Browse the repository at this point in the history
* add conversion jrc to us dollar (in progress)

* add parameter to convert jrc eur to us dollar

* replace None with False
  • Loading branch information
Santonia27 authored Jan 15, 2025
1 parent 1ee407e commit d28b14e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions hydromt_fiat/api/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Units(str, Enum):
class Conversion(float, Enum):
meters_to_feet = 3.28084
feet_to_meters = 0.3048
eur_to_us_dollars = 1.327 #Average exchange rate in 2010


class Currency(str, Enum):
Expand Down
11 changes: 9 additions & 2 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def setup_exposure_buildings(
bf_conversion: bool = False,
keep_unclassified: bool = True,
dst_crs: Union[str, None] = None,
damage_translation_fn: Union[Path, str] = None
damage_translation_fn: Union[Path, str] = None,
eur_to_us_dollar: bool = False
) -> None:
"""Setup building exposure (vector) data for Delft-FIAT.
Expand Down Expand Up @@ -398,6 +399,8 @@ def setup_exposure_buildings(
it is taken from the region attribute of `FiatModel`. By default None
damage_translation_fn: Union[Path, str], optional
The path to the translation function that can be used to relate user damage curves with user damages.
eur_to_us_dollar: bool
Convert JRC Damage Values (Euro 2010) into US-Dollars (2025)
"""
# In case the unit is passed as a pydantic value get the string
if hasattr(unit, "value"):
Expand All @@ -419,6 +422,7 @@ def setup_exposure_buildings(
ground_floor_height,
extraction_method,
ground_elevation=ground_elevation,
eur_to_us_dollar = eur_to_us_dollar
)

else:
Expand All @@ -440,7 +444,8 @@ def setup_exposure_buildings(
bf_conversion=bf_conversion,
keep_unclassified=keep_unclassified,
damage_translation_fn = damage_translation_fn,
gfh_attribute_name = gfh_attribute_name
gfh_attribute_name = gfh_attribute_name,
eur_to_us_dollar = eur_to_us_dollar
)

if (asset_locations != occupancy_type) and occupancy_object_type is not None:
Expand Down Expand Up @@ -586,6 +591,7 @@ def update_max_potential_damage(
attribute_name: Union[str, List[str], None] = None,
method_damages: Union[str, List[str], None] = "nearest",
max_dist: float = 10,
eur_to_us_dollar: bool = False
):
if self.exposure:
self.exposure.setup_max_potential_damage(
Expand All @@ -595,6 +601,7 @@ def update_max_potential_damage(
attribute_name=attribute_name,
method_damages=method_damages,
max_dist=max_dist,
eur_to_us_dollar = eur_to_us_dollar
)

def update_ground_elevation(
Expand Down
10 changes: 9 additions & 1 deletion hydromt_fiat/workflows/damage_values.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pandas as pd
from pathlib import Path
from typing import Union
from hydromt_fiat.api.data_types import Conversion

default_jrc_max_damage_adjustment_values = {
"construction_cost_vs_depreciated_value_res": 0.6,
Expand All @@ -21,6 +22,7 @@
def preprocess_jrc_damage_values(
jrc_base_damage_values: pd.DataFrame,
country: str,
eur_to_us_dollar: bool = False,
max_damage_adjustment_values: dict = default_jrc_max_damage_adjustment_values,
) -> dict:
"""Preprocess the JRC damage values data.
Expand All @@ -31,6 +33,8 @@ def preprocess_jrc_damage_values(
The JRC damage values data.
country : str
The country to filter the data on.
eur_to_us_dollar: bool
Convert JRC Damage Values (Euro 2010) into US-Dollars (2025)
Returns
-------
Expand Down Expand Up @@ -81,7 +85,11 @@ def preprocess_jrc_damage_values(
+ ((jrc_base_value * cc_vs_dv * (1 - up) * mu) * mdci)
),
}


if eur_to_us_dollar:
for damage_types, occupancy_types in damage_values.items():
for occupancy_type in occupancy_types:
occupancy_types[occupancy_type] *= Conversion.eur_to_us_dollars.value
return damage_values


Expand Down
15 changes: 13 additions & 2 deletions hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def setup_buildings_from_single_source(
gfh_unit: Units = None,
ground_elevation: Union[int, float, str, Path, None] = None,
grnd_elev_unit: Units = None,
eur_to_us_dollar: bool = False
) -> None:
"""Set up asset locations and other available data from a single source.
Expand All @@ -165,6 +166,10 @@ def setup_buildings_from_single_source(
height to the assets.
extraction_method : str
The extract_method to be used for all of the assets.
extraction_method : str
The extract_method to be used for all of the assets.
eur_to_us_dollar: bool
Convert JRC Damage Values (Euro 2010) into US-Dollars (2025)
"""
if str(source).upper() == "NSI":
# The NSI data is selected, so get the assets from the NSI
Expand Down Expand Up @@ -339,6 +344,7 @@ def setup_buildings_from_multiple_sources(
bf_conversion: bool = False,
keep_unclassified: bool = True,
damage_translation_fn: Union[Path, str] = None,
eur_to_us_dollar: bool = False,
):
"""
Set up the exposure data using multiple sources.
Expand Down Expand Up @@ -395,6 +401,8 @@ def setup_buildings_from_multiple_sources(
damage_translation_fn : Path, str
The path to the file that contains the translation of the damage types to
the damage values. If None, the default translation file will be used.
eur_to_us_dollar: bool
Convert JRC Damage Values (Euro 2010) into US-Dollars (2025)
Returns
-------
Expand All @@ -408,7 +416,7 @@ def setup_buildings_from_multiple_sources(
occupancy_source, occupancy_attr, keep_unclassified=keep_unclassified
)
self.setup_max_potential_damage(
max_potential_damage, damage_types, country=country, damage_translation_fn = damage_translation_fn
max_potential_damage, damage_types, country=country, damage_translation_fn = damage_translation_fn, eur_to_us_dollar = eur_to_us_dollar
)
if (
any(
Expand Down Expand Up @@ -923,6 +931,7 @@ def setup_max_potential_damage(
max_dist: float = 10,
country: Union[str, None] = None,
damage_translation_fn: Union[str, Path] = None,
eur_to_us_dollar: bool = False
) -> None:
"""Setup the max potential damage column of the exposure data in various ways.
Expand All @@ -942,6 +951,8 @@ def setup_max_potential_damage(
_description_, by default 10
damage_translation_fn: Union[Path, str], optional
The path to the translation function that can be used to relate user damage curves with user damages.
eur_to_us_dollar: bool
Convert JRC Damage Values (Euro 2010) into US-Dollars (2025)
"""
if damage_types is None:
damage_types = ["total"]
Expand Down Expand Up @@ -1029,7 +1040,7 @@ def setup_max_potential_damage(
f"No country specified, using the '{country}' JRC damage values."
)

damage_values = preprocess_jrc_damage_values(damage_source, country)
damage_values = preprocess_jrc_damage_values(damage_source, country, eur_to_us_dollar)

elif max_potential_damage == "hazus_max_potential_damages":
damage_source = self.data_catalog.get_dataframe(max_potential_damage)
Expand Down

0 comments on commit d28b14e

Please sign in to comment.