def __init__(self, store_dir, step, shared, block_size=None, tmp=None, force=False): self.gfmapping = [ (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), {'un': (0, -1), 'ue': (3, -1), 'uz': (5, -1)}), (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), {'un': (1, -1), 'ue': (4, -1), 'uz': (6, -1)}), (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), {'un': (2, -1), 'uz': (7, -1)}), (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), {'un': (8, -1), 'uz': (9, -1)}), ] self.store = gf.store.Store(store_dir, 'w') if step == 0: block_size = (1, 1, self.store.config.ndistances) else: if block_size is None: block_size = (1, 1, 51) if len(self.store.config.ns) == 2: block_size = block_size[1:] gf.builder.Builder.__init__( self, self.store.config, step, block_size=block_size, force=force) baseconf = self.store.get_extra('qssp') conf = QSSPConfigFull(**baseconf.items()) conf.gf_directory = pjoin(store_dir, 'qssp_green') conf.earthmodel_1d = self.store.config.earthmodel_1d deltat = self.store.config.deltat if 'time_window' not in shared: d = self.store.make_timing_params( conf.time_region[0], conf.time_region[1], force=force) tmax = math.ceil(d['tmax'] / deltat) * deltat tmin = math.floor(d['tmin'] / deltat) * deltat shared['time_window'] = tmax - tmin shared['tstart'] = tmin self.tstart = shared['tstart'] conf.time_window = shared['time_window'] self.tmp = tmp if self.tmp is not None: util.ensuredir(self.tmp) util.ensuredir(conf.gf_directory) self.qssp_config = conf
def __init__(self, partial_db_path, output_db_path, gfdb_config, block_nx, qseis_config, cutting=None, extra_traces_dir=None, tag='', tmp=None ): GFDBBuilder.__init__(self, partial_db_path, output_db_path, gfdb_config, block_nx, extra_traces_dir=extra_traces_dir, tmp=tmp) self.qseis_config = qseis_config self.tag = tag self.cutting = cutting self.gfmapping = [ (MomentTensor( m=symmat6(1,0,0,1,0,0) ), {'r': (1, +1), 't': (4, +1), 'z': (6, +1) }), (MomentTensor( m=symmat6(0,0,0,0,1,1) ), {'r': (2, +1), 't': (5, +1), 'z': (7, +1) }), (MomentTensor( m=symmat6(0,0,1,0,0,0) ), {'r': (3, +1), 'z': (8, +1) }), ] if gfdb_config['ng'] == 10: self.gfmapping.append( (MomentTensor( m=symmat6(0,1,0,0,0,0) ), {'r': (9, +1), 'z': (10, +1) }), )
def preconstrain(self, x): d = self.get_parameter_dict(x) m6 = num.array([d.rmnn, d.rmee, d.rmdd, d.rmne, d.rmnd, d.rmed], dtype=num.float) m9 = mtm.symmat6(*m6) if self.mt_type == 'deviatoric': trace_m = num.trace(m9) m_iso = num.diag([trace_m / 3., trace_m / 3., trace_m / 3.]) m9 -= m_iso elif self.mt_type == 'dc': mt = mtm.MomentTensor(m=m9) m9 = mt.standard_decomposition()[1][2] m0_unscaled = math.sqrt(num.sum(m9.A**2)) / math.sqrt(2.) m9 /= m0_unscaled m6 = mtm.to6(m9) d.rmnn, d.rmee, d.rmdd, d.rmne, d.rmnd, d.rmed = m6 x = self.get_parameter_array(d) source = self.get_source(x) for t in self.targets: if (self.distance_min > num.asarray(t.distance_to(source))).any(): raise Forbidden() return x
def oldloadf(file): d = {} try: for line in file: if line.lstrip().startswith('#'): continue toks = line.split(' = ', 1) if len(toks) == 2: k, v = toks[0].strip(), toks[1].strip() if k in ('name', 'region', 'catalog', 'magnitude_type'): d[k] = v if k in (('latitude longitude magnitude depth duration ' 'north_shift east_shift ' 'mnn mee mdd mne mnd med strike1 dip1 rake1 ' 'strike2 dip2 rake2 duration').split()): d[k] = float(v) if k == 'time': d[k] = util.str_to_time(v) if k == 'tags': d[k] = [x.strip() for x in v.split(',')] if line.startswith('---'): d['have_separator'] = True break except Exception as e: raise FileParseError(e) if not d: raise EOF() if 'have_separator' in d and len(d) == 1: raise EmptyEvent() mt = None m6 = [d[x] for x in 'mnn mee mdd mne mnd med'.split() if x in d] if len(m6) == 6: mt = moment_tensor.MomentTensor(m=moment_tensor.symmat6(*m6)) else: sdr = [d[x] for x in 'strike1 dip1 rake1'.split() if x in d] if len(sdr) == 3: moment = 1.0 if 'moment' in d: moment = d['moment'] elif 'magnitude' in d: moment = moment_tensor.magnitude_to_moment(d['magnitude']) mt = moment_tensor.MomentTensor(strike=sdr[0], dip=sdr[1], rake=sdr[2], scalar_moment=moment) return (d.get('latitude', 0.0), d.get('longitude', 0.0), d.get('north_shift', 0.0), d.get('east_shift', 0.0), d.get('time', 0.0), d.get('name', ''), d.get('depth', None), d.get('magnitude', None), d.get('magnitude_type', None), d.get('region', None), d.get('catalog', None), mt, d.get('duration', None), d.get('tags', []))
def testChile(self): m_use = symmat6( 1.040, -0.030, -1.010, 0.227, -1.510, -0.120)*1e29*dynecm mt = MomentTensor(m_up_south_east=m_use) sdr = mt.both_strike_dip_rake() self.assertSame(sdr[0], (174., 73., 83.), 1., 'chile fail 1') self.assertSame(sdr[1], (18., 18., 112.), 1., 'chile fail 2')
def testChile(self): m_use = symmat6(1.040, -0.030, -1.010, 0.227, -1.510, -0.120) * 1e29 * dynecm mt = MomentTensor(m_up_south_east=m_use) sdr = mt.both_strike_dip_rake() self.assertSame(sdr[0], (174., 73., 83.), 1., 'chile fail 1') self.assertSame(sdr[1], (18., 18., 112.), 1., 'chile fail 2')
def __init__(self, *args): QFrame.__init__(self, *args) self._mt = mtm.MomentTensor(m=mtm.symmat6(1., -1., 2., 0., -2., 1.)) setupdata = [(LinValControl, 'Strike 1', 0., 360., 0., 0), (LinValControl, 'Dip 1', 0., 90., 0., 1), (LinValControl, 'Slip-Rake 1', -180., 180., 0., 2), (LinValControl, 'Strike 2', 0., 360., 0., 3), (LinValControl, 'Dip 2', 0., 90., 0., 4), (LinValControl, 'Slip-Rake 2', -180., 180., 0., 5)] layout = QGridLayout() self.setLayout(layout) val_controls = [] for irow, (typ, name, vmin, vmax, vcur, ind) in enumerate(setupdata): val_control = typ() val_control.setup(name, vmin, vmax, vcur, ind) val_controls.append(val_control) for icol, widget in enumerate(val_control.widgets()): layout.addWidget(widget, irow, icol) self.connect(val_control, SIGNAL('valchange(PyQt_PyObject,int)'), self.valchange) self.val_controls = val_controls self.adjust_values()
def __init__(self, *args): qw.QFrame.__init__(self, *args) self._mt = mtm.MomentTensor(m=mtm.symmat6(1., -1., 2., 0., -2., 1.)) setupdata = [ (LinValControl, 'Strike 1', 0., 360., 0., 0), (LinValControl, 'Dip 1', 0., 90., 0., 1), (LinValControl, 'Slip-Rake 1', -180., 180., 0., 2), (LinValControl, 'Strike 2', 0., 360., 0., 3), (LinValControl, 'Dip 2', 0., 90., 0., 4), (LinValControl, 'Slip-Rake 2', -180., 180., 0., 5)] layout = qw.QGridLayout() self.setLayout(layout) val_controls = [] for irow, (typ, name, vmin, vmax, vcur, ind) in enumerate(setupdata): val_control = typ() val_control.setup(name, vmin, vmax, vcur, ind) val_controls.append(val_control) for icol, widget in enumerate(val_control.widgets()): layout.addWidget(widget, irow, icol) val_control.valchanged.connect( self.valchange) self.val_controls = val_controls self.adjust_values()
def test_random_mts(self): nx = 2 for x in range(nx): m6 = num.random.random(6)*2.-1. m = mtm.symmat6(*m6) mt = mtm.MomentTensor(m=m) self.compare_beachball(mt)
def test_specific_mts(self): for m6 in [(1., 0., 0., 0., 0., 0.), (0., 1., 0., 0., 0., 0.), (0., 0., 1., 0., 0., 0.), (0., 0., 0., 1., 0., 0.), (0., 0., 0., 0., 1., 0.), (0., 0., 0., 0., 0., 1.)]: m = mtm.symmat6(*m6) mt = mtm.MomentTensor(m=m) self.compare_beachball(mt)
def __init__(self, store_dir, step, shared, block_size=None, tmp=None ): self.gfmapping = [ (MomentTensor( m=symmat6(1,0,0,1,0,0) ), {'r': (0, +1), 't': (3, +1), 'z': (5, +1) }), (MomentTensor( m=symmat6(0,0,0,0,1,1) ), {'r': (1, +1), 't': (4, +1), 'z': (6, +1) }), (MomentTensor( m=symmat6(0,0,1,0,0,0) ), {'r': (2, +1), 'z': (7, +1) }), (MomentTensor( m=symmat6(0,1,0,0,0,0) ), {'r': (8, +1), 'z': (9, +1) })] self.store = gf.store.Store(store_dir, 'w') if block_size is None: block_size = (1,1,100) if len(self.store.config.ns) == 2: block_size = block_size[1:] gf.builder.Builder.__init__(self, self.store.config, step, block_size=block_size) baseconf = self.store.get_extra('qseis') conf = QSeisConfigFull(**baseconf.items()) conf.earthmodel_1d = self.store.config.earthmodel_1d deltat = 1.0/self.gf_config.sample_rate if 'time_window_min' not in shared: d = self.store.make_timing_params(conf.time_region[0], conf.time_region[1]) shared['time_window_min'] = d['tlenmax_vred'] shared['time_start'] = d['tmin_vred'] shared['time_reduction_velocity'] = d['vred'] / km time_window_min = shared['time_window_min'] conf.time_start = shared['time_start'] conf.time_reduction_velocity = shared['time_reduction_velocity'] conf.nsamples = nextpow2(int(round(time_window_min / deltat)) + 1) conf.time_window = (conf.nsamples-1)*deltat self.qseis_config = conf self.tmp = tmp if self.tmp is not None: util.ensuredir(self.tmp)
def __init__(self, partial_db_path, output_db_path, gfdb_config, block_nx, qseis_config, cutting=None, extra_traces_dir=None, tag='', tmp=None): GFDBBuilder.__init__(self, partial_db_path, output_db_path, gfdb_config, block_nx, extra_traces_dir=extra_traces_dir, tmp=tmp) self.qseis_config = qseis_config self.tag = tag self.cutting = cutting self.gfmapping = [ (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), { 'r': (1, +1), 't': (4, +1), 'z': (6, +1) }), (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), { 'r': (2, +1), 't': (5, +1), 'z': (7, +1) }), (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), { 'r': (3, +1), 'z': (8, +1) }), ] if gfdb_config['ng'] == 10: self.gfmapping.append((MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), { 'r': (9, +1), 'z': (10, +1) }), )
def test_random_mts(self, **kwargs): nx = 10 for x in range(nx): m6 = num.random.random(6) * 2. - 1. m = mtm.symmat6(*m6) mt = mtm.MomentTensor(m=m) self.compare_beachball(mt, **kwargs) for x in range(nx): mt = mtm.MomentTensor.random_mt() self.compare_beachball(mt, **kwargs)
def _parse_mt_page(self, page): d = {} for k in 'Scale', 'Mrr', 'Mtt', 'Mpp', 'Mrt', 'Mrp', 'Mtp': r = k.encode('ascii') + br'\s*=?\s*(\S+)' m = re.search(r, page) if m: s = m.group(1).replace(b'10**', b'1e') d[k.lower()] = float(s) m = symmat6(*(d[x] for x in 'mrr mtt mpp mrt mrp mtp'.split())) m *= d['scale'] mt = MomentTensor(m_up_south_east=m) return mt
def _parse_mt_page(self, page): d = {} for k in 'Scale', 'Mrr', 'Mtt', 'Mpp', 'Mrt', 'Mrp', 'Mtp': r = k+r'\s*=?\s*(\S+)' m = re.search(r, page) if m: s = m.group(1).replace('10**', '1e') d[k.lower()] = float(s) m = symmat6(*(d[x] for x in 'mrr mtt mpp mrt mrp mtp'.split())) m *= d['scale'] mt = MomentTensor(m_up_south_east=m) return mt
def work_block(self, index): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = \ self.get_block_extents(index) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = \ self.get_block_extents(index) conf = copy.deepcopy(self.qseis_config) logger.info('Starting block %i / %i' % (index+1, self.nblocks)) conf.source_depth = float(sz/km) conf.receiver_depth = float(rz/km) runner = QSeisRunner(tmp=self.tmp) dx = self.gf_config.distance_delta distances = num.linspace(firstx, firstx + (nx-1)*dx, nx).tolist() if distances[-1] < self.gf_config.distance_max: # add global max distance, because qseis does some adjustments with # this value distances.append(self.gf_config.distance_max) mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), {'r': (0, +1), 't': (3, +1), 'z': (5, +1)}) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), {'r': (1, +1), 't': (4, +1), 'z': (6, +1)}) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), {'r': (2, +1), 'z': (7, +1)}) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), {'r': (8, +1), 'z': (9, +1)}) component_scheme = self.store.config.component_scheme off = 0 if component_scheme == 'elastic8': off = 8 elif component_scheme == 'elastic10': off = 10 msf = (None, { 'fz.tr': (off+0, +1), 'fh.tr': (off+1, +1), 'fh.tt': (off+2, -1), 'fz.tz': (off+3, +1), 'fh.tz': (off+4, +1)}) if component_scheme == 'elastic5': gfsneeded = (0, 0, 0, 0, 1, 1) gfmapping = [msf] elif component_scheme == 'elastic8': gfsneeded = (1, 1, 1, 1, 0, 0) gfmapping = [mmt1, mmt2, mmt3] elif component_scheme == 'elastic10': gfsneeded = (1, 1, 1, 1, 0, 0) gfmapping = [mmt1, mmt2, mmt3, mmt4] elif component_scheme == 'elastic13': gfsneeded = (1, 1, 1, 1, 1, 1) gfmapping = [mmt1, mmt2, mmt3, msf] elif component_scheme == 'elastic15': gfsneeded = (1, 1, 1, 1, 1, 1) gfmapping = [mmt1, mmt2, mmt3, mmt4, msf] conf.gf_sw_source_types = gfsneeded conf.receiver_distances = [d/km for d in distances] conf.receiver_azimuths = [0.0] * len(distances) for mt, gfmap in gfmapping: if mt: m = mt.m() f = float conf.source_mech = QSeisSourceMechMT( mnn=f(m[0, 0]), mee=f(m[1, 1]), mdd=f(m[2, 2]), mne=f(m[0, 1]), mnd=f(m[0, 2]), med=f(m[1, 2])) else: conf.source_mech = None if any(conf.gf_sw_source_types) or conf.source_mech is not None: runner.run(conf) if any(c in gfmap for c in qseis_components): rawtraces = runner.get_traces('seis') else: rawtraces = runner.get_traces('gf') interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: continue x = tr.meta['distance'] if x > firstx + (nx-1)*dx: continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) if conf.cut: tmin = self.store.t(conf.cut[0], args[:-1]) tmax = self.store.t(conf.cut[1], args[:-1]) if None in (tmin, tmax): continue tr.chop(tmin, tmax) tmin = tr.tmin tmax = tr.tmax if conf.fade: ta, tb, tc, td = [ self.store.t(v, args[:-1]) for v in conf.fade] if None in (ta, tb, tc, td): continue if not (ta <= tb and tb <= tc and tc <= td): raise QSeisError( 'invalid fade configuration') t = tr.get_xdata() fin = num.interp(t, [ta, tb], [0., 1.]) fout = num.interp(t, [tc, td], [1., 0.]) anti_fin = 1. - fin anti_fout = 1. - fout y = tr.ydata sum_anti_fin = num.sum(anti_fin) sum_anti_fout = num.sum(anti_fout) if sum_anti_fin != 0.0: yin = num.sum(anti_fin*y) / sum_anti_fin else: yin = 0.0 if sum_anti_fout != 0.0: yout = num.sum(anti_fout*y) / sum_anti_fout else: yout = 0.0 y2 = anti_fin*yin + fin*fout*y + anti_fout*yout if conf.relevel_with_fade_in: y2 -= yin tr.set_ydata(y2) gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn('%i insertions skipped (duplicates)' % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() conf.gf_sw_source_types = (0, 0, 0, 0, 0, 0) logger.info('Done with block %i / %i' % (index+1, self.nblocks))
def work_block(self, index): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = \ self.get_block_extents(index) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = \ self.get_block_extents(index) logger.info('Starting block %i / %i' % (index + 1, self.nblocks)) dx = self.gf_config.distance_delta distances = num.linspace(firstx, firstx + (nx - 1) * dx, nx).tolist() mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), { 'r': (0, +1), 't': (3, +1), 'z': (5, +1) }) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), { 'r': (1, +1), 't': (4, +1), 'z': (6, +1) }) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), { 'r': (2, +1), 'z': (7, +1) }) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), { 'r': (8, +1), 'z': (9, +1) }) mmt0 = (MomentTensor(m=symmat6(1, 1, 1, 0, 0, 0)), { 'r': (0, +1), 'z': (1, +1) }) component_scheme = self.store.config.component_scheme if component_scheme == 'elastic8': gfmapping = [mmt1, mmt2, mmt3] elif component_scheme == 'elastic10': gfmapping = [mmt1, mmt2, mmt3, mmt4] elif component_scheme == 'elastic2': gfmapping = [mmt0] elif component_scheme == 'elastic5': gfmapping = [((1., 1., 0.), { 'r': (1, +1), 'z': (4, +1), 't': (2, +1) }), ((0., 0., 1.), { 'r': (0, +1), 'z': (3, +1) })] else: raise gf.UnavailableScheme( 'fomosto backend "ahfullgreen" cannot handle component scheme ' '"%s"' % component_scheme) for source_mech, gfmap in gfmapping: rawtraces = make_traces( self.store.config.earthmodel_1d.require_homogeneous(), source_mech, 1.0 / self.store.config.sample_rate, distances, num.zeros_like(distances), sz, rz) interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: logger.debug('%s not in gfmap' % tr.channel) continue x = tr.meta['distance'] if x > firstx + (nx - 1) * dx: logger.error("x out of range") continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) tr = tr.snap() gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn('%i insertions skipped (duplicates)' % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() logger.info('Done with block %i / %i' % (index + 1, self.nblocks))
"mt3", "mt4", "mt5", "dc?", "_", "_", ] order_mapping = dict(zip(order, range(len(order)))) wanted = ["name", "lat", "lon", "depth"] events = [] with open(fn, "r") as f: for line in f.readlines(): data = line.split() kwargs = {} for kw in wanted: val = data[order_mapping[kw]] val = float(val) if kw is not "name" else val val = float(val) * 1000.0 if kw is "depth" else val kwargs.update({kw: val}) time = str_to_time("%s %s" % (data[order_mapping["date"]].replace("/", "-"), data[order_mapping["time"]])) kwargs.update({"time": time}) m = num.array([num.float(data[order_mapping["mt%i" % i]]) for i in range(6)]) mt = MomentTensor(m=symmat6(*m) * float(data[order_mapping["moment"]])) kwargs.update({"moment_tensor": mt}) e = Event(**kwargs) events.append(e) dump_events(events, "events2008_mt.pf")
def pyrocko_moment_tensor(self): return mt.MomentTensor(m=mt.symmat6(*self.m6_astuple))
def pyrocko_moment_tensor(self): m0 = self.moment return mt.MomentTensor(m=mt.symmat6(m0, m0, m0, 0., 0., 0.))
def oldloadf(file): d = {} try: for line in file: if line.lstrip().startswith('#'): continue toks = line.split(' = ', 1) if len(toks) == 2: k, v = toks[0].strip(), toks[1].strip() if k in ('name', 'region', 'catalog', 'magnitude_type'): d[k] = v if k in (('latitude longitude magnitude depth duration ' 'mnn mee mdd mne mnd med strike1 dip1 rake1 ' 'strike2 dip2 rake2 duration').split()): d[k] = float(v) if k == 'time': d[k] = util.str_to_time(v) if line.startswith('---'): d['have_separator'] = True break except Exception as e: raise FileParseError(e) if not d: raise EOF() if 'have_separator' in d and len(d) == 1: raise EmptyEvent() mt = None m6 = [d[x] for x in 'mnn mee mdd mne mnd med'.split() if x in d] if len(m6) == 6: mt = moment_tensor.MomentTensor(m=moment_tensor.symmat6(*m6)) else: sdr = [d[x] for x in 'strike1 dip1 rake1'.split() if x in d] if len(sdr) == 3: moment = 1.0 if 'moment' in d: moment = d['moment'] elif 'magnitude' in d: moment = moment_tensor.magnitude_to_moment(d['magnitude']) mt = moment_tensor.MomentTensor( strike=sdr[0], dip=sdr[1], rake=sdr[2], scalar_moment=moment) return ( d.get('latitude', 0.0), d.get('longitude', 0.0), d.get('time', 0.0), d.get('name', ''), d.get('depth', None), d.get('magnitude', None), d.get('magnitude_type', None), d.get('region', None), d.get('catalog', None), mt, d.get('duration', None))
def work_block(self, index): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = \ self.get_block_extents(index) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = \ self.get_block_extents(index) logger.info('Starting block %i / %i' % (index+1, self.nblocks)) dx = self.gf_config.distance_delta distances = num.linspace(firstx, firstx + (nx-1)*dx, nx).tolist() mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), {'r': (0, +1), 't': (3, +1), 'z': (5, +1)}) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), {'r': (1, +1), 't': (4, +1), 'z': (6, +1)}) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), {'r': (2, +1), 'z': (7, +1)}) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), {'r': (8, +1), 'z': (9, +1)}) mmt0 = (MomentTensor(m=symmat6(1, 1, 1, 0, 0, 0)), {'r': (0, +1), 'z': (1, +1)}) component_scheme = self.store.config.component_scheme if component_scheme == 'elastic8': gfmapping = [mmt1, mmt2, mmt3] elif component_scheme == 'elastic10': gfmapping = [mmt1, mmt2, mmt3, mmt4] elif component_scheme == 'elastic2': gfmapping = [mmt0] elif component_scheme == 'elastic5': gfmapping = [ ((1., 1., 0.), {'r': (1, +1), 'z': (4, +1), 't': (2, +1)}), ((0., 0., 1.), {'r': (0, +1), 'z': (3, +1)})] else: raise gf.UnavailableScheme( 'fomosto backend "ahfullgreen" cannot handle component scheme ' '"%s"' % component_scheme) for source_mech, gfmap in gfmapping: rawtraces = make_traces( self.store.config.earthmodel_1d.require_homogeneous(), source_mech, 1.0/self.store.config.sample_rate, distances, num.zeros_like(distances), sz, rz) interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: logger.debug('%s not in gfmap' % tr.channel) continue x = tr.meta['distance'] if x > firstx + (nx-1)*dx: logger.error("x out of range") continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) tr = tr.snap() gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn('%i insertions skipped (duplicates)' % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() logger.info('Done with block %i / %i' % (index+1, self.nblocks))
def work_block(self, index): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = \ self.get_block_extents(index) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = \ self.get_block_extents(index) conf = copy.deepcopy(self.ahfullgreen_config) logger.info('Starting block %i / %i' % (index + 1, self.nblocks)) conf.source_depth = float(sz) conf.receiver_depth = float(rz) runner = AhfullgreenRunner(tmp=self.tmp) dx = self.gf_config.distance_delta distances = num.linspace(firstx, firstx + (nx - 1) * dx, nx).tolist() mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), { 'r': (0, +1), 't': (3, +1), 'z': (5, +1) }) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), { 'r': (1, +1), 't': (4, +1), 'z': (6, +1) }) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), { 'r': (2, +1), 'z': (7, +1) }) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), { 'r': (8, +1), 'z': (9, +1) }) component_scheme = self.store.config.component_scheme if component_scheme == 'elastic8': gfmapping = [mmt1, mmt2, mmt3] if component_scheme == 'elastic10': gfmapping = [mmt1, mmt2, mmt3, mmt4] conf.receiver_distances = distances for mt, gfmap in gfmapping: if mt: conf.source_mech = mt else: conf.source_mech = None if conf.source_mech is not None: runner.run(conf) rawtraces = runner.get_traces() interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: logger.debug('%s not in gfmap' % tr.channel) continue x = tr.meta['distance'] if x > firstx + (nx - 1) * dx: logger.error("x out of range") continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) if conf.cut: tmin = self.store.t(conf.cut[0], args[:-1]) tmin = math.floor(tmin / conf.deltat) * conf.deltat tmax = self.store.t(conf.cut[1], args[:-1]) tmax = math.ceil(tmax / conf.deltat) * conf.deltat if None in (tmin, tmax): continue tr.chop(tmin, tmax) tr = tr.snap() if conf.fade: ta, tb, tc, td = [ self.store.t(v, args[:-1]) for v in conf.fade ] if None in (ta, tb, tc, td): continue if not (ta <= tb and tb <= tc and tc <= td): raise AhfullgreenError( 'invalid fade configuration') t = tr.get_xdata() fin = num.interp(t, [ta, tb], [0., 1.]) fout = num.interp(t, [tc, td], [1., 0.]) anti_fin = 1. - fin anti_fout = 1. - fout y = tr.ydata sum_anti_fin = num.sum(anti_fin) sum_anti_fout = num.sum(anti_fout) if sum_anti_fin != 0.0: yin = num.sum(anti_fin * y) / sum_anti_fin else: yin = 0.0 if sum_anti_fout != 0.0: yout = num.sum(anti_fout * y) / sum_anti_fout else: yout = 0.0 y2 = anti_fin * yin + fin * fout * y + anti_fout * yout if conf.relevel_with_fade_in: y2 -= yin tr.set_ydata(y2) gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn('%i insertions skipped (duplicates)' % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() conf.gf_sw_source_types = (0, 0, 0, 0, 0, 0) logger.info('Done with block %i / %i' % (index + 1, self.nblocks))
class Event(Object): '''Seismic event representation :param lat: latitude of hypocenter (default 0.0) :param lon: longitude of hypocenter (default 0.0) :param time: origin time as float in seconds after '1970-01-01 00:00:00 :param name: event identifier as string (optional) :param depth: source depth (optional) :param magnitude: magnitude of event (optional) :param region: source region (optional) :param catalog: name of catalog that lists this event (optional) :param moment_tensor: moment tensor as :py:class:`moment_tensor.MomentTensor` instance (optional) :param duration: source duration as float (optional) ''' lat = Float.T(default=0.0) lon = Float.T(default=0.0) time = Timestamp.T(default=util.str_to_time('1970-01-01 00:00:00')) name = String.T(default='', optional=True) depth = Float.T(optional=True) magnitude = Float.T(optional=True) magnitude_type = String.T(optional=True) region = String.T(optional=True) catalog = String.T(optional=True) moment_tensor = moment_tensor.MomentTensor.T(optional=True) duration = Float.T(optional=True) def __init__(self, lat=0., lon=0., time=0., name='', depth=None, magnitude=None, magnitude_type=None, region=None, load=None, loadf=None, catalog=None, moment_tensor=None, duration=None): vals = None if load is not None: vals = Event.oldload(load) elif loadf is not None: vals = Event.oldloadf(loadf) if vals: lat, lon, time, name, depth, magnitude, magnitude_type, region, \ catalog, moment_tensor, duration = vals Object.__init__(self, lat=lat, lon=lon, time=time, name=name, depth=depth, magnitude=magnitude, magnitude_type=magnitude_type, region=region, catalog=catalog, moment_tensor=moment_tensor, duration=duration) def time_as_string(self): return util.time_to_str(self.time) def set_name(self, name): self.name = name def olddump(self, filename): file = open(filename, 'w') self.olddumpf(file) file.close() def olddumpf(self, file): file.write('name = %s\n' % self.name) file.write('time = %s\n' % util.time_to_str(self.time)) if self.lat is not None: file.write('latitude = %.12g\n' % self.lat) if self.lon is not None: file.write('longitude = %.12g\n' % self.lon) if self.magnitude is not None: file.write('magnitude = %g\n' % self.magnitude) file.write('moment = %g\n' % moment_tensor.magnitude_to_moment(self.magnitude)) if self.magnitude_type is not None: file.write('magnitude_type = %s\n' % self.magnitude_type) if self.depth is not None: file.write('depth = %.10g\n' % self.depth) if self.region is not None: file.write('region = %s\n' % self.region) if self.catalog is not None: file.write('catalog = %s\n' % self.catalog) if self.moment_tensor is not None: m = self.moment_tensor.m() sdr1, sdr2 = self.moment_tensor.both_strike_dip_rake() file.write( ('mnn = %g\nmee = %g\nmdd = %g\nmne = %g\nmnd = %g\nmed = %g\n' 'strike1 = %g\ndip1 = %g\nrake1 = %g\n' 'strike2 = %g\ndip2 = %g\nrake2 = %g\n') % ((m[0, 0], m[1, 1], m[2, 2], m[0, 1], m[0, 2], m[1, 2]) + sdr1 + sdr2)) if self.duration is not None: file.write('duration = %g\n' % self.duration) @staticmethod def unique(events, deltat=10., group_cmp=(lambda a, b: cmp(a.catalog, b.catalog))): groups = Event.grouped(events, deltat) events = [] for group in groups: if group: group.sort(group_cmp) events.append(group[-1]) return events @staticmethod def grouped(events, deltat=10.): events = list(events) groups = [] for ia, a in enumerate(events): groups.append([]) haveit = False for ib, b in enumerate(events[:ia]): if abs(b.time - a.time) < deltat: groups[ib].append(a) haveit = True break if not haveit: groups[ia].append(a) groups = [g for g in groups if g] groups.sort(key=lambda g: sum(e.time for e in g) / len(g)) return groups @staticmethod def dump_catalog(events, filename=None, stream=None): if filename is not None: file = open(filename, 'w') else: file = stream try: i = 0 for ev in events: ev.olddumpf(file) file.write('--------------------------------------------\n') i += 1 finally: if filename is not None: file.close() @staticmethod def oldload(filename): with open(filename, 'r') as file: return Event.oldloadf(file) @staticmethod def oldloadf(file): d = {} try: for line in file: if line.lstrip().startswith('#'): continue toks = line.split(' = ', 1) if len(toks) == 2: k, v = toks[0].strip(), toks[1].strip() if k in ('name', 'region', 'catalog', 'magnitude_type'): d[k] = v if k in (('latitude longitude magnitude depth duration ' 'mnn mee mdd mne mnd med strike1 dip1 rake1 ' 'strike2 dip2 rake2 duration').split()): d[k] = float(v) if k == 'time': d[k] = util.str_to_time(v) if line.startswith('---'): d['have_separator'] = True break except Exception, e: raise FileParseError(e) if not d: raise EOF() if 'have_separator' in d and len(d) == 1: raise EmptyEvent() mt = None m6 = [d[x] for x in 'mnn mee mdd mne mnd med'.split() if x in d] if len(m6) == 6: mt = moment_tensor.MomentTensor(m=moment_tensor.symmat6(*m6)) else: sdr = [d[x] for x in 'strike1 dip1 rake1'.split() if x in d] if len(sdr) == 3: moment = 1.0 if 'moment' in d: moment = d['moment'] elif 'magnitude' in d: moment = moment_tensor.magnitude_to_moment(d['magnitude']) mt = moment_tensor.MomentTensor(strike=sdr[0], dip=sdr[1], rake=sdr[2], scalar_moment=moment) return (d.get('latitude', 0.0), d.get('longitude', 0.0), d.get('time', 0.0), d.get('name', ''), d.get('depth', None), d.get('magnitude', None), d.get('magnitude_type', None), d.get('region', None), d.get('catalog', None), mt, d.get('duration', None))
def work_block(self, iblock): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = \ self.get_block_extents(iblock) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = \ self.get_block_extents(iblock) source_depth = float(sz / km) conf_s = copy.deepcopy(self.qseis_s_config) conf_r = copy.deepcopy(self.qseis_r_config) gf_directory = op.abspath(self.qseis_baseconf.gf_directory) fk_path = op.join(gf_directory, 'green_%.3fkm.fk' % source_depth) info_path = op.join(gf_directory, 'green_%.3fkm.info' % source_depth) conf_s.fk_path = fk_path conf_s.info_path = info_path conf_r.fk_path = fk_path conf_r.info_path = info_path if self.step == 0 and os.path.isfile(fk_path): logger.info('Skipping step %i / %i, block %i / %i' '(GF already exists)' % (self.step + 1, self.nsteps, iblock + 1, self.nblocks)) return logger.info('Starting step %i / %i, block %i / %i' % (self.step + 1, self.nsteps, iblock + 1, self.nblocks)) dx = self.gf_config.distance_delta conf_r.wavelet_duration = 0.001 * self.gf_config.sample_rate if self.step == 0: conf_s.source_depth = source_depth runner = QSeisSRunner(tmp=self.tmp) runner.run(conf_s) else: conf_r.receiver = QSeisRReceiver(lat=90 - firstx * cake.m2d, lon=180., tstart=0.0, distance=firstx) conf_r.source = QSeis2dSource(lat=90 - 0.001 * dx * cake.m2d, lon=0.0, depth=source_depth) runner = QSeisRRunner(tmp=self.tmp) mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), { 'r': (0, 1), 't': (3, 1), 'z': (5, 1) }) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), { 'r': (1, 1), 't': (4, 1), 'z': (6, 1) }) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), { 'r': (2, 1), 'z': (7, 1) }) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), { 'r': (8, 1), 'z': (9, 1) }) gfmapping = [mmt1, mmt2, mmt3, mmt4] for mt, gfmap in gfmapping: if mt: m = mt.m() f = float conf_r.source_mech = QSeisRSourceMechMT(mnn=f(m[0, 0]), mee=f(m[1, 1]), mdd=f(m[2, 2]), mne=f(m[0, 1]), mnd=f(m[0, 2]), med=f(m[1, 2])) else: conf_r.source_mech = None if conf_r.source_mech is not None: runner.run(conf_r) rawtraces = runner.get_traces() interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: continue x = tr.meta['distance'] if x > firstx + (nx - 1) * dx: continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) if self.qseis_baseconf.cut: tmin = self.store.t(self.qseis_baseconf.cut[0], args[:-1]) tmax = self.store.t(self.qseis_baseconf.cut[1], args[:-1]) if None in (tmin, tmax): continue tr.chop(tmin, tmax) tmin = tr.tmin tmax = tr.tmax if self.qseis_baseconf.fade: ta, tb, tc, td = [ self.store.t(v, args[:-1]) for v in self.qseis_baseconf.fade ] if None in (ta, tb, tc, td): continue if not (ta <= tb and tb <= tc and tc <= td): raise QSeis2dError( 'invalid fade configuration') t = tr.get_xdata() fin = num.interp(t, [ta, tb], [0., 1.]) fout = num.interp(t, [tc, td], [1., 0.]) anti_fin = 1. - fin anti_fout = 1. - fout y = tr.ydata sum_anti_fin = num.sum(anti_fin) sum_anti_fout = num.sum(anti_fout) if sum_anti_fin != 0.0: yin = num.sum(anti_fin * y) / sum_anti_fin else: yin = 0.0 if sum_anti_fout != 0.0: yout = num.sum(anti_fout * y) / sum_anti_fout else: yout = 0.0 y2 = anti_fin * yin + \ fin * fout * y + \ anti_fout * yout if self.qseis_baseconf.relevel_with_fade_in: y2 -= yin tr.set_ydata(y2) gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn('%i insertions skipped (duplicates)' % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() logger.info('Done with step %i / %i, block %i / %i' % (self.step + 1, self.nsteps, iblock + 1, self.nblocks))
fig = plt.figure() axes1 = fig.add_subplot(2, 3, 1, aspect=1.0) axes2 = fig.add_subplot(2, 3, 2, aspect=1.0) axes3 = fig.add_subplot(2, 3, 3, aspect=1.0) axes4 = fig.add_subplot(2, 3, 4, projection="3d", aspect=1.0) axes5 = fig.add_subplot(2, 3, 5, projection="3d", aspect=1.0) try: import mopad except ImportError: mopad = None for x in range(nx): # m6 = num.random.random(6)*2.-1. m6 = (-2.0, -2.0, -2.0, 0.0, 0.0, 0.0) m = mtm.symmat6(*m6) mt = mtm.MomentTensor(m=m) # mt = mt.deviatoric() # strike = 270. # dip = 0.0 # rake = 0.01 # strike = 360. # dip = 28.373841741182012 # rake = 90. # mt = mtm.MomentTensor( # strike=strike, # dip=dip, # rake=rake)
def pyrocko_moment_tensor(self): return mtm.MomentTensor(m=mtm.symmat6(*self.m6_astuple) * self.moment)
def __init__(self, *args): qw.QWidget.__init__(self, *args) mt = mtm.MomentTensor(m=mtm.symmat6(1., -1., 2., 0., -2., 1.)) self._mt = mt self.set_moment_tensor(mt)
def __init__(self, *args): QWidget.__init__(self, *args) mt = mtm.MomentTensor(m=mtm.symmat6(1., -1., 2., 0., -2., 1.)) print mt self._mt = mt self.set_moment_tensor(mt)
def scaled_m6(self): m9 = mtm.symmat6(*self.m6) m0_unscaled = math.sqrt(num.sum(m9.A ** 2)) / math.sqrt(2.) m9 /= m0_unscaled m6 = mtm.to6(m9) return m6
def work_block(self, index): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = \ self.get_block_extents(index) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = \ self.get_block_extents(index) conf = copy.deepcopy(self.qseis_config) logger.info('Starting block %i / %i' % (index + 1, self.nblocks)) conf.source_depth = float(sz / km) conf.receiver_depth = float(rz / km) runner = QSeisRunner(tmp=self.tmp) dx = self.gf_config.distance_delta distances = num.linspace(firstx, firstx + (nx - 1) * dx, nx).tolist() if distances[-1] < self.gf_config.distance_max: # add global max distance, because qseis does some adjustments with # this value distances.append(self.gf_config.distance_max) mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), { 'r': (0, +1), 't': (3, +1), 'z': (5, +1) }) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), { 'r': (1, +1), 't': (4, +1), 'z': (6, +1) }) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), { 'r': (2, +1), 'z': (7, +1) }) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), { 'r': (8, +1), 'z': (9, +1) }) component_scheme = self.store.config.component_scheme off = 0 if component_scheme == 'elastic8': off = 8 elif component_scheme == 'elastic10': off = 10 msf = (None, { 'fz.tr': (off + 0, +1), 'fh.tr': (off + 1, +1), 'fh.tt': (off + 2, -1), 'fz.tz': (off + 3, +1), 'fh.tz': (off + 4, +1) }) if component_scheme == 'elastic5': gfsneeded = (0, 0, 0, 0, 1, 1) gfmapping = [msf] elif component_scheme == 'elastic8': gfsneeded = (1, 1, 1, 1, 0, 0) gfmapping = [mmt1, mmt2, mmt3] elif component_scheme == 'elastic10': gfsneeded = (1, 1, 1, 1, 0, 0) gfmapping = [mmt1, mmt2, mmt3, mmt4] elif component_scheme == 'elastic13': gfsneeded = (1, 1, 1, 1, 1, 1) gfmapping = [mmt1, mmt2, mmt3, msf] elif component_scheme == 'elastic15': gfsneeded = (1, 1, 1, 1, 1, 1) gfmapping = [mmt1, mmt2, mmt3, mmt4, msf] conf.gf_sw_source_types = gfsneeded conf.receiver_distances = [d / km for d in distances] conf.receiver_azimuths = [0.0] * len(distances) for mt, gfmap in gfmapping: if mt: m = mt.m() f = float conf.source_mech = QSeisSourceMechMT(mnn=f(m[0, 0]), mee=f(m[1, 1]), mdd=f(m[2, 2]), mne=f(m[0, 1]), mnd=f(m[0, 2]), med=f(m[1, 2])) else: conf.source_mech = None if any(conf.gf_sw_source_types) or conf.source_mech is not None: runner.run(conf) if any(c in gfmap for c in qseis_components): rawtraces = runner.get_traces('seis') else: rawtraces = runner.get_traces('gf') interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: continue x = tr.meta['distance'] if x > firstx + (nx - 1) * dx: continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) if conf.cut: tmin = self.store.t(conf.cut[0], args[:-1]) tmax = self.store.t(conf.cut[1], args[:-1]) if None in (tmin, tmax): continue tr.chop(tmin, tmax) tmin = tr.tmin tmax = tr.tmax if conf.fade: ta, tb, tc, td = [ self.store.t(v, args[:-1]) for v in conf.fade ] if None in (ta, tb, tc, td): continue if not (ta <= tb and tb <= tc and tc <= td): raise QSeisError('invalid fade configuration') t = tr.get_xdata() fin = num.interp(t, [ta, tb], [0., 1.]) fout = num.interp(t, [tc, td], [1., 0.]) anti_fin = 1. - fin anti_fout = 1. - fout y = tr.ydata sum_anti_fin = num.sum(anti_fin) sum_anti_fout = num.sum(anti_fout) if sum_anti_fin != 0.0: yin = num.sum(anti_fin * y) / sum_anti_fin else: yin = 0.0 if sum_anti_fout != 0.0: yout = num.sum(anti_fout * y) / sum_anti_fout else: yout = 0.0 y2 = anti_fin * yin + fin * fout * y + anti_fout * yout if conf.relevel_with_fade_in: y2 -= yin tr.set_ydata(y2) gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn('%i insertions skipped (duplicates)' % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() conf.gf_sw_source_types = (0, 0, 0, 0, 0, 0) logger.info('Done with block %i / %i' % (index + 1, self.nblocks))
def work_block(self, index): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = self.get_block_extents(index) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = self.get_block_extents(index) conf = copy.deepcopy(self.ahfullgreen_config) logger.info("Starting block %i / %i" % (index + 1, self.nblocks)) conf.source_depth = float(sz) conf.receiver_depth = float(rz) runner = AhfullgreenRunner(tmp=self.tmp) dx = self.gf_config.distance_delta distances = num.linspace(firstx, firstx + (nx - 1) * dx, nx).tolist() mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), {"r": (0, +1), "t": (3, +1), "z": (5, +1)}) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), {"r": (1, +1), "t": (4, +1), "z": (6, +1)}) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), {"r": (2, +1), "z": (7, +1)}) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), {"r": (8, +1), "z": (9, +1)}) component_scheme = self.store.config.component_scheme if component_scheme == "elastic8": gfmapping = [mmt1, mmt2, mmt3] if component_scheme == "elastic10": gfmapping = [mmt1, mmt2, mmt3, mmt4] conf.receiver_distances = distances for mt, gfmap in gfmapping: if mt: conf.source_mech = mt else: conf.source_mech = None if conf.source_mech is not None: runner.run(conf) rawtraces = runner.get_traces() interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: logger.debug("%s not in gfmap" % tr.channel) continue x = tr.meta["distance"] if x > firstx + (nx - 1) * dx: logger.error("x out of range") continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) if conf.cut: tmin = self.store.t(conf.cut[0], args[:-1]) tmin = math.floor(tmin / conf.deltat) * conf.deltat tmax = self.store.t(conf.cut[1], args[:-1]) tmax = math.ceil(tmax / conf.deltat) * conf.deltat if None in (tmin, tmax): continue tr.chop(tmin, tmax) tr = tr.snap() if conf.fade: ta, tb, tc, td = [self.store.t(v, args[:-1]) for v in conf.fade] if None in (ta, tb, tc, td): continue if not (ta <= tb and tb <= tc and tc <= td): raise AhfullgreenError("invalid fade configuration") t = tr.get_xdata() fin = num.interp(t, [ta, tb], [0.0, 1.0]) fout = num.interp(t, [tc, td], [1.0, 0.0]) anti_fin = 1.0 - fin anti_fout = 1.0 - fout y = tr.ydata sum_anti_fin = num.sum(anti_fin) sum_anti_fout = num.sum(anti_fout) if sum_anti_fin != 0.0: yin = num.sum(anti_fin * y) / sum_anti_fin else: yin = 0.0 if sum_anti_fout != 0.0: yout = num.sum(anti_fout * y) / sum_anti_fout else: yout = 0.0 y2 = anti_fin * yin + fin * fout * y + anti_fout * yout if conf.relevel_with_fade_in: y2 -= yin tr.set_ydata(y2) gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn("%i insertions skipped (duplicates)" % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() conf.gf_sw_source_types = (0, 0, 0, 0, 0, 0) logger.info("Done with block %i / %i" % (index + 1, self.nblocks))
def work_block(self, iblock): if len(self.store.config.ns) == 2: (sz, firstx), (sz, lastx), (ns, nx) = \ self.get_block_extents(iblock) rz = self.store.config.receiver_depth else: (rz, sz, firstx), (rz, sz, lastx), (nr, ns, nx) = \ self.get_block_extents(iblock) source_depth = float(sz / km) conf_s = copy.deepcopy(self.qseis_s_config) conf_r = copy.deepcopy(self.qseis_r_config) gf_directory = op.abspath(self.qseis_baseconf.gf_directory) fk_path = op.join(gf_directory, 'green_%.3fkm.fk' % source_depth) info_path = op.join(gf_directory, 'green_%.3fkm.info' % source_depth) conf_s.fk_path = fk_path conf_s.info_path = info_path conf_r.fk_path = fk_path conf_r.info_path = info_path if self.step == 0 and os.path.isfile(fk_path): logger.info('Skipping step %i / %i, block %i / %i' '(GF already exists)' % (self.step + 1, self.nsteps, iblock + 1, self.nblocks)) return logger.info( 'Starting step %i / %i, block %i / %i' % (self.step + 1, self.nsteps, iblock + 1, self.nblocks)) dx = self.gf_config.distance_delta conf_r.wavelet_duration = 0.001 * self.gf_config.sample_rate if self.step == 0: conf_s.source_depth = source_depth runner = QSeisSRunner(tmp=self.tmp) runner.run(conf_s) else: conf_r.receiver = QSeisRReceiver(lat=90 - firstx * cake.m2d, lon=180., tstart=0.0, distance=firstx) conf_r.source = QSeis2dSource(lat=90 - 0.001 * dx * cake.m2d, lon=0.0, depth=source_depth) runner = QSeisRRunner(tmp=self.tmp) mmt1 = (MomentTensor(m=symmat6(1, 0, 0, 1, 0, 0)), {'r': (0, 1), 't': (3, 1), 'z': (5, 1)}) mmt2 = (MomentTensor(m=symmat6(0, 0, 0, 0, 1, 1)), {'r': (1, 1), 't': (4, 1), 'z': (6, 1)}) mmt3 = (MomentTensor(m=symmat6(0, 0, 1, 0, 0, 0)), {'r': (2, 1), 'z': (7, 1)}) mmt4 = (MomentTensor(m=symmat6(0, 1, 0, 0, 0, 0)), {'r': (8, 1), 'z': (9, 1)}) gfmapping = [mmt1, mmt2, mmt3, mmt4] for mt, gfmap in gfmapping: if mt: m = mt.m() f = float conf_r.source_mech = QSeisRSourceMechMT( mnn=f(m[0, 0]), mee=f(m[1, 1]), mdd=f(m[2, 2]), mne=f(m[0, 1]), mnd=f(m[0, 2]), med=f(m[1, 2])) else: conf_r.source_mech = None if conf_r.source_mech is not None: runner.run(conf_r) rawtraces = runner.get_traces() interrupted = [] def signal_handler(signum, frame): interrupted.append(True) original = signal.signal(signal.SIGINT, signal_handler) self.store.lock() duplicate_inserts = 0 try: for itr, tr in enumerate(rawtraces): if tr.channel not in gfmap: continue x = tr.meta['distance'] if x > firstx + (nx - 1) * dx: continue ig, factor = gfmap[tr.channel] if len(self.store.config.ns) == 2: args = (sz, x, ig) else: args = (rz, sz, x, ig) if self.qseis_baseconf.cut: tmin = self.store.t( self.qseis_baseconf.cut[0], args[:-1]) tmax = self.store.t( self.qseis_baseconf.cut[1], args[:-1]) if None in (tmin, tmax): continue tr.chop(tmin, tmax) tmin = tr.tmin tmax = tr.tmax if self.qseis_baseconf.fade: ta, tb, tc, td = [ self.store.t(v, args[:-1]) for v in self.qseis_baseconf.fade] if None in (ta, tb, tc, td): continue if not (ta <= tb and tb <= tc and tc <= td): raise QSeis2dError( 'invalid fade configuration') t = tr.get_xdata() fin = num.interp(t, [ta, tb], [0., 1.]) fout = num.interp(t, [tc, td], [1., 0.]) anti_fin = 1. - fin anti_fout = 1. - fout y = tr.ydata sum_anti_fin = num.sum(anti_fin) sum_anti_fout = num.sum(anti_fout) if sum_anti_fin != 0.0: yin = num.sum(anti_fin * y) / sum_anti_fin else: yin = 0.0 if sum_anti_fout != 0.0: yout = num.sum(anti_fout * y) / sum_anti_fout else: yout = 0.0 y2 = anti_fin * yin + \ fin * fout * y + \ anti_fout * yout if self.qseis_baseconf.relevel_with_fade_in: y2 -= yin tr.set_ydata(y2) gf_tr = gf.store.GFTrace.from_trace(tr) gf_tr.data *= factor try: self.store.put(args, gf_tr) except gf.store.DuplicateInsert: duplicate_inserts += 1 finally: if duplicate_inserts: logger.warn('%i insertions skipped (duplicates)' % duplicate_inserts) self.store.unlock() signal.signal(signal.SIGINT, original) if interrupted: raise KeyboardInterrupt() logger.info( 'Done with step %i / %i, block %i / %i' % (self.step + 1, self.nsteps, iblock + 1, self.nblocks))
fig = plt.figure() axes1 = fig.add_subplot(2, 3, 1, aspect=1.) axes2 = fig.add_subplot(2, 3, 2, aspect=1.) axes3 = fig.add_subplot(2, 3, 3, aspect=1.) axes4 = fig.add_subplot(2, 3, 4, projection='3d', aspect=1.) axes5 = fig.add_subplot(2, 3, 5, projection='3d', aspect=1.) try: import mopad except ImportError: mopad = None for x in range(nx): #m6 = num.random.random(6)*2.-1. m6 = (-2.0, -2.0, -2., 0., 0., 0.) m = mtm.symmat6(*m6) mt = mtm.MomentTensor(m=m) #mt = mt.deviatoric() #strike = 270. #dip = 0.0 #rake = 0.01 #strike = 360. #dip = 28.373841741182012 #rake = 90. #mt = mtm.MomentTensor( # strike=strike, # dip=dip, # rake=rake)