GNS-Science / toshi-hazard-haste

A caching API for hazard components.
GNU Affero General Public License v3.0
0 stars 0 forks source link

Feature: CoV maps #4

Open chrisdicaprio opened 2 years ago

chrisdicaprio commented 2 years ago

We want to be able to calculate coefficient of variation (CoV) maps for a given probability of exceedance (PoE).

This is done by (at every grid point)

  1. interpolate the mean hazard curve onto the desired PoE using the existing approach. The resulting shaking level is called the target_level
  2. Interpolate the CoV curve to get the CoV at the target_level. This is done by treating shaking levels as the x-values and CoV as the y values in the interpolation (opposite of how interpolation is done in step 1). NB: use log-log interpolation
chrisdicaprio commented 2 years ago
def compute_cov_at_poe(levels,values_mean,values_cov,poe,inv_time):

    rp = -inv_time/np.log(1-poe)
    try:
        target_level = np.exp( np.interp( np.log(1/rp), np.flip(np.log(values_mean)), np.flip(np.log(levels)) ) )
    except:
        breakpoint()
    return np.exp( np.interp(np.log(target_level),np.log(levels),np.log(values_cov)) )