Example #1
0
    def smooth(self, path='', parameters=None, span=0.):
        """ Smooths SPECFEM2D kernels by convolving them with a Gaussian
        """
        from seisflows.tools.array import meshsmooth, stack

        #assert parameters == self.parameters

        # implementing nproc > 1 would be straightforward, but a bit tedious
        #assert self.mesh.nproc == 1

        kernels = self.load(path, suffix='_kernel')
        if not span:
            return kernels

        # set up grid
        x = sem.read(PATH.MODEL_INIT, 'x', 0)
        z = sem.read(PATH.MODEL_INIT, 'z', 0)
        mesh = stack(x, z)

        for key in parameters or self.parameters:
            kernels[key] = [meshsmooth(kernels[key][0], mesh, span)]

        unix.rm(path + '_nosmooth')
        unix.mv(path, path + '_nosmooth')
        self.save(path, kernels, suffix='_kernel')
Example #2
0
    def smooth(self, path='', parameters='dummy', span=0. ):
        """ Smooths SPECFEM2D kernels by convolving them with a Gaussian
        """
        from seisflows.tools.array import meshsmooth, stack

        #assert parameters == self.parameters

        # implementing nproc > 1 would be straightforward, but a bit tedious
        #assert self.mesh.nproc == 1

        kernels = self.load(path, suffix='_kernel')
        if not span:
            return kernels

        # set up grid
        _,x = loadbypar(PATH.MODEL_INIT, ['x'], 0)
        _,z = loadbypar(PATH.MODEL_INIT, ['z'], 0)
        mesh = stack(x[0], z[0])

        for key in self.parameters:
            kernels[key] = [meshsmooth(kernels[key][0], mesh, span)]

        unix.rm(path + '_nosmooth')
        unix.mv(path, path + '_nosmooth')
        self.save(path, kernels, suffix='_kernel')
Example #3
0
    def smooth(self, path='', span=0., parameters=[]):
        """ Smooths SPECFEM2D kernels by convolving them with a Gaussian
        """
        from seisflows.tools.array import meshsmooth, stack

        kernels = self.load(path, suffix='_kernel')
        if not span:
            return kernels

        x = kernels['x'][0]
        z = kernels['z'][0]
        mesh = stack(x, z)

        for key in parameters:
            kernels[key] = [meshsmooth(kernels[key][0], mesh, span)]

        unix.mv(path, path + '_nosmooth')
        self.save(path, kernels)
Example #4
0
    def apply_smoothing(self, parameter):
        from seisflows.tools.array import meshsmooth, stack

        coords = []
        for key in ['x', 'z']:
            coords += [sem.read(PATH.MODEL_INIT, key, 0)]
        mesh = stack(*coords)
        
        for suffix in ['_nu']:
            path = PATH.MUMFORD_SHAH_OUTPUT

            if PAR.SMOOTH_EDGES > 0.:
                # backup original
                kernel = sem.read(path, parameter+suffix, 0)
                sem.write(kernel, path, parameter+suffix+'_nosmooth', 0)

                # apply smoothing operator
                kernel = meshsmooth(kernel, mesh, PAR.SMOOTH_EDGES)
                sem.write(kernel, path, parameter+suffix, 0)
def smooth_legacy(input_path='', output_path='', parameters=[], span=0.):
        solver = sys.modules['seisflows_solver']
        PATH = sys.modules['seisflows_paths']

        if not exists(input_path):
            raise Exception

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

        if solver.mesh_properties.nproc!=1:
            raise NotImplementedError

        # intialize arrays
        kernels = {}
        for key in parameters or solver.parameters:
            kernels[key] = []

        coords = {}
        for key in ['x', 'z']:
            coords[key] = []

        # read kernels
        for key in parameters or solver.parameters:
            kernels[key] += solver.io.read_slice(input_path, key+'_kernel', 0)

        if not span:
            return kernels

        # read coordinates
        for key in ['x', 'z']:
            coords[key] += solver.io.read_slice(PATH.MODEL_INIT, key, 0)

        mesh = array.stack(coords['x'][0], coords['z'][0])

        # apply smoother
        for key in parameters or solver.parameters:
            kernels[key] = [array.meshsmooth(kernels[key][0], mesh, span)]

        # write smooth kernels
        for key in parameters or solver.parameters:
            solver.io.write_slice(kernels[key][0], output_path, key+'_kernel', 0)
Example #6
0
def smooth_legacy(input_path='', output_path='', parameters=[], span=0.):
    solver = sys.modules['seisflows_solver']
    PATH = sys.modules['seisflows_paths']

    if not exists(input_path):
        raise Exception

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

    if solver.mesh_properties.nproc != 1:
        raise NotImplementedError

    # intialize arrays
    kernels = {}
    for key in parameters or solver.parameters:
        kernels[key] = []

    coords = {}
    for key in ['x', 'z']:
        coords[key] = []

    # read kernels
    for key in parameters or solver.parameters:
        kernels[key] += solver.io.read_slice(input_path, key + '_kernel', 0)

    if not span:
        return kernels

    # read coordinates
    for key in ['x', 'z']:
        coords[key] += solver.io.read_slice(PATH.MODEL_INIT, key, 0)

    mesh = array.stack(coords['x'][0], coords['z'][0])

    # apply smoother
    for key in parameters or solver.parameters:
        kernels[key] = [array.meshsmooth(kernels[key][0], mesh, span)]

    # write smooth kernels
    for key in parameters or solver.parameters:
        solver.io.write_slice(kernels[key][0], output_path, key + '_kernel', 0)
Example #7
0
    def smooth(self, path='', tag='gradient', span=0.):
        """smooths SPECFEM2D kernels by convolving them with a Gaussian"""
        from seisflows.tools.array import meshsmooth

        parts = self.load(path + '/' + tag)
        if not span:
            return parts

        # set up grid
        x = parts['x'][0]
        z = parts['z'][0]
        lx = x.max() - x.min()
        lz = z.max() - z.min()
        nn = x.size
        nx = np.around(np.sqrt(nn * lx / lz))
        nz = np.around(np.sqrt(nn * lx / lz))

        # perform smoothing
        for key in self.inversion_parameters:
            parts[key] = [meshsmooth(x, z, parts[key][0], span, nx, nz)]
        unix.mv(path + '/' + tag, path + '/' + '_nosmooth')
        self.save(path + '/' + tag, parts)
Example #8
0
def smooth_legacy(path='', parameters=[], span=0.):
    solver = sys.modules['seisflows_solver']
    PATH = sys.modules['seisflows_paths']

    # intialize arrays
    kernels = {}
    for key in parameters or solver.parameters:
        kernels[key] = []

    coords = {}
    for key in ['x', 'z']:
        coords[key] = []

    # read kernels
    for key in parameters or solver.parameters:
        kernels[key] += solver.io.read_slice(path, key + '_kernel', 0)

    if not span:
        return kernels

    # read coordinates
    for key in ['x', 'z']:
        coords[key] += solver.io.read_slice(PATH.MODEL_INIT, key, 0)

    mesh = array.stack(coords['x'][0], coords['z'][0])

    #mesh = array.stack(solver.mesh_properties.coords['x'][0],
    #                   solver.mesh_properties.coords['z'][0])

    for key in parameters or solver.parameters:
        kernels[key] = [array.meshsmooth(kernels[key][0], mesh, span)]

    unix.rm(path + '_nosmooth')
    unix.mv(path, path + '_nosmooth')

    unix.mkdir(path)
    for key in parameters or solver.parameters:
        solver.io.write_slice(kernels[key][0], path, key + '_kernel', 0)
Example #9
0
    def smooth(self, path='', parameters=None, span=0.):
        """ For a long time SPECFEM2D lacked its own smoothing utility; this 
          method was intended only as a crude workaround
        """
        from seisflows.tools import array

        assert self.mesh_properties.nproc == 1,\
            msg.SmoothingError_SPECFEM2D

        kernels = self.load(path, suffix='_kernel')
        if not span:
            return kernels

        # set up grid
        x = sem.read(PATH.MODEL_INIT, 'x', 0)
        z = sem.read(PATH.MODEL_INIT, 'z', 0)
        mesh = array.stack(x, z)

        for key in parameters or self.parameters:
            kernels[key] = [array.meshsmooth(kernels[key][0], mesh, span)]

        unix.rm(path + '_nosmooth')
        unix.mv(path, path + '_nosmooth')
        self.save(path, kernels, suffix='_kernel')