From 3ed996e666b3aadd17c51b08e3ac9fe20e216b6f Mon Sep 17 00:00:00 2001 From: Santonia27 <145111392+Santonia27@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:55:18 +0100 Subject: [PATCH] reverse length unit (#420) --- docs/data/hazus.rst | 2 +- docs/data/jrc.rst | 2 +- docs/user_guide/user_guide_overview.rst | 4 ++-- .../aggregation_zones_test1/settings.toml | 2 +- .../aggregation_zones_test2/settings.toml | 2 +- .../fiat_model/settings.toml | 2 +- .../fiat_model_aggregation1/settings.toml | 2 +- .../fiat_model_aggregation2/settings.toml | 2 +- .../settings.toml | 2 +- .../settings.toml | 2 +- examples/global_OSM_JRC.ipynb | 4 ++-- hydromt_fiat/api/data_types.py | 2 +- hydromt_fiat/api/exposure_vm.py | 8 ++++---- hydromt_fiat/fiat.py | 18 ++++++++--------- hydromt_fiat/interface/config.py | 2 +- hydromt_fiat/workflows/exposure_vector.py | 20 +++++++++---------- tests/test_SVI_exposure.py | 2 +- tests/test_equity_data.py | 2 +- tests/test_integration.py | 4 ++-- tests/test_vulnerability_exposure.py | 4 ++-- ...nerability_exposure_add_to_data_catalog.py | 4 ++-- ...t_vulnerability_exposure_global_default.py | 2 +- ...nerability_expousure_with_user_dem_data.py | 2 +- 23 files changed, 48 insertions(+), 48 deletions(-) diff --git a/docs/data/hazus.rst b/docs/data/hazus.rst index 336a0a78..157773d8 100644 --- a/docs/data/hazus.rst +++ b/docs/data/hazus.rst @@ -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 diff --git a/docs/data/jrc.rst b/docs/data/jrc.rst index 2a2f33fe..629ced56 100644 --- a/docs/data/jrc.rst +++ b/docs/data/jrc.rst @@ -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 diff --git a/docs/user_guide/user_guide_overview.rst b/docs/user_guide/user_guide_overview.rst index ab925492..09e90182 100644 --- a/docs/user_guide/user_guide_overview.rst +++ b/docs/user_guide/user_guide_overview.rst @@ -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] @@ -40,7 +40,7 @@ See below how the `setup_exposure_buildings` method can be used to build or upda damage_types = max_potential_damage = ground_floor_height = - length_unit = + unit = The following method is used to build or update the **exposure** data: diff --git a/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test1/settings.toml b/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test1/settings.toml index afdc6768..4852e807 100644 --- a/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test1/settings.toml +++ b/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test1/settings.toml @@ -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" diff --git a/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test2/settings.toml b/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test2/settings.toml index afdc6768..4852e807 100644 --- a/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test2/settings.toml +++ b/examples/data/aggregation_zones/fiat_model/output/aggregation_zones_test2/settings.toml @@ -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" diff --git a/examples/data/aggregation_zones/fiat_model/settings.toml b/examples/data/aggregation_zones/fiat_model/settings.toml index 37815d99..bbcce362 100644 --- a/examples/data/aggregation_zones/fiat_model/settings.toml +++ b/examples/data/aggregation_zones/fiat_model/settings.toml @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv" [exposure.geom] crs = "EPSG:4326" -length_unit = "feet" +unit = "feet" file1 = "./exposure/buildings.gpkg" diff --git a/examples/data/aggregation_zones/fiat_model_aggregation1/settings.toml b/examples/data/aggregation_zones/fiat_model_aggregation1/settings.toml index 37815d99..bbcce362 100644 --- a/examples/data/aggregation_zones/fiat_model_aggregation1/settings.toml +++ b/examples/data/aggregation_zones/fiat_model_aggregation1/settings.toml @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv" [exposure.geom] crs = "EPSG:4326" -length_unit = "feet" +unit = "feet" file1 = "./exposure/buildings.gpkg" diff --git a/examples/data/aggregation_zones/fiat_model_aggregation2/settings.toml b/examples/data/aggregation_zones/fiat_model_aggregation2/settings.toml index 37815d99..bbcce362 100644 --- a/examples/data/aggregation_zones/fiat_model_aggregation2/settings.toml +++ b/examples/data/aggregation_zones/fiat_model_aggregation2/settings.toml @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv" [exposure.geom] crs = "EPSG:4326" -length_unit = "feet" +unit = "feet" file1 = "./exposure/buildings.gpkg" diff --git a/examples/data/setup_exposure_buildings/test_vulnerability_and_exposure_NSI/settings.toml b/examples/data/setup_exposure_buildings/test_vulnerability_and_exposure_NSI/settings.toml index 37815d99..bbcce362 100644 --- a/examples/data/setup_exposure_buildings/test_vulnerability_and_exposure_NSI/settings.toml +++ b/examples/data/setup_exposure_buildings/test_vulnerability_and_exposure_NSI/settings.toml @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv" [exposure.geom] crs = "EPSG:4326" -length_unit = "feet" +unit = "feet" file1 = "./exposure/buildings.gpkg" diff --git a/examples/data/setup_exposure_buildings_with_dem_data/test_vulnerability_and_exposure_NSI/settings.toml b/examples/data/setup_exposure_buildings_with_dem_data/test_vulnerability_and_exposure_NSI/settings.toml index 37815d99..bbcce362 100644 --- a/examples/data/setup_exposure_buildings_with_dem_data/test_vulnerability_and_exposure_NSI/settings.toml +++ b/examples/data/setup_exposure_buildings_with_dem_data/test_vulnerability_and_exposure_NSI/settings.toml @@ -20,5 +20,5 @@ file = "./exposure/exposure.csv" [exposure.geom] crs = "EPSG:4326" -length_unit = "feet" +unit = "feet" file1 = "./exposure/buildings.gpkg" diff --git a/examples/global_OSM_JRC.ipynb b/examples/global_OSM_JRC.ipynb index ef979a54..943aaaec 100644 --- a/examples/global_OSM_JRC.ipynb +++ b/examples/global_OSM_JRC.ipynb @@ -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", @@ -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", diff --git a/hydromt_fiat/api/data_types.py b/hydromt_fiat/api/data_types.py index 71c09238..0630870c 100644 --- a/hydromt_fiat/api/data_types.py +++ b/hydromt_fiat/api/data_types.py @@ -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 diff --git a/hydromt_fiat/api/exposure_vm.py b/hydromt_fiat/api/exposure_vm.py index 9a67d61c..a9884ead 100644 --- a/hydromt_fiat/api/exposure_vm.py +++ b/hydromt_fiat/api/exposure_vm.py @@ -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( @@ -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( @@ -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, @@ -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, diff --git a/hydromt_fiat/fiat.py b/hydromt_fiat/fiat.py index 149554b4..163b7bca 100644 --- a/hydromt_fiat/fiat.py +++ b/hydromt_fiat/fiat.py @@ -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, @@ -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 @@ -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, ) @@ -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( @@ -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) @@ -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 @@ -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 ) diff --git a/hydromt_fiat/interface/config.py b/hydromt_fiat/interface/config.py index 4d0de7c7..9647def5 100644 --- a/hydromt_fiat/interface/config.py +++ b/hydromt_fiat/interface/config.py @@ -40,7 +40,7 @@ class ExposureGeomModel(BaseModel): crs: str file1: str file2: str - length_unit: str + unit: str damage_unit: str diff --git a/hydromt_fiat/workflows/exposure_vector.py b/hydromt_fiat/workflows/exposure_vector.py index 12c4538b..7624de6c 100644 --- a/hydromt_fiat/workflows/exposure_vector.py +++ b/hydromt_fiat/workflows/exposure_vector.py @@ -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. @@ -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$ """ @@ -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 @@ -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}") @@ -1467,12 +1467,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 ) @@ -2023,13 +2023,13 @@ def get_continent_name(self, continent_code: str) -> str: def unit_conversion(self, parameter: str,unit: Union[str, Units]) -> Union[str, Units]: # Unit conversion - if unit != self.length_unit: - if (unit == Units.meters.value) and (self.length_unit == Units.feet.value): + 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) diff --git a/tests/test_SVI_exposure.py b/tests/test_SVI_exposure.py index b911ac81..3fd28e74 100644 --- a/tests/test_SVI_exposure.py +++ b/tests/test_SVI_exposure.py @@ -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", diff --git a/tests/test_equity_data.py b/tests/test_equity_data.py index f035e238..33d087e2 100644 --- a/tests/test_equity_data.py +++ b/tests/test_equity_data.py @@ -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", diff --git a/tests/test_integration.py b/tests/test_integration.py index abb43279..8f43c602 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -56,7 +56,7 @@ "occupancy_type": "NSI", "max_potential_damage": "NSI", "ground_floor_height": "NSI", - "length_unit": "feet", + "unit": "feet", }, "setup_hazard": { "map_fn": [ @@ -96,7 +96,7 @@ "occupancy_type": "NSI", "max_potential_damage": "NSI", "ground_floor_height": "NSI", - "length_unit": "feet", + "unit": "feet", }, "setup_hazard": { "map_fn": [ diff --git a/tests/test_vulnerability_exposure.py b/tests/test_vulnerability_exposure.py index 30d86130..68b51f34 100644 --- a/tests/test_vulnerability_exposure.py +++ b/tests/test_vulnerability_exposure.py @@ -57,7 +57,7 @@ "max_potential_damage": "NSI", "damage_types": ["structure", "content"], "ground_floor_height": "NSI", - "length_unit": "feet", + "unit": "feet", }, }, "region": _region, @@ -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", diff --git a/tests/test_vulnerability_exposure_add_to_data_catalog.py b/tests/test_vulnerability_exposure_add_to_data_catalog.py index bdb740d8..9d3a63b2 100644 --- a/tests/test_vulnerability_exposure_add_to_data_catalog.py +++ b/tests/test_vulnerability_exposure_add_to_data_catalog.py @@ -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"], }, }, @@ -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"], }, }, diff --git a/tests/test_vulnerability_exposure_global_default.py b/tests/test_vulnerability_exposure_global_default.py index a7cfe2e3..799a46cd 100644 --- a/tests/test_vulnerability_exposure_global_default.py +++ b/tests/test_vulnerability_exposure_global_default.py @@ -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", }, }, diff --git a/tests/test_vulnerability_expousure_with_user_dem_data.py b/tests/test_vulnerability_expousure_with_user_dem_data.py index f4b52b16..9a25ac98 100644 --- a/tests/test_vulnerability_expousure_with_user_dem_data.py +++ b/tests/test_vulnerability_expousure_with_user_dem_data.py @@ -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,