Skip to content

Commit

Permalink
Merge branch 'feature/event_set_flood_damages' of github.com:nismod/o…
Browse files Browse the repository at this point in the history
…pen-gira into feature/event_set_flood_damages
  • Loading branch information
thomas-fred committed Feb 12, 2024
2 parents 4801815 + bb27beb commit 47fa4d3
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions workflow/transport-flood/flood_damages.smk
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ rule event_set_direct_damages:
unsplit = rules.create_transport_network.output.edges, # for pre-intersection geometry
exposure = rules.rasterise_osm_network.output.geoparquet
output:
damage_fraction = "{OUTPUT_DIR}/direct_damages/{DATASET}_{FILTER_SLUG}/{HAZARD_SLUG}/fraction/{SLICE_SLUG}.geoparquet",
damage_cost = "{OUTPUT_DIR}/direct_damages/{DATASET}_{FILTER_SLUG}/{HAZARD_SLUG}/cost/{SLICE_SLUG}.geoparquet",
damage_fraction = "{OUTPUT_DIR}/direct_damages/{DATASET}_{FILTER_SLUG}/{HAZARD_SLUG}/fraction/{SLICE_SLUG}.gpq",
damage_cost = "{OUTPUT_DIR}/direct_damages/{DATASET}_{FILTER_SLUG}/{HAZARD_SLUG}/cost/{SLICE_SLUG}.gpq",
params:
# determine the network type from the filter, e.g. road, rail
network_type=lambda wildcards: wildcards.FILTER_SLUG.replace('filter-', ''),
Expand All @@ -58,5 +58,36 @@ rule event_set_direct_damages:

"""
Test with:
snakemake --cores 1 results/direct_damages/thailand-latest_filter-road/hazard-jba-event/EAD_and_cost_per_RP/slice-5.geoparquet
"""
snakemake --cores 1 results/direct_damages/thailand-latest_filter-road/hazard-jba-event/cost/slice-5.gpq
"""


rule concat_event_set_direct_damages:
input:
slices = lambda wildcards: expand(
os.path.join(
"{OUTPUT_DIR}",
"direct_damages",
"{DATASET}_{FILTER_SLUG}",
"{HAZARD_SLUG}",
"cost",
"slice-{i}.gpq",
),
**wildcards,
i=range(config["slice_count"])
),
output:
damage_cost = "{OUTPUT_DIR}/direct_damages/{DATASET}_{FILTER_SLUG}/{HAZARD_SLUG}/cost.gpq",
run:
import geopandas as gpd
import pandas as pd

slices = []
for path in input.slices:
slices.append(gpd.read_parquet(path))
pd.concat(slices).to_parquet(output.damage_cost)

"""
Test with:
snakemake -c1 results/direct_damages/thailand-latest_filter-road/hazard-jba-event/cost.gpq
"""

0 comments on commit 47fa4d3

Please sign in to comment.