def _create_psgrn_pscmp_store(self): mod = cake.LayeredModel.from_scanlines( cake.read_nd_model_str(''' 0. 5.8 3.46 2.6 1264. 600. 20. 5.8 3.46 2.6 1264. 600. 20. 6.5 3.85 2.9 1283. 600. 35. 6.5 3.85 2.9 1283. 600. mantle 35. 8.04 4.48 3.58 1449. 600. 77.5 8.045 4.49 3.5 1445. 600. 77.5 8.045 4.49 3.5 180.6 75. 120. 8.05 4.5 3.427 180. 75. 120. 8.05 4.5 3.427 182.6 76.06 165. 8.175 4.509 3.371 188.7 76.55 210. 8.301 4.518 3.324 201. 79.4 210. 8.3 4.52 3.321 336.9 133.3 410. 9.03 4.871 3.504 376.5 146.1 410. 9.36 5.08 3.929 414.1 162.7 660. 10.2 5.611 3.918 428.5 172.9 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip())) store_dir = mkdtemp(prefix='gfstore') self.tempdirs.append(store_dir) store_id = 'psgrn_pscmp_test' version = '2008a' c = psgrn_pscmp.PsGrnPsCmpConfig() c.psgrn_config.sampling_interval = 1. c.psgrn_config.version = version c.pscmp_config.version = version config = gf.meta.ConfigTypeA(id=store_id, ncomponents=10, sample_rate=1. / (3600. * 24.), receiver_depth=0. * km, source_depth_min=0. * km, source_depth_max=20. * km, source_depth_delta=0.25 * km, distance_min=0. * km, distance_max=40. * km, distance_delta=0.25 * km, modelling_code_id='psgrn_pscmp.%s' % version, earthmodel_1d=mod, tabulated_phases=[]) config.validate() gf.store.Store.create_editables(store_dir, config=config, extra={'psgrn_pscmp': c}) store = gf.store.Store(store_dir, 'r') store.close() psgrn_pscmp.build(store_dir, nworkers=4) return store_dir
def _create_psgrn_pscmp_store(self): mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str(''' 0. 5.8 3.46 2.6 1264. 600. 20. 5.8 3.46 2.6 1264. 600. 20. 6.5 3.85 2.9 1283. 600. 35. 6.5 3.85 2.9 1283. 600. mantle 35. 8.04 4.48 3.58 1449. 600. 77.5 8.045 4.49 3.5 1445. 600. 77.5 8.045 4.49 3.5 180.6 75. 120. 8.05 4.5 3.427 180. 75. 120. 8.05 4.5 3.427 182.6 76.06 165. 8.175 4.509 3.371 188.7 76.55 210. 8.301 4.518 3.324 201. 79.4 210. 8.3 4.52 3.321 336.9 133.3 410. 9.03 4.871 3.504 376.5 146.1 410. 9.36 5.08 3.929 414.1 162.7 660. 10.2 5.611 3.918 428.5 172.9 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip())) store_dir = mkdtemp(prefix='gfstore') self.tempdirs.append(store_dir) store_id = 'psgrn_pscmp_test' version = '2008a' c = psgrn_pscmp.PsGrnPsCmpConfig() c.psgrn_config.sampling_interval = 1. c.psgrn_config.version = version c.pscmp_config.version = version config = gf.meta.ConfigTypeA( id=store_id, ncomponents=10, sample_rate=1./(3600. * 24.), receiver_depth=0.*km, source_depth_min=0.*km, source_depth_max=20.*km, source_depth_delta=0.25*km, distance_min=0.*km, distance_max=40.*km, distance_delta=0.25*km, modelling_code_id='psgrn_pscmp.%s' % version, earthmodel_1d=mod, tabulated_phases=[]) config.validate() gf.store.Store.create_editables( store_dir, config=config, extra={'psgrn_pscmp': c}) store = gf.store.Store(store_dir, 'r') store.close() psgrn_pscmp.build(store_dir, nworkers=4) return store_dir
def test_fomosto_vs_psgrn_pscmp(self): mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str(''' 0. 5.8 3.46 2.6 1264. 600. 20. 5.8 3.46 2.6 1264. 600. 20. 6.5 3.85 2.9 1283. 600. 35. 6.5 3.85 2.9 1283. 600. mantle 35. 8.04 4.48 3.58 1449. 600. 77.5 8.045 4.49 3.5 1445. 600. 77.5 8.045 4.49 3.5 180.6 75. 120. 8.05 4.5 3.427 180. 75. 120. 8.05 4.5 3.427 182.6 76.06 165. 8.175 4.509 3.371 188.7 76.55 210. 8.301 4.518 3.324 201. 79.4 210. 8.3 4.52 3.321 336.9 133.3 410. 9.03 4.871 3.504 376.5 146.1 410. 9.36 5.08 3.929 414.1 162.7 660. 10.2 5.611 3.918 428.5 172.9 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip())) store_dir = mkdtemp(prefix='gfstore') self.tempdirs.append(store_dir) store_id = 'psgrn_pscmp_test' version = '2008a' c = psgrn_pscmp.PsGrnPsCmpConfig() c.psgrn_config.sampling_interval = 1. c.psgrn_config.version = version c.pscmp_config.version = version config = gf.meta.ConfigTypeA( id=store_id, ncomponents=10, sample_rate=1. / (3600. * 24.), receiver_depth=0. * km, source_depth_min=0. * km, source_depth_max=5. * km, source_depth_delta=0.1 * km, distance_min=0. * km, distance_max=40. * km, distance_delta=0.1 * km, modelling_code_id='psgrn_pscmp.%s' % version, earthmodel_1d=mod, tabulated_phases=[]) config.validate() gf.store.Store.create_editables( store_dir, config=config, extra={'psgrn_pscmp': c}) store = gf.store.Store(store_dir, 'r') store.close() # build store try: psgrn_pscmp.build(store_dir, nworkers=1) except psgrn_pscmp.PsCmpError as e: if str(e).find('could not start psgrn/pscmp') != -1: logger.warn('psgrn/pscmp not installed; ' 'skipping test_pyrocko_gf_vs_pscmp') return else: raise origin = gf.Location( lat=10., lon=-15.) # test GF store TestRF = dict( lat=origin.lat, lon=origin.lon, depth=2. * km, width=2. * km, length=5. * km, rake=90., dip=45., strike=45., slip=1.) source = gf.RectangularSource(**TestRF) neast = 40 nnorth = 40 N, E = num.meshgrid(num.linspace(-20. * km, 20. * km, nnorth), num.linspace(-20. * km, 20. * km, neast)) starget = gf.StaticTarget( lats=num.array([origin.lat] * N.size), lons=num.array([origin.lon] * N.size), north_shifts=N.flatten(), east_shifts=E.flatten(), interpolation='nearest_neighbor') engine = gf.LocalEngine(store_dirs=[store_dir]) t0 = time() r = engine.process(source, starget) t1 = time() logger.info('pyrocko stacking time %f' % (t1 - t0)) un_fomosto = r.static_results()[0].result['displacement.n'] ue_fomosto = r.static_results()[0].result['displacement.e'] ud_fomosto = r.static_results()[0].result['displacement.d'] # test against direct pscmp output lats, lons = ortd.ne_to_latlon( origin.lat, origin.lon, N.flatten(), E.flatten()) pscmp_sources = [psgrn_pscmp.PsCmpRectangularSource(**TestRF)] cc = c.pscmp_config cc.observation = psgrn_pscmp.PsCmpScatter(lats=lats, lons=lons) cc.rectangular_source_patches = pscmp_sources ccf = psgrn_pscmp.PsCmpConfigFull(**cc.items()) ccf.psgrn_outdir = os.path.join(store_dir, c.gf_outdir) + '/' t2 = time() runner = psgrn_pscmp.PsCmpRunner(keep_tmp=False) runner.run(ccf) ps2du = runner.get_results(component='displ')[0] t3 = time() logger.info('pscmp stacking time %f' % (t3 - t2)) un_pscmp = ps2du[:, 0] ue_pscmp = ps2du[:, 1] ud_pscmp = ps2du[:, 2] num.testing.assert_allclose(un_fomosto, un_pscmp, atol=0.002) num.testing.assert_allclose(ue_fomosto, ue_pscmp, atol=0.002) num.testing.assert_allclose(ud_fomosto, ud_pscmp, atol=0.002)
def _create_psgrn_pscmp_store(cls, extra_config=None): mod = cake.LayeredModel.from_scanlines( cake.read_nd_model_str(''' 0. 5.8 3.46 2.6 1264. 600. 20. 5.8 3.46 2.6 1264. 600. 20. 6.5 3.85 2.9 1283. 600. 35. 6.5 3.85 2.9 1283. 600. mantle 35. 8.04 4.48 3.58 1449. 600. 77. 8.045 4.49 3.5 1445. 600. 77. 8.045 4.49 3.5 180.6 75. 120. 8.05 4.5 3.427 180. 75. 120. 8.05 4.5 3.427 182.6 76.06 165. 8.175 4.509 3.371 188.7 76.55 210. 8.301 4.518 3.324 201. 79.4 210. 8.3 4.52 3.321 336.9 133.3 410. 9.03 4.871 3.504 376.5 146.1 410. 9.36 5.08 3.929 414.1 162.7 660. 10.2 5.611 3.918 428.5 172.9 660. 10.79 5.965 4.229 1349. 549.6 5e17 1e19 1'''.lstrip())) store_dir = mkdtemp(prefix='gfstore') # store_dir = '/tmp/pscmp_gfstore' cls.tempdirs.append(store_dir) store_id = 'psgrn_pscmp_test' if not extra_config: c = psgrn_pscmp.PsGrnPsCmpConfig() c.psgrn_config.sampling_interval = 1. else: c = extra_config version = '2008a' c.psgrn_config.version = version c.pscmp_config.version = version config = gf.meta.ConfigTypeA(id=store_id, modelling_code_id='psgrn_pscmp.%s' % version, earthmodel_1d=mod, sample_rate=1. / (3600. * 24.), component_scheme='elastic10', tabulated_phases=[], ncomponents=10, receiver_depth=0. * km, source_depth_min=0. * km, source_depth_max=6. * km, source_depth_delta=0.25 * km, distance_min=0. * km, distance_max=40. * km, distance_delta=.25 * km) config.validate() if not os.path.exists(os.path.join(store_dir, 'config')): gf.store.Store.create_editables(store_dir, config=config, extra={'psgrn_pscmp': c}) store = gf.store.Store(store_dir, 'r') store.close() # build store try: psgrn_pscmp.build(store_dir, nworkers=cpu_count()) except psgrn_pscmp.PsCmpError as e: if str(e).find('could not start psgrn/pscmp') != -1: logger.warn('psgrn/pscmp not installed; ' 'skipping test_pyrocko_gf_vs_pscmp') return else: raise e return store_dir, c
def test_fomosto_vs_psgrn_pscmp(self): mod = cake.LayeredModel.from_scanlines( cake.read_nd_model_str(''' 0. 5.8 3.46 2.6 1264. 600. 20. 5.8 3.46 2.6 1264. 600. 20. 6.5 3.85 2.9 1283. 600. 35. 6.5 3.85 2.9 1283. 600. mantle 35. 8.04 4.48 3.58 1449. 600. 77.5 8.045 4.49 3.5 1445. 600. 77.5 8.045 4.49 3.5 180.6 75. 120. 8.05 4.5 3.427 180. 75. 120. 8.05 4.5 3.427 182.6 76.06 165. 8.175 4.509 3.371 188.7 76.55 210. 8.301 4.518 3.324 201. 79.4 210. 8.3 4.52 3.321 336.9 133.3 410. 9.03 4.871 3.504 376.5 146.1 410. 9.36 5.08 3.929 414.1 162.7 660. 10.2 5.611 3.918 428.5 172.9 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip())) store_dir = mkdtemp(prefix='gfstore') self.tempdirs.append(store_dir) store_id = 'psgrn_pscmp_test' version = '2008a' c = psgrn_pscmp.PsGrnPsCmpConfig() c.psgrn_config.sampling_interval = 1. c.psgrn_config.version = version c.pscmp_config.version = version config = gf.meta.ConfigTypeA(id=store_id, ncomponents=10, sample_rate=1. / (3600. * 24.), receiver_depth=0. * km, source_depth_min=0. * km, source_depth_max=5. * km, source_depth_delta=0.1 * km, distance_min=0. * km, distance_max=40. * km, distance_delta=0.1 * km, modelling_code_id='psgrn_pscmp.%s' % version, earthmodel_1d=mod, tabulated_phases=[]) config.validate() gf.store.Store.create_editables(store_dir, config=config, extra={'psgrn_pscmp': c}) store = gf.store.Store(store_dir, 'r') store.close() # build store try: psgrn_pscmp.build(store_dir, nworkers=1) except psgrn_pscmp.PsCmpError as e: if str(e).find('could not start psgrn/pscmp') != -1: logger.warn('psgrn/pscmp not installed; ' 'skipping test_pyrocko_gf_vs_pscmp') return else: raise origin = gf.Location(lat=10., lon=-15.) # test GF store TestRF = dict(lat=origin.lat, lon=origin.lon, depth=2. * km, width=2. * km, length=5. * km, rake=90., dip=45., strike=45., slip=1.) source = gf.RectangularSource(**TestRF) neast = 40 nnorth = 40 N, E = num.meshgrid(num.linspace(-20. * km, 20. * km, nnorth), num.linspace(-20. * km, 20. * km, neast)) starget = gf.StaticTarget(lats=num.array([origin.lat] * N.size), lons=num.array([origin.lon] * N.size), north_shifts=N.flatten(), east_shifts=E.flatten(), interpolation='nearest_neighbor') engine = gf.LocalEngine(store_dirs=[store_dir]) t0 = time() r = engine.process(source, starget) t1 = time() logger.info('pyrocko stacking time %f' % (t1 - t0)) un_fomosto = r.static_results()[0].result['displacement.n'] ue_fomosto = r.static_results()[0].result['displacement.e'] ud_fomosto = r.static_results()[0].result['displacement.d'] # test against direct pscmp output lats, lons = ortd.ne_to_latlon(origin.lat, origin.lon, N.flatten(), E.flatten()) pscmp_sources = [psgrn_pscmp.PsCmpRectangularSource(**TestRF)] cc = c.pscmp_config cc.observation = psgrn_pscmp.PsCmpScatter(lats=lats, lons=lons) cc.rectangular_source_patches = pscmp_sources ccf = psgrn_pscmp.PsCmpConfigFull(**cc.items()) ccf.psgrn_outdir = os.path.join(store_dir, c.gf_outdir) + '/' t2 = time() runner = psgrn_pscmp.PsCmpRunner(keep_tmp=False) runner.run(ccf) ps2du = runner.get_results(component='displ')[0] t3 = time() logger.info('pscmp stacking time %f' % (t3 - t2)) un_pscmp = ps2du[:, 0] ue_pscmp = ps2du[:, 1] ud_pscmp = ps2du[:, 2] num.testing.assert_allclose(un_fomosto, un_pscmp, atol=0.002) num.testing.assert_allclose(ue_fomosto, ue_pscmp, atol=0.002) num.testing.assert_allclose(ud_fomosto, ud_pscmp, atol=0.002)