END-TO-END IMPACT CALCULATION

Before computing the impact of a given exposure and hazard, it is important to correctly match the exposures’ coordinates with the hazard centroids. Try to have similar resolutions in exposures and hazard. By the impact calculation the nearest neighbor for each exposure to the hazard’s centroids is searched.

Set first the Exposures and use its coordinates information to set a matching Hazard.

POINT EXPOSURES

If the exposures are points, compute your hazard at that points (if possible).

[1]:
%matplotlib inline
# EXAMPLE: POINT EXPOSURES WITH POINT HAZARD
import numpy as np
from climada.entity import Exposures, ImpactFuncSet, IFTropCyclone
from climada.hazard import Centroids, TCTracks, TropCyclone
from climada.engine import Impact

# Set Exposures in points
exp_pnt = Exposures(crs={'init':'epsg:4326'})
exp_pnt['latitude'] = np.array([21.899326, 21.960728, 22.220574, 22.298390, 21.787977, 21.787977, 21.981732])
exp_pnt['longitude'] = np.array([88.307422, 88.565362, 88.378337, 87.806356, 88.348835, 88.348835, 89.246521])
exp_pnt['value'] = np.array([1.0e5, 1.2e5, 1.1e5, 1.1e5, 2.0e5, 2.5e5, 0.5e5])
exp_pnt.check()
exp_pnt.plot_scatter(buffer=0.05)

# Set Hazard in Exposures points
# set centroids from exposures coordinates
centr_pnt = Centroids()
centr_pnt.set_lat_lon(exp_pnt.latitude.values, exp_pnt.longitude.values, exp_pnt.crs)
# compute Hazard in that centroids
tr_pnt = TCTracks()
tr_pnt.read_ibtracs_netcdf(storm_id='2007314N10093')
tc_pnt = TropCyclone()
tc_pnt.set_from_tracks(tr_pnt, centroids=centr_pnt)
tc_pnt.check()
tc_pnt.plot_intensity(1)

# Set impact function
if_pnt = ImpactFuncSet()
if_tc = IFTropCyclone()
if_tc.set_emanuel_usa()
if_pnt.append(if_tc)
if_pnt.check()

# Compute Impact
imp_pnt = Impact()
imp_pnt.calc(exp_pnt, if_pnt, tc_pnt)
# nearest neighbor of exposures to centroids gives identity
print('Nearest neighbor hazard.centroids indexes for each exposure:', exp_pnt.centr_TC.values)
imp_pnt.plot_scatter_eai_exposure(ignore_zero=False, buffer=0.05)
2019-06-18 20:11:50,738 - climada - DEBUG - Loading default config file: /Users/aznarsig/Documents/Python/climada_python/climada/conf/defaults.conf
2019-06-18 20:11:52,552 - climada.entity.exposures.base - INFO - tag metadata set to default value:  File:
 Description:
2019-06-18 20:11:52,553 - climada.entity.exposures.base - INFO - ref_year metadata set to default value: 2018
2019-06-18 20:11:52,553 - climada.entity.exposures.base - INFO - value_unit metadata set to default value: USD
2019-06-18 20:11:52,554 - climada.entity.exposures.base - INFO - meta metadata set to default value: None
2019-06-18 20:11:52,554 - climada.entity.exposures.base - INFO - Setting if_ to default impact functions ids 1.
2019-06-18 20:11:52,556 - climada.entity.exposures.base - INFO - centr_ not set.
2019-06-18 20:11:52,556 - climada.entity.exposures.base - INFO - deductible not set.
2019-06-18 20:11:52,558 - climada.entity.exposures.base - INFO - cover not set.
2019-06-18 20:11:52,559 - climada.entity.exposures.base - INFO - category_id not set.
2019-06-18 20:11:52,560 - climada.entity.exposures.base - INFO - region_id not set.
2019-06-18 20:11:52,560 - climada.entity.exposures.base - INFO - geometry not set.
/Users/aznarsig/anaconda3/envs/climada_up/lib/python3.7/site-packages/matplotlib/tight_layout.py:176: UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations.
  warnings.warn('Tight layout not applied. The left and right margins '
2019-06-18 20:11:56,209 - climada.hazard.tc_tracks - INFO - Reading 2007314N10093: SIDR
2019-06-18 20:11:56,603 - climada.hazard.trop_cyclone - INFO - Mapping 1 tracks to 7 centroids.
2019-06-18 20:12:00,736 - climada.entity.exposures.base - INFO - Matching 7 exposures with 7 centroids.
2019-06-18 20:12:00,740 - climada.engine.impact - INFO - Calculating damage for 7 assets (>0) and 1 events.
2019-06-18 20:12:00,740 - climada.engine.impact - INFO - Missing exposures impact functions for hazard if_TC. Using impact functions in if_.
Nearest neighbor hazard.centroids indexes for each exposure: [0 1 2 3 4 5 6]
2019-06-18 20:12:00,747 - climada.entity.exposures.base - INFO - tag metadata set to default value:  File:
 Description:
2019-06-18 20:12:00,750 - climada.entity.exposures.base - INFO - ref_year metadata set to default value: 2018
2019-06-18 20:12:00,750 - climada.entity.exposures.base - INFO - meta metadata set to default value: None
2019-06-18 20:12:00,751 - climada.entity.exposures.base - INFO - Setting if_ to default impact functions ids 1.
2019-06-18 20:12:00,753 - climada.entity.exposures.base - INFO - centr_ not set.
2019-06-18 20:12:00,755 - climada.entity.exposures.base - INFO - deductible not set.
2019-06-18 20:12:00,755 - climada.entity.exposures.base - INFO - cover not set.
2019-06-18 20:12:00,757 - climada.entity.exposures.base - INFO - category_id not set.
2019-06-18 20:12:00,758 - climada.entity.exposures.base - INFO - region_id not set.
2019-06-18 20:12:00,758 - climada.entity.exposures.base - INFO - geometry not set.
[1]:
(<Figure size 648x936 with 2 Axes>,
 array([[<cartopy.mpl.geoaxes.GeoAxesSubplot object at 0x1c209fb978>]],
       dtype=object))
../_images/tutorial_climada_engine_Impact_3_4.png
../_images/tutorial_climada_engine_Impact_3_5.png
../_images/tutorial_climada_engine_Impact_3_6.png

EXPOSURES FROM A RASTER

If the exposures represent values per pixel (belong to a raster), transform your hazard to a raster in the same reference system using the raster resampling options.

BlackMarble and LitPop belong to this category.

[2]:
# EXAMPLE: RASTER EXPOSURES WITH RASTER HAZARD
from rasterio.warp import Resampling
from climada.entity import LitPop, ImpactFuncSet, ImpactFunc
from climada.hazard import Hazard
from climada.engine import Impact
from climada.util.constants import HAZ_DEMO_FL

# Exposures belonging to a raster contain the meta attribute
exp_ras = LitPop()
exp_ras.set_country(countries=['VEN'], res_km=10, fin_mode='income_group')
exp_ras.reset_index()
exp_ras.check()
exp_ras.plot_raster()
print('Raster properties exposures:', exp_ras.meta)

# Resample hazard raster to the exposures' ones
haz_ras = Hazard('FL')
# check how other resampling methods affect to final impact
haz_ras.set_raster([HAZ_DEMO_FL], dst_crs=exp_ras.meta['crs'], transform=exp_ras.meta['transform'],
                   width=exp_ras.meta['width'], height=exp_ras.meta['height'],
                   resampling=Resampling.nearest)
haz_ras.intensity[haz_ras.intensity==-9999] = 0 # correct no data values
haz_ras.check()
haz_ras.plot_intensity(1)
print('Raster properties centroids:', haz_ras.centroids.meta)

# Set dummy impact function
if_ras = ImpactFuncSet()
if_dum = ImpactFunc()
if_dum.id = 1
if_dum.name = 'dummy'
if_dum.intensity_unit = 'm'
if_dum.haz_type = 'FL'
if_dum.intensity = np.linspace(0, 10, 100)
if_dum.mdd = np.linspace(0, 10, 100)
if_dum.paa = np.ones(if_dum.intensity.size)
if_ras.append(if_dum)
if_ras.check()

# Compute impact
imp_ras = Impact()
imp_ras.calc(exp_ras, if_ras, haz_ras)
# nearest neighbor of exposures to centroids is not identity because litpop does not contain data outside the country polygon
print('Nearest neighbor hazard.centroids indexes for each exposure:', exp_ras.centr_FL.values)
imp_ras.plot_raster_eai_exposure()
2019-06-18 20:12:03,882 - climada.entity.exposures.litpop - INFO - Generating LitPop data at a resolution of 300.0 arcsec.
2019-06-18 20:12:07,088 - climada.entity.exposures.gpw_import - INFO - Reference year: 2016. Using nearest available year for GWP population data: 2015
2019-06-18 20:12:07,089 - climada.entity.exposures.gpw_import - INFO - GPW Version v4.11
2019-06-18 20:12:19,409 - climada.util.finance - INFO - GDP VEN 2014: 4.824e+11.
2019-06-18 20:12:19,481 - climada.util.finance - INFO - Income group VEN 2016: 3.
2019-06-18 20:12:19,904 - climada.entity.exposures.litpop - INFO - Creating the LitPop exposure took 17 s
2019-06-18 20:12:19,905 - climada.entity.exposures.base - INFO - Hazard type not set in if_
2019-06-18 20:12:19,906 - climada.entity.exposures.base - INFO - centr_ not set.
2019-06-18 20:12:19,906 - climada.entity.exposures.base - INFO - deductible not set.
2019-06-18 20:12:19,907 - climada.entity.exposures.base - INFO - cover not set.
2019-06-18 20:12:19,908 - climada.entity.exposures.base - INFO - category_id not set.
2019-06-18 20:12:19,908 - climada.entity.exposures.base - INFO - geometry not set.
2019-06-18 20:12:19,926 - climada.entity.exposures.base - INFO - Hazard type not set in if_
2019-06-18 20:12:19,927 - climada.entity.exposures.base - INFO - centr_ not set.
2019-06-18 20:12:19,927 - climada.entity.exposures.base - INFO - deductible not set.
2019-06-18 20:12:19,928 - climada.entity.exposures.base - INFO - cover not set.
2019-06-18 20:12:19,929 - climada.entity.exposures.base - INFO - category_id not set.
2019-06-18 20:12:19,930 - climada.entity.exposures.base - INFO - geometry not set.
2019-06-18 20:12:19,931 - climada.entity.exposures.base - INFO - Setting geometry points.
2019-06-18 20:12:20,006 - climada.entity.exposures.base - INFO - Raster from resolution 0.0833333333333286 to 0.0833333333333286.
Raster properties exposures: {'width': 163, 'height': 138, 'crs': {'init': 'epsg:4326', 'no_defs': True}, 'transform': Affine(0.0833333333333286, 0.0, -73.41666666666669,
       0.0, -0.0833333333333286, 12.166666666666664)}
2019-06-18 20:12:21,677 - climada.util.coordinates - INFO - Reading /Users/aznarsig/Documents/Python/climada_python/data/demo/SC22000_VE__M1.grd.gz
Raster properties centroids: {'driver': 'GSBG', 'dtype': 'float32', 'nodata': 1.701410009187828e+38, 'width': 163, 'height': 138, 'count': 1, 'crs': {'init': 'epsg:4326', 'no_defs': True}, 'transform': Affine(0.0833333333333286, 0.0, -73.41666666666669,
       0.0, -0.0833333333333286, 12.166666666666664)}
2019-06-18 20:12:24,571 - climada.entity.exposures.base - INFO - Matching 10770 exposures with 22494 centroids.
2019-06-18 20:12:24,574 - climada.engine.impact - INFO - Calculating damage for 10717 assets (>0) and 1 events.
2019-06-18 20:12:24,575 - climada.engine.impact - INFO - Missing exposures impact functions for hazard if_FL. Using impact functions in if_.
Nearest neighbor hazard.centroids indexes for each exposure: [5705 5543 5706 ... 7659 7822 7660]
2019-06-18 20:12:24,584 - climada.entity.exposures.base - INFO - tag metadata set to default value:  File:
 Description:
2019-06-18 20:12:24,585 - climada.entity.exposures.base - INFO - ref_year metadata set to default value: 2018
2019-06-18 20:12:24,585 - climada.entity.exposures.base - INFO - meta metadata set to default value: None
2019-06-18 20:12:24,586 - climada.entity.exposures.base - INFO - Setting if_ to default impact functions ids 1.
2019-06-18 20:12:24,588 - climada.entity.exposures.base - INFO - centr_ not set.
2019-06-18 20:12:24,589 - climada.entity.exposures.base - INFO - deductible not set.
2019-06-18 20:12:24,590 - climada.entity.exposures.base - INFO - cover not set.
2019-06-18 20:12:24,591 - climada.entity.exposures.base - INFO - category_id not set.
2019-06-18 20:12:24,591 - climada.entity.exposures.base - INFO - region_id not set.
2019-06-18 20:12:24,592 - climada.entity.exposures.base - INFO - geometry not set.
2019-06-18 20:12:24,593 - climada.entity.exposures.base - INFO - Setting geometry points.
2019-06-18 20:12:24,680 - climada.entity.exposures.base - INFO - Raster from resolution 0.0833333333333286 to 0.0833333333333286.
[2]:
(<Figure size 648x936 with 2 Axes>,
 array([[<cartopy.mpl.geoaxes.GeoAxesSubplot object at 0x1c2746c780>]],
       dtype=object))
../_images/tutorial_climada_engine_Impact_5_2.png
../_images/tutorial_climada_engine_Impact_5_3.png
../_images/tutorial_climada_engine_Impact_5_4.png
[ ]: