Skip to content

Commit

Permalink
if-statemnent unit conversion. read_geoms generalize for file type
Browse files Browse the repository at this point in the history
  • Loading branch information
Santonia27 committed Nov 21, 2024
1 parent 2a7d2a8 commit 09708ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
21 changes: 13 additions & 8 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,19 +1286,24 @@ def read_geoms(self):

fns = glob.glob(Path(self.root, "geoms", "*.geojson").as_posix())
if self.spatial_joins["aggregation_areas"]:
fns_aggregation = glob.glob(Path(self.root, "geoms", "aggregation_areas","*.geojson").as_posix())
fns.append(fns_aggregation[0])
fns_aggregation = glob.glob(Path(self.root, "geoms", "aggregation_areas/*").as_posix())
fns.extend(fns_aggregation)
if self.spatial_joins["additional_attributes"]:
if len(glob.glob(Path(self.root, "geoms", "additional_attributes","*.geojson").as_posix())) > 0:
fns_additional_attributes = glob.glob(Path(self.root, "geoms", "additional_attributes","*.geojson").as_posix())
fns.append(fns_additional_attributes[0])
if len(glob.glob(Path(self.root, "geoms", "additional_attributes/*").as_posix())) > 0:
fns_additional_attributes = glob.glob(Path(self.root, "geoms", "additional_attributes/*").as_posix())
fns.extend(fns_additional_attributes)
if len(glob.glob(Path(self.root, "geoms", "building_footprints","*.geojson").as_posix())) > 0:
fns_building_footprints = glob.glob(Path(self.root, "geoms", "building_footprints","*.geojson").as_posix())
fns.append(fns_building_footprints[0])
fns_building_footprints = glob.glob(Path(self.root, "geoms", "building_footprints/*").as_posix())
self.building_footprint = gpd.read_file(fns_building_footprints[0])
if len(fns) >= 1:
self.logger.info("Reading static geometries")
for fn in fns:
name = Path(fn).stem
if "aggregation_areas" in fn:
name = f"aggregation_areas/{Path(fn).stem}"
elif "additional_attributes" in fn:
name = f"additional_attributes/{Path(fn).stem}"
else:
name = Path(fn).stem
self.set_geoms(gpd.read_file(fn), name=name)

def write(self):
Expand Down
7 changes: 4 additions & 3 deletions hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ def setup_ground_elevation(
)

# Unit conversion
self.unit_conversion("Ground Elevation", grnd_elev_unit)
if grnd_elev_unit:
self.unit_conversion(parameter = "Ground Elevation", unit = grnd_elev_unit)

else:
self.logger.warning(
Expand Down Expand Up @@ -2021,8 +2022,8 @@ def get_continent_name(self, continent_code: str) -> str:
}
return continent_dict[continent_code]

def unit_conversion(self, parameter: str,unit: Union[str, Units]) -> Union[str, Units]:
# Unit conversion
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):
self.exposure_db[parameter] = self.exposure_db[
Expand Down

0 comments on commit 09708ab

Please sign in to comment.