예제 #1
0
def get_seis_cov_velocity_models(engine,
                                 sources,
                                 targets,
                                 arrival_taper,
                                 filterer,
                                 plot=False,
                                 n_jobs=1):
    '''
    Calculate model prediction uncertainty matrix with respect to uncertainties
    in the velocity model for station and channel.
    Input:
    :py:class:`gf.Engine` - contains synthetics generation machine
    :py:class:`gf.Targets` - targets to be processed
    :py:class: `heart.ArrivalTaper` - Determines Tapering around Phase Arrival
    '''

    ref_target = copy.deepcopy(targets[0])

    reference_taperer = heart.get_phase_taperer(engine, sources[0], ref_target,
                                                arrival_taper)

    synths, _ = heart.seis_synthetics(engine,
                                      sources,
                                      targets,
                                      arrival_taper,
                                      filterer,
                                      nprocs=n_jobs,
                                      reference_taperer=reference_taperer,
                                      plot=plot)

    return num.cov(synths, rowvar=0)
예제 #2
0
    def perform(self, node, inputs, output):
        """
        Perform method of the Operator to calculate synthetic displacements.

        Parameters
        ----------
        inputs : list
            of :class:`numpy.ndarray`
        output : list
            1) of synthetic waveforms of :class:`numpy.ndarray`
               (n x nsamples)
            2) of start times of the first waveform samples
               :class:`numpy.ndarray` (n x 1)
        """
        synths = output[0]
        tmins = output[1]

        point = {vname: i for vname, i in zip(self.varnames, inputs)}

        mpoint = utility.adjust_point_units(point)

        source_points = utility.split_point(mpoint)

        for i, source in enumerate(self.sources):
            utility.update_source(source, **source_points[i])
            source.time += self.event.time

        synths[0], tmins[0] = heart.seis_synthetics(
            engine=self.engine,
            sources=self.sources,
            targets=self.targets,
            arrival_taper=self.arrival_taper,
            wavename=self.wavename,
            filterer=self.filterer,
            pre_stack_cut=self.pre_stack_cut)
예제 #3
0
파일: covariance.py 프로젝트: shineusn/beat
def seismic_cov_velocity_models(engine,
                                sources,
                                targets,
                                arrival_taper,
                                wavename,
                                filterer,
                                plot=False,
                                n_jobs=1):
    '''
    Calculate model prediction uncertainty matrix with respect to uncertainties
    in the velocity model for station and channel.

    Parameters
    ----------
    engine : :class:`pyrocko.gf.seismosizer.LocalEngine`
        contains synthetics generation machine
    sources : list
        of :class:`pyrocko.gf.seismosizer.Source`
    targets : list
        of :class:`pyrocko.gf.seismosizer.Targets`
    arrival_taper : :class: `heart.ArrivalTaper`
        determines tapering around phase Arrival
    filterer : :class:`heart.Filter`
        determines the bandpass-filtering corner frequencies
    plot : boolean
        open snuffler and browse traces if True
    n_jobs : int
        number of processors to be used for calculation

    Returns
    -------
    :class:`numpy.ndarray` with Covariance due to velocity model uncertainties
    '''

    ref_target = copy.deepcopy(targets[0])

    reference_taperer = heart.get_phase_taperer(engine,
                                                sources[0],
                                                wavename=wavename,
                                                target=ref_target,
                                                arrival_taper=arrival_taper)

    t0 = time()
    synths, _ = heart.seis_synthetics(engine=engine,
                                      sources=sources,
                                      targets=targets,
                                      arrival_taper=arrival_taper,
                                      wavename=wavename,
                                      filterer=filterer,
                                      nprocs=n_jobs,
                                      reference_taperer=reference_taperer,
                                      plot=plot,
                                      pre_stack_cut=True,
                                      outmode='array')
    t1 = time()
    logger.debug('Trace generation time %f' % (t1 - t0))

    return num.cov(synths, rowvar=0)
예제 #4
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)
예제 #5
0
파일: covariance.py 프로젝트: wangyf/beat
def seismic_cov_velocity_models(engine,
                                sources,
                                targets,
                                arrival_taper,
                                arrival_time,
                                wavename,
                                filterer,
                                plot=False,
                                n_jobs=1):
    '''
    Calculate model prediction uncertainty matrix with respect to uncertainties
    in the velocity model for station and channel.

    Parameters
    ----------
    engine : :class:`pyrocko.gf.seismosizer.LocalEngine`
        contains synthetics generation machine
    sources : list
        of :class:`pyrocko.gf.seismosizer.Source`
    targets : list
        of :class:`pyrocko.gf.seismosizer.Targets`
    arrival_taper : :class: `heart.ArrivalTaper`
        determines tapering around phase Arrival
    arrival_time : None or :class:`numpy.NdArray` or float
        of phase to apply taper, if None theoretic arrival of ray tracing used
    filterer : :class:`heart.Filter`
        determines the bandpass-filtering corner frequencies
    plot : boolean
        open snuffler and browse traces if True
    n_jobs : int
        number of processors to be used for calculation

    Returns
    -------
    :class:`numpy.ndarray` with Covariance due to velocity model uncertainties
    '''

    arrival_times = num.ones(len(targets), dtype='float64') * arrival_time

    t0 = time()
    synths, _ = heart.seis_synthetics(engine=engine,
                                      sources=sources,
                                      targets=targets,
                                      arrival_taper=arrival_taper,
                                      wavename=wavename,
                                      filterer=filterer,
                                      arrival_times=arrival_times,
                                      pre_stack_cut=True,
                                      plot=plot,
                                      outmode='array',
                                      chop_bounds=['b', 'c'])

    t1 = time()
    logger.debug('Trace generation time %f' % (t1 - t0))

    return num.cov(synths, rowvar=0)
예제 #6
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
예제 #7
0
파일: theanof.py 프로젝트: xiaolongma/beat
    def perform(self, node, inputs, output):

        synths = output[0]
        tmins = output[1]

        point = {
            var: inp
            for var, inp in zip(config.joint_vars_geometry, inputs)
        }

        mpoint = utility.adjust_point_units(point)

        source_points = utility.split_point(mpoint)

        for i, source in enumerate(self.sources):
            utility.update_source(source, **source_points[i])
            source.time += self.event.time
            heart.adjust_fault_reference(source, input_depth='top')

        synths[0], tmins[0] = heart.seis_synthetics(self.engine, self.sources,
                                                    self.targets,
                                                    self.arrival_taper,
                                                    self.filterer)
예제 #8
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
        """
        outmode = kwargs.pop('outmode', 'stacked_traces')
        chop_bounds = kwargs.pop('chop_bounds', ['a', 'd'])
        order = kwargs.pop('order', 'list')
        nprocs = kwargs.pop('nprocs', 1)

        self.point2sources(point)

        sc = self.config
        synths = []
        obs = []
        for wmap in self.wavemaps:
            wc = wmap.config
            wmap.prepare_data(source=self.events[wc.event_idx],
                              engine=self.engine,
                              outmode=outmode,
                              chop_bounds=chop_bounds)

            arrival_times = wmap._arrival_times
            if self.config.station_corrections:
                try:
                    arrival_times += point[wmap.time_shifts_id][
                        wmap.station_correction_idxs]
                except KeyError:  # got reference point from config
                    arrival_times += float(point[self.correction_name]) * \
                        num.ones(wmap.n_t)

            if self.nevents == 1:
                logger.debug('Using all sources for each wavemap!')
                sources = self.sources
            else:
                logger.debug('Using individual sources based on event index '
                             'for each wavemap!')
                sources = [self.sources[wc.event_idx]]

            synthetics, _ = heart.seis_synthetics(
                engine=self.engine,
                sources=sources,
                targets=wmap.targets,
                arrival_taper=wc.arrival_taper,
                wavename=wmap.name,
                filterer=wc.filterer,
                pre_stack_cut=sc.pre_stack_cut,
                arrival_times=arrival_times,
                outmode=outmode,
                chop_bounds=chop_bounds,
                nprocs=nprocs,
                # plot=True,
                **kwargs)

            if self.config.station_corrections:
                # set tmin to data tmin
                for tr, dtr in zip(synthetics, wmap._prepared_data):
                    if isinstance(tr, list):
                        for t in tr:
                            t.tmin = dtr.tmin
                            t.tmax = dtr.tmax
                    else:
                        tr.tmin = dtr.tmin
                        tr.tmax = dtr.tmax

            if order == 'list':
                synths.extend(synthetics)
                obs.extend(wmap._prepared_data)

            elif order == 'wmap':
                synths.append(synthetics)
                obs.append(wmap._prepared_data)

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

        return synths, obs
예제 #9
0
파일: seismic.py 프로젝트: braunfuss/beat
    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
        """
        outmode = kwargs.pop('outmode', 'stacked_traces')
        chop_bounds = kwargs.pop('chop_bounds', ['a', 'd'])
        order = kwargs.pop('order', 'list')

        self.point2sources(point)

        sc = self.config
        synths = []
        obs = []
        for wmap in self.wavemaps:
            wc = wmap.config
            wmap.prepare_data(
                source=self.event,
                engine=self.engine,
                outmode=outmode,
                chop_bounds=chop_bounds)

            arrival_times = wmap._arrival_times
            if self.config.station_corrections:
                try:
                    arrival_times += point[
                        self.correction_name][wmap.station_correction_idxs]
                except IndexError:  # got reference point from config
                    arrival_times += float(point[self.correction_name]) * \
                        num.ones(wmap.n_t)

            synthetics, _ = 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,
                arrival_times=arrival_times,
                outmode=outmode,
                chop_bounds=chop_bounds,
                **kwargs)

            if order == 'list':
                synths.extend(synthetics)
                obs.extend(wmap._prepared_data)

            elif order == 'wmap':
                synths.append(synthetics)
                obs.append(wmap._prepared_data)

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

        return synths, obs
예제 #10
0
engine = gf.LocalEngine(store_superdirs=store_superdirs)

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

targets = sc.wavemaps[0].targets
filterer = sc.wavemaps[0].config.filterer
ntargets = len(targets)

gfs = ffi.load_gf_library(
    directory=project_dir + '/ffi/linear_gfs/',
    filename='seismic_uparr_any_P_0')
ats = gfs.reference_times - arrival_taper.b

traces, tmins = heart.seis_synthetics(
    engine, patches, targets, arrival_times=ats,
    wavename='any_P', arrival_taper=arrival_taper,
    filterer=filterer, outmode='stacked_traces')

targetidxs = num.lib.index_tricks.s_[:]

if False:
    # for station corrections maybe in the future?
    station_corrections = num.zeros(len(traces))
    starttimes = (num.tile(starttimes, ntargets) + num.repeat(
        station_corrections, fault.npatches)).reshape(
            ntargets, fault.npatches)
    targetidxs = num.atleast_2d(num.arange(ntargets)).T

gfs.set_stack_mode('numpy')
synthetics_nn = gfs.stack_all(
    targetidxs=targetidxs,
예제 #11
0
파일: models.py 프로젝트: xiaolongma/beat
    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
        -------
        Dictionary with keys according to datasets containing the synthetics
        as lists.
        """
        tpoint = copy.deepcopy(point)

        tpoint = utility.adjust_point_units(tpoint)

        # remove hyperparameters from point
        hps = self.config.problem_config.hyperparameters

        if len(hps) > 0:
            for hyper in hps.keys():
                if hyper in tpoint:
                    tpoint.pop(hyper)
                else:
                    pass

        d = dict()

        if self._seismic_flag:
            tpoint['time'] += self.event.time

        source_points = utility.split_point(tpoint)

        for i, source in enumerate(self.sources):
            utility.update_source(source, **source_points[i])

        dsources = utility.transform_sources(
            self.sources, self.config.problem_config.datasets)

        # seismic
        if self._seismic_flag:
            sc = self.config.seismic_config
            seis_synths, _ = heart.seis_synthetics(
                engine=self.engine,
                sources=dsources['seismic'],
                targets=self.stargets,
                arrival_taper=sc.arrival_taper,
                filterer=sc.filterer, **kwargs)

            d['seismic'] = seis_synths

        # geodetic
        if self._geodetic_flag:
            gc = self.config.geodetic_config

            crust_inds = [0]

            geo_synths = []
            for crust_ind in crust_inds:
                for gtarget in self.gtargets:
                    disp = heart.geo_layer_synthetics(
                        gc.gf_config.store_superdir,
                        crust_ind,
                        lons=gtarget.lons,
                        lats=gtarget.lats,
                        sources=dsources['geodetic'])
                    geo_synths.append((
                        disp[:, 0] * gtarget.los_vector[:, 0] + \
                        disp[:, 1] * gtarget.los_vector[:, 1] + \
                        disp[:, 2] * gtarget.los_vector[:, 2]))

            d['geodetic'] = geo_synths

        return d