Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79150888
gtrk2nbd
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Aug 25, 00:31
Size
4 KB
Mime Type
text/x-python
Expires
Tue, Aug 27, 00:31 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20156741
Attached To
rPNBODY pNbody
gtrk2nbd
View Options
#!/usr/bin/env python
'''
Convert glups .trk files into gwinparameters file
Yves Revaz
mer oct 25 10:27:24 CEST 2006
'''
import sys
import string
import os
from optparse import OptionParser
import glob
from math import *
from Gtools import io
from pNbody import libutil
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser.add_option("-o",
action="store",
dest="singleoutputfile",
type="string",
default = None,
help="name of the single outupt file",
metavar=" FILE")
parser.add_option("--eye",
action="store",
dest="eye",
type="string",
default = 'default',
help="eye to compute ('default','both','right','left')",
metavar=" TYPE")
parser.add_option("--basename",
action="store",
dest="basename",
type="string",
default = None,
help="image base name",
metavar=" STRING")
parser.add_option("--snapfiles",
action="store",
dest="snapfiles",
type="string",
default = None,
help=" /data/snap/snapshot_* ",
metavar=" STRING")
parser.add_option("--size",
action="store",
dest="size",
type="string",
default = "(512,512)",
help="size (x,y)",
metavar=" STRING")
(options, args) = parser.parse_args()
if len(args) == 0:
print "you must specify at least a filename"
sys.exit(0)
files = args
return files,options
#######################################
# GET OPTIONS
#######################################
# get options
files,options = parse_options()
eye = options.eye
basename = options.basename
size = options.size
snapfiles = options.snapfiles
singleoutputfile = options.singleoutputfile
#######################################
# LOOP
#######################################
exec("size = %s"%(size))
if singleoutputfile==None:
if eye == 'default':
os.system('rm -rf center')
os.system('mkdir center')
elif eye == 'right':
os.system('rm -rf right')
os.system('mkdir right')
elif eye == 'left':
os.system('rm -rf left')
os.system('mkdir left')
elif eye == 'both':
os.system('rm -rf right')
os.system('mkdir right')
os.system('rm -rf left')
os.system('mkdir left')
else:
pass
# set files names
nfiles = len(files)
if snapfiles!=None:
snapfiles = glob.glob(snapfiles)
snapfiles.sort()
nsnap = len(snapfiles)
if nsnap > 1:
m = int(round(float(nfiles)/float(nsnap))) #+ 1
else:
m = 1
if m == 0:
print "not enough files"
print "to much snapshot"
sys.exit()
else:
m = 1
final_snapfiles=[]
i = 0
for file in files:
if basename!=None:
final_snapfiles.append(basename)
else:
isnap = int( float(nsnap)/float(nfiles) * i )
final_snapfiles.append(os.path.basename(snapfiles[isnap]))
print i,isnap,m,snapfiles[isnap]
i = i+1
i = 0
old_final_snapfile = '-'
# read files
for file in files:
dic = io.read_track(file)
#glparam = {}
#for key in dic.keys():
# k = string.split(key,':')
# if k[0]=='Observer_0':
# glparam[k[1]]=dic[key]
if singleoutputfile!=None:
io.write_nbodyparam(singleoutputfile,dic,eye,size)
sys.exit()
if old_final_snapfile == final_snapfiles[i]:
j = j + 1
else:
j = 0
old_final_snapfile = final_snapfiles[i]
# write
if eye == 'default':
outputfile = "center/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,eye,size)
elif eye == 'right':
outputfile = "right/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,eye,size)
elif eye == 'left':
outputfile = "left/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,eye,size)
elif eye == 'both':
outputfile = "right/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,'right',size)
outputfile = "left/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,'left',size)
else:
pass
i = i + 1
Event Timeline
Log In to Comment