def combine(self, path=''): """ combines SPECFEM3D kernels """ unix.cd(self.getpath) # create temporary files and directories dirs = unix.ls(path) with open('kernels_list.txt', 'w') as file: file.write('\n'.join(dirs) + '\n') unix.mkdir('INPUT_KERNELS') unix.mkdir('OUTPUT_SUM') for dir in dirs: src = path + '/' + dir dst = 'INPUT_KERNELS' + '/' + dir unix.ln(src, dst) # sum kernels self.mpirun(PATH.SOLVER_BINARIES + '/' + 'xsum_kernels') unix.mv('OUTPUT_SUM', path + '/' + 'sum') # remove temporary files and directories unix.rm('INPUT_KERNELS') unix.rm('kernels_list.txt') unix.cd(path)
def sum_residuals(self, path='', suffix=''): """ Returns sum of squares of residuals """ src = path + '/' + 'residuals' dst = PATH.OPTIMIZE + '/' + 'f_' + suffix residuals = [] for file in unix.ls(src): fromfile = np.loadtxt(src + '/' + file) residuals.append(fromfile**2.) np.savetxt(dst, [np.sum(residuals)])
def sum_residuals(self, path='', suffix=''): """ Returns sum of squares of residuals """ src = path +'/'+ 'residuals' dst = PATH.OPTIMIZE +'/'+ 'f_' + suffix residuals = [] for file in unix.ls(src): fromfile = np.loadtxt(src +'/'+ file) residuals.append(fromfile**2.) np.savetxt(dst, [np.sum(residuals)])
def sum_residuals(self, path='', suffix=''): """ Sums residuals to obtain misfit function value """ src = path +'/'+ 'residuals' dst = PATH.OPTIMIZE +'/'+ 'f_' + suffix residuals = [] for file in unix.ls(src): fromfile = np.loadtxt(src +'/'+ file) residuals.append(fromfile**2.) np.savetxt(dst, [np.sum(residuals)])
def combine(self, path=''): """ combines SPECFEM3D_GLOBE kernels """ dirs = unix.ls(path) # initialize kernels unix.cd(path) for key in self.model_parameters: if key not in self.inversion_parameters: for i in range(PAR.NPROC): proc = '%06d' % i name = self.kernel_map[key] src = PATH.GLOBAL + '/' + 'mesh' + '/' + key + '/' + proc dst = path + '/' + 'sum' + '/' + 'proc' + proc + '_' + name + '.bin' savebin(np.load(src), dst) # create temporary files and directories unix.cd(self.getpath) with open('kernels_list.txt', 'w') as file: file.write('\n'.join(dirs) + '\n') unix.mkdir('INPUT_KERNELS') unix.mkdir('OUTPUT_SUM') for dir in dirs: src = path + '/' + dir dst = 'INPUT_KERNELS' + '/' + dir unix.ln(src, dst) # sum kernels self.mpirun(PATH.SOLVER_BINARIES + '/' + 'xsum_kernels') unix.mv('OUTPUT_SUM', path + '/' + 'sum') # remove temporary files and directories unix.rm('INPUT_KERNELS') unix.rm('kernels_list.txt') unix.cd(path)
def combine(self, path=''): """combines SPECFEM2D kernels""" subprocess.call([self.getpath + '/' + 'bin/xsmooth_sem'] + [str(len(unix.ls(path)))] + [path])