def test_matrices(self): # distance matrix lons = numpy.array([84., 84., 84., 85.5, 85.5, 85.5, 87., 87., 87.]) lats = numpy.array([26., 27.5, 29., 26., 27.5, 29., 26., 27.5, 29.]) dmatrix = geo.geodetic.distance_matrix(lons, lats) aae(dmatrix.sum(), 18539.6131407) # spatial correlation sca = spatial_correlation_array(dmatrix, imts, 'yes') aae(sca.sum(), 36.000370229) # spatial covariance std = numpy.array([(0.5, 0.52, 0.64, 0.73)] * 9, imt_dt) # 9 sites scov = spatial_covariance_array([std[n] for n in imt_dt.names], sca) aae(scov.sum(), 13.166200147) # cross correlation ccor = cross_correlation_matrix(imts, 'yes') aae(ccor.sum(), 10.49124788) # cholesky decomposition L = cholesky(scov, ccor) self.assertEqual(L.shape, (36, 36)) aae(L.sum(), 30.5121263) # intensity val = numpy.array( [(5.38409665, 3.9383686, 3.55435415, 4.37692394)] * 9, imt_dt) shakemap = numpy.zeros(9, shakemap_dt) # 9 sites shakemap['lon'] = lons shakemap['lat'] = lats shakemap['vs30'] = numpy.array([301.17] * 9) shakemap['val'] = val shakemap['std'] = std _, gmfs = to_gmfs( shakemap, 'yes', 'no', site_effects=False, trunclevel=3, num_gmfs=2, seed=42) # shape (N, E, M) aae(gmfs[..., 0].sum(axis=0), [0.3708301, 0.5671011]) # PGA _, gmfs = to_gmfs( shakemap, 'yes', 'yes', site_effects=True, trunclevel=3, num_gmfs=2, seed=42) aae(gmfs[..., 0].sum(axis=0), [0.5127146, 0.7800232]) # PGA aae(gmfs[..., 2].sum(axis=0), [0.4932519, 0.6731384]) # SA(1.0) # disable spatial correlation _, gmfs = to_gmfs( shakemap, 'no', 'no', site_effects=False, trunclevel=3, num_gmfs=2, seed=42) # shape (N, E, M) aae(gmfs[..., 0].sum(axis=0), [0.370832, 0.5670994]) # PGA _, gmfs = to_gmfs( shakemap, 'no', 'yes', site_effects=True, trunclevel=3, num_gmfs=2, seed=42) aae(gmfs[..., 0].sum(axis=0), [0.5127171, 0.7800206]) # PGA aae(gmfs[..., 2].sum(axis=0), [0.4932519, 0.6731384]) # SA(1.0)
def test_matrices(self): # distance matrix lons = numpy.array([84., 84., 84., 85.5, 85.5, 85.5, 87., 87., 87.]) lats = numpy.array([26., 27.5, 29., 26., 27.5, 29., 26., 27.5, 29.]) dmatrix = geo.geodetic.distance_matrix(lons, lats) aae(dmatrix.sum(), 18539.6131407) # spatial correlation sca = spatial_correlation_array(dmatrix, imts, 'spatial') aae(sca.sum(), 36.000370229) # spatial covariance std = numpy.array([(0.5, 0.52, 0.64, 0.73)] * 9, imt_dt) # 9 sites scov = spatial_covariance_array([std[n] for n in imt_dt.names], sca) aae(scov.sum(), 13.166200147) # cross correlation ccor = cross_correlation_matrix(imts, 'cross') aae(ccor.sum(), 10.49124788) # cholesky decomposition L = cholesky(scov, ccor) self.assertEqual(L.shape, (36, 36)) aae(L.sum(), 30.5121263) # intensity val = numpy.array([(5.38409665, 3.9383686, 3.55435415, 4.37692394)] * 9, imt_dt) shakemap = numpy.zeros(9, shakemap_dt) # 9 sites shakemap['lon'] = lons shakemap['lat'] = lats shakemap['vs30'] = numpy.array([301.17] * 9) shakemap['val'] = val shakemap['std'] = std gmfs = to_gmfs(shakemap, crosscorr='corr', site_effects=False, trunclevel=3, num_gmfs=2, seed=42) # shape (R, N, E, M) aae(gmfs[..., 0].sum(axis=1), [[0.3708301, 0.5671011]]) # PGA gmfs = to_gmfs(shakemap, crosscorr='cross', site_effects=True, trunclevel=3, num_gmfs=2, seed=42) aae(gmfs[..., 0].sum(axis=1), [[0.4101717, 0.6240185]]) # PGA aae(gmfs[..., 2].sum(axis=1), [[0.3946015, 0.5385107]]) # SA(1.0)
def test_matrices(self): # distance matrix lons = numpy.array([84., 84., 84., 85.5, 85.5, 85.5, 87., 87., 87.]) lats = numpy.array([26., 27.5, 29., 26., 27.5, 29., 26., 27.5, 29.]) dmatrix = geo.geodetic.distance_matrix(lons, lats) aae(dmatrix.sum(), 18539.6131407) # spatial correlation sca = spatial_correlation_array(dmatrix, imts, 'yes') aae(sca.sum(), 36.000370229) # spatial covariance std = numpy.array([(0.5, 0.52, 0.64, 0.73)] * 9, imt_dt) # 9 sites scov = spatial_covariance_array([std[n] for n in imt_dt.names], sca) aae(scov.sum(), 13.166200147) # cross correlation ccor = cross_correlation_matrix(imts, 'yes') aae(ccor.sum(), 10.49124788) # cholesky decomposition L = cholesky(scov, ccor) self.assertEqual(L.shape, (36, 36)) aae(L.sum(), 30.5121263) # intensity val = numpy.array([(5.38409665, 3.9383686, 3.55435415, 4.37692394)] * 9, imt_dt) shakemap = numpy.zeros(9, shakemap_dt) # 9 sites shakemap['lon'] = lons shakemap['lat'] = lats shakemap['vs30'] = numpy.array([301.17] * 9) shakemap['val'] = val shakemap['std'] = std _, gmfs = to_gmfs(shakemap, 'yes', 'no', site_effects=False, trunclevel=3, num_gmfs=2, seed=42) # shape (N, E, M) aae(gmfs[..., 0].sum(axis=0), [0.3708301, 0.5671011]) # PGA _, gmfs = to_gmfs(shakemap, 'yes', 'yes', site_effects=True, trunclevel=3, num_gmfs=2, seed=42) aae(gmfs[..., 0].sum(axis=0), [0.5127146, 0.7800232]) # PGA aae(gmfs[..., 2].sum(axis=0), [0.4932519, 0.6731384]) # SA(1.0) # disable spatial correlation _, gmfs = to_gmfs(shakemap, 'no', 'no', site_effects=False, trunclevel=3, num_gmfs=2, seed=42) # shape (N, E, M) aae(gmfs[..., 0].sum(axis=0), [0.370832, 0.5670994]) # PGA _, gmfs = to_gmfs(shakemap, 'no', 'yes', site_effects=True, trunclevel=3, num_gmfs=2, seed=42) aae(gmfs[..., 0].sum(axis=0), [0.5127171, 0.7800206]) # PGA aae(gmfs[..., 2].sum(axis=0), [0.4932519, 0.6731384]) # SA(1.0) # set stddev to zero shakemap['std'] = 0 with self.assertRaises(ValueError) as ctx: to_gmfs(shakemap, 'no', 'yes', site_effects=True, trunclevel=3, num_gmfs=2, seed=42) self.assertIn('stddev==0 for IMT=PGA', str(ctx.exception))