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

Remove relative path in site toml #464

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions flood_adapt/dbs_classes/dbs_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Any

from flood_adapt.dbs_classes.dbs_template import DbsTemplate
from flood_adapt.object_model.benefit import Benefit
from flood_adapt.object_model.interface.scenarios import IScenario
from flood_adapt.object_model.scenario import Scenario

Expand Down Expand Up @@ -110,8 +109,8 @@ def check_higher_level_usage(self, name: str) -> list[str]:
"""
# Get all the benefits
benefits = [
Benefit.load_file(path)
for path in self._database.benefits.list_objects()["path"]
self._database.benefits.get(name)
for name in self._database.benefits.list_objects()["name"]
]

# Check in which benefits this scenario is used
Expand Down
2 changes: 1 addition & 1 deletion flood_adapt/dbs_classes/dbs_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_aggregation_areas(self) -> dict:
aggregation_areas = {}
for aggr_dict in self._database.site.attrs.fiat.aggregation:
aggregation_areas[aggr_dict.name] = gpd.read_file(
self._database.static_path / "site" / aggr_dict.file,
self._database.static_path / aggr_dict.file,
engine="pyogrio",
).to_crs(4326)
# Use always the same column name for name labels
Expand Down
7 changes: 2 additions & 5 deletions flood_adapt/integrator/fiat_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ def __init__(self, model_root: str, database_path: str) -> None:
if self.site.attrs.fiat.bfe.table:
self.bfe["mode"] = "table"
self.bfe["table"] = (
Path(database_path)
/ "static"
/ "site"
/ self.site.attrs.fiat.bfe.table
Path(database_path) / "static" / self.site.attrs.fiat.bfe.table
)
else:
self.bfe["mode"] = "geom"
# Map is always needed!
self.bfe["geom"] = (
Path(database_path) / "static" / "site" / self.site.attrs.fiat.bfe.geom
Path(database_path) / "static" / self.site.attrs.fiat.bfe.geom
)

self.bfe["name"] = self.site.attrs.fiat.bfe.field_name
Expand Down
2 changes: 1 addition & 1 deletion flood_adapt/integrator/sfincs_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def add_green_infrastructure(
continue
# load geodataframe
aggr_areas = gpd.read_file(
measure_path.parents[2] / "static" / "site" / aggr_dict.file,
measure_path.parents[2] / "static" / aggr_dict.file,
engine="pyogrio",
).to_crs(4326)
# keep only aggregation area chosen
Expand Down
4 changes: 2 additions & 2 deletions flood_adapt/object_model/benefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ def cba_aggregation(self):
for i, n in enumerate(self.site_info.attrs.fiat.aggregation)
if n.name == aggr_name
][0]
aggr_areas_path = self.site_toml_path.parent.joinpath(
self.site_info.attrs.fiat.aggregation[ind].file
aggr_areas_path = self.database_input_path.parent.joinpath(
"static", self.site_info.attrs.fiat.aggregation[ind].file
)

aggr_areas = gpd.read_file(aggr_areas_path, engine="pyogrio")
Expand Down
8 changes: 4 additions & 4 deletions flood_adapt/object_model/direct_impacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def preprocess_fiat(self):
)
dem = self.database.static_path / "Dem" / self.site_info.attrs.dem.filename
aggregation_areas = [
self.database.static_path / "site" / aggr.file
self.database.static_path / aggr.file
for aggr in self.site_info.attrs.fiat.aggregation
]
attribute_names = [
Expand Down Expand Up @@ -357,7 +357,7 @@ def _create_equity(self, metrics_path):

# Create Equity object
equity = Equity(
census_table=self.site_toml_path.parent.joinpath(
census_table=self.database.static_path.joinpath(
self.site_info.attrs.fiat.aggregation[ind].equity.census_data
),
damages_table=fiat_data,
Expand Down Expand Up @@ -420,7 +420,7 @@ def _create_aggregation(self, metrics_path):
for i, n in enumerate(self.site_info.attrs.fiat.aggregation)
if n.name == aggr_label
][0]
aggr_areas_path = self.site_toml_path.parent.joinpath(
aggr_areas_path = self.database.static_path.joinpath(
self.site_info.attrs.fiat.aggregation[ind].file
)

Expand All @@ -447,7 +447,7 @@ def _create_footprints(self, fiat_results_df):
if not self.site_info.attrs.fiat.building_footprints:
raise ValueError("No building footprints are provided.")
# Get footprints file
footprints_path = self.site_toml_path.parent.joinpath(
footprints_path = self.database.static_path.joinpath(
self.site_info.attrs.fiat.building_footprints
)
# Define where footprint results are saved
Expand Down
16 changes: 8 additions & 8 deletions tests/test_object_model/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,36 @@ def test_dict():
"floodmap_type": "water_level",
"non_building_names": ["road"],
"damage_unit": "$",
"building_footprints": "../templates/fiat/footprints/Buildings.shp",
"building_footprints": "templates/fiat/footprints/Buildings.shp",
"roads_file_name": "spatial2.gpkg",
"new_development_file_name": "spatial3.gpkg",
"save_simulation": "False",
"svi": {
"geom": "../templates/fiat/svi/CDC_svi_2020.gpkg",
"geom": "templates/fiat/svi/CDC_svi_2020.gpkg",
"field_name": "SVI",
},
"bfe": {
"geom": "../bfe/bfe.geojson",
"table": "../bfe/bfe.csv",
"geom": "bfe/bfe.geojson",
"table": "bfe/bfe.csv",
"field_name": "bfe",
},
"aggregation": [
{
"name": "aggr_lvl_1",
"file": "../templates/fiat/aggregation_areas/aggr_lvl_1.geojson",
"file": "templates/fiat/aggregation_areas/aggr_lvl_1.geojson",
"field_name": "name",
"equity": {
"census_data": "../templates/fiat/equity/census_data_aggr_lvl_1.csv",
"census_data": "templates/fiat/equity/census_data_aggr_lvl_1.csv",
"percapitaincome_label": "PerCapitaIncome",
"totalpopulation_label": "TotalPopulation",
},
},
{
"name": "aggr_lvl_2",
"file": "../templates/fiat/aggregation_areas/aggr_lvl_2.geojson",
"file": "templates/fiat/aggregation_areas/aggr_lvl_2.geojson",
"field_name": "name",
"equity": {
"census_data": "../templates/fiat/equity/census_data_aggr_lvl_2.csv",
"census_data": "templates/fiat/equity/census_data_aggr_lvl_2.csv",
"percapitaincome_label": "PerCapitaIncome",
"totalpopulation_label": "TotalPopulation",
},
Expand Down
Loading