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

Bug fixes in hazard setup #255

Merged
merged 5 commits into from
Jan 4, 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
24 changes: 15 additions & 9 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import csv
import logging
import os
from pathlib import Path
from typing import List, Optional, Union

import xarray as xr
import geopandas as gpd
import hydromt
import pandas as pd
Expand Down Expand Up @@ -504,16 +505,21 @@ def setup_hazard(

for idx, da_map_fn in enumerate(params["map_fn_lst"]):
# read maps and retrieve their attributes
da_map_fn, da_name, da_type = read_maps(params, da_map_fn, idx)

da = self.data_catalog.get_rasterdataset(
if isinstance(da_map_fn, os.PathLike):
# if path is provided read and load it as xarray
da_map_fn, da_name, da_type = read_maps(params, da_map_fn, idx)
da = self.data_catalog.get_rasterdataset(
da_map_fn
) # removed geom=self.region because it is not always there

elif isinstance(da_map_fn, xr.DataArray):
# if xarray is provided directly assign that
da = da_map_fn
da_name = 'hazard_map'
da_type = map_type
else:
raise ValueError("The hazard map provided should be a path like object or an DataArray")
# Convert to units of the exposure data if required
if (
self.exposure in locals() or self.exposure in globals()
): # change to be sure that the unit information is available from the expousure dataset
if self.exposure: # change to be sure that the unit information is available from the exposure dataset
if self.exposure.unit != da.units:
da = da * unit_conversion_factor

Expand Down Expand Up @@ -603,7 +609,7 @@ def setup_hazard(
"hazard.settings.subset",
[(self.maps[hazard_map].name) for hazard_map in self.maps.keys()][0]
if not risk_output
else sorted_rp,
else sorted_names,
)

self.set_config(
Expand Down
6 changes: 1 addition & 5 deletions hydromt_fiat/workflows/hazard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from hydromt_fiat.validation import *
from pathlib import Path
import geopandas as gpd
from ast import literal_eval
import os
import xarray as xr
Expand All @@ -10,8 +9,6 @@
# from hydromt_sfincs import SfincsModel
from typing import Union
from typing import Tuple
from hydromt.data_catalog import DataCatalog
import geopandas as gpd


def create_lists(
Expand Down Expand Up @@ -440,8 +437,7 @@ def create_risk_dataset(
sorted_names = []

for key, value in dict_rp_name.items():
map_ordered = maps[value].rename(str(key))
sorted_maps.append(map_ordered)
sorted_maps.append(maps[value])
sorted_names.append(value)

da = xr.merge(sorted_maps)
Expand Down
Loading