Пример #1
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]

        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])
            # reset source time may result in store error otherwise
            source.time = 0.

        synths[0] = heart.geo_synthetics(
            engine=self.engine,
            targets=self.targets,
            sources=self.sources,
            outmode='stacked_array')
Пример #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
    def point2sources(self, point):
        """
        Updates the composite source(s) (in place) with the point values.
        """
        tpoint = copy.deepcopy(point)
        tpoint = utility.adjust_point_units(tpoint)

        # remove hyperparameters from point
        hps = self.config.get_hypernames()

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

        source = self.sources[0]
        source_params = source.keys() + source.stf.keys()

        for param in tpoint.keys():
            if param not in source_params:
                tpoint.pop(param)

        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])
Пример #4
0
    def point2sources(self, point):
        """
        Updates the composite source(s) (in place) with the point values.
        """
        tpoint = copy.deepcopy(point)
        tpoint = utility.adjust_point_units(tpoint)

        # remove hyperparameters from point
        hps = self.config.get_hypernames()

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

        source_params = self.sources[0].keys()

        for param in tpoint.keys():
            if param not in source_params:
                tpoint.pop(param)

        source_points = utility.split_point(tpoint)

        for i, source in enumerate(self.sources):
            utility.update_source(source, **source_points[i])
            # reset source time may result in store error otherwise
            source.time = 0.
Пример #5
0
def init_reference_sources(source_points, n_sources, source_type, stf_type):
    reference_sources = []
    for i in range(n_sources):
        #rf = source_catalog[source_type](stf=stf_catalog[stf_type]()) maybe future if several meshtypes
        rf = RectangularSource(stf=stf_catalog[stf_type]())
        utility.update_source(rf, **source_points[i])
        reference_sources.append(rf)

    return reference_sources
Пример #6
0
    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)
Пример #7
0
    def point2sources(self, point):
        """
        Updates the composite source(s) (in place) with the point values.

        Parameters
        ----------
        point : dict
            with random variables from solution space
        """
        tpoint = copy.deepcopy(point)
        tpoint = utility.adjust_point_units(tpoint)

        # remove hyperparameters from point
        hps = self.config.get_hypernames()

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

        source = self.sources[0]
        source_params = list(source.keys()) + list(source.stf.keys())

        for param in list(tpoint.keys()):
            if param not in source_params:
                tpoint.pop(param)

        # update source times
        if self.nevents == 1:
            tpoint['time'] += self.event.time  # single event
        else:
            for i, event in enumerate(self.events):  # multi event
                tpoint['time'][i] += event.time

        source_points = utility.split_point(tpoint)

        for i, source in enumerate(self.sources):
            utility.update_source(source, **source_points[i])
Пример #8
0
    def point2sources(self, point, input_depth='top'):
        """
        Updates the composite source(s) (in place) with the point values.

        Parameters
        ----------
        point : dict
            with random variables from solution space
        input_depth : string
            may be either 'top'- input coordinates are transformed to center
            'center' - input coordinates are not transformed
        """
        tpoint = copy.deepcopy(point)
        tpoint = utility.adjust_point_units(tpoint)

        # remove hyperparameters from point
        hps = self.config.get_hypernames()

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

        source = self.sources[0]
        source_params = list(source.keys()) + list(source.stf.keys())

        for param in list(tpoint.keys()):
            if param not in source_params:
                tpoint.pop(param)

        tpoint['time'] += self.event.time

        source_points = utility.split_point(tpoint)

        for i, source in enumerate(self.sources):
            utility.update_source(source,
                                  input_depth=input_depth,
                                  **source_points[i])
Пример #9
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
        -------
        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
Пример #10
0
    def update_weights(self, point, n_jobs=1, plot=False):
        """
        Calculate and update model prediction uncertainty covariances
        due to uncertainty in the velocity model with respect to one point
        in the solution space. Shared variables are updated.

        Parameters
        ----------
        point : :func:`pymc3.Point`
            Dictionary with model parameters, for which the covariance matrixes
            with respect to velocity model uncertainties are calculated
        n_jobs : int
            Number of processors to use for calculation of seismic covariances
        plot : boolean
            Flag for opening the seismic waveforms in the snuffler
        """
        tpoint = copy.deepcopy(point)

        # update sources
        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():
                tpoint.pop(hyper)

        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

            for j, channel in enumerate(sc.channels):
                for i, station in enumerate(self.stations):
                    logger.debug('Channel %s of Station %s ' % (
                        channel, station.station))
                    crust_targets = heart.init_targets(
                        stations=[station],
                        channels=channel,
                        sample_rate=sc.gf_config.sample_rate,
                        crust_inds=range(sc.gf_config.n_variations))

                    cov_pv = cov.get_seis_cov_velocity_models(
                        engine=self.engine,
                        sources=dsources['seismic'],
                        targets=crust_targets,
                        arrival_taper=sc.arrival_taper,
                        filterer=sc.filterer,
                        plot=plot, n_jobs=n_jobs)

                    cov_pv = utility.ensure_cov_psd(cov_pv)

                    self.engine.close_cashed_stores()

                    index = j * len(self.stations) + i

                    self.stargets[index].covariance.pred_v = cov_pv
                    icov = self.stargets[index].covariance.inverse
                    self.sweights[index].set_value(icov)

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

            for i, gtarget in enumerate(self.gtargets):
                logger.debug('Track %s' % gtarget.track)
                cov_pv = cov.get_geo_cov_velocity_models(
                    store_superdir=gc.gf_config.store_superdir,
                    crust_inds=range(gc.gf_config.n_variations),
                    dataset=gtarget,
                    sources=dsources['geodetic'])

                cov_pv = utility.ensure_cov_psd(cov_pv)

                gtarget.covariance.pred_v = cov_pv
                icov = gtarget.covariance.inverse
                self.gweights[i].set_value(icov)