Change of Hazard/Risk Assessment for Wildfire#

This notebook is a supplement to the Hazard and Risk assessment notebooks. It depends on the outputs of these notebooks to function.

In the following, differences between the computed historical and future wildfire susceptibility, hazard and risk are visualized, with projected changes of the machine learning model input parameters providing additional context to understand found differences.

Load libraries#

Importing libraries required for the processing and visualization of data.

import pathlib

import numpy as np
import xarray as xr

import matplotlib.pyplot as plt
import matplotlib.colors
import matplotlib.patches

Data configuration#

Important

The data visualized in this notebook is created by the hazard and risk assessment workflows. Only data configurations for which these workflow notebooks have been run previously to generate the input data for this notebook will work.

Region selection#

Use the region name assigned in the hazard and risk notebooks.

areaname = "Catalonia" # example configuration: Catalonia

Historical and future configuration#

Choose a historical period and future scenario, period and climate model as in the Hazard assessment.

Tip

You can return to this point of the workflow and rerun the following cells for different combinations of RCP scenario, time period and climate model to explore different the risk in different futures.

hist_period = "199110"

future_scenario = "RCP45"
future_period = "202140"
climate_model = "CLMcom_CCLM"

Preparation#

Load a raster mask that defines the region for plotting:

Path configuration#

data_path_area = pathlib.Path(f"./data_{areaname}")

# Output rasters from hazard and risk assessment
suscep_path = data_path_area / "susceptibility"
hazard_path = data_path_area / "hazard"
risk_path = data_path_area / "risk"

# Resized ECLIPS-2.0 data folder (region-specific)
clim_path = data_path_area / "climate"

# DEM raster for masking
dem_path = data_path_area / "dem"
dem_path_clip = dem_path / "dem_clip.tif" # output

# Filename part for historical susceptibility/hazard/risk
hist_config_id = f"HIST_{hist_period}"
hist_period_print = hist_period[:-2] + "-" + hist_period[-2:]

# Filename part for future susceptibility/hazard/risk
future_config_id = f"{future_scenario}_{climate_model}_{future_period}"
future_period_print = future_period[:-2] + "-" + future_period[-2:]

# Output folder for map plots
maps_path = data_path_area / "maps"
maps_path.mkdir(parents=True, exist_ok=True)

Plot function for difference maps#

ref = xr.open_dataarray(dem_path_clip).squeeze()
mask = np.isnan(ref.values)
def plot_difference(ax, hist, future, classes_values, mask=None, title=None):
    classes_colors = ['navy',  'lightgray', 'darkred']
    classes_names = ['Decrease', 'No changes', 'Increase']
    cmap = matplotlib.colors.ListedColormap(classes_colors)
    norm = matplotlib.colors.BoundaryNorm(classes_values, cmap.N)
    classes_handles = [matplotlib.patches.Patch(color=color) for color in classes_colors]
    # Compute difference of fields
    diff = np.ma.masked_array(future - hist, mask=mask)
    # Plot with legend and disable plot frame
    ax.imshow(diff, cmap=cmap, norm=norm)
    ax.legend(handles=classes_handles, labels=classes_names, loc="lower right")
    ax.axis("off")
    ax.set_title(title)

Difference of Susceptibility#

Difference of Susceptibility maps between the historical and future climate:

suscep_hist = xr.open_dataarray(suscep_path / f"suscep_{hist_config_id}.tif").squeeze()
suscep_future = xr.open_dataarray(suscep_path / f"suscep_{future_config_id}.tif").squeeze()
fig, ax = plt.subplots(1, 1, figsize=(10, 10), dpi=150)

plot_difference(ax, suscep_hist, suscep_future, classes_values=[-3.1, -0.1, 0.1, 3], mask=mask, title=(
    "Degree of susceptibility change\n"
    f"{future_period_print} {future_scenario} ({climate_model}) - Historical {hist_period_print}"
))

fig.tight_layout()
fig.savefig(maps_path / f"change_suscep_{hist_config_id}_{future_config_id}.png")
../../../../_images/07b710c019ce162e5455a140d50ec9fa6117504546bad726bc4ff75373f13e82.png

Difference of Hazard#

hazard_hist = xr.open_dataarray(hazard_path / f"hazard_{hist_config_id}.tif").squeeze()
hazard_future = xr.open_dataarray(hazard_path / f"hazard_{future_config_id}.tif").squeeze()
fig, ax = plt.subplots(1, 1, figsize=(10, 10), dpi=150)

plot_difference(ax, hazard_hist, hazard_future, classes_values=[-5.1, 0, 0.1, 5], mask=mask, title=(
    "Degree of hazard change\n"
    f"{future_period_print} {future_scenario} ({climate_model}) - Historical {hist_period_print}"
))

fig.tight_layout()
fig.savefig(maps_path / f"change_hazard_{hist_config_id}_{future_config_id}.png")
../../../../_images/146c4680b46c558fb3500154daaacacc32fc7e3c9a156c276b642be55c30ce10.png

Difference of Risk#

Economy#

risk_econ_hist = xr.open_dataarray(risk_path / f"risk1_economical_{hist_config_id}.tif").squeeze()
risk_econ_future = xr.open_dataarray(risk_path / f"risk1_economical_{future_config_id}.tif").squeeze()
fig, ax = plt.subplots(1, 1, figsize=(10, 10), dpi=150)

plot_difference(ax, risk_econ_hist, risk_econ_future, classes_values=[-5.1, 0, 0.1, 5], mask=mask, title=(
    "Risk change in economy\n"
    f"{future_period_print} {future_scenario} ({climate_model}) - Historical {hist_period_print}"
))

fig.tight_layout()
fig.savefig(maps_path / f"change_risk1_economical_{hist_config_id}_{future_config_id}.png")
../../../../_images/ca955bd507a32bf1d80358992f308c1b72415af7c58341af9c512dc6cda9adf6.png

Population#

risk_pop_hist = xr.open_dataarray(risk_path / f"risk1_population_{hist_config_id}.tif").squeeze()
risk_pop_future = xr.open_dataarray(risk_path / f"risk1_population_{future_config_id}.tif").squeeze()
fig, ax = plt.subplots(1, 1, figsize=(10, 10), dpi=150)

plot_difference(ax, risk_pop_hist, risk_pop_future, classes_values=[-5.1, 0, 0.1, 5], mask=mask, title=(
    "Risk change in population\n"
    f"{future_period_print} {future_scenario} ({climate_model}) - Historical {hist_period_print}"
))

fig.tight_layout()
fig.savefig(maps_path / f"change_risk1_population_{hist_config_id}_{future_config_id}.png")
../../../../_images/4c6fa989a7cbda5652e7ec695f209b815d4760352a3e9ffebf321d8416448471.png

Roads#

risk_roads_hist = xr.open_dataarray(risk_path / f"risk2_roads_{hist_config_id}.tif").squeeze()
risk_roads_future = xr.open_dataarray(risk_path / f"risk2_roads_{future_config_id}.tif").squeeze()
fig, ax = plt.subplots(1, 1, figsize=(10, 10), dpi=150)

plot_difference(ax, risk_roads_hist, risk_roads_future, classes_values=[-5.1, 0, 0.1, 5], mask=mask, title=(
    "Risk change in roads\n"
    f"{future_period_print} {future_scenario} ({climate_model}) - Historical {hist_period_print}"
))

fig.tight_layout()
fig.savefig(maps_path / f"change_risk2_roads_{hist_config_id}_{future_config_id}.png")
../../../../_images/138b205e50a42dcf588a229b362fee4ef288826dadf305755db025bc90eb2f28.png

Climate variable changes in time#

Let’s check the climate input to find the logic behind changes in the risk hazard or susceptibility maps.

Load data#

hist_clim_files = list(sorted((clim_path / hist_config_id).glob("*.tif")))
future_clim_files = list(sorted((clim_path / future_config_id).glob("*.tif")))
def rename(ds):
    name = pathlib.Path(ds.encoding["source"]).name
    name = "_".join(name.split("_")[:-1])
    return ds["band_data"].rename(name).squeeze()

hist_clim = xr.open_mfdataset(hist_clim_files, preprocess=rename)
future_clim = xr.open_mfdataset(future_clim_files, preprocess=rename)

Plot difference maps#

var_names = list(hist_clim.data_vars)

nvars = len(var_names)
ncols = 3
nrows = int(np.ceil(nvars / ncols))
fig, axs = plt.subplots(nrows, ncols, figsize=(12, nrows*3))
axs = axs.flatten()

fig.suptitle(f"Change: {future_period_print} {future_scenario} ({climate_model}) - Historical {hist_period_print}\n")

# Fill panels with difference plot for each variable
for ax, var_name in zip(axs, var_names):
    diff_clim = future_clim[var_name] - hist_clim[var_name]
    maxval = np.max(np.abs(diff_clim)).values # to enforce symmetric colorbar range
    im = ax.imshow(diff_clim.values, vmin=-maxval, vmax=maxval, cmap="RdBu_r")
    plt.colorbar(im, ax=ax, shrink=0.5)
    ax.set_title(var_name)
    ax.axis("off")

# Remove left-over plot panels
for ax in axs[nvars:]:
    ax.remove()

fig.tight_layout()
fig.savefig(maps_path / f"change_clim_vars_{hist_config_id}_{future_config_id}.png")
../../../../_images/1218d1dec3798d9d9dec959c515e8f0f739224ff6849cfc19e36d0d817c51249.png

Contributors#