Change tile-by-tile computation to asset-by-asset
The code should be changed to return to an asset-by-asset computation to speed up the calculations.
Computing the ground-motion field when the calculator splits the exposure into tiles is very time consuming compared to the case when the exposure model is processed only asset by asset.
The easy and fast solution to compute the ground-motion field for all the assets when the exposure model is processed only asset by asset is as below:
- The ground-motion field for all the assets is computed once (named full ground-motion field) and stored in an array with same number and order of assets as the exposure file. For each asset, the relevant row from the full ground-motion field is taken as the corresponding ground-motion value.
There are many ways to compute the ground-motion field for all the exposure assets when the calculator is splitting the exposure model into tiles but the most straight-forward solutions are as below:
-
Interpolate the ground-motion values for assets of a tile each time, separately in a tile . This can be almost 520 times slower than the case above. Because whole the given ground-motion field is used for interpolation repeatedly in tiles.
-
Interpolate the ground-motion values for all assets of the exposure mode once just like the case
1
but then write the full ground-motion field into a dictionary along with theasset-ids
as the dictionary keys. Whenever in a tile, the corresponding ground-motion values can be read from the dictionary using theasset-ids
.
This makes the program 23 times faster than the case2
but still 23 times slower than the case1
.
A benefit of doing computations tile by tile is to later run the tiles in parallel and speed up the computation. Tile-by-tile computation is now pretty slow and I do not feel the need to spend time on optimizing it now, because the exposure format will anyway change in the future.
The codes using the methods 2
and 3
are stored in the branch Tile_by_tile_damagecalculator
named losscalculator_compute_GMF_per_tile
and losscalculator
respectively in case we need to later reuse or improve them.