Esempio n. 1
0
    def perform(self, node, inputs, output):
        tmins = inputs[0]
        z = output[0]

        z[0] = heart.taper_filter_traces(
            self.traces, self.arrival_taper,
            self.filterer, tmins, outmode='array')
Esempio n. 2
0
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)
Esempio n. 3
0
    def get_synthetics(self, point, **kwargs):
        """
        Get synthetics for given point in solution space.

        Parameters
        ----------
        point : :func:`pymc3.Point`
            Dictionary with model parameters
        kwargs especially to change output of seismic forward model
            outmode = 'traces'/ 'array' / 'data'

        Returns
        -------
        default: array of synthetics for all targets
        """

        self.point2sources(point)

        sc = self.config
        synths = []
        obs = []
        for wmap in self.wavemaps:
            wc = wmap.config

            synthetics, tmins = heart.seis_synthetics(
                engine=self.engine,
                sources=self.sources,
                targets=wmap.targets,
                arrival_taper=wc.arrival_taper,
                wavename=wmap.name,
                filterer=wc.filterer,
                pre_stack_cut=sc.pre_stack_cut,
                **kwargs)

            if self.config.station_corrections:
                sh = point[self.correction_name][wmap.station_correction_idxs]

                for i, tr in enumerate(synthetics):
                    tr.tmin += sh[i]
                    tr.tmax += sh[i]

            synths.extend(synthetics)

            obs_tr = heart.taper_filter_traces(wmap.datasets,
                                               arrival_taper=wc.arrival_taper,
                                               filterer=wc.filterer,
                                               tmins=tmins,
                                               **kwargs)

            obs.extend(obs_tr)

        return synths, obs
Esempio n. 4
0
    def get_synthetics(self, point, **kwargs):
        """
        Get synthetics for given point in solution space.

        Parameters
        ----------
        point : :func:`pymc3.Point`
            Dictionary with model parameters
        kwargs especially to change output of the forward model

        Returns
        -------
        list with :class:`heart.SeismicDataset` synthetics for each target
        """
        order = kwargs.pop('order', 'list')

        ref_idx = self.config.gf_config.reference_model_idx
        if len(self.gfs.keys()) == 0:
            self.load_gfs(
                crust_inds=[ref_idx],
                make_shared=False)

        tpoint = copy.deepcopy(point)

        hps = self.config.get_hypernames()

        for hyper in hps:
            if hyper in tpoint:
                tpoint.pop(hyper)

        nuc_dip_idx, nuc_strike_idx = self.fault.fault_locations2idxs(
            positions_dip=tpoint['nucleation_dip'],
            positions_strike=tpoint['nucleation_strike'],
            backend='numpy')

        starttimes = self.fault.get_subfault_starttimes(
            index=0,
            rupture_velocities=tpoint['velocities'],
            nuc_dip_idx=nuc_dip_idx,
            nuc_strike_idx=nuc_strike_idx).flatten()

        patchidx = self.fault.patchmap(
            index=0, dipidx=nuc_dip_idx, strikeidx=nuc_strike_idx)

        synth_traces = []
        obs_traces = []
        for wmap in self.wavemaps:
            synthetics = num.zeros(
                (wmap.n_t, wmap.config.arrival_taper.nsamples(
                    self.config.gf_config.sample_rate)))
            for var in self.slip_varnames:
                key = self.get_gflibrary_key(
                    crust_ind=ref_idx, wavename=wmap.name, component=var)

                try:
                    gflibrary = self.gfs[key]
                except KeyError:
                    raise KeyError(
                        'GF library %s not loaded! Loaded GFs:'
                        ' %s' % (key, utility.list2string(self.gfs.keys())))

                gflibrary.set_stack_mode('numpy')
                synthetics += gflibrary.stack_all(
                    starttimes=starttimes,
                    durations=tpoint['durations'],
                    slips=tpoint[var],
                    interpolation=wmap.config.interpolation)

            wmap_synthetics = []
            for i, target in enumerate(wmap.targets):
                tr = Trace(
                    ydata=synthetics[i, :],
                    tmin=float(
                        gflibrary.reference_times[i] +
                        tpoint['nucleation_time']),
                    deltat=gflibrary.deltat)

                tr.set_codes(*target.codes)
                wmap_synthetics.append(tr)

            if self.config.station_corrections:
                sh = point[
                    self.correction_name][wmap.station_correction_idxs]

                for i, tr in enumerate(synth_traces):
                    tr.tmin += sh[i]
                    tr.tmax += sh[i]

            wmap_obs = heart.taper_filter_traces(
                wmap.datasets,
                arrival_taper=wmap.config.arrival_taper,
                filterer=wmap.config.filterer,
                tmins=(gflibrary.get_all_tmins(patchidx)),
                **kwargs)

            if order == 'list':
                synth_traces.extend(wmap_synthetics)
                obs_traces.extend(wmap_obs)

            elif order == 'wmap':
                synth_traces.append(wmap_synthetics)
                obs_traces.append(wmap_obs)

            else:
                raise ValueError('Order "%s" is not supported' % order)

        return synth_traces, obs_traces
Esempio n. 5
0
    def assemble_seismic_results(self, point):
        """
        Assemble seismic traces for given point in solution space.

        Parameters
        ----------
        point : :func:`pymc3.Point`
            Dictionary with model parameters

        Returns
        -------
        List with :class:`heart.SeismicResult`
        """
        assert self._seismic_flag

        logger.debug('Assembling seismic waveforms ...')

        if self._geodetic_flag:
            self._geodetic_flag = False
            reset_flag = True
        else:
            reset_flag = False

        syn_proc_traces = self.get_synthetics(
            point, outmode='stacked_traces')['seismic']

        tmins = [tr.tmin for tr in syn_proc_traces]

        at = copy.deepcopy(self.config.seismic_config.arrival_taper)

        obs_proc_traces = heart.taper_filter_traces(
            self.data_traces,
            arrival_taper=at,
            filterer=self.config.seismic_config.filterer,
            tmins=tmins,
            outmode='traces')

        self.config.seismic_config.arrival_taper = None

        syn_filt_traces = self.get_synthetics(
            point, outmode='data')['seismic']

        obs_filt_traces = heart.taper_filter_traces(
            self.data_traces,
            filterer=self.config.seismic_config.filterer,
            outmode='traces')

        factor = 2.
        for i, (trs, tro) in enumerate(zip(syn_filt_traces, obs_filt_traces)):

            trs.chop(tmin=tmins[i] - factor * at.fade,
                     tmax=tmins[i] + factor * at.fade + at.duration)
            tro.chop(tmin=tmins[i] - factor * at.fade,
                     tmax=tmins[i] + factor * at.fade + at.duration)

        self.config.seismic_config.arrival_taper = at

        results = []
        for i, obstr in enumerate(obs_proc_traces):
            dtrace = obstr.copy()
            dtrace.set_ydata(
                (obstr.get_ydata() - syn_proc_traces[i].get_ydata()))

            taper = trace.CosTaper(
                tmins[i],
                tmins[i] + at.fade,
                tmins[i] + at.duration - at.fade,
                tmins[i] + at.duration)
            results.append(heart.SeismicResult(
                    processed_obs=obstr,
                    processed_syn=syn_proc_traces[i],
                    processed_res=dtrace,
                    filtered_obs=obs_filt_traces[i],
                    filtered_syn=syn_filt_traces[i],
                    taper=taper))

        if reset_flag:
            self._geodetic_flag = True

        return results