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

Add secondary object type #413

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Add secondary object type #413

wants to merge 21 commits into from

Conversation

Santonia27
Copy link
Collaborator

@Santonia27 Santonia27 commented Nov 7, 2024

  • add secondary Object type column if not existing and use Primary object type values (needed in the database builder)
  • divided the units into: unit (model unit - default feet), gfh_unit, ground_elevation unit >> Now they can all be provided in the config file under setup_exposure_buildings
  • added a conversion function for gfh and ground elevation. If these units != model unit they will be converted to the model unit
  • updated the OSM download code. The code before seemed to divide the asset geometries into some weird shapes using the occupancy geometries
  • added 'Multipolygon' to some if statements as I had data with only multipolygons. >> Maybe we need to discuss this as I have no experience with the geometries and I don't know if this will make a difference in the model output. If so we can remove it but then we need to think of a solution how to handle multipolygon data or we leave it to the user to clean it up fully before

@panosatha panosatha self-requested a review November 15, 2024 13:12
Copy link
Collaborator

@panosatha panosatha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made some comments on some things that I think need some improvements.
In general I think we should have units as arguments only in the setup functions that use external inputs. Then the units of the actual exposure vector object should be decided when the object is created.

hydromt_fiat/api/data_types.py Outdated Show resolved Hide resolved
@@ -81,25 +80,28 @@ class ExposureBuildingsSettings(BaseModel):
occupancy_type: str
max_potential_damage: str
ground_floor_height: Union[str, float]
unit: Units
gfh_unit: Union[str, Units] = None
unit: Union[str, Units]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to have the Union here? Isn't the main purpose of the Units enumerator to only allow these values?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still uses the Union. Should change that as well, right?

@@ -82,6 +82,8 @@ def __init__(
unit: str = Units.feet.value,
country: str = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the country attribute does not seem to be used now

Copy link
Collaborator

@panosatha panosatha Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still not used. Should we delete it?

@Santonia27 country is used for OSM and JRC setup

hydromt_fiat/workflows/exposure_vector.py Outdated Show resolved Hide resolved
@@ -323,11 +331,13 @@ def setup_buildings_from_multiple_sources(
max_potential_damage: Union[str, Path],
ground_floor_height: Union[int, float, str, Path, None],
extraction_method: str,
unit: str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that "unit" is not used anymore

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should delete this


# Remove the objects that do not have a Primary Object Type, that were not
# overlapping with the land use map, or that had a land use type of 'nan'.
if "Primary Object Type" in gdf.columns:
nr_without_primary_object = len(
gdf.loc[gdf["Primary Object Type"].isna()].index
) + len(gdf.loc[gdf["Primary Object Type"] != ""].index)
) + len(gdf.loc[gdf["Primary Object Type"] == ""].index)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it is better to actually change all the "" cells to None, so from this point onwards you can use only a single filtering with .isna() isntead of having to do both?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

hydromt_fiat/fiat.py Outdated Show resolved Hide resolved
hydromt_fiat/fiat.py Outdated Show resolved Hide resolved
@@ -398,10 +407,13 @@ def setup_exposure_buildings(
max_potential_damage,
ground_floor_height,
extraction_method,
unit,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I think the unit should not be an input arguments (see above my comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this again

hydromt_fiat/fiat.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@panosatha panosatha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still some small changes needed

@@ -81,25 +80,28 @@ class ExposureBuildingsSettings(BaseModel):
occupancy_type: str
max_potential_damage: str
ground_floor_height: Union[str, float]
unit: Units
gfh_unit: Union[str, Units] = None
unit: Union[str, Units]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still uses the Union. Should change that as well, right?

@@ -313,13 +312,15 @@ def setup_exposure_buildings(
max_potential_damage: Union[str, Path],
ground_floor_height: Union[int, float, str, Path, None],
unit: str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be Units = None, and maybe put it somewhere on top, because now it is in between the ground_floor_height and the gfh_unit which is kind of confusing.

Moreover maybe better to rename it to length_unit as we discussed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I make it None I cannot place it above a parameter without default input. Also I'm wondering if the model unit maybe should not be optional? It seems important to set the base unit by the user and not a default that the user may not be aware of? What's your opinion on that?

@@ -386,7 +394,7 @@ def setup_exposure_buildings(
asset_locations,
ground_floor_height,
extraction_method,
ground_elevation_file=ground_elevation_file,
ground_elevation=ground_elevation,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we not use the units in this method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not used in the function, same as in the function below (took it out there)

@@ -323,11 +331,13 @@ def setup_buildings_from_multiple_sources(
max_potential_damage: Union[str, Path],
ground_floor_height: Union[int, float, str, Path, None],
extraction_method: str,
unit: str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should delete this

@@ -398,10 +406,13 @@ def setup_exposure_buildings(
max_potential_damage,
ground_floor_height,
extraction_method,
unit,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit should be delete from here and from the method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its used in the function, why delete?

    if hasattr(length_unit, "value"):
        length_unit = length_unit.value

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

@@ -82,6 +82,8 @@ def __init__(
unit: str = Units.feet.value,
country: str = None,
Copy link
Collaborator

@panosatha panosatha Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still not used. Should we delete it?

@Santonia27 country is used for OSM and JRC setup

@@ -399,6 +411,9 @@ def setup_asset_locations(self, asset_locations: str) -> None:

# Set the asset locations to the geometry variable (self.exposure_geoms)
# and set the geom name
if len(assets.columns) > 2:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


# Remove the objects that do not have a Primary Object Type, that were not
# overlapping with the land use map, or that had a land use type of 'nan'.
if "Primary Object Type" in gdf.columns:
nr_without_primary_object = len(
gdf.loc[gdf["Primary Object Type"].isna()].index
) + len(gdf.loc[gdf["Primary Object Type"] != ""].index)
) + len(gdf.loc[gdf["Primary Object Type"] == ""].index)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

@@ -398,10 +407,13 @@ def setup_exposure_buildings(
max_potential_damage,
ground_floor_height,
extraction_method,
unit,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this again

Copy link

sonarcloud bot commented Nov 19, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants