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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4455, Wed Aug 24 23:39:30 2016 UTC revision 4456, Thu Aug 25 04:03:27 2016 UTC
# Line 64  Line 64 
64      COEFF = llist("base"+str,base)+llist("xsq"+str,xsq)+llist("ysq"+str,ysq)+llist("diag"+str,diag) #convert coeff to strings      COEFF = llist("base"+str,base)+llist("xsq"+str,xsq)+llist("ysq"+str,ysq)+llist("diag"+str,diag) #convert coeff to strings
65      return COEFF      return COEFF
66    
 def coeffToBase2(coeff, str):  
     # print "coeff: ",len(coeff), " -",coeff  
     if (coeff== [0,0,0,0,0,0,0,0,0]):  
         return ""  
     else:  
         [a,b,c,d,e,f,g,h,i]= coeff  
         s=""  
         base = [b,c]  
         if (base == [0,0]):  
             1  
         else:  
             s+= llist("base"+str,base)  
         xsq=[d,g]  
         if (xsq == [0,0]):  
             1  
         else:  
             xsq=[d,g]  
             s+= llist("xsq"+str,xsq)  
         ysq=[f,h]  
         if (ysq == [0,0]):  
             1  
         else:  
             ysq=[f,h]  
             s+= llist("ysq"+str,ysq)  
         diag=[a,e,i]  
         if (diag==[0,0,0]):  
             1  
         else:  
             s+=llist("diag"+str,diag) #convert coeff to strings  
         return s  
   
67    
68    
69  # shape-input field  # shape-input field
70  # outSize-samples  # outSize-samples
71  # orig- name of synthetic field created with coefficients  # orig- name of synthetic field created with coefficients
72  def createSingleField(itype, outSize, orig, coeff):  def createSingleField(itype, outSize, orig, coeffOrig):
73      # print "inside create singlefield: "+orig+" ty: "+itype.name,"coeff:",coeff      # print "inside create singlefield: "+orig+" ty: "+itype.name,"coeff:",coeff
74      outputnrrd=orig+".nrrd"      outputnrrd=orig+".nrrd"
75      sout=str(outSize)      sout=str(outSize)
76      tty = itype.tensorType      tty = itype.tensorType
77    
78      def tyToCmd(f):      def tyToCmd(f, str, coeff):
79          if (tty==ty_scalarT):          if (tty==ty_scalarT):
80              return f("", coeff)              return f(""+ str, coeff)
81          elif (tty==ty_vec2T):          elif (tty==ty_vec2T):
82              [v1, v2]=coeff              [v1, v2]=coeff
83              return f("1", v1) + f("2", v2)              return f("1"+ str, v1) + f("2"+ str, v2)
84          elif (tty==ty_vec3T):          elif (tty==ty_vec3T):
85              [v1, v2, v3]=coeff              [v1, v2, v3]=coeff
86              return f("1", v1) + f("2", v2) + f("3", v3)              return f("1"+ str, v1) + f("2"+ str, v2) + f("3"+ str, v3)
87            elif (tty==ty_vec4T):
88                [v1, v2, v3, v4]=coeff
89                return f("1"+ str, v1) + f("2"+ str, v2) + f("3"+ str, v3)+ f("4"+ str, v4)
90          elif(tty ==ty_mat2x2T):          elif(tty ==ty_mat2x2T):
91              [m1, m2] = coeff              [m1, m2] = coeff
92              [v1, v2] = m1              [v1, v2] = m1
93              [v3, v4] = m2              [v3, v4] = m2
94              COEFF = f("1", v1) + f("2", v2) + f("3", v3) + f("4", v4)              COEFF = f("1"+ str, v1) + f("2"+ str, v2) + f("3"+ str, v3) + f("4"+ str, v4)
95                return COEFF
96            elif(tty ==ty_mat2x3T):
97                [m1, m2] = coeff
98                [v1, v2, v3] = m1
99                [v4, v5,v6] = m2
100                COEFF = f("1"+ str, v1) + f("2"+ str, v2) + f("3"+ str, v3) + f("4"+ str, v4)+f("5"+ str, v5) + f("6"+ str, v6)
101              return COEFF              return COEFF
102          elif(tty ==ty_mat3x3T):          elif(tty ==ty_mat3x3T):
103              [m1, m2, m3] = coeff              [m1, m2, m3] = coeff
104              [v1, v2, v3] = m1              [v1, v2, v3] = m1
105              [v4, v5, v6] = m2              [v4, v5, v6] = m2
106              [v7, v8, v9] = m3              [v7, v8, v9] = m3
107              COEFF = f("1", v1) + f("2", v2) + f("3", v3)              COEFF = f("1"+ str, v1) + f("2"+ str, v2) + f("3"+ str, v3)
108              COEFF+= f("4", v4) + f("5", v5) + f("6", v6)              COEFF+= f("4"+ str, v4) + f("5"+ str, v5) + f("6"+ str, v6)
109              COEFF+= f("7", v7) + f("8", v8) + f("9", v9)              COEFF+= f("7"+ str, v7) + f("8"+ str, v8) + f("9"+ str, v9)
110                return COEFF
111            elif(tty ==ty_mat4x4T):
112                [m1, m2, m3, m4] = coeff
113                [v1, v2, v3,v4] = m1
114                [v5, v6, v7, v8] = m2
115                [v9, v10, v11, v12] = m3
116                [v13, v14, v15, v16] = m4
117                COEFF = f("1"+ str, v1) + f("2"+ str, v2) + f("3"+ str, v3)
118                COEFF += f("4"+ str, v4) + f("5"+ str, v5) + f("6"+ str, v6)
119                COEFF += f("7"+ str, v7) + f("8"+ str, v8) + f("9"+ str, v9)
120                COEFF += f("10"+ str, v10) +f("11"+ str, v11) + f("12"+ str, v12)
121                COEFF += f("13"+ str, v13)+f("14"+ str, v14)
122              return COEFF              return COEFF
123    
124            elif(tty ==ty_mat3x2T):
125                [m1, m2, m3] = coeff
126                [v1, v2] = m1
127                [v3, v4] = m2
128                [v5, v6] = m3
129                COEFF = f("1"+ str, v1) + f("2"+ str, v2) + f("3"+ str, v3)
130                COEFF+= f("4"+ str, v4) + f("5"+ str, v5) + f("6"+ str, v6)
131                return COEFF
132    
133          else:          else:
134              raise Exception("shape is not supported", itype.name)              raise Exception("shape is not supported", itype.name)
135      def get_Params():      def get_Params():
136    
137          if(fty.get_dim(itype)==1):          if(fty.get_dim(itype)==1):
138              # convert vector coefficients to string for 1-dimension              # convert vector coefficients to string for 1-dimension
139              COEFF = tyToCmd(coeffToBase_d1)              COEFF = tyToCmd(coeffToBase_d1, "", coeffOrig)
140              SIZE=" -width 1 -sz0 "+ sout     # giving sample size              SIZE=" -width 1 -sz0 "+ sout     # giving sample size
141              return COEFF + SIZE              return COEFF + SIZE
142          elif(fty.get_dim(itype)==2):          elif(fty.get_dim(itype)==2):
143              COEFF = tyToCmd(coeffToBase_d2)              COEFF = tyToCmd(coeffToBase_d2, "", coeffOrig)
144              SIZE=" -sz0 "+ sout +" -sz1 "+ sout +" -width 1"    # giving sample size              SIZE=" -sz0 "+ sout +" -sz1 "+ sout +" -width 1"    # giving sample size
145              return COEFF + SIZE              return COEFF + SIZE
146          elif(fty.get_dim(itype)==3):          elif(fty.get_dim(itype)==3):
147              if(fty.isEq_id(itype, ty_scalarF_d3)):              if(fty.isEq_id(itype, ty_scalarF_d3)):
148                  #print "itype",itype.name                  [z0, z1, z2] = coeffOrig
149                  #print "coeff",len(coeff)                  COEFF = tyToCmd(coeffToBase_d2, "_z0", z0)
150                  #print coeff                  COEFF += tyToCmd(coeffToBase_d2, "_z1", z1)
151                  [z0,z1,z2]=coeff                  COEFF += tyToCmd(coeffToBase_d2, "_z2", z2)
                 COEFF=coeffToBase(z0, "_z0")+coeffToBase(z1, "_z1")+coeffToBase(z2, "_z2")  
152                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
153                  return COEFF + SIZE                  return COEFF + SIZE
154              elif(fty.isEq_id(itype,ty_vec2F_d3)):              elif(fty.isEq_id(itype,ty_vec2F_d3)):
155                  [[az0,az1,az2],[bz0,bz1,bz2]]=coeff                  [v1, v2] = coeffOrig
156                  COEFF=coeffToBase(az0, "1_z0")+coeffToBase(az1, "1_z1")+coeffToBase(az2, "1_z2")                  [az0,az1,az2] = v1
157                  COEFF+=coeffToBase(bz0, "2_z0")+coeffToBase(bz1, "2_z1")+coeffToBase(bz2, "2_z2")                  [bz0,bz1,bz2] = v2
158                    z0 = [az0, bz0]
159                    z1 = [az1, bz1]
160                    z2 = [az2, bz2]
161                    COEFF = tyToCmd(coeffToBase_d2, "_z0", z0)
162                    COEFF += tyToCmd(coeffToBase_d2, "_z1", z1)
163                    COEFF += tyToCmd(coeffToBase_d2, "_z2", z2)
164                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
165                  return COEFF + SIZE                  return COEFF + SIZE
166              elif(fty.isEq_id(itype,ty_vec3F_d3)):              elif(fty.isEq_id(itype,ty_vec3F_d3)):
167                  [[az0,az1,az2],[bz0,bz1,bz2],[cz0,cz1,cz2]]=coeff                  [v1, v2, v3] = coeffOrig
168                  COEFF=coeffToBase(az0, "1_z0")+coeffToBase(az1, "1_z1")+coeffToBase(az2, "1_z2")                  [az0, az1, az2] = v1
169                  COEFF+=coeffToBase(bz0, "2_z0")+coeffToBase(bz1, "2_z1")+coeffToBase(bz2, "2_z2")                  [bz0, bz1, bz2] = v2
170                  COEFF+=coeffToBase(cz0, "3_z0")+coeffToBase(cz1, "3_z1")+coeffToBase(cz2, "3_z2")                  [cz0, cz1, cz2] = v3
171                    z0 = [az0, bz0, cz0]
172                    z1 = [az1, bz1, cz1]
173                    z2 = [az2, bz2, cz2]
174                    COEFF = tyToCmd(coeffToBase_d2, "_z0", z0)
175                    COEFF += tyToCmd(coeffToBase_d2, "_z1", z1)
176                    COEFF += tyToCmd(coeffToBase_d2, "_z2", z2)
177                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
178                  return COEFF + SIZE                  return COEFF + SIZE
179                elif(fty.isEq_id(itype,ty_vec4F_d3)):
180                    [v1, v2, v3, v4] = coeffOrig
181                    [az0, az1, az2] = v1
182                    [bz0, bz1, bz2] = v2
183                    [cz0, cz1, cz2] = v3
184                    [dz0, dz1, dz2] = v4
185                    z0 = [az0, bz0, cz0, dz0]
186                    z1 = [az1, bz1, cz1, dz1]
187                    z2 = [az2, bz2, cz2, dz2]
188                    COEFF = tyToCmd(coeffToBase_d2, "_z0", z0)
189                    COEFF += tyToCmd(coeffToBase_d2, "_z1", z1)
190                    COEFF += tyToCmd(coeffToBase_d2, "_z2", z2)
191                    SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
192                    return COEFF + SIZE
193    
194              elif(fty.isEq_id(itype, ty_mat2x2F_d3)):              elif(fty.isEq_id(itype, ty_mat2x2F_d3)):
195                  [m0, m1] = coeff                  [[v1, v2], [v3, v4]] = coeffOrig
196                  [[az0, az1, az2], [bz0, bz1, bz2]] = m0                  [az0, az1, az2] = v1
197                  [[cz0, cz1, cz2], [dz0, dz1, dz2]] = m1                  [bz0, bz1, bz2] = v2
198                  COEFF= coeffToBase(az0, "1_z0")+coeffToBase(az1, "1_z1")+coeffToBase(az2, "1_z2")                  [cz0, cz1, cz2] = v3
199                  COEFF+=coeffToBase(bz0, "2_z0")+coeffToBase(bz1, "2_z1")+coeffToBase(bz2, "2_z2")                  [dz0, dz1, dz2] = v4
200                  COEFF+=coeffToBase(cz0, "3_z0")+coeffToBase(cz1, "3_z1")+coeffToBase(cz2, "3_z2")                  z0 = [[az0, bz0], [cz0, dz0]]
201                  COEFF+=coeffToBase(dz0, "4_z0")+coeffToBase(dz1, "4_z1")+coeffToBase(dz2, "4_z2")                  z1 = [[az1, bz1], [cz1, dz1]]
202                    z2 = [[az2, bz2], [cz2, dz2]]
203                    COEFF = tyToCmd(coeffToBase_d2, "_z0", z0)
204                    COEFF += tyToCmd(coeffToBase_d2, "_z1", z1)
205                    COEFF += tyToCmd(coeffToBase_d2, "_z2", z2)
206    
207                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
208                  return COEFF + SIZE                  return COEFF + SIZE
209              elif(fty.isEq_id(itype, ty_mat3x3F_d3)):              elif(fty.isEq_id(itype, ty_mat3x3F_d3)):
210                  [m0, m1, m2] = coeff                  [[v1, v2, v3], [v4, v5, v6], [v7, v8, v9]] = coeffOrig
211                  [[az0, az1, az2], [bz0, bz1, bz2], [cz0, cz1, cz2]] = m0                  [az0, az1, az2] = v1
212                  [[dz0, dz1, dz2], [ez0, ez1, ez2], [fz0, fz1, fz2]] = m1                  [bz0, bz1, bz2] = v2
213                  [[gz0, gz1, gz2], [hz0, hz1, hz2], [iz0, iz1, iz2]] = m2                  [cz0, cz1, cz2] = v3
214                    [dz0, dz1, dz2] = v4
215                  COEFF= coeffToBase(az0, "1_z0")+coeffToBase(az1, "1_z1")+coeffToBase(az2, "1_z2")                  [ez0, ez1, ez2] = v5
216                  COEFF+=coeffToBase(bz0, "2_z0")+coeffToBase(bz1, "2_z1")+coeffToBase(bz2, "2_z2")                  [fz0, fz1, fz2] = v6
217                  COEFF+=coeffToBase(cz0, "3_z0")+coeffToBase(cz1, "3_z1")+coeffToBase(cz2, "3_z2")                  [gz0, gz1, gz2] = v7
218                  COEFF+=coeffToBase(dz0, "4_z0")+coeffToBase(dz1, "4_z1")+coeffToBase(dz2, "4_z2")                  [hz0, hz1, hz2] = v8
219                  COEFF+= coeffToBase(ez0, "5_z0")+coeffToBase(ez1,"5_z1")+coeffToBase(ez2, "5_z2")                  [iz0, iz1, iz2] = v9
220                  COEFF+=coeffToBase(fz0, "6_z0")+coeffToBase(fz1, "6_z1")+coeffToBase(fz2, "6_z2")                  z0 = [[az0, bz0, cz0], [dz0, ez0, fz0], [gz0, hz0, iz0]]
221                  COEFF+=coeffToBase(gz0, "7_z0")+coeffToBase(gz1, "7_z1")+coeffToBase(gz2, "7_z2")                  z1 = [[az1, bz1, cz1], [dz1, ez1, fz1], [gz1, hz1, iz1]]
222                  COEFF+=coeffToBase(hz0, "8_z0")+coeffToBase(hz1, "8_z1")+coeffToBase(hz2, "8_z2")                  z2 = [[az2, bz2, cz2], [dz2, ez2, fz2], [gz2, hz2, iz2]]
223                  COEFF+=coeffToBase(iz0, "9_z0")+coeffToBase(iz1, "9_z1")+coeffToBase(iz2, "9_z2")                  COEFF = tyToCmd(coeffToBase_d2, "_z0", z0)
224                    COEFF += tyToCmd(coeffToBase_d2, "_z1", z1)
225                    COEFF += tyToCmd(coeffToBase_d2, "_z2", z2)
226    
227    
228                    #print ("cmd",COEFF)
229                    SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
230                    return COEFF + SIZE
231                elif(fty.isEq_id(itype, ty_mat4x4F_d3)):
232                    [[v1, v2, v3, v4], [v5, v6, v7, v8], [v9, v10, v11, v12], [v13, v14, v15, v16]] = coeffOrig
233                    [az0, az1, az2] = v1
234                    [bz0, bz1, bz2] = v2
235                    [cz0, cz1, cz2] = v3
236                    [dz0, dz1, dz2] = v4
237                    [ez0, ez1, ez2] = v5
238                    [fz0, fz1, fz2] = v6
239                    [gz0, gz1, gz2] = v7
240                    [hz0, hz1, hz2] = v8
241                    [iz0, iz1, iz2] = v9
242                    [jz0, jz1, jz2] = v10
243                    [kz0, kz1, kz2] = v11
244                    [lz0, lz1, lz2] = v12
245                    [mz0, mz1, mz2] = v13
246                    [nz0, nz1, nz2] = v14
247                    [oz0, oz1, oz2] = v13
248                    [pz0, pz1, pz2] = v14
249                    z0 = [[az0, bz0, cz0, dz0], [ez0, fz0, gz0, hz0], [iz0, jz0, kz0, lz0], [mz0, nz0, oz0, pz0]]
250                    z1 = [[az1, bz1, cz1, dz1], [ez1, fz1, gz1, hz1], [iz1, jz1, kz1, lz1], [mz1, nz1, oz1, pz1]]
251                    z2 =[[az2, bz2, cz2, dz2], [ez2, fz2, gz2, hz2], [iz2, jz2, kz2, lz2], [mz2, nz2, oz2, pz2]]
252                    COEFF = tyToCmd(coeffToBase_d2, "_z0", z0)
253                    COEFF += tyToCmd(coeffToBase_d2, "_z1", z1)
254                    COEFF += tyToCmd(coeffToBase_d2, "_z2", z2)
255    
256    
257                  #print ("cmd",COEFF)                  #print ("cmd",COEFF)
258                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size                  SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size

Legend:
Removed from v.4455  
changed lines
  Added in v.4456

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