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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3946 - (download) (as text) (annotate)
Sat Jun 11 00:39:19 2016 UTC (3 years, 2 months ago) by cchiw
File size: 4328 byte(s)
 added outer prod
import sys
import re
import os

from obj_apply import *
from obj_ty import *
from obj_operator import *
from obj_field import *
#constants
branch="/Users/chariseechiw/diderot/vis12/bin/diderotc --exec "

#convert coeffs
def llist(cmd, coeff):
    a=" -"+cmd
    for i in coeff:
        a+=" "+str(i)
    return a

#call program due to field type
def progName(itype,outSize):
    #call program due to field type
    if (fty.isEq_id(itype,ty_scalarF_d2)):
        return ("symb_fsd2"," -which 0 "," -s 1 "+str(outSize * outSize))          # 2-d scalar field
    elif(fty.isEq_id(itype,ty_vec2F_d2)):                      # 2-d length 2 vector field
        return ("symb_fv2d2"," -which 0 "," -s 1 "+str(2*outSize *outSize))         # creates field with coefficients for each axis
    elif (fty.isEq_id(itype,ty_scalarF_d3)):
        return ("symb_fsd3"," -which 0 "," -s 1 "+str(outSize * outSize * outSize))          # 3-d scalar field
    elif(fty.isEq_id(itype,ty_vec3F_d3)):                      # 2-d length 2 vector field
        size = 3* outSize *outSize*outSize
        return ("fs3d-vec"," -which 0 "," -s 1 "+str(size))         # creates field with coefficients for each axis
    else:
        raise "type not supported in program name:"


# base,xsq,ysq,diag-coeffs
def coeffToBase(coeff, str):
    [a,b,c,d,e,f,g,h,i]= coeff
    base = [b,c]
    xsq=[d,g]
    ysq=[f,h]
    diag=[a,e,i]
    COEFF = llist("base"+str,base)+llist("xsq"+str,xsq)+llist("ysq"+str,ysq)+llist("diag"+str,diag) #convert coeff to strings
    return COEFF

# shape-input field
# outSize-samples
# orig- name of synthetic field created with coefficients
def createSingleField(itype,outSize,orig,  coeff):
    #print "inside create singlefield: "+orig+" ty: "+itype.name,"coeff:",coeff
    outputnrrd=orig+".nrrd"
    sout=str(outSize)
    def get_Params():
        if(fty.isEq_id(itype,ty_vec2F_d2)):
            [v0,v1]=coeff
            COEFF = coeffToBase(v0, "1")+coeffToBase(v1, "2")#convert coeff to strings
            SIZE=" -sz0 "+ sout +" -sz1 "+ sout +" -width 1"    # giving sample size
            return COEFF + SIZE
        elif(fty.isEq_id(itype,ty_vec3F_d3)):
            [[az0,az1,az2],[bz0,bz1,bz2],[cz0,cz1,cz2]]=coeff
            COEFF=coeffToBase(az0, "1_z0")+coeffToBase(az1, "1_z1")+coeffToBase(az2, "1_z2")
            COEFF+=coeffToBase(bz0, "2_z0")+coeffToBase(bz1, "2_z1")+coeffToBase(bz2, "2_z2")
            COEFF+=coeffToBase(cz0, "3_z0")+coeffToBase(cz1, "3_z1")+coeffToBase(cz2, "3_z2")
            SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
            return COEFF + SIZE
        if(fty.get_dim(itype)==2):
            COEFF = coeffToBase(coeff, "")#convert coeff to strings
            SIZE=" -sz0 "+ sout +" -sz1 "+ sout +" -width 1"    # giving sample size
            return COEFF + SIZE
        elif(fty.get_dim(itype)==3):
            
            [z0,z1,z2]=coeff
            COEFF=coeffToBase(z0, "_z0")+coeffToBase(z1, "_z1")+coeffToBase(z2, "_z2")
            SIZE=" -sz0 "+ sout +" -sz1 "+ sout+" -sz2 "+ sout +" -width 1"    # giving sample size
            return COEFF + SIZE
        else:
            raise "dim not supported:"
    PARAMS = get_Params()
    # get program name and which command
    (e_Orig,w_coeff,w_shape) = progName(itype, outSize)
    p_Orig=  e_Orig+".diderot"
    #compile program
    os.system(branch+p_Orig)
    #execute program
    os.system("./"+e_Orig+w_coeff+PARAMS+"| unu save -f nrrd -o "+outputnrrd)
    os.system("unu reshape -i "+outputnrrd+w_shape+" | unu save -f text -o "+orig+".txt")
    #save nrrd file
    os.system("rm *.o")
    os.system("rm *.h")
    os.system("rm *.c")
    os.system("rm "+e_Orig)

def createField(appC,outSize, coeffs):
    #app = apply.get_all_Fields(appC)
    #itypes = apply.get_types(app)
    #exps =  apply.get_exps(app)
    flds = apply.get_all_Fields(appC)
    itypes = []
    exps = []
    # print "fields-length", len(flds)
    for j in range(len(flds)):
        i = flds[j]
        itypes.append(i.fldty)
        #print "j:",j,"coeffs",coeffs[j],"itypes",itypes[j].name
    
    exps = flds
    for (i,c,s)in zip(exps, coeffs,itypes):
        # print field.toStr(i)
        if(field.get_isField(i)): # not a tensor type

            createSingleField(s,outSize,i.inputfile, c)

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