Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/ein16/synth/d2/test_createField.py
ViewVC logotype

Annotation of /branches/ein16/synth/d2/test_createField.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4236 - (view) (download) (as text)

1 : cchiw 3865 import sys
2 :     import re
3 :     import os
4 :    
5 : cchiw 3915 from obj_apply import *
6 :     from obj_ty import *
7 :     from obj_operator import *
8 : cchiw 3939 from obj_field import *
9 : cchiw 3865 #constants
10 :     branch="/Users/chariseechiw/diderot/vis12/bin/diderotc --exec "
11 :    
12 : cchiw 3939 #convert coeffs
13 : cchiw 3865 def llist(cmd, coeff):
14 :     a=" -"+cmd
15 :     for i in coeff:
16 :     a+=" "+str(i)
17 :     return a
18 :    
19 :     #call program due to field type
20 : cchiw 4236 def progName(itype, outSize):
21 : cchiw 3865 #call program due to field type
22 : cchiw 4158 if (fty.isEq_id(itype,ty_scalarF_d1)):
23 : cchiw 4236 #print "kitten-made a 1-d field"
24 : cchiw 4158 return ("symb_fsd1"," -which 0 "," -s 1 "+str(outSize)) # 1-d scalar field
25 :     elif (fty.isEq_id(itype,ty_scalarF_d2)):
26 : cchiw 3865 return ("symb_fsd2"," -which 0 "," -s 1 "+str(outSize * outSize)) # 2-d scalar field
27 : cchiw 3939 elif(fty.isEq_id(itype,ty_vec2F_d2)): # 2-d length 2 vector field
28 :     return ("symb_fv2d2"," -which 0 "," -s 1 "+str(2*outSize *outSize)) # creates field with coefficients for each axis
29 : cchiw 4230 elif(fty.isEq_id(itype, ty_mat2x2F_d2)): # 2-d matrx 2x2
30 :     return ("symb_fm2x2d2"," -which 0 "," -s 1 "+str(4*outSize *outSize))
31 :     # creates field with coefficients for each axis
32 : cchiw 3939 elif (fty.isEq_id(itype,ty_scalarF_d3)):
33 :     return ("symb_fsd3"," -which 0 "," -s 1 "+str(outSize * outSize * outSize)) # 3-d scalar field
34 :     elif(fty.isEq_id(itype,ty_vec3F_d3)): # 2-d length 2 vector field
35 :     size = 3* outSize *outSize*outSize
36 : cchiw 4230 return ("symb_fv3d3"," -which 0 "," -s 1 "+str(size)) # creates field with coefficients for each axis
37 : cchiw 4236 elif(fty.isEq_id(itype, ty_mat2x2F_d3)):
38 :     # 3-d matrix field
39 :     size = 4* outSize *outSize*outSize
40 :     return ("symb_fm2x2d3"," -which 0 "," -s 1 "+str(size))
41 : cchiw 4230 elif(fty.isEq_id(itype, ty_mat3x3F_d3)):
42 :     # 3-d matrix field
43 :     size = 9* outSize *outSize*outSize
44 :     return ("symb_fm3x3d3"," -which 0 "," -s 1 "+str(size))
45 : cchiw 3874 else:
46 : cchiw 4236 raise Exception("type not supported in program name:"+itype.name)
47 : cchiw 3865
48 : cchiw 3939
49 :     # base,xsq,ysq,diag-coeffs
50 :     def coeffToBase(coeff, str):
51 : cchiw 4230 # print "coeff: ",len(coeff), " -",coeff
52 : cchiw 3939 [a,b,c,d,e,f,g,h,i]= coeff
53 :     base = [b,c]
54 :     xsq=[d,g]
55 :     ysq=[f,h]
56 :     diag=[a,e,i]
57 :     COEFF = llist("base"+str,base)+llist("xsq"+str,xsq)+llist("ysq"+str,ysq)+llist("diag"+str,diag) #convert coeff to strings
58 :     return COEFF
59 :    
60 : cchiw 4230 def coeffToBase2(coeff, str):
61 :     # print "coeff: ",len(coeff), " -",coeff
62 :     if (coeff== [0,0,0,0,0,0,0,0,0]):
63 :     return ""
64 :     else:
65 :     [a,b,c,d,e,f,g,h,i]= coeff
66 :     s=""
67 :     base = [b,c]
68 :     if (base == [0,0]):
69 :     1
70 :     else:
71 :     s+= llist("base"+str,base)
72 :     xsq=[d,g]
73 :     if (xsq == [0,0]):
74 :     1
75 :     else:
76 :     xsq=[d,g]
77 :     s+= llist("xsq"+str,xsq)
78 :     ysq=[f,h]
79 :     if (ysq == [0,0]):
80 :     1
81 :     else:
82 :     ysq=[f,h]
83 :     s+= llist("ysq"+str,ysq)
84 :     diag=[a,e,i]
85 :     if (diag==[0,0,0]):
86 :     1
87 :     else:
88 :     s+=llist("diag"+str,diag) #convert coeff to strings
89 :     return s
90 :    
91 :    
92 :    
93 : cchiw 3874 # shape-input field
94 :     # outSize-samples
95 :     # orig- name of synthetic field created with coefficients
96 :     def createSingleField(itype,outSize,orig, coeff):
97 : cchiw 3946 #print "inside create singlefield: "+orig+" ty: "+itype.name,"coeff:",coeff
98 : cchiw 3865 outputnrrd=orig+".nrrd"
99 :     sout=str(outSize)
100 : cchiw 3939 def get_Params():
101 : cchiw 4158 if(fty.get_dim(itype)==1):
102 :     [a,b,c]=coeff
103 :     COEFF ="-base "+str(a)+" "+str(b)+" "+str(c)#convert coeff to strings
104 :     SIZE=" -sz0 "+ sout +" -width 1" # giving sample size
105 :     return COEFF + SIZE
106 :     elif(fty.get_dim(itype)==2):
107 : cchiw 4230 #2d vector field
108 :     if(fty.isEq_id(itype, ty_mat2x2F_d2)):
109 :     [m0,m1]=coeff
110 :     [v1,v3] = m0
111 :     [v2,v4] = m1
112 :     COEFF = coeffToBase(v1, "1")+coeffToBase(v2, "2")+coeffToBase(v3, "3")+coeffToBase(v4, "4")#convert coeff to strings
113 :     SIZE=" -sz0 "+ sout +" -sz1 "+ sout +" -width 1" # giving sample size
114 :     return COEFF + SIZE
115 :     elif(fty.isEq_id(itype, ty_vec2F_d2)):
116 :     [v0,v1]=coeff
117 :     COEFF = coeffToBase(v0, "1")+coeffToBase(v1, "2")#convert coeff to strings
118 :     SIZE=" -sz0 "+ sout +" -sz1 "+ sout +" -width 1" # giving sample size
119 :     return COEFF + SIZE
120 :     elif(fty.isEq_id(itype, ty_scalarF_d2)):
121 :     # scalar field
122 :     COEFF = coeffToBase(coeff, "")#convert coeff to strings
123 :     SIZE=" -sz0 "+ sout +" -sz1 "+ sout +" -width 1" # giving sample size
124 :     return COEFF + SIZE
125 :     else:
126 :     raise "shape for dimension 2 is not supported"
127 : cchiw 3939 elif(fty.get_dim(itype)==3):
128 : cchiw 4230 if(fty.isEq_id(itype, ty_scalarF_d3)):
129 :     [z0,z1,z2]=coeff
130 :     COEFF=coeffToBase(z0, "_z0")+coeffToBase(z1, "_z1")+coeffToBase(z2, "_z2")
131 :     SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1" # giving sample size
132 :     return COEFF + SIZE
133 :     elif(fty.isEq_id(itype,ty_vec3F_d3)):
134 :     [[az0,az1,az2],[bz0,bz1,bz2],[cz0,cz1,cz2]]=coeff
135 :     COEFF=coeffToBase(az0, "1_z0")+coeffToBase(az1, "1_z1")+coeffToBase(az2, "1_z2")
136 :     COEFF+=coeffToBase(bz0, "2_z0")+coeffToBase(bz1, "2_z1")+coeffToBase(bz2, "2_z2")
137 :     COEFF+=coeffToBase(cz0, "3_z0")+coeffToBase(cz1, "3_z1")+coeffToBase(cz2, "3_z2")
138 :     SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1" # giving sample size
139 :     return COEFF + SIZE
140 : cchiw 4236 elif(fty.isEq_id(itype, ty_mat2x2F_d3)):
141 :     [m0, m1] = coeff
142 :     [[az0, az1, az2], [cz0, cz1, cz2]] = m0
143 :     [[bz0, bz1, bz2], [dz0, dz1, dz2]] = m1
144 :     COEFF= coeffToBase(az0, "1_z0")+coeffToBase(az1, "1_z1")+coeffToBase(az2, "1_z2")
145 :     COEFF+=coeffToBase(bz0, "2_z0")+coeffToBase(bz1, "2_z1")+coeffToBase(bz2, "2_z2")
146 :     COEFF+=coeffToBase(cz0, "3_z0")+coeffToBase(cz1, "3_z1")+coeffToBase(cz2, "3_z2")
147 :     COEFF+=coeffToBase(dz0, "4_z0")+coeffToBase(dz1, "4_z1")+coeffToBase(dz2, "4_z2")
148 :     SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1" # giving sample size
149 :     return COEFF + SIZE
150 :    
151 : cchiw 4230 elif(fty.isEq_id(itype, ty_mat3x3F_d3)):
152 :     [m0, _,_] = coeff
153 :     # [[z0_1, z0_2, z0_3],[z1_1, z1_2, z1_3],[z2_1, z2_2, z2_3]]= m0
154 :    
155 :     [[z0_1, z1_1, z2_1],[z0_2, z1_2, z2_2],[z0_3, z1_3, z2_3]]= m0
156 :     #[[z0_4, z1_2, z2_2],[z0_5, z1_5, z2_5],[z0_6, z1_8, z2_8]]= m1
157 :     # [[z0_7, z1_3, z2_3],[z0_8, z1_6, z2_6],[z0_9, z1_9, z2_9]]= m2
158 :     print ("\n\n\n")
159 :     print ("\n\ncoeff-m0_1_z0:", z0_1)
160 :     print ("coeef", coeffToBase2(z0_1, "1_z0"))
161 :     print ("\n\n\n")
162 :     print ("\n\ncoeff-m0_1_z1:", z1_1)
163 :     print ("coeff",coeffToBase2(z1_1, "1_z1"))
164 :     print ("\n\n\n")
165 :     print ("\n\ncoeff-z2_1:", z2_1)
166 :     print ("coeff",coeffToBase2(z2_1, "1_z2"))
167 :     print ("\n\n\n")
168 :     print ("\n\n\n")
169 :     COEFF=coeffToBase2(z0_1, "1_z0")+coeffToBase2(z1_1, "1_z1")+coeffToBase2(z2_1, "1_z2")
170 :     print ("coeffs", COEFF)
171 :     print ("\n\n\n")
172 :     print ("\n\ncoeff-z0_2 :", z0_2)
173 :     print ("coeff",coeffToBase2(z0_2, "2_z0"))
174 :     print ("\n\n\n")
175 :    
176 :    
177 :    
178 :    
179 :     COEFF+=coeffToBase2(z0_2, "2_z0")+coeffToBase2(z1_2, "2_z1")+coeffToBase2(z2_2, "2_z2")
180 :     COEFF+=coeffToBase2(z0_3, "3_z0")+coeffToBase2(z1_3, "3_z1")+coeffToBase2(z2_3, "3_z2")
181 :    
182 :     # COEFF+=coeffToBase(z0_4, "4_z0")+coeffToBase(z1_4, "4_z1")+coeffToBase(z2_4, "4_z2")
183 :     # COEFF+=coeffToBase(z0_5, "5_z0")+coeffToBase(z1_5, "5_z1")+coeffToBase(z2_5, "5_z2")
184 :     # COEFF+=coeffToBase(z0_6, "6_z0")+coeffToBase(z1_5, "6_z1")+coeffToBase(z2_6, "6_z2")
185 :    
186 :     # COEFF+=coeffToBase(z0_7, "7_z0")+coeffToBase(z1_7, "7_z1")+coeffToBase(z2_7, "7_z2")
187 :     # COEFF+=coeffToBase(z0_8, "8_z0")+coeffToBase(z1_8, "8_z1")+coeffToBase(z2_8, "8_z2")
188 :     # COEFF+=coeffToBase(z0_9, "9_z0")+coeffToBase(z1_9, "9_z1")+coeffToBase(z2_9, "9_z2")
189 : cchiw 4236 #print ("cmd",COEFF)
190 : cchiw 4230 SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1" # giving sample size
191 :     return COEFF + SIZE
192 :     else:
193 :     raise "shape for dimension 3 is not supported"
194 : cchiw 3939 else:
195 :     raise "dim not supported:"
196 :     PARAMS = get_Params()
197 : cchiw 3865 # get program name and which command
198 : cchiw 4236 #print "create field A"
199 : cchiw 3874 (e_Orig,w_coeff,w_shape) = progName(itype, outSize)
200 : cchiw 4236 #print "create field B"
201 : cchiw 3865 p_Orig= e_Orig+".diderot"
202 :     #compile program
203 : cchiw 4236 os.system("cp symb/"+ p_Orig +" "+ p_Orig)
204 :     #print "create field C",(branch+p_Orig)
205 : cchiw 3865 os.system(branch+p_Orig)
206 :     #execute program
207 : cchiw 4236 #print "create field D"
208 :     #print "+e_Orig+w_coeff+PARAMS-0./",e_Orig+w_coeff+PARAMS
209 : cchiw 4230 os.system("./"+e_Orig+w_coeff+PARAMS)
210 : cchiw 4236 #print "+e_Orig+w_coeff+PARAMS-1"
211 :     #print "create field E"
212 :     #print ("./"+e_Orig+w_coeff+PARAMS+"| unu save -f nrrd -o "+outputnrrd)
213 : cchiw 3865 os.system("./"+e_Orig+w_coeff+PARAMS+"| unu save -f nrrd -o "+outputnrrd)
214 : cchiw 4236 #print "create field F"
215 :     #print ("unu reshape -i "+outputnrrd+w_shape+" | unu save -f text -o "+orig+".txt")
216 : cchiw 3865 os.system("unu reshape -i "+outputnrrd+w_shape+" | unu save -f text -o "+orig+".txt")
217 :     #save nrrd file
218 :     os.system("rm *.o")
219 :     os.system("rm *.h")
220 :     os.system("rm *.c")
221 :     os.system("rm "+e_Orig)
222 :    
223 : cchiw 3939 def createField(appC,outSize, coeffs):
224 : cchiw 3946 #app = apply.get_all_Fields(appC)
225 :     #itypes = apply.get_types(app)
226 :     #exps = apply.get_exps(app)
227 :     flds = apply.get_all_Fields(appC)
228 :     itypes = []
229 :     exps = []
230 :     # print "fields-length", len(flds)
231 :     for j in range(len(flds)):
232 :     i = flds[j]
233 :     itypes.append(i.fldty)
234 :     #print "j:",j,"coeffs",coeffs[j],"itypes",itypes[j].name
235 :    
236 :     exps = flds
237 : cchiw 3939 for (i,c,s)in zip(exps, coeffs,itypes):
238 : cchiw 3946 # print field.toStr(i)
239 : cchiw 3939 if(field.get_isField(i)): # not a tensor type
240 : cchiw 3946
241 : cchiw 3939 createSingleField(s,outSize,i.inputfile, c)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0