def test_double(self): fname = gettemp(double_ampl_func) df = read_csv(fname, { 'ampcode': ampcode_dt, None: numpy.float64 }, index='ampcode') a = Amplifier(self.imtls, df, self.soil_levels) poes = a.amplify_one(b'A', 'SA(0.1)', self.hcurve[1]).flatten() numpy.testing.assert_allclose(poes, [ 0.985122, 0.979701, 0.975965, 0.96634, 0.922497, 0.886351, 0.790249 ], atol=1E-6) # poes, [0.989, 0.985, 0.98, 0.97, 0.94, 0.89, 0.79], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.2)', self.hcurve[2]).flatten() numpy.testing.assert_allclose(poes, [ 0.985122, 0.979701, 0.975965, 0.96634, 0.922497, 0.886351, 0.790249 ], atol=1E-6) # poes, [0.989, 0.985, 0.98, 0.97, 0.94, 0.89, 0.79], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.5)', self.hcurve[3]).flatten() numpy.testing.assert_allclose(poes, [ 0.985122, 0.979701, 0.975965, 0.96634, 0.922497, 0.886351, 0.790249 ], atol=1E-6) # poes, [0.989, 0.985, 0.98, 0.97, 0.94, 0.89, 0.79], atol=1E-6) # amplify GMFs without sigmas gmvs = a._amplify_gmvs(b'A', numpy.array([.1, .2, .3]), 'SA(0.5)') numpy.testing.assert_allclose(gmvs, [.2, .4, .6])
def test_simple(self): fname = gettemp(simple_ampl_func) df = read_csv(fname, { 'ampcode': ampcode_dt, None: numpy.float64 }, index='ampcode') a = Amplifier(self.imtls, df, self.soil_levels) # a.check(self.vs30, vs30_tolerance=1) poes = a.amplify_one(b'A', 'SA(0.1)', self.hcurve[1]).flatten() numpy.testing.assert_allclose(poes, [ 0.981141, 0.975771, 0.964955, 0.935616, 0.882413, 0.785659, 0.636667 ], atol=1e-6) poes = a.amplify_one(b'A', 'SA(0.2)', self.hcurve[2]).flatten() numpy.testing.assert_allclose(poes, [ 0.981141, 0.975771, 0.964955, 0.935616, 0.882413, 0.785659, 0.636667 ], atol=1e-6) poes = a.amplify_one(b'A', 'SA(0.5)', self.hcurve[3]).flatten() numpy.testing.assert_allclose(poes, [ 0.981681, 0.976563, 0.967238, 0.940109, 0.890456, 0.799286, 0.686047 ], atol=1e-6) # Amplify GMFs with sigmas numpy.random.seed(42) gmvs = a._amplify_gmvs(b'A', numpy.array([.005, .010, .015]), 'PGA') numpy.testing.assert_allclose(gmvs, [0.005401, 0.010356, 0.016704], atol=1E-5)
def test_double(self): fname = gettemp(double_ampl_func) aw = read_csv(fname, {'ampcode': ampcode_dt, None: numpy.float64}) a = Amplifier(self.imtls, aw) poes = a.amplify_one(b'A', 'SA(0.1)', self.hcurve[1]).flatten() numpy.testing.assert_allclose(poes, [ 0.989, 0.989, 0.985, 0.98, 0.97, 0.94, 0.89, 0.79, 0.69, 0.09, 0.09 ], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.2)', self.hcurve[2]).flatten() numpy.testing.assert_allclose(poes, [ 0.989, 0.989, 0.985, 0.98, 0.97, 0.94, 0.89, 0.79, 0.69, 0.09, 0.09 ], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.5)', self.hcurve[3]).flatten() numpy.testing.assert_allclose(poes, [ 0.989, 0.989, 0.985, 0.98, 0.97, 0.94, 0.89, 0.79, 0.69, 0.09, 0.09 ], atol=1E-6) # amplify GMFs without sigmas gmvs = a._amplify_gmvs(b'A', numpy.array([.1, .2, .3]), 'SA(0.5)') numpy.testing.assert_allclose(gmvs, [.2, .4, .6])
def test_simple(self): fname = gettemp(simple_ampl_func) aw = read_csv(fname, {'ampcode': ampcode_dt, None: numpy.float64}) a = Amplifier(self.imtls, aw, self.soil_levels) a.check(self.vs30, vs30_tolerance=1) poes = a.amplify_one(b'A', 'SA(0.1)', self.hcurve[1]).flatten() numpy.testing.assert_allclose( poes, [0.985002, 0.979997, 0.970004, 0.940069, 0.889961, 0.79, 0.690037], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.2)', self.hcurve[2]).flatten() numpy.testing.assert_allclose( poes, [0.985002, 0.979997, 0.970004, 0.940069, 0.889961, 0.79, 0.690037], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.5)', self.hcurve[3]).flatten() numpy.testing.assert_allclose( poes, [0.985002, 0.979996, 0.969991, 0.940012, 0.889958, 0.79, 0.690037], atol=1E-6) # amplify GMFs with sigmas numpy.random.seed(42) gmvs = a._amplify_gmvs(b'A', numpy.array([.005, .010, .015]), 'PGA') numpy.testing.assert_allclose(gmvs, [0.005307, 0.010093, 0.016804], atol=1E-5)
def test_gmf_cata(self): fname = gettemp(cata_ampl_func) df = read_csv(fname, {'ampcode': ampcode_dt, None: numpy.float64}, index='ampcode') imtls = DictArray({'PGA': [numpy.nan]}) a = Amplifier(imtls, df) numpy.random.seed(42) # must be fixed gmvs1 = a._amplify_gmvs(b'z1', numpy.array([.1, .2, .3]), 'PGA') aac(gmvs1, [0.217124, 0.399295, 0.602515], atol=1E-5) gmvs2 = a._amplify_gmvs(b'z2', numpy.array([.1, .2, .3]), 'PGA') aac(gmvs2, [0.266652, 0.334187, 0.510845], atol=1E-5) numpy.random.seed(43) # changing the seed the results change a lot gmvs1 = a._amplify_gmvs(b'z1', numpy.array([.1, .2, .3]), 'PGA') aac(gmvs1, [0.197304, 0.293422, 0.399669], atol=1E-5) gmvs2 = a._amplify_gmvs(b'z2', numpy.array([.1, .2, .3]), 'PGA') aac(gmvs2, [0.117069, 0.517284, 0.475571], atol=1E-5)
def test_gmf_with_uncertainty(self): fname = gettemp(gmf_ampl_func) aw = read_csv(fname, {'ampcode': ampcode_dt, None: numpy.float64}) imtls = {'PGA': self.imls} a = Amplifier(imtls, aw, self.soil_levels) res = [] nsim = 10000 numpy.random.seed(42) # must be fixed for i in range(nsim): gmvs = a._amplify_gmvs(b'A', numpy.array([.1, .2, .3]), 'PGA') res.append(list(gmvs)) res = numpy.array(res) dat = numpy.reshape(numpy.tile([.1, .2, .3], nsim), (nsim, 3)) computed = numpy.std(numpy.log(res / dat), axis=0) expected = numpy.array([0.3, 0.3, 0.3]) msg = "Computed and expected std do not match" numpy.testing.assert_almost_equal(computed, expected, 2, err_msg=msg)
def test_simple(self): # # MP: checked using hand calculations some values of the poes computed # considering uncertainty # fname = gettemp(simple_ampl_func) df = read_csv(fname, { 'ampcode': ampcode_dt, None: numpy.float64 }, index='ampcode') a = Amplifier(self.imtls, df, self.soil_levels) a.check(self.vs30, vs30_tolerance=1) poes = a.amplify_one(b'A', 'SA(0.1)', self.hcurve[1]).flatten() numpy.testing.assert_allclose(poes, [ 0.985008, 0.980001, 0.970019, 0.94006, 0.890007, 0.790198, 0.690201 ], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.2)', self.hcurve[2]).flatten() numpy.testing.assert_allclose(poes, [ 0.985008, 0.980001, 0.970019, 0.94006, 0.890007, 0.790198, 0.690201 ], atol=1E-6) poes = a.amplify_one(b'A', 'SA(0.5)', self.hcurve[3]).flatten() numpy.testing.assert_allclose(poes, [ 0.985109, 0.980022, 0.970272, 0.940816, 0.890224, 0.792719, 0.692719 ], atol=1E-6) # Amplify GMFs with sigmas numpy.random.seed(42) gmvs = a._amplify_gmvs(b'A', numpy.array([.005, .010, .015]), 'PGA') numpy.testing.assert_allclose(gmvs, [0.005401, 0.010356, 0.016704], atol=1E-5)