Skip to content

Commit

Permalink
Change WRI Inundation hazard selectors behaviour. (#335)
Browse files Browse the repository at this point in the history
Remove exception for historical scenario in coastal and riverine
selectors.
In _get_resource_source_path use the minimum year available.

Signed-off-by: Xavier Barrachina Civera <[email protected]>
Co-authored-by: Arfima Dev <[email protected]>
  • Loading branch information
xbarra and devarfima authored Aug 16, 2024
1 parent 5ebd4cc commit 9ac2d6c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
18 changes: 4 additions & 14 deletions src/physrisk/hazard_models/core_hazards.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,10 @@ def _get_source_path(
if scenarios is None:
scenarios = next(
s
for s in sorted(
resource.scenarios, key=lambda s: next(y for y in s.years)
)
for s in sorted(resource.scenarios, key=lambda s: min(s.years))
)
proxy_scenario = scenarios.id
year = next(s for s in scenarios.years)
year = min(scenarios.years)
return resource.path.format(
id=indicator_id, scenario=proxy_scenario, year=year
)
Expand Down Expand Up @@ -216,11 +214,7 @@ def _select_coastal_inundation(
year: int,
hint: Optional[HazardDataHint] = None,
):
return (
candidates.with_model_id("nosub").first()
if scenario == "historical"
else candidates.with_model_id("wtsub/95").first()
)
return candidates.with_model_id("wtsub/95").first()

@staticmethod
def _select_riverine_inundation(
Expand All @@ -229,11 +223,7 @@ def _select_riverine_inundation(
year: int,
hint: Optional[HazardDataHint] = None,
):
return (
candidates.with_model_gcm("historical").first()
if scenario == "historical"
else candidates.with_model_gcm("MIROC-ESM-CHEM").first()
)
return candidates.with_model_gcm("MIROC-ESM-CHEM").first()

@staticmethod
def _select_riverine_inundation_tudelft(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def get_data_requests(
self.hazard_type,
asset.longitude,
asset.latitude,
scenario=scenario,
year=2030,
scenario="historical",
year=-1,
indicator_id=self.indicator_id,
buffer=self.buffer,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/api/data_requests_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_generic_source_path(self):
assert result_flood == "inundation/wri/v2/inunriver_rcp8p5_MIROC-ESM-CHEM_2050"
assert (
result_flood_hist
== "inundation/wri/v2/inunriver_historical_000000000WATCH_1980"
== "inundation/wri/v2/inunriver_rcp4p5_MIROC-ESM-CHEM_2030"
)
assert (
result_heat_hint
Expand Down
2 changes: 1 addition & 1 deletion tests/api/impact_requests_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_thermal_power_generation(self):
root,
longitudes,
latitudes,
"inundation/wri/v2/inunriver_rcp8p5_MIROC-ESM-CHEM_2030",
"inundation/wri/v2/inunriver_rcp4p5_MIROC-ESM-CHEM_2030",
shape,
np.array(
[
Expand Down
3 changes: 2 additions & 1 deletion tests/data/hazard_model_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ def wbgt_gzn_joint_parameter_set():
def inundation_paths():
paths = []
for model, scenario, year in [
("MIROC-ESM-CHEM", "rcp4p5", 2030),
("MIROC-ESM-CHEM", "rcp8p5", 2080),
("000000000WATCH", "historical", 1980),
]:
paths.append(
get_source_path_wri_riverine_inundation(
Expand All @@ -380,6 +380,7 @@ def inundation_paths():
)
for model, scenario, year in [
("wtsub/95", "rcp8p5", "2080"),
("wtsub/95", "rcp4p5", "2030"),
("wtsub", "historical", "hist"),
("nosub", "historical", "hist"),
]:
Expand Down

0 comments on commit 9ac2d6c

Please sign in to comment.