def _create_benchmark_store(self): conf = gf.ConfigTypeA(id='benchmark_store', source_depth_min=0., source_depth_max=2., source_depth_delta=1., distance_min=1.0, distance_max=5001.0, distance_delta=5.0, sample_rate=2.0, ncomponents=5) deltat = 1.0 / conf.sample_rate store_dir = mkdtemp(prefix='gfstore') self.tempdirs.append(store_dir) gf.Store.create(store_dir, config=conf) store = gf.Store(store_dir, 'w') for args in conf.iter_nodes(): nsamples = int(round(args[1])) data = num.ones(nsamples) itmin = int(round(args[1])) tr = gf.GFTrace(data=data, itmin=itmin, deltat=deltat) store.put(args, tr) store.close() return store_dir
def create(self, deltat=1.0, nrecords=10): d = mkdtemp(prefix='gfstore') store = gf.BaseStore.create(d, deltat, nrecords, force=True) store = gf.BaseStore(d, mode='w') for i in range(nrecords): data = num.asarray(num.random.random(random.randint(0, 7)), dtype=gf.gf_dtype) tr = gf.GFTrace(data=data, itmin=1 + i) store.put(i, tr) store.close() self.tempdirs.append(d) return d
def _create_pulse_store(self): conf = gf.ConfigTypeB(id='pulse', receiver_depth_min=0., receiver_depth_max=10., receiver_depth_delta=10., source_depth_min=0., source_depth_max=1000., source_depth_delta=10., distance_min=10., distance_max=1000., distance_delta=10., sample_rate=200., ncomponents=2., component_scheme='elastic2') pulse = PulseConfig() # fnyq_spatial = pulse.velocity / math.sqrt(conf.distance_delta**2 + # conf.source_depth_delta**2) store_dir = mkdtemp(prefix='gfstore') self.tempdirs.append(store_dir) gf.Store.create(store_dir, config=conf, force=True, extra={'pulse': pulse}) deltat = conf.deltat store = gf.Store(store_dir, mode='w') for args in store.config.iter_nodes(level=-1): rdepth, sdepth, surfdist = args dist = math.sqrt((rdepth - sdepth)**2 + surfdist**2) tarr = dist / pulse.velocity tmin = tarr - 5 * pulse.fwhm tmax = tarr + 5 * pulse.fwhm itmin = int(num.floor(tmin / deltat)) itmax = int(num.ceil(tmax / deltat)) tmin = itmin * deltat tmax = itmax * deltat nsamples = itmax - itmin + 1 t = tmin + num.arange(nsamples) * deltat data = pulse.evaluate(dist, t) phi = math.atan2(rdepth - sdepth, surfdist) data = [data * math.cos(phi), data * math.sin(phi)] for icomponent, data in enumerate(data): is_zero = num.all(data == 0.0) tr = gf.GFTrace(data=data, itmin=itmin, deltat=deltat, is_zero=is_zero) store.put(args + (icomponent, ), tr) store.close() return store_dir
def test_sum(self): nrecords = 8 random.seed(0) num.random.seed(0) store = gf.BaseStore(self.create(nrecords=nrecords)) from pyrocko.gf import store_ext store.open() store_ext.store_mapping_init( store.cstore, 'type_0', arr([0]), arr([nrecords-1]), arr([1]), num.array([nrecords], dtype=num.uint64), 1) for deci in (1, 2, 3, 4): for i in range(300): n = random.randint(0, 5) indices = num.random.randint(nrecords, size=n) weights = num.random.random(n) shifts = num.random.random(n)*nrecords shifts[::2] = num.round(shifts[::2]) for itmin, nsamples in [(None, None), (random.randint(0, nrecords), random.randint(0, nrecords))]: a = store.sum( indices, shifts, weights, itmin=itmin, nsamples=nsamples, decimate=deci) b = store.sum( indices, shifts, weights, itmin=itmin, nsamples=nsamples, decimate=deci, implementation='alternative') c = store.sum( indices, shifts, weights, itmin=itmin, nsamples=nsamples, decimate=deci, implementation='reference') self.assertEqual(a.itmin, c.itmin) num.testing.assert_array_almost_equal( a.data, c.data, 2) self.assertEqual(b.itmin, c.itmin) num.testing.assert_array_almost_equal( b.data, c.data, 2) if deci != 1: continue nthreads = 1 source_coords = num.zeros((n, 5)) source_coords[:, 4] = indices receiver_coords = num.zeros((1, 5)) source_terms = num.zeros((n, 1)) source_terms[:, 0] = weights results = store_ext.store_calc_timeseries( store.cstore, source_coords, source_terms, shifts, receiver_coords, 'dummy', 'nearest_neighbor', num.array( [itmin if itmin is not None else 0], dtype=num.int32), num.array( [nsamples if nsamples is not None else -1], dtype=num.int32), nthreads) d = gf.GFTrace(*results[0][:2]) self.assertEqual(a.itmin, d.itmin) num.testing.assert_array_almost_equal( a.data, d.data, 2) store.close()