def __run(prog, args, inp, out, verb, exe, postproc=None): prog = prog.strip() if args == None: args = '' else: args = args.strip() cmd = os.path.join(rsf.prog.RSFROOT, 'bin', prog) if exe == 'g': # get output assert out == None out_str = ivlad.getout(prog, args, inp, verb) if postproc == None: return out_str else: return postproc(out_str) elif exe == 'p': # call part of a pipe if args != '': cmd += ' ' + args return cmd else: if inp != None: cmd += ' <' + inp.strip() if out != None: cmd += ' >' + out.strip() if args != '': cmd += ' ' + args if exe == 'l': # log return cmd else: # exe=='x', execute ivlad.exe(cmd, verb)
def main(par): f1 = sys.argv[1] + ' ' f2 = sys.argv[2] f1_type = ivlad.getout('sfgettype', stdin=f1) if f1_type != 'SF_FLOAT': raise m8rex.TypeHandlingNotImplemented(f1_type) dims_str = ivlad.getout('sffiledims', 'parform=n', f1) ndims = int(dims_str.split(':')[0]) cmd = 'sfspike mag=0 ' fields = 'n o d unit label'.split() for i in range(ndims): for z in fields: cmd += ivlad.getout('sfget', ['parform=y', z + str(i + 1)], f1) + ' ' cmd += ' >' + f2 ivlad.exe(cmd) return ivlad.unix_success
def __run(prog, args, inp, out, verb, exe, postproc=None): prog = prog.strip() if args == None: args = '' else: args = args.strip() cmd = os.path.join(rsf.prog.RSFROOT,'bin',prog) if exe == 'g': # get output assert out == None out_str = ivlad.getout(prog, args, inp, verb) if postproc == None: return out_str else: return postproc(out_str) elif exe == 'p': # call part of a pipe if args != '': cmd += ' ' + args return cmd else: if inp != None: cmd += ' <' + inp.strip() if out != None: cmd += ' >' + out.strip() if args != '': cmd += ' ' + args if exe == 'l': # log return cmd else: # exe=='x', execute ivlad.exe(cmd, verb)
def download_imgs(imgs_to_download, wikiroot, imgdir): for imgfile in sorted(imgs_to_download.keys()): ivlad.msg('Downloading: ' + imgfile) img_url = wikiroot + img_dir_basename + '/' + \ imgs_to_download[imgfile] + '/' + imgfile img_file = os.path.join(imgdir, imgfile) ivlad.exe('curl ' + img_url + '>' + img_file)
def download_imgs(imgs_to_download, wikiroot, imgdir): for imgfile in sorted(imgs_to_download.keys()): ivlad.msg('Downloading: ' + imgfile) img_url = wikiroot + img_dir_basename + '/' + \ imgs_to_download[imgfile] + '/' + imgfile img_file = os.path.join(imgdir,imgfile) ivlad.exe('curl ' + img_url + '>' + img_file)
def main(par): verb = par.bool('verb', False) dryrun = par.bool('dryrun', False) # sfbyte arguments: bytepars = {} for key in ['gainpanel', 'pclip', 'clip']: bytepars[key] = par.string(key, None) # sfgrey3 arguments: color = par.string('color', None) lbl = int(100000000 * random.random()) suffix = '.' + str(lbl) + ivlad.ext prefix = sys.argv[0].rstrip('.py') + '.' tmp_filenm = prefix + 'inp' + suffix bar_filenm = prefix + 'bar' + suffix # Redirect the input if not dryrun: tmp_file = open(tmp_filenm, 'w') tmp_file.write(sys.stdin.read()) tmp_file.close() sf._set_xmode('l') cmd_list = [ '# Redirect input to ' + tmp_filenm, sf.bar(tmp_filenm, bar_filenm) ] ivlad.exe(cmd_list, verb, dryrun) if dryrun: cmd = '<' + tmp_filenm + ' sfbyte | sfgrey3 scalebar=y bar=' cmd += bar_filenm + ' >stdout' ivlad.msg(cmd, verb) else: p1 = subprocess.Popen(['sfbyte'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) tmp_file = open(tmp_filenm, 'r') p1.stdin.write(tmp_file.read()) p2 = subprocess.Popen(['sfgrey3', 'scalebar=y', 'bar=' + bar_filenm], stdin=p1.stdout, stdout=subprocess.PIPE) sys.stdout.write(p2.stdout.read()) p1.stdin.close() tmp_file.close() p2.stdout.close() cmd = sf.rm([tmp_filenm, bar_filenm]) ivlad.exe(cmd, verb, dryrun) return ivlad.unix_success
def main(par): verb = par.bool('verb' , False) dryrun = par.bool('dryrun', False) # sfbyte arguments: bytepars = {} for key in ['gainpanel', 'pclip', 'clip']: bytepars[key] = par.string(key, None) # sfgrey3 arguments: color = par.string('color', None) lbl = int(100000000*random.random()) suffix = '.' + str(lbl) + ivlad.ext prefix = sys.argv[0].rstrip('.py') + '.' tmp_filenm = prefix + 'inp' + suffix bar_filenm = prefix + 'bar' + suffix # Redirect the input if not dryrun: tmp_file = open(tmp_filenm, 'w') tmp_file.write(sys.stdin.read()) tmp_file.close() sf._set_xmode('l') cmd_list = ['# Redirect input to ' + tmp_filenm, sf.bar(tmp_filenm, bar_filenm)] ivlad.exe(cmd_list, verb, dryrun) if dryrun: cmd = '<' + tmp_filenm + ' sfbyte | sfgrey3 scalebar=y bar=' cmd+= bar_filenm + ' >stdout' ivlad.msg(cmd, verb) else: p1 = subprocess.Popen(['sfbyte'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) tmp_file = open(tmp_filenm, 'r') p1.stdin.write(tmp_file.read()) p2 = subprocess.Popen(['sfgrey3', 'scalebar=y', 'bar='+bar_filenm], stdin=p1.stdout, stdout=subprocess.PIPE) sys.stdout.write(p2.stdout.read()) p1.stdin.close() tmp_file.close() p2.stdout.close() cmd = sf.rm([tmp_filenm, bar_filenm]) ivlad.exe(cmd, verb, dryrun) return ivlad.unix_success
def main(par): verb = par.bool('verb', False) inp = par.string('inp') # ifile.rsf out_basenm = os.path.basename(inp).rstrip(ivlad.ext) + '_split' outdir = par.string('outdir', (out_basenm + ivlad.ext)) # Default is ifile_split.rsf nthick = par.int('nthick', 1) # slice thickness ivlad.chk_param_limit(nthick, 'nthick', 1, '>') lastdim = str(ivlad.ndims(inp)) n = int(ivlad.getout('sfget', ['parform=n', 'n' + lastdim], inp)) ivlad.chk_param_limit(nthick, 'nthick', n, '<') if not os.path.isdir(outdir): os.mkdir(outdir) # Slices will be called 01.rsf, etc. Avoid datapath aliasing: dpath = 'datapath=$DATAPATH/' + out_basenm + '_' nslices_whole = int(math.floor(n / nthick)) f = 0 for i in range(nslices_whole): i_str = ivlad.add_zeros(i, nslices_whole) i_slc = os.path.join(outdir, i_str + '_stdout' + ivlad.ext) cmd = '<%s sfwindow f%s=%d ' % (inp, lastdim, f) cmd += 'n%s=%d %s > %s' % (lastdim, nthick, dpath, i_slc) ivlad.exe(cmd, verb) f += nthick ist = n - nslices_whole * nthick # Incomplete Slice Thickness if ist > 0: i_str = ivlad.add_zeros(i + 1, nslices_whole) i_slc = os.path.join(outdir, i_str + '_stdout' + ivlad.ext) cmd = '<%s sfwindow f%s=%d ' % (inp, lastdim, f) cmd += 'n%s=%d > %s' % (lastdim, ist, i_slc) ivlad.exe(cmd, verb) return ivlad.unix_success
def main(par): verb = par.bool('verb', False) inp = par.string('inp') # ifile.rsf out_basenm = os.path.basename(inp).rstrip(ivlad.ext) + '_split' outdir = par.string('outdir',(out_basenm+ivlad.ext)) # Default is ifile_split.rsf nthick = par.int('nthick', 1) # slice thickness ivlad.chk_param_limit(nthick, 'nthick', 1, '>') lastdim = str(ivlad.ndims(inp)) n = int(ivlad.getout('sfget',['parform=n','n'+lastdim], inp)) ivlad.chk_param_limit(nthick, 'nthick', n, '<') if not os.path.isdir(outdir): os.mkdir(outdir) # Slices will be called 01.rsf, etc. Avoid datapath aliasing: dpath = 'datapath=$DATAPATH/' + out_basenm + '_' nslices_whole = int(math.floor(n/nthick)) f = 0 for i in range(nslices_whole): i_str = ivlad.add_zeros(i,nslices_whole) i_slc = os.path.join(outdir, i_str + '_stdout' + ivlad.ext) cmd = '<%s sfwindow f%s=%d ' % (inp, lastdim,f) cmd += 'n%s=%d %s > %s' % (lastdim, nthick, dpath, i_slc) ivlad.exe(cmd, verb) f += nthick ist = n - nslices_whole * nthick # Incomplete Slice Thickness if ist > 0: i_str = ivlad.add_zeros(i+1,nslices_whole) i_slc = os.path.join(outdir, i_str + '_stdout' + ivlad.ext) cmd = '<%s sfwindow f%s=%d ' % (inp, lastdim, f) cmd += 'n%s=%d > %s' % (lastdim, ist, i_slc) ivlad.exe(cmd, verb) return ivlad.unix_success
def main(par): prog = par.string('prog') # Non-madagascar utility inp = par.string('inp') # Input file tpar_str = par.string('tpar') # Translated params, i.e.: "ni1=n1 ni2=n2" ipar_str = par.string('ipar') # Independent params, i.e. "perc=100 cmap=rgb" verb = par.bool('verb',False) tpar_out = '' if tpar_str != None: for tpar in tpar_str.split(): thispar = tpar.split('=') tpar_out += thispar[0] + '=' + \ ivlad.getout('sfget', ['parform=n', thispar[1]], inp, verb) +' ' data = ivlad.getout('sfin',['info=n',inp]) ivlad.exe(prog + ' <' + data + ' ' + tpar_out + ' ' + ipar_str, verb) return ivlad.unix_success
def main(par): prog = par.string('prog') # Non-madagascar utility inp = par.string('inp') # Input file tpar_str = par.string('tpar') # Translated params, i.e.: "ni1=n1 ni2=n2" ipar_str = par.string( 'ipar') # Independent params, i.e. "perc=100 cmap=rgb" verb = par.bool('verb', False) tpar_out = '' if tpar_str != None: for tpar in tpar_str.split(): thispar = tpar.split('=') tpar_out += thispar[0] + '=' + \ ivlad.getout('sfget', ['parform=n', thispar[1]], inp, verb) +' ' data = ivlad.getout('sfin', ['info=n', inp]) ivlad.exe(prog + ' <' + data + ' ' + tpar_out + ' ' + ipar_str, verb) return ivlad.unix_success
def main(par): f1 = sys.argv[1] + ' ' f2 = sys.argv[2] f1_type = ivlad.getout('sfgettype', stdin=f1) if f1_type != 'SF_FLOAT': raise m8rex.TypeHandlingNotImplemented(f1_type) dims_str = ivlad.getout('sffiledims','parform=n',f1) ndims = int(dims_str.split(':')[0]) cmd = 'sfspike mag=0 ' fields = 'n o d unit label'.split() for i in range(ndims): for z in fields: cmd += ivlad.getout('sfget',['parform=y',z+str(i+1)],f1) + ' ' cmd += ' >' + f2 ivlad.exe(cmd) return ivlad.unix_success
def main(par): verb = par.bool('verb', False) # Display what is wrong with the dataset mydir = par.string('dir','.') # Directory with files recursive = par.bool('rec', False) # Whether to go down recursively chk4nan = par.bool('chk4nan',False) # Check for NaN values. Expensive!! valid_files_list = [] if recursive: for root, dirs, files in os.walk(mydir): valid_files_list += \ ivlad.list_valid_rsf_files(root, files, chk4nan) else: files = [x for x in os.listdir(mydir) if os.path.isfile(x)] valid_files_list += \ ivlad.list_valid_rsf_files(mydir, files, chk4nan) for f in valid_files_list: bfile = ivlad.getout('sfin',['info=n',f]) ivlad.msg(f + ': ' + bfile, verb) ivlad.exe('touch -c ' + bfile) return ivlad.unix_success
def main(par): verb = par.bool('verb', False) # Display what is wrong with the dataset mydir = par.string('dir','.') # Directory with files recursive = par.bool('rec', False) # Whether to go down recursively chk4nan = par.bool('chk4nan',False) # Check for NaN values. Expensive!! valid_files_list = [] if recursive: for root, dirs, files in os.walk(mydir): valid_files_list += \ ivlad.list_valid_rsf_files(root, files, chk4nan) else: files = filter(lambda x:os.path.isfile(x),os.listdir(mydir)) valid_files_list += \ ivlad.list_valid_rsf_files(mydir, files, chk4nan) for f in valid_files_list: bfile = ivlad.getout('sfin',['info=n',f]) ivlad.msg(f + ': ' + bfile, verb) ivlad.exe('touch -c ' + bfile) return ivlad.unix_success