示例#1
0
    def _theano_c_wrapper(self):

        Slownesses = self.get_slownesses()

        slownesses = tt.dvector('slownesses')
        slownesses.tag.test_value = Slownesses.flatten()

        nuc_x = tt.lscalar('nuc_x')
        nuc_x.tag.test_value = self.nuc_x

        nuc_y = tt.lscalar('nuc_y')
        nuc_y.tag.test_value = self.nuc_y

        cleanup = theanof.Sweeper(self.patch_size / km, self.n_patch_dip,
                                  self.n_patch_strike, 'c')

        start_times = cleanup(slownesses, nuc_y, nuc_x)

        t0 = time()
        f = function([slownesses, nuc_y, nuc_x], start_times)
        t1 = time()
        theano_c_wrap_start_times = f(Slownesses.flatten(), self.nuc_y,
                                      self.nuc_x)
        print('tc', theano_c_wrap_start_times)
        t2 = time()
        logger.info('Theano C wrapper compile time %f' % (t1 - t0))
        logger.info('done theano C wrapper fast_sweeping in %f' % (t2 - t1))
        print('Theano C wrapper compile time %f' % (t1 - t0))
        return theano_c_wrap_start_times
示例#2
0
    def __init__(self, sc, project_dir, events, hypers=False):

        super(SeismicDistributerComposite, self).__init__(sc,
                                                          events,
                                                          project_dir,
                                                          hypers=hypers)

        self.gfs = {}
        self.gf_names = {}
        self.choppers = {}
        self.sweep_implementation = 'c'

        self._mode = 'ffi'
        self.gfpath = os.path.join(project_dir, self._mode,
                                   bconfig.linear_gf_dir_name)

        self.config = sc
        dgc = sc.gf_config.discretization_config

        for pw, pl in zip(dgc.patch_widths, dgc.patch_lengths):
            if pw != pl:
                raise ValueError(
                    'So far only square patches supported in kinematic'
                    ' model! - fast_sweeping issues')

        if len(sc.gf_config.reference_sources) > 1:
            logger.warning(
                'So far only rupture propagation on each subfault individually'
            )

        self.fault = self.load_fault_geometry()

        logger.info('Fault(s) discretized to %s [km]'
                    ' patches.' % utility.list2string(dgc.patch_lengths))

        if not hypers:
            self.sweepers = []
            for idx in range(self.fault.nsubfaults):
                n_p_dip, n_p_strike = \
                    self.fault.ordering.get_subfault_discretization(idx)

                self.sweepers.append(
                    theanof.Sweeper(dgc.patch_lengths[idx], n_p_dip,
                                    n_p_strike, self.sweep_implementation))

            for wmap in self.wavemaps:
                logger.info('Preparing data of "%s" for optimization' %
                            wmap.name)
                wmap.prepare_data(source=self.events[wmap.config.event_idx],
                                  engine=self.engine,
                                  outmode='array',
                                  chop_bounds=['b', 'c'])
示例#3
0
    def __init__(self, sc, project_dir, event, hypers=False):

        super(SeismicDistributerComposite, self).__init__(sc,
                                                          event,
                                                          project_dir,
                                                          hypers=hypers)

        self.gfs = {}
        self.gf_names = {}
        self.choppers = {}
        self.sweep_implementation = 'c'

        self._mode = 'ffi'
        self.gfpath = os.path.join(project_dir, self._mode,
                                   bconfig.linear_gf_dir_name)

        self.config = sc
        sgfc = sc.gf_config

        for pw, pl in zip(sgfc.patch_widths, sgfc.patch_lengths):
            if pw != pl:
                raise ValueError(
                    'So far only square patches supported in kinematic'
                    ' model! - fast_sweeping issues')

        if len(sgfc.reference_sources) > 1:
            raise ValueError('So far only one reference plane supported! - '
                             'fast_sweeping issues')

        self.fault = self.load_fault_geometry()
        # TODO: n_subfaultssupport
        n_p_dip, n_p_strike = self.fault.get_subfault_discretization(0)

        logger.info('Fault(s) discretized to %s [km]'
                    ' patches.' % utility.list2string(sgfc.patch_lengths))

        if not hypers:
            self.sweeper = theanof.Sweeper(sgfc.patch_lengths[0], n_p_dip,
                                           n_p_strike,
                                           self.sweep_implementation)

            for wmap in self.wavemaps:

                logger.info('Preparing data of "%s" for optimization' %
                            wmap.name)
                wmap.prepare_data(source=self.event,
                                  engine=self.engine,
                                  outmode='array')
示例#4
0
    def __init__(self, sc, project_dir, event, hypers=False):

        super(SeismicDistributerComposite, self).__init__(sc,
                                                          event,
                                                          project_dir,
                                                          hypers=hypers)

        self.gfs = {}
        self.gf_names = {}
        self.choppers = {}
        self.sweep_implementation = 'c'

        self.slip_varnames = bconfig.static_dist_vars
        self._mode = 'ffi'
        self.gfpath = os.path.join(project_dir, self._mode,
                                   bconfig.linear_gf_dir_name)

        self.config = sc
        sgfc = sc.gf_config

        if sgfc.patch_width != sgfc.patch_length:
            raise ValueError(
                'So far only square patches supported in kinematic'
                ' model! - fast_sweeping issues')

        if len(sgfc.reference_sources) > 1:
            raise ValueError('So far only one reference plane supported! - '
                             'fast_sweeping issues')

        self.fault = self.load_fault_geometry()
        n_p_dip, n_p_strike = self.fault.get_subfault_discretization(0)

        logger.info('Fault discretized to %s [km]'
                    ' patches.' % sgfc.patch_length)
        if not hypers:
            self.sweeper = theanof.Sweeper(sgfc.patch_length, n_p_dip,
                                           n_p_strike,
                                           self.sweep_implementation)

            for wmap in self.wavemaps:
                self.choppers[wmap.name] = theanof.SeisDataChopper(
                    sample_rate=sc.gf_config.sample_rate,
                    traces=wmap.datasets,
                    arrival_taper=wmap.config.arrival_taper,
                    filterer=wmap.config.filterer)