def do_variance_estimate(self, wmap): filterer = wmap.config.filterer scalings = [] for i, (tr, target) in enumerate(zip(wmap.datasets, wmap.targets)): wavename = None # None uses first tabulated phase arrival_time = heart.get_phase_arrival_time( engine=self.engine, source=self.events[wmap.config.event_idx], target=target, wavename=wavename) if arrival_time < tr.tmin: logger.warning( 'no data for variance estimation on pre-P arrival' ' in wavemap %s, for trace %s!' % ( wmap._mapid, list2string(tr.nslc_id))) logger.info( 'Using reference arrival "%s" instead!' % wmap.name) arrival_time = heart.get_phase_arrival_time( engine=self.engine, source=self.events[wmap.config.event_idx], target=target, wavename=wmap.name) if filterer: ctrace = tr.copy() # apply all the filters for filt in filterer: filt.apply(ctrace) ctrace = ctrace.chop( tmin=tr.tmin, tmax=arrival_time - self.pre_arrival_time) nslc_id_str = list2string(ctrace.nslc_id) data = ctrace.get_ydata() if data.size == 0: raise ValueError( 'Trace %s contains no pre-P arrival data! Please either ' 'remove/blacklist or make sure data contains times before' ' the P arrival time!' % nslc_id_str) scaling = num.nanvar(data) if num.isfinite(scaling).all(): logger.debug( 'Variance estimate of %s = %g' % (nslc_id_str, scaling)) scalings.append(scaling) else: raise ValueError( 'Pre P-trace of %s contains Inf or' ' NaN!' % nslc_id_str) return scalings
def seismic_data_covariance(data_traces, engine, filterer, sample_rate, arrival_taper, event, targets): ''' Calculate SubCovariance Matrix of trace object following Duputel et al. 2012 GJI "Uncertainty estimations for seismic source inversions" p. 5 Parameters ---------- data_traces : list of :class:`pyrocko.trace.Trace` containing observed data engine : :class:`pyrocko.gf.seismosizer.LocalEngine` processing object for synthetics calculation filterer : :class:`heart.Filter` determines the bandpass-filtering corner frequencies sample_rate : float sampling rate of data_traces and GreensFunction stores arrival_taper : :class: `heart.ArrivalTaper` determines tapering around phase Arrival event : :class:`pyrocko.meta.Event` reference event from catalog targets : list of :class:`pyrocko.gf.seismosizer.Targets` Returns ------- :class:`numpy.ndarray` Notes ----- Cd(i,j) = (Variance of trace)*exp(-abs(ti-tj)/ (shortest period T0 of waves)) i,j are samples of the seismic trace ''' wavename = 'any_P' # hardcode here, want always pre P time tzero = 1. / filterer.upper_corner dt = 1. / sample_rate ataper = arrival_taper n = int(num.ceil((num.abs(ataper.a) + ataper.d) / dt)) csub = sub_data_covariance(n, dt, tzero) cov_ds = [] for tr, target in zip(data_traces, targets): arrival_time = heart.get_phase_arrival_time(engine=engine, source=event, target=target, wavename=wavename) ctrace = tr.chop(tmin=tr.tmin, tmax=arrival_time - num.abs(ataper.b), inplace=False) cov_ds.append(num.var(ctrace.ydata, ddof=1) * csub) return cov_ds
def _process_patch_seismic( engine, gfs, targets, patch, patchidx, durations, starttimes): # ensur event reference time logger.debug('Using reference event source time ...') patch.time = gfs.config.event.time # ensure stf anchor point at -1 patch.stf.anchor = -1 source_patches_durations = [] logger.info('Patch Number %i', patchidx) for duration in durations: pcopy = patch.clone() pcopy.stf.duration = float(duration) source_patches_durations.append(pcopy) for j, target in enumerate(targets): traces, _ = heart.seis_synthetics( engine=engine, sources=source_patches_durations, targets=[target], arrival_taper=None, arrival_times=num.array(None), wavename=gfs.config.wave_config.name, filterer=None, reference_taperer=None, outmode='data') # getting event related arrival time valid for all patches # as common reference event_arrival_time = heart.get_phase_arrival_time( engine=engine, source=gfs.config.event, target=target, wavename=gfs.config.wave_config.name) gfs.set_patch_time(targetidx=j, tmin=event_arrival_time) for starttime in starttimes: shifted_arrival_time = event_arrival_time - starttime synthetics_array = heart.taper_filter_traces( traces=traces, arrival_taper=gfs.config.wave_config.arrival_taper, filterer=gfs.config.wave_config.filterer, arrival_times=num.ones(durations.size) * shifted_arrival_time, outmode='array', chop_bounds=['b', 'c']) gfs.put( entries=synthetics_array, targetidx=j, patchidx=patchidx, durations=durations, starttimes=starttime)
def do_variance_estimate(self, wmap): filterer = wmap.config.filterer scalings = [] for i, (tr, target) in enumerate(zip(wmap.datasets, wmap.targets)): wavename = 'any_P' # hardcode here, want always pre P time arrival_time = heart.get_phase_arrival_time( engine=self.engine, source=self.event, target=target, wavename=wavename) if arrival_time < tr.tmin: logger.warning( 'no data for variance estimation on pre-P arrival' ' in wavemap %s, for trace %s!' % ( wmap._mapid, list2string(tr.nslc_id))) logger.info( 'Using reference arrival "%s" instead!' % wmap.name) arrival_time = heart.get_phase_arrival_time( engine=self.engine, source=self.event, target=target, wavename=wmap.name) if filterer is not None: ctrace = tr.copy() ctrace.bandpass( corner_hp=filterer.lower_corner, corner_lp=filterer.upper_corner, order=filterer.order) ctrace = ctrace.chop( tmin=tr.tmin, tmax=arrival_time - self.pre_arrival_time) scaling = num.var(ctrace.get_ydata()) scalings.append(scaling) return scalings
def get_seismic_data_covariances(data_traces, engine, filterer, sample_rate, arrival_taper, event, targets): ''' Calculate SubCovariance Matrix of trace object following Duputel et al. 2012 GJI "Uncertainty estimations for seismic source inversions" p. 5 Cd(i,j) = (Variance of trace)*exp(-abs(ti-tj)/ (shortest period T0 of waves)) i,j are samples of the seismic trace ''' tzero = 1. / filterer.upper_corner dt = 1. / sample_rate ataper = arrival_taper n = int(num.ceil((num.abs(ataper.a) + ataper.d) / dt)) csub = sub_data_covariance(n, dt, tzero) cov_ds = [] for i, tr in enumerate(data_traces): # assure getting P-wave arrival time tmp_target = copy.deepcopy(targets[i]) tmp_target.codes = (tmp_target.codes[:3] + ('Z', )) arrival_time = heart.get_phase_arrival_time(engine=engine, source=event, target=tmp_target) ctrace = tr.chop(tmin=tr.tmin, tmax=arrival_time - num.abs(ataper.b), inplace=False) cov_ds.append(num.var(ctrace.ydata, ddof=1) * csub) return cov_ds