def sum_timeseries(): results = [] for itarget, target in enumerate(targets): params = store_ext.make_sum_params( store.cstore, source_coords_arr, source_terms, target.coords5[num.newaxis, :].copy(), scheme, interpolation, nthreads) for weights, irecords in params: neach = irecords.size // dsource.times.size delays2 = num.repeat(dsource.times, neach) r = store_ext.store_sum( store.cstore, irecords, delays2, weights, int(itmin[itarget]), int(nsamples[itarget])) results.append(r) return results
def make_param_c(): return store_ext.make_sum_params( store.cstore, source_coords_arr, mts_arr, receiver_coords_arr, 'elastic10', interpolation, nthreads)
def fwd_model_seperate(interpolation=interp[0]): args = (store.cstore, dsource.coords5(), mts_arr, static_target.coords5, 'elastic10', interpolation, nthreads) sum_params = store_ext.make_sum_params(*args) out = {} for icomp, comp in enumerate(scheme_desc): weights, irecords = sum_params[icomp] out[comp] = store_ext.store_sum_static( store.cstore, irecords, delays_s, weights, pos, ntargets**2, nthreads) return out
def sum_timeseries(): results = [] for itarget, target in enumerate(targets): params = store_ext.make_sum_params( store.cstore, source_coords_arr, mts_arr, target.coords5[num.newaxis, :].copy(), 'elastic10', interpolation, nthreads) for weights, irecords in params: d = num.zeros(irecords.shape[0], dtype=num.float32) r = store_ext.store_sum(store.cstore, irecords, d, weights, int(itmin[itarget]), int(nsamples[itarget])) results.append(r) return results
def test_sum_static(self): from pyrocko.gf import store_ext benchmark.show_factor = True store = gf.Store(self.get_qseis_store_dir()) store.open() src_length = 2 * km src_width = 5 * km ntargets = 1600 interp = ['nearest_neighbor', 'multilinear'] interpolation = interp[0] source = gf.RectangularSource(lat=0., lon=0., depth=5 * km, north_shift=0., east_shift=0., width=src_width, length=src_length) static_target = gf.StaticTarget( north_shifts=5 * km + random.rand(ntargets) * 5 * km, east_shifts=0 * km + random.rand(ntargets) * 5 * km) targets = static_target.get_targets() dsource = source.discretize_basesource(store, targets[0]) source_coords_arr = dsource.coords5() mts_arr = dsource.m6s receiver_coords_arr = num.empty((len(targets), 5)) for itarget, target in enumerate(targets): receiver = target.receiver(store) receiver_coords_arr[itarget, :] = \ [receiver.lat, receiver.lon, receiver.north_shift, receiver.east_shift, receiver.depth] def sum_target(cstore, irecords, delays_t, delays_s, weights, pos, nthreads): @benchmark.labeled('sum-timeseries-np%d' % nthreads) def sum_timeseries(): nsummands = weights.size // ntargets res = num.zeros(ntargets) for t in range(ntargets): sl = slice(t * nsummands, (t + 1) * nsummands) r = store_ext.store_sum(cstore, irecords[sl], delays_t[sl], weights[sl], pos, 1) res[t] = r[0] return res @benchmark.labeled('sum-static-np%d' % nthreads) def sum_static(): return store_ext.store_sum_static(cstore, irecords, delays_s, weights, pos, ntargets, nthreads) return sum_timeseries(), sum_static() args = (store.cstore, source_coords_arr, mts_arr, receiver_coords_arr, 'elastic10', interpolation, 0) benchmark.clear() for nthreads in [1, 2, 4]: for (weights, irecords) in store_ext.make_sum_params(*args): delays_t = num.zeros_like(weights, dtype=num.float64) delays_s = dsource.times.astype(num.float64) pos = 6 t, s = sum_target(store.cstore, irecords, delays_t, delays_s, weights, pos, nthreads) # print benchmark.__str__(header=False) num.testing.assert_equal(t, s) benchmark.clear()
def test_sum_static(self): from pyrocko.gf import store_ext benchmark.show_factor = True store = gf.Store(self.get_qseis_store_dir()) store.open() src_length = 2 * km src_width = 5 * km ntargets = 1600 interp = ['nearest_neighbor', 'multilinear'] interpolation = interp[0] source = gf.RectangularSource( lat=0., lon=0., depth=5*km, north_shift=0., east_shift=0., width=src_width, length=src_length) static_target = gf.StaticTarget( north_shifts=5*km + random.rand(ntargets) * 5*km, east_shifts=0*km + random.rand(ntargets) * 5*km) targets = static_target.get_targets() dsource = source.discretize_basesource(store, targets[0]) source_coords_arr = dsource.coords5() mts_arr = dsource.m6s receiver_coords_arr = num.empty((len(targets), 5)) for itarget, target in enumerate(targets): receiver = target.receiver(store) receiver_coords_arr[itarget, :] = \ [receiver.lat, receiver.lon, receiver.north_shift, receiver.east_shift, receiver.depth] def sum_target(cstore, irecords, delays_t, delays_s, weights, pos, nthreads): @benchmark.labeled('sum-timeseries-np%d' % nthreads) def sum_timeseries(): nsummands = weights.size // ntargets res = num.zeros(ntargets) for t in range(ntargets): sl = slice(t*nsummands, (t+1) * nsummands) r = store_ext.store_sum( cstore, irecords[sl], delays_t[sl], weights[sl], pos, 1) res[t] = r[0] return res @benchmark.labeled('sum-static-np%d' % nthreads) def sum_static(): return store_ext.store_sum_static( cstore, irecords, delays_s, weights, pos, ntargets, nthreads) return sum_timeseries(), sum_static() args = (store.cstore, source_coords_arr, mts_arr, receiver_coords_arr, 'elastic10', interpolation, 0) benchmark.clear() for nthreads in [1, 2, 4]: for (weights, irecords) in store_ext.make_sum_params(*args): delays_t = num.zeros_like(weights, dtype=num.float64) delays_s = dsource.times.astype(num.float64) pos = 6 t, s = sum_target(store.cstore, irecords, delays_t, delays_s, weights, pos, nthreads) # print benchmark.__str__(header=False) num.testing.assert_equal(t, s) benchmark.clear()