本文整理汇总了Python中seisflows.tools.unix.cd函数的典型用法代码示例。如果您正苦于以下问题:Python cd函数的具体用法?Python cd怎么用?Python cd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_kernels
def export_kernels(self, path):
unix.cd(self.kernel_databases)
# work around conflicting name conventions
files = []
files += glob('*proc??????_alpha_kernel.bin')
files += glob('*proc??????_alpha[hv]_kernel.bin')
files += glob('*proc??????_reg1_alpha_kernel.bin')
files += glob('*proc??????_reg1_alpha[hv]_kernel.bin')
unix.rename('alpha', 'vp', files)
files = []
files += glob('*proc??????_beta_kernel.bin')
files += glob('*proc??????_beta[hv]_kernel.bin')
files += glob('*proc??????_reg1_beta_kernel.bin')
files += glob('*proc??????_reg1_beta[hv]_kernel.bin')
unix.rename('beta', 'vs', files)
# hack to deal with problems on parallel filesystem
unix.mkdir(join(path, 'kernels'), noexit=True)
unix.mkdir(join(path, 'kernels', basename(self.getpath)))
src = join(glob('*_kernel.bin'))
dst = join(path, 'kernels', basename(self.getpath))
unix.mv(src, dst)
示例2: clip
def clip(self, path='', parameters=[], minval=-np.inf, maxval=np.inf):
""" Clips kernels by convolving them with a Gaussian. Wrapper over
xclip_sem utility.
"""
assert exists(path)
assert len(parameters) > 0
unix.cd(self.getpath)
for name in self.parameters:
self.mpirun(
PATH.SPECFEM_BIN +'/'+ 'xclip_sem '
+ str(minval) + ' '
+ str(maxval) + ' '
+ name + '_kernel' + ' '
+ path + '/ '
+ path + '/ ')
# move input files
src = path
dst = path + '_noclip'
unix.mkdir(dst)
for name in self.parameters:
unix.mv(glob(src+'/*'+name+'.bin'), dst)
# rename output files
unix.rename('_clip', '', glob(src+'/*'))
示例3: submit
def submit(self, workflow):
"""Submits job
"""
unix.mkdir(PATH.OUTPUT)
unix.cd(PATH.OUTPUT)
# save current state
self.checkpoint()
# construct resource list
nodes = int(PAR.NTASK / PAR.NODESIZE)
cores = PAR.NTASK % PAR.NODESIZE
hours = int(PAR.WALLTIME / 60)
minutes = PAR.WALLTIME % 60
resources = 'walltime=%02d:%02d:00'%(hours, minutes)
if nodes == 0:
resources += ',mem=%dgb,nodes=1:ppn=%d'%(PAR.MEMORY, cores)
elif cores == 0:
resources += ',mem=%dgb,nodes=%d:ppn=%d'%(PAR.MEMORY, nodes, PAR.NODESIZE)
else:
resources += ',mem=%dgb,nodes=%d:ppn=%d+1:ppn=%d'%(PAR.MEMORY, nodes, PAR.NODESIZE, cores)
# construct arguments list
unix.run('qsub '
+ '-N %s '%PAR.TITLE
+ '-o %s '%(PATH.SUBMIT +'/'+ 'output.log')
+ '-l %s '%resources
+ '-j %s '%'oe'
+ findpath('system') +'/'+ 'wrappers/submit '
+ '-F %s '%PATH.OUTPUT)
示例4: submit
def submit(self, workflow):
""" Submits workflow
"""
unix.mkdir(PATH.OUTPUT)
unix.cd(PATH.OUTPUT)
unix.mkdir(PATH.SUBMIT+'/'+'output.pbs')
self.checkpoint()
hours = PAR.WALLTIME/60
minutes = PAR.WALLTIME%60
walltime = 'walltime=%02d:%02d:00 ' % (hours, minutes)
ncpus = PAR.NODESIZE
mpiprocs = PAR.NODESIZE
# prepare qsub arguments
unix.run( 'qsub '
+ '%s ' % PAR.PBSARGS
+ '-l select=1:ncpus=%d:mpiprocs=%d ' % (ncpus, mpiprocs)
+ '-l %s ' % walltime
+ '-N %s ' % PAR.TITLE
+ '-j %s '%'oe'
+ '-o %s ' % (PATH.SUBMIT+'/'+'output.log')
+ '-V '
+ ' -- ' + findpath('seisflows.system') +'/'+ 'wrappers/submit '
+ PATH.OUTPUT)
示例5: update
def update(self):
""" Updates L-BFGS algorithm history
"""
unix.cd(self.path)
s = self.load('m_new') - self.load('m_old')
y = self.load('g_new') - self.load('g_old')
m = len(s)
n = self.memory
if self.memory_used == 0:
S = np.memmap('LBFGS/S', mode='w+', dtype='float32', shape=(m, n))
Y = np.memmap('LBFGS/Y', mode='w+', dtype='float32', shape=(m, n))
S[:, 0] = s
Y[:, 0] = y
self.memory_used = 1
else:
S = np.memmap('LBFGS/S', mode='r+', dtype='float32', shape=(m, n))
Y = np.memmap('LBFGS/Y', mode='r+', dtype='float32', shape=(m, n))
S[:, 1:] = S[:, :-1]
Y[:, 1:] = Y[:, :-1]
S[:, 0] = s
Y[:, 0] = y
if self.memory_used < self.memory:
self.memory_used += 1
return S, Y
示例6: combine
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)
示例7: write_receivers
def write_receivers(self):
unix.cd(self.getpath)
key = 'use_existing_STATIONS'
val = '.true.'
setpar(key, val)
_, h = preprocess.load('traces/obs')
solvertools.write_receivers(h.nr, h.rx, h.rz)
示例8: submit
def submit(self, workflow):
"""Submits job
"""
unix.mkdir(PATH.OUTPUT)
unix.cd(PATH.OUTPUT)
# save current state
self.checkpoint()
# construct resource list
nodes = PAR.NTASK/PAR.NODESIZE
cores = PAR.NTASK%PAR.NODESIZE
hours = PAR.WALLTIME/60
minutes = PAR.WALLTIME%60
resources = 'walltime=%02d:%02d:00 '%(hours, minutes)
if nodes == 0:
resources += ',nodes=1:ppn=%d'%cores
elif cores == 0:
resources += ',nodes=%d:ppn=16'%nodes
else:
resources += ',nodes=%d:ppn=16+1:ppn=%d'%(nodes, cores)
# construct arguments list
unix.run('qsub '
+ '-N %s '%PAR.TITLE
+ '-o %s '%(PATH.SUBMIT +'/'+ 'output.log')
+ '-l %s '%resources
+ '-j %s '%'oe'
+ findpath('system') +'/'+ 'pbs/wrapper_qsub '
+ PATH.OUTPUT,
shell=True)
示例9: smooth
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)
示例10: generate_mesh
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.getpath)
if model_type in ['gll']:
par = getpar('MODEL').strip()
if par != 'gll':
if self.getnode == 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)
self.call('bin/xmeshfem3D')
self.call('bin/xgenerate_databases')
self.export_model(PATH.OUTPUT +'/'+ model_name)
else:
raise NotImplementedError
示例11: run
def run(self, classname, funcname, hosts='all', **kwargs):
""" Runs tasks in serial or parallel on specified hosts
"""
# to avoid cryptic MPI messages, use "--mca_warn_on_fork 0" as the
# default value for MPIARGS, and use subprocess.call rather than
# call_catch to invoke mpiexec
self.checkpoint()
self.save_kwargs(classname, funcname, kwargs)
if hosts == 'all':
unix.cd(join(findpath('seisflows.system'), 'wrappers'))
subprocess.call(PAR.MPIEXEC + ' '
+ '-n %d ' % PAR.NTASK
+ PAR.MPIARGS + ' '
+ 'run_mpi' + ' '
+ PATH.OUTPUT + ' '
+ classname + ' '
+ funcname,
shell=True)
elif hosts == 'head':
unix.cd(join(findpath('seisflows.system'), 'wrappers'))
subprocess.call(PAR.MPIEXEC + ' '
+ '-n 1 '
+ PAR.MPIARGS + ' '
+ 'run_mpi_head' + ' '
+ PATH.OUTPUT + ' '
+ classname + ' '
+ funcname,
shell=True)
else:
raise(KeyError('Hosts parameter not set/recognized.'))
示例12: smooth
def smooth(self, path='', parameters=[], span=0.):
""" Smooths kernels by convolving them with a Gaussian. Wrapper over
xsmooth_sem utility.
"""
assert exists(path)
assert len(parameters) > 0
# apply smoothing operator
unix.cd(self.getpath)
for name in parameters:
print ' smoothing', name
self.mpirun(
PATH.SPECFEM_BIN +'/'+ 'xsmooth_sem '
+ str(span) + ' '
+ str(span) + ' '
+ name + '_kernel' + ' '
+ path + '/ '
+ path + '/ ',
output=self.getpath+'/'+'OUTPUT_FILES/output_smooth_sem.txt')
print ''
# move input files
src = path
dst = path + '_nosmooth'
unix.mkdir(dst)
for name in self.parameters:
unix.mv(glob(src+'/*'+name+'.bin'), dst)
# rename output files
unix.rename('_smooth', '', glob(src+'/*'))
示例13: run
def run(self, classname, funcname, hosts='all', **kwargs):
""" Runs tasks in serial or parallel on specified hosts
"""
self.checkpoint()
self.save_kwargs(classname, funcname, kwargs)
if hosts == 'all':
unix.cd(join(findpath('seisflows.system'), 'wrappers'))
unix.run('mpiexec -n {} '.format(PAR.NTASK)
+ PAR.MPIARGS + ' '
+ 'run_mpi' + ' '
+ PATH.OUTPUT + ' '
+ classname + ' '
+ funcname)
elif hosts == 'head':
unix.cd(join(findpath('seisflows.system'), 'wrappers'))
unix.run('mpiexec -n 1 '
+ PAR.MPIARGS + ' '
+ 'run_mpi_head' + ' '
+ PATH.OUTPUT + ' '
+ classname + ' '
+ funcname)
else:
raise(KeyError('Hosts parameter not set/recognized.'))
示例14: adjoint
def adjoint(self):
""" Perform adjoint simulation. Must launch from /bin
"""
unix.cd(join(self.getpath, 'bin'))
script = './xewf2d'
super(ewf2d, self).mpirun(script, PATH.SUBMIT + '/dump')
unix.cd(PATH.SUBMIT)
示例15: submit
def submit(self, workflow):
""" Submits job
"""
unix.mkdir(PATH.OUTPUT)
unix.cd(PATH.OUTPUT)
self.checkpoint()
workflow.main()