def generate_mesh(self,
                      model_path=None,
                      model_name=None,
                      model_type='gll'):
        """ Performs meshing and database generation
        """
        assert (model_name)
        assert (model_type)

        self.initialize_solver_directories()
        unix.cd(self.cwd)

        if model_type == 'gll':
            assert (exists(model_path))
            self.check_mesh_properties(model_path)

            unix.cp(glob(model_path + '/' + '*'), self.model_databases)

            call_solver(system.mpiexec(), 'bin/xmeshfem3D')

            if self.taskid == 0:
                self.export_model(PATH.OUTPUT + '/' + model_name)

        else:
            raise NotImplementedError
Beispiel #2
0
    def smooth(self, input_path='', output_path='', parameters=[], span=0.):
        """ Smooths kernels by convolving them with a Gaussian.  Wrapper over 
            xsmooth_sem utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        # apply smoothing operator
        unix.cd(self.cwd)

        files = []
        files += glob(PATH.MODEL_INIT + '/proc??????_x.bin')
        files += glob(PATH.MODEL_INIT + '/proc??????_z.bin')
        files += glob(PATH.MODEL_INIT + '/proc??????_NSPEC_ibool.bin')
        files += glob(PATH.MODEL_INIT + '/proc??????_jacobian.bin')
        for file in files:
            unix.cp(file, input_path)

        for name in parameters or self.parameters:
            print(' smoothing', name)
            call_solver(system.mpiexec(),
                        PATH.SPECFEM_BIN + '/' + 'xsmooth_sem ' + str(span) +
                        ' ' + str(span) + ' ' + name + '_kernel' + ' ' +
                        input_path + '/ ' + output_path + '/ F',
                        output=output_path + '/smooth_' + name + '.log')

        print('')

        # rename output files
        files = glob(output_path + '/*')
        unix.rename('_smooth', '', files)
Beispiel #3
0
    def combine(self, input_path='', output_path='', parameters=[]):
        """ Sums individual source contributions. Wrapper over xcombine_sem
            utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        unix.cd(self.cwd)

        names = self.check_source_names()
        subset = [names[isrc] for isrc in self._source_subset]

        with open('kernel_paths', 'w') as f:
            f.writelines([join(input_path, dir) + '\n' for dir in subset])

        # SAGA component - include contributions from reference gradient
        remainder = list(set(self._source_names) - set(subset))

        with open('kernel_paths', 'a') as f:
            f.writelines(
                [join(PATH.GRAD_AGG, dir) + '\n' for dir in remainder])

        for name in parameters or self.parameters:
            call_solver(
                system.mpiexec(), PATH.SPECFEM_BIN + '/' + 'xcombine_sem ' +
                name + '_kernel' + ' ' + 'kernel_paths' + ' ' + output_path)
Beispiel #4
0
    def combine_vol_data(self, output_path='', quantity=''):
        """
        This does not work
        Call Specfems executable combine_vol_data_vtk on kernels or model files
        """
        if not exists(output_path):
            unix.mkdir(output_path)

        # This should probably be moved to its own function
        # def import_kernels()
        unix.cd(self.cwd)
        src = glob(join(PATH.GRAD, self.source_name, "*{}*".format(quantity)))
        dst = join(self.cwd, "kernels")
        unix.mkdir(dst)
        unix.ln(src=src, dst=dst)

        solver_call = " ".join([
            PATH.SPECFEM_BIN + '/' + 'xcombine_vol_data_vtk',
            0,  # NPROC_START
            PAR.NPROC,  # NPROC_END
            quantity,  # QUANTITY
            dst,  # DIR_IN
            dst,  # DIR_OUT, we will rename the files first
            0  # GPU ACCEL
        ])
        call_solver(system_mpiexec(), solver_call)

        unix.rm(dst)
        print ''
Beispiel #5
0
    def smooth(self, input_path='', output_path='', parameters=[], span=0.):
        """ Smooths kernels by convolving them with a Gaussian.  Wrapper over 
            xsmooth_sem utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        # apply smoothing operator
        unix.cd(self.cwd)
        for name in parameters or self.parameters:
            print ' smoothing', name
            call_solver(system.mpiexec(),
                        PATH.SPECFEM_BIN + '/' + 'xsmooth_sem ' + str(span) +
                        ' ' + str(span) + ' ' + name + '_kernel' + ' ' +
                        input_path + '/ ' + output_path + '/ ',
                        output='/dev/null')

        print ''

        # rename output files
        files = glob(output_path + '/*')
        unix.rename('_smooth', '', files)
    def generate_mesh(self, model_path=None, model_name=None, model_type='gll'):
        """ Performs meshing and database generation
        """
        assert(model_name)
        assert(model_type)

        self.initialize_solver_directories()
        unix.cd(self.cwd)

        if model_type in ['gll']:
            par = getpar('MODEL').strip()
            if par != 'gll':
                if self.taskid == 0:
                    print 'WARNING: Unexpected Par_file setting:'
                    print 'MODEL =', par
            
            assert(exists(model_path))
            self.check_mesh_properties(model_path)

            src = glob(model_path +'/'+ '*')
            dst = self.model_databases
            unix.cp(src, dst)

            call_solver(system.mpiexec(), 'bin/xmeshfem3D')
            call_solver(system.mpiexec(), 'bin/xgenerate_databases')

            if self.taskid == 0:
                self.export_model(PATH.OUTPUT +'/'+ model_name)

        else:
            raise NotImplementedError
Beispiel #7
0
    def generate_mesh(self,
                      model_path=None,
                      model_name=None,
                      model_type='gll'):
        """ Performs meshing and database generation
        """
        print 'specfem3d_nz.generate mesh'
        assert (model_name)
        assert (model_type)

        unix.cd(self.cwd)

        if model_type in ['gll']:
            par = getpar('MODEL').strip()
            if par != 'gll':
                if self.taskid == 0:
                    print 'WARNING: Unexpected Par_file setting:'
                    print 'MODEL =', par

            assert (exists(model_path))
            self.check_mesh_properties(model_path)

            src = glob(model_path + '/' + '*')
            dst = self.model_databases
            unix.cp(src, dst)

            call_solver(system.mpiexec(), 'bin/xgenerate_databases')

            if self.taskid == 0:
                self.export_model(PATH.OUTPUT + '/' + model_name)

        else:
            raise NotImplementedError
Beispiel #8
0
    def generate_data(self, **model_kwargs):
        """ Generates data (perform meshing and database generation first)
        """
        self.generate_mesh(**model_kwargs)

        unix.cd(self.cwd)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.false.')

        call_solver(system.mpiexec(), 'bin/xmeshfem2D', output='mesher.log')
        call_solver(system.mpiexec(), 'bin/xspecfem2D', output='solver.log')

        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*.su')
            # work around SPECFEM2D's different file names (depending on the
            # version used :
            # ?? junliu
            # _d?
            unix.rename('single_d.su', 'single.su', src)
            src = glob('OUTPUT_FILES/*.su')
            dst = 'traces/obs'
            unix.mv(src, dst)

        if PAR.SAVETRACES:
            self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
Beispiel #9
0
    def smooth(self, input_path='', output_path='', parameters=[], span=0.):
        """ Smooths kernels by convolving them with a Gaussian.  Wrapper over 
            xsmooth_sem utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        # apply smoothing operator
        unix.cd(self.cwd)
        for name in parameters or self.parameters:
            print ' smoothing', name
            call_solver(
                system.mpiexec(),
                PATH.SPECFEM_BIN +'/'+ 'xsmooth_sem '
                + str(span) + ' '
                + str(span) + ' '
                + name + '_kernel' + ' '
                + input_path + '/ '
                + output_path + '/ ',
                output='/dev/null')

        print ''

        # rename output files
        files = glob(output_path+'/*')
        unix.rename('_smooth', '', files)
    def combine(self, input_path='', output_path='', parameters=[]):
        """ Sums individual source contributions. Wrapper over xcombine_sem
            utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        unix.cd(self.cwd)

        names = self.check_source_names()
        subset = [names[isrc] for isrc in self._source_subset]

        with open('kernel_paths', 'w') as f:
            f.writelines([join(input_path, dir)+'\n' for dir in subset])

        # SAGA component - include contributions from reference gradient
        remainder = list(set(self._source_names) - set(subset))

        with open('kernel_paths', 'a') as f:
            f.writelines([join(PATH.GRAD_AGG, dir)+'\n' for dir in remainder])

        for name in parameters or self.parameters:
            call_solver(
                system.mpiexec(),
                PATH.SPECFEM_BIN +'/'+ 'xcombine_sem '
                + name + '_kernel' + ' '
                + 'kernel_paths' + ' '
                + output_path)
Beispiel #11
0
    def generate_data(self, **model_kwargs):
        """ 
        Generates data in the synthetic-synthetic comparison case.
        Not for use in the real-data problem. Differs from specfem3d.nz in that
        it automatically calls generate mesh for the true model, rather than
        passing them in as kwargs.
        """
        # Prepare for the forward simulation
        self.generate_mesh(**model_kwargs)

        print 'specfem3d_nz.generate data'
        unix.cd(self.cwd)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        setpar('ATTENUATION ', '.true.')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        # seismic unix format
        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*_d?_SU')
            dst = 'traces/obs'
            unix.mv(src, dst)
        # ascii sem output format
        elif PAR.FORMAT == "ascii":
            src = glob('OUTPUT_FILES/*sem?')
            dst = 'traces/obs'
            unix.mv(src, dst)

        if PAR.SAVETRACES:
            self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
 def adjoint(self):
     """ Calls SPECFEM3D_GLOBE adjoint solver
     """
     solvertools.setpar('SIMULATION_TYPE', '3')
     solvertools.setpar('SAVE_FORWARD', '.false.')
     unix.rm('SEM')
     unix.ln('traces/adj', 'SEM')
     call_solver(system.mpiexec(), 'bin/xspecfem3D')
 def adjoint(self):
     """ Calls SPECFEM3D_GLOBE adjoint solver
     """
     solvertools.setpar('SIMULATION_TYPE', '3')
     solvertools.setpar('SAVE_FORWARD', '.false.')
     unix.rm('SEM')
     unix.ln('traces/adj', 'SEM')
     call_solver(system.mpiexec(), 'bin/xspecfem3D')
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM3D_GLOBE forward solver
        """
        solvertools.setpar('SIMULATION_TYPE', '1')
        solvertools.setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['ASCII', 'ascii']:
            src = glob('OUTPUT_FILES/*.sem.ascii')
            dst = path
            unix.mv(src, dst)
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM3D_GLOBE forward solver
        """
        solvertools.setpar('SIMULATION_TYPE', '1')
        solvertools.setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['ASCII', 'ascii']:
            src = glob('OUTPUT_FILES/*.sem.ascii')
            dst = path
            unix.mv(src, dst)
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM2D forward solver
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')

        call_solver(system.mpiexec(), 'bin/xmeshfem2D')
        call_solver(system.mpiexec(), 'bin/xspecfem2D')

        if PAR.FORMAT in ['SU', 'su']:
            filenames = glob('OUTPUT_FILES/*.su')
            unix.mv(filenames, path)
Beispiel #17
0
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM2D forward solver
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xmeshfem2D')

        call_solver(system.mpiexec(), 'bin/xspecfem2D')

        if PAR.FORMAT in ['SU', 'su']:
            filenames = glob('OUTPUT_FILES/*.su')
            unix.mv(filenames, path)
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM3D forward solver
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xgenerate_databases')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*_d?_SU')
            dst = path
            unix.mv(src, dst)
Beispiel #19
0
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM3D forward solver
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xgenerate_databases')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*_d?_SU')
            dst = path
            unix.mv(src, dst)
Beispiel #20
0
    def adjoint_att(self):
        """ Calls SPECFEM2D adjoint solver
        """
        unix.rm('SEM')
        unix.ln('traces/adj_att', 'SEM')

        # hack to deal with different SPECFEM2D name conventions for
        # regular traces and 'adjoint' traces
        if PAR.FORMAT in ['SU', 'su']:
            files = glob('traces/adj_att/*.su')
            unix.rename('.su', '.su.adj', files)

        call_solver(system.mpiexec(), 'bin/xspecfem2D')
Beispiel #21
0
    def adjoint(self):
        """ Calls SPECFEM2D adjoint solver
        """
        setpar('SIMULATION_TYPE', '3')
        setpar('SAVE_FORWARD', '.false.')
        unix.rm('SEM')
        unix.ln('traces/adj', 'SEM')

        # hack to deal with different SPECFEM2D name conventions for
        # regular traces and 'adjoint' traces
        if PAR.FORMAT in ['SU', 'su']:
            files = glob('traces/adj/*.su')
            unix.rename('.su', '.su.adj', files)

        call_solver(system.mpiexec(), 'bin/xspecfem2D')
Beispiel #22
0
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM2D forward solver
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')

        call_solver(system.mpiexec(), 'bin/xmeshfem2D')
        call_solver(system.mpiexec(), 'bin/xspecfem2D')

        if PAR.FORMAT in ['SU', 'su']:
            filenames = glob('OUTPUT_FILES/*.su')
            # work around SPECFEM2D's different file names (depending on the
            # version used :
            unix.rename('single_p.su', 'single.su', filenames)
            filenames = glob('OUTPUT_FILES/*.su')
            unix.mv(filenames, path)
    def adjoint(self):
        """ Calls SPECFEM2D adjoint solver
        """
        setpar('SIMULATION_TYPE', '3')
        setpar('SAVE_FORWARD', '.false.')
        unix.rm('SEM')
        unix.ln('traces/adj', 'SEM')

        # hack to deal with different SPECFEM2D name conventions for
        # regular traces and 'adjoint' traces
        if PAR.FORMAT in ['SU', 'su']:
            files = glob('traces/adj/*.su')
            unix.rename('.su', '.su.adj', files)

        call_solver(system.mpiexec(), 'bin/xmeshfem2D')
        call_solver(system.mpiexec(), 'bin/xspecfem2D')
    def generate_data(self, **model_kwargs):
        """ Generates data
        """
        self.generate_mesh(**model_kwargs)

        unix.cd(self.cwd)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['ASCII', 'ascii']:
            src = glob('OUTPUT_FILES/*.sem.ascii')
            dst = 'traces/obs'
            unix.mv(src, dst)

        if PAR.SAVETRACES:
            self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
    def generate_data(self, **model_kwargs):
        """ Generates data
        """
        self.generate_mesh(**model_kwargs)

        unix.cd(self.cwd)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        if PAR.FORMAT in ['ASCII', 'ascii']:
            src = glob('OUTPUT_FILES/*.sem.ascii')
            dst = 'traces/obs'
            unix.mv(src, dst)

        if PAR.SAVETRACES:
            self.export_traces(PATH.OUTPUT+'/'+'traces/obs')
Beispiel #26
0
    def forward(self, path='traces/syn'):
        """ Calls SPECFEM3D forward solver and then moves files into path
        """
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.true.')
        setpar('ATTENUATION ', '.true.')
        call_solver(system.mpiexec(), 'bin/xgenerate_databases')
        call_solver(system.mpiexec(), 'bin/xspecfem3D')

        # seismic unix output format
        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*_d?_SU')
            dst = path
            unix.mv(src, dst)
        # ascii sem output format
        elif PAR.FORMAT == "ascii":
            src = glob('OUTPUT_FILES/*sem?')
            dst = path
            unix.mv(src, dst)
Beispiel #27
0
    def generate_data(self, **model_kwargs):
        """ Generates data
        """
        self.generate_mesh(**model_kwargs)

        unix.cd(self.cwd)
        setpar('SIMULATION_TYPE', '1')
        setpar('SAVE_FORWARD', '.false.')

        call_solver(system.mpiexec(), 'bin/xmeshfem2D', output='mesher.log')
        call_solver(system.mpiexec(), 'bin/xspecfem2D')

        if PAR.FORMAT in ['SU', 'su']:
            src = glob('OUTPUT_FILES/*.su')
            dst = 'traces/obs'
            unix.mv(src, dst)

        if PAR.SAVETRACES:
            self.export_traces(PATH.OUTPUT + '/' + 'traces/obs')
Beispiel #28
0
    def combine(self, input_path='', output_path='', parameters=[]):
        """ Sums individual source contributions. Wrapper over xcombine_sem
            utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        unix.cd(self.cwd)
        with open('kernel_paths', 'w') as file:
            file.writelines(
                [join(input_path, name + '\n') for name in self.source_names])

        for name in parameters or self.parameters:
            call_solver(
                system.mpiexec(), PATH.SPECFEM_BIN + '/' + 'xcombine_sem ' +
                name + '_kernel' + ' ' + 'kernel_paths' + ' ' + output_path)
Beispiel #29
0
    def smooth(self, input_path='', output_path='', parameters=[], span=0.):
        """ Smooths kernels by convolving them with a Gaussian.  Wrapper over 
            xsmooth_sem utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        # apply smoothing operator
        unix.cd(self.cwd)

        src = '/scratch/gpfs/etienneb/2D_inversion_80_elem/model_init80/proc000000_x.bin'
        dst = '/scratch/gpfs/etienneb/2D_inversion_80_elem/scratch/evalgrad/kernels/sum_nosmooth'
        unix.cp(src, dst)
        src = '/scratch/gpfs/etienneb/2D_inversion_80_elem/model_init80/proc000000_z.bin'
        unix.cp(src, dst)
        src = '/scratch/gpfs/etienneb/2D_inversion_80_elem/model_init80/proc000000_NSPEC_ibool.bin'
        unix.cp(src, dst)
        src = '/scratch/gpfs/etienneb/2D_inversion_80_elem/model_init80/proc000000_jacobian.bin'
        unix.cp(src, dst)
        print input_path
        for name in parameters or self.parameters:
            print ' smoothing', name
            call_solver(
                system.mpiexec(),
                PATH.SPECFEM_BIN +'/'+ 'xsmooth_sem '
                + str(span) + ' '
                + str(span) + ' '
                + name + '_kernel' + ' '
                + input_path + '/ '
                + output_path + '/ T',
                output='/scratch/gpfs/etienneb/2D_inversion_80_elem/smooth_output.log')

        print ''

        # rename output files
        files = glob(output_path+'/*')
        unix.rename('_smooth', '', files)
Beispiel #30
0
    def combine(self, input_path='', output_path='', parameters=[]):
        """ Sums individual source contributions. Wrapper over xcombine_sem
            utility.
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        unix.cd(self.cwd)
        with open('kernel_paths', 'w') as file:
            file.writelines([join(input_path, name+'\n')
                for name in self.source_names])

        for name in parameters or self.parameters:
            call_solver(
                system.mpiexec(),
                PATH.SPECFEM_BIN +'/'+ 'xcombine_sem '
                + name + '_kernel' + ' '
                + 'kernel_paths' + ' '
                + output_path)
    def generate_mesh(self, model_path=None, model_name=None, model_type='gll'):
        """ Performs meshing and database generation
        """
        assert(model_name)
        assert(model_type)

        self.initialize_solver_directories()
        unix.cd(self.cwd)

        if model_type == 'gll':
            assert (exists(model_path))
            self.check_mesh_properties(model_path)

            unix.cp(glob(model_path +'/'+ '*'), self.model_databases)

            call_solver(system.mpiexec(), 'bin/xmeshfem3D')

            if self.taskid == 0:
                self.export_model(PATH.OUTPUT +'/'+ model_name)

        else:
            raise NotImplementedError
Beispiel #32
0
    def smooth(self,
               input_path='',
               output_path='',
               parameters=[],
               span_h=0.,
               span_v=0.):
        """ Smooths kernels by convolving them with a Gaussian.  Wrapper over 
            xsmooth_sem utility. 
            smooth() in base.py has the incorrect command line call, specfem 
            requires that NPROC be specified
        """
        if not exists(input_path):
            raise Exception

        if not exists(output_path):
            unix.mkdir(output_path)

        # apply smoothing operator
        unix.cd(self.cwd)
        print 'smoothing parameters ', self.parameters
        for name in parameters or self.parameters:
            print 'smoothing', name
            solver_call = " ".join([
                PATH.SPECFEM_BIN + '/' + 'xsmooth_sem',  # ./bin/xsmooth_sem
                str(span_h),  # SIGMA_H
                str(span_v),  # SIGMA_V
                name + '_kernel',  # KERNEL_NAME
                input_path + '/',  # INPUT_DIR
                output_path + '/',  # OUTPUT_DIR
                '.false'  # USE_GPU
            ])
            call_solver(system.mpiexec(), solver_call)
        print ''

        # rename output files
        files = glob(output_path + '/*')
        unix.rename('_smooth', '', files)