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')
def getxz(self): model_path = PATH.OUTPUT + '/' + 'model_init' try: m = solver.load(model_path) x = m['x'][0] z = m['z'][0] except: from seisflows.seistools.io.sem import read x = read(model_path, 'x', 0) z = read(model_path, 'z', 0) return x, z
def load(self, path, prefix='', suffix='', verbose=False): """ reads SPECFEM model or kernels Models are stored in Fortran binary format and separated into multiple files according to material parameter and processor rank. """ minmax = Minmax(self.parameters) model = Model(self.parameters) for iproc in range(self.mesh_properties.nproc): for key in self.parameters: model[key] += [sem.read(path, prefix + key + suffix, iproc)] # keep track of min, max #minmax.update(key, model[key][iproc]) #if verbose: # minmax.write(path, logpath=PATH.SUBMIT) return model
def check_mesh_properties(self, path=None, parameters=None): if not hasattr(self, '_mesh_properties'): if not path: path = PATH.MODEL_INIT if not parameters: parameters = self.parameters nproc = 0 ngll = [] while True: dummy = sem.read(path, parameters[0], nproc) ngll += [len(dummy)] nproc += 1 if not exists('%s/proc%06d_%s.bin' % (path, nproc, parameters[0])): break self._mesh_properties = Struct([['nproc', nproc], ['ngll', ngll]]) return self._mesh_properties