示例#1
0
def harmplotterGNU(bw,harms,mode="NONE"):
    """GNUPlot some harmonics"""
    import Gnuplot, Gnuplot.funcutils    
    g=Gnuplot.Gnuplot()
    g.title('Input Data')
    y=array(SHT.azimuthal_measurement_points(bw))
    x=array(SHT.declination_measurement_points(bw))
    g('set parametric')
    g('set xrange [0:pi]')
    g('set yrange [0:2*pi]')
    g('set data style lines')
    g('set hidden3d')
  #  g('set pm3d')
    g('set contour base')
    g.xlabel('theta (declination)')
    g.ylabel('phi (azimuth)')
    class funcboy:
        def __init__(self,harms,mode="NONE"):
            self.harms=harms
            self.mode=mode
        def val(self,theta,phi):
            d,rdata=SHT.harmonizer([(theta,phi)],self.harms,mode=self.mode)
            result=float(rdata[0])
            return result

      
    f=funcboy(harms,mode=mode)
    g.splot(Gnuplot.funcutils.compute_GridData(x,y,f.val))#GridData(m,x,y))
    raw_input('Please press return to continue...\n')
示例#2
0
def NSSHT(bw,points,
          rdata,
          mode="COS_SIN",
          RSphere=1.0, #This is the sphere that the points would
                       #would be on if they were not constrained
                       #to a cylinder
          harmtype='_{n}^{m}',
          returnIntermediates=False):
    """ given a bandwidth, and some real data collected at a number of data points this should return the
    Spherical Harmonic Transform using the Pseudo-Inverse"""
    indicies=SHT.genindicies_top(bw)
    harms=UnityWeight_COSSIN_Harmonics(indicies,
                                       harmtype=harmtype,
                                       RSphere=RSphere)
    M=matrixbuilder(harms,points)
    Minv=p_inv(M)

    tmp=dot(Minv,rdata)
    # Since the result is in a form 
    # T,Tprime,T,Tprime we reorganize it
    # to be like (T,Tprime),(T,Tprime),...
    Q=[]
    for i in range(len(tmp)):
        if is_odd(i):
            Q.append((tmp[i-1],tmp[i]))

    cos_sinresult=zip(indicies,Q)
    if mode=="COS_SIN":
        if returnIntermediates:
            return cos_sinresult,tmp,M,Minv
        else:
            return cos_sinresult
    else:
        print "I have not thought of this yet, maybe later"
        raise Exception
def fieldfind(R, HelixSegList, filename):
    harmonicBW = 12
    RSphereList = [R, 0.95 * R, 0.5 * R, 0.25 * R]
    Big_rvect, Big_zvect, Big_fieldBox = Boxfieldfind(R, HelixSegList)
    Small_rvect, Small_zvect, Small_fieldBox = Boxfieldfind(R, HelixSegList, BoxSize=R)
    theta_phi_points = SHT.measurement_points(harmonicBW)
    BFieldonSpheres = [Sphericalfieldfind(R, HelixSegList, Rsphere, theta_phi_points) for Rsphere in RSphereList]

    BFieldSHTs = []
    for BField in BFieldonSpheres:
        fields = transpose(BField)
        Bx = fields[0]
        By = fields[1]
        Bz = fields[2]
        Bs = fields[3]
        tmp = [SHT.SHT(harmonicBW, realdata=f, mode="COS_SIN") for f in fields]
        BFieldSHTs.append(tmp)

    q = [
        "['Units_r','Units_z','Units_B'],Big_rvect,Big_zvect,Big_fieldBox(Bx,By,Bz,fieldsquared),Small_rvect,Small_zvect,Small_fieldBox(Bx,By,Bz,fieldsquared),harmonicBW,RSphereList,BFieldonSpheres,BFieldSHTs(one for each RSphere and (Bx,By,Bz,B2) for each one)",
        ["meters", "meters", "teslas"],
        Big_rvect,
        Big_zvect,
        Big_fieldBox,
        Small_rvect,
        Small_zvect,
        Small_fieldBox,
        harmonicBW,
        RSphereList,
        BFieldonSpheres,
        BFieldSHTs,
    ]
    f = file(filename, "w+")
    cPickle.dump(q, f)
    f.close()
示例#4
0
def harmonizer_tester(n,m,harms,bw,Rsphere,mode="NONE"):
    """
    This function shows the data produced by the harmonizer function
    at a number of data points given a certain set of harmonic components

    see 'anothertester'
    """

    meas_points=[]#SHT.measurement_points(bw)
    for theta,phi in SHT.measurement_points(bw):
        meas_points.append(Vector([Rsphere,theta,phi],type="SPHERICAL"))
    d,rdata=SHT.harmonizer(meas_points,harms,mode=mode,pointType="VECTOR");

    harmplotterMAT(bw,harms,mode=mode)
 
    l=SHT.SHT(bw,realdata=rdata,mode=mode,Rref=Rsphere)
    pprint(l)
    return
示例#5
0
def tester():
    bw=4;
    num=len(SHT.measurement_points(bw))
    rdata=[1 for i in range(num)];
    idata=[0 for i in range(num)];
    pprint(bw)
    pprint(rdata)
    pprint(idata)
    #pprint(len(SHT.measurement_points(bw)))
    l=SHT.SHT(bw,rdata,idata)
    pprint(l)
    return
示例#6
0
def multitester():
    """
     This function generates some data
     and then when the SHT is taken it should
     have the same harmonic components as were
     origininally generated
    """
    bw=8;
    #harmtype='_{n,m}'
    harmtype='_{n}^{m}'
    Rsphere=0.08
    meas_points=[]
    for theta,phi in SHT.measurement_points(bw):
        meas_points.append(Vector([Rsphere,theta,phi],type="SPHERICAL"))
    
    mode = "COS_SIN"
    harms=[((0,0),(1.0,0.0)),
           ((1,0),(1.0,0.0)),
           ((2,0),(1.0,0.0)),
           ((3,0),(1.0,0.0)),
           ((4,0),(2.0,0.0)),
           ((1,1),(1.0,1.0)),
           ((2,1),(1.0,1.0)),
           ((2,2),(0.0,1.0)),
           ((7,6),(0.0,20))]
    #harms=[((1,1),(1.0,0.0))]
           
    d,rdata=SHT.harmonizer(meas_points,harms,mode=mode,pointType="VECTOR",harmtype=harmtype)
  


    SHT.harmplotterMAT(bw,harms,Rsphere,mode=mode,harmtype=harmtype,type="3D")
    print "I am about to SHT"
    l=SHT.SHT(bw,realdata=rdata,mode=mode,Rref=Rsphere,harmtype=harmtype)
    print "I SHTed"
    pprint(l)

    return
示例#7
0
def SHTmeasurement_points(bw,r):#,color=(0,1,0)):
    """Return the SHT.measurement_points in terms of the point construct"""
    meas_points=SHT.measurement_points(bw)
    result=[Vector((r,theta,phi),type="SPHERICAL") for theta,phi in meas_points]#,color=color)
    return result
示例#8
0
 def val(self,theta,phi):
     d,rdata=SHT.harmonizer([(theta,phi)],self.harms,mode=self.mode)
     result=float(rdata[0])
     return result