示例#1
0
    def finalize(cls):
        print '%14.7e %14.7e'%tuple(loadnpy('m_new'))

        m_new = loadnpy('m_new')
        m_old = loadnpy('m_old')

        d = np.linalg.norm(m_new-m_old)/np.linalg.norm(m_new)
        if d < 1.e-5:
            print 'Stopping criteria met.\n'
            sys.exit()
示例#2
0
    def finalize(cls):
        m_new = loadnpy('m_new')
        m_old = loadnpy('m_old')

        if PAR.VERBOSE > 0:
            print '%14.7e %14.7e'%tuple(m_new)

        if cls.status(m_new, m_old):
            print 'Test successful: stopping criteria met.\n'
            np.savetxt('niter', [cls.iter], '%d')
            sys.exit(0)

        elif cls.iter >= PAR.END:
            print 'Maximum number of iterations exceeded.\n'
            sys.exit(-1)
示例#3
0
 def write_model(self, path='', suffix=''):
     """ Writes model in format used by solver
     """
     unix.mkdir(path)
     src = PATH.OPTIMIZE +'/'+ 'm_' + suffix
     dst = path +'/'+ 'model'
     parts = solver.split(loadnpy(src))
     solver.save(dst, parts)
 def write_model(self, path='', suffix=''):
     """ Writes model in format used by solver
     """
     unix.mkdir(path)
     src = PATH.OPTIMIZE + '/' + 'm_' + suffix
     dst = path + '/' + 'model'
     parts = solver.split(loadnpy(src))
     solver.save(dst, parts)
示例#5
0
    def compute_direction_newton(cls):
        optimize.initialize_newton()

        for ilcg in range(PAR.LCGMAX):
            m = loadnpy('m_lcg')
            g = problem.grad(m)
            savenpy('g_lcg', g)
            isdone = optimize.iterate_newton()
            if isdone:
                break
    def evaluate_gradient(cls):
        m = loadnpy('m_new')
        f = problem.func(m)
        g = problem.grad(m)

        savetxt('f_new', f)
        savenpy('g_new', g)

        if PAR.OPTIMIZE in ['SRVM']:
            optimize.update_SRVM()
示例#7
0
    def compute_direction_newton(cls):
        optimize.initialize_newton()

        for ilcg in range(PAR.LCGMAX):
            m = loadnpy('m_lcg')
            g = problem.grad(m)
            savenpy('g_lcg', g)
            isdone = optimize.iterate_newton()
            if isdone:
                break
示例#8
0
 def save_model(self):
     src = PATH.OPTIMIZE +'/'+ 'm_new'
     dst = join(PATH.OUTPUT, 'model_%04d' % optimize.iter)
     parts = solver.split(loadnpy(src))
     vp_min, vp_max = 300,3750
     vs_min, vs_max = 50,2800
     #for key in ['vp', 'vs']:
     #    for iproc in range(PAR.NPROC):
     #        if key == 'vp':
     #            np.clip(parts[key][iproc], vp_min, vp_max)
     #        if key == 'vs':
     #            np.clip(parts[key][iproc], vs_min, vs_max)
     solver.save(dst, parts)
示例#9
0
文件: misfit.py 项目: icui/seisflows
def Phase2_se(syn, nt, dt, ft_obs, freq_mask):
    # waveform difference in the frequency domain, considering orthogonal frequencies
    nstep = len(syn)
    wadj = 0.0  #np.zeros(nstep)
    ntpss = PAR.NTPSS
    #create a frequential mask
    m = loadnpy(PATH.ORTHO + '/freq_idx')
    ft_syn = fft(syn[-ntpss:])[m]
    obs = ft_syn / ft_obs

    phase = np.vectorize(cmath.phase)
    phase_obs = phase(obs)

    wadj = (freq_mask * phase_obs**2).sum()
    return wadj
示例#10
0
    def split(self, file, path, suffix):
        """ Split numpy arrays into separate vectors and save to binary files for solver.
        """

        npar = len(self.parameters)
        ipar = 0

        # load numpy file
        nv = loadnpy(file)
        n = int(len(nv) / npar)

        for par in self.parameters:
            v = nv[(ipar*n):(ipar*n) + n]
            v = extend_pml_velocities(v, p.nx, p.nz, p.ncpml, p.use_cpml_left, p.use_cpml_right, p.use_cpml_top,
                                           p.use_cpml_bottom)

            filename = join(path, par + suffix)
            self.save(filename, v)
            ipar += 1
示例#11
0
 def save_model(self):
     src = PATH.OPTIMIZE + '/' + 'm_new'
     dst = join(PATH.OUTPUT, 'model_%04d' % optimize.iter)
     solver.save(dst, solver.split(loadnpy(src)))
示例#12
0
 def load(self, filename):
     return loadnpy(PATH.OPTIMIZE + '/' + filename)
示例#13
0
 def save_model(self):
     src = PATH.OPTIMIZE +'/'+ 'm_new'
     dst = join(PATH.OUTPUT, 'model_%04d' % optimize.iter)
     solver.save(dst, solver.split(loadnpy(src)))
示例#14
0
 def load(self, filename):
     # reads vectors from disk
     return loadnpy(PATH.OPTIMIZE+'/'+filename)
示例#15
0
 def load(self, filename):
     # reads vectors from disk
     return loadnpy(PATH.OPTIMIZE + '/' + filename)
示例#16
0
 def evaluate_function(cls):
     m = loadnpy('m_try')
     f = problem.func(m)
     savetxt('f_try',f)
     print f
示例#17
0
 def evaluate_gradient(cls):
     m = loadnpy('m_new')
     f = problem.func(m)
     g = problem.grad(m)
     savetxt('f_new', f)
     savenpy('g_new', g)
示例#18
0
 def evaluate_function(cls):
     m = loadnpy('m_try')
     f = problem.func(m)
     savetxt('f_try', f)
示例#19
0
 def evaluate_gradient(cls):
     m = loadnpy('m_new')
     f = problem.func(m)
     g = problem.grad(m)
     savetxt('f_new',f)
     savenpy('g_new',g)