Exemplo n.º 1
0
    def insert_file(self,myfilestr=r'c:\sqltest\\mnl1p004.ng5'):
        mydatareader=readicp.datareader()
        mydata=mydatareader.readbuffer(myfilestr)
        print mydata.metadata['file_info']['filename']
        #insert file into database
        s='insert into catalog VALUES(NULL,?,NULL,0)'
        splacevalues=(mydata.metadata['file_info']['filename'],)
        file_id=sqlexecute(self.conn,s,splacevalues)
        print 'catalog instantiated'

        for tablename, tablevalues in mydata.data.iteritems():
            s='insert into fields VALUES(NULL,?,?)'
            sparams=(file_id, tablename)
            field_id=sqlexecute(self.conn,s,sparams)
            print 'inserted %s into field table'%(tablename,)
            if isinstance(tablevalues,list):
                for point_num in N.arange(len(tablevalues)):
                    if tablename=='Counts':
                        s='insert into measurement VALUES (NULL,?,?,?,?,?)'
                        sparams=(file_id,field_id,point_num,tablevalues[point_num],N.sqrt(tablevalues[point_num]))
                    else:
                        s='insert into measurement VALUES (NULL,?,?,?,?,NULL)'
                        sparams=(file_id,field_id,point_num,tablevalues[point_num])
                    sqlexecute(self.conn,s,sparams)
        self.create_meta_tables(mydata.metadata,file_id)
        return
Exemplo n.º 2
0
def readmeshfiles(mydirectory,myfilebase,myend,eflag='hhl'):
    myfilebaseglob=myfilebase+'*.'+myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readicp.datareader()
    Qx=N.array([])
    Qy=N.array([])
    Qz=N.array([])
    
    Counts=N.array([])
    mon0=80000.0
    for currfile in flist:
        print currfile
        mydata=mydatareader.readbuffer(currfile)
        mon=mydata.header['count_info']['monitor']
        Qx=N.concatenate((Qx,N.array(mydata.data['Qx'])))
        Qy=N.concatenate((Qy,N.array(mydata.data['Qy'])))
        Qz=N.concatenate((Qz,N.array(mydata.data['Qz'])))
        Counts=N.concatenate((Counts,N.array(mydata.data['Counts'])*mon0/mon))
    if eflag=='hhl':
        xa,ya,za=prep_data2(Qx,Qz,Counts)
        return xa,ya,za,Qx,Qz,Counts
    elif eflag=='hkk':
        xa,ya,za=prep_data2(Qy,Qx,Counts)
        return xa,ya,za,Qx,Qy,Counts
    elif eflag=='hkh':
        xa,ya,za=prep_data2(Qx,Qy,Counts)
    return xa,ya,za
Exemplo n.º 3
0
    def insert_file(self, myfilestr=r'c:\sqltest\\mnl1p004.ng5'):
        mydatareader = readicp.datareader()
        mydata = mydatareader.readbuffer(myfilestr)
        print mydata.metadata['file_info']['filename']
        #insert file into database
        s = 'insert into catalog VALUES(NULL,?,NULL,0)'
        splacevalues = (mydata.metadata['file_info']['filename'], )
        file_id = sqlexecute(self.conn, s, splacevalues)
        print 'catalog instantiated'

        for tablename, tablevalues in mydata.data.iteritems():
            s = 'insert into fields VALUES(NULL,?,?)'
            sparams = (file_id, tablename)
            field_id = sqlexecute(self.conn, s, sparams)
            print 'inserted %s into field table' % (tablename, )
            if isinstance(tablevalues, list):
                for point_num in N.arange(len(tablevalues)):
                    if tablename == 'Counts':
                        s = 'insert into measurement VALUES (NULL,?,?,?,?,?)'
                        sparams = (file_id, field_id, point_num,
                                   tablevalues[point_num],
                                   N.sqrt(tablevalues[point_num]))
                    else:
                        s = 'insert into measurement VALUES (NULL,?,?,?,?,NULL)'
                        sparams = (file_id, field_id, point_num,
                                   tablevalues[point_num])
                    sqlexecute(self.conn, s, sparams)
        self.create_meta_tables(mydata.metadata, file_id)
        return
Exemplo n.º 4
0
def readmeshfiles(mydirectory,myfilebase,myend,eflag='hhl'):
    myfilebaseglob=myfilebase+'*.'+myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readicp.datareader()
    Qx=N.array([])
    Qy=N.array([])
    Qz=N.array([])

    Counts=N.array([])
    #mon0=240000.0
    mon0=65000.0
    for currfile in flist:
        print currfile
        mydata=mydatareader.readbuffer(currfile)
        mon=mydata.header['count_info']['monitor']

        o1=N.array([mydata.header['orient1']['h'],mydata.header['orient1']['k'],mydata.header['orient1']['l']])
        o2=N.array([mydata.header['orient2']['h'],mydata.header['orient2']['k'],mydata.header['orient2']['l']])
        o3=N.cross(o1,o2)
        h=N.array(mydata.data['Qx'])
        k=N.array(mydata.data['Qy'])
        l=N.array(mydata.data['Qz'])
        A=N.array([o1,o2,o3]).T
        a_arr=[]
        b_arr=[]
        for i in range(len(h)):
            hkl=N.array([h[i],k[i],l[i]])
            sol=N.linalg.solve(A,hkl)
            a=sol[0]
            b=sol[1]
            a_arr.append(a)
            b_arr.append(b)


        if eflag=='weird':
            Qx=N.concatenate((Qx,a_arr))
            Qy=N.concatenate((Qy,b_arr))
        else:
            Qx=N.concatenate((Qx,N.array(mydata.data['Qx'])))
            Qy=N.concatenate((Qy,N.array(mydata.data['Qy'])))
            Qz=N.concatenate((Qz,N.array(mydata.data['Qz'])))
        Counts=N.concatenate((Counts,N.array(mydata.data['Counts'])*mon0/mon))
    if eflag=='hhl':
        xa,ya,za=prep_data2(Qx,Qz,Counts)
    elif eflag=='hkk':
        xa,ya,za=prep_data2(Qy,Qx,Counts)
    elif eflag=='hkh':
        xa,ya,za=prep_data2(Qx,Qy,Counts)
    elif eflag=='weird':
        xa,ya,za=prep_data2(Qy,Qx,Counts)

    return xa,ya,za
Exemplo n.º 5
0
def readmeshfiles(mydirectory,myfilebase,myend,eflag='hhl'):
    myfilebaseglob=myfilebase+'*.'+myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readicp.datareader()
    Qx=N.array([])
    Qy=N.array([])
    Qz=N.array([])
    
    Counts=N.array([])
    #mon0=240000.0
    mon0=65000.0
    for currfile in flist:
        print currfile
        mydata=mydatareader.readbuffer(currfile)
        mon=mydata.header['count_info']['monitor']
        
        o1=N.array([mydata.header['orient1']['h'],mydata.header['orient1']['k'],mydata.header['orient1']['l']])
        o2=N.array([mydata.header['orient2']['h'],mydata.header['orient2']['k'],mydata.header['orient2']['l']])
        o3=N.cross(o1,o2)
        h=N.array(mydata.data['Qx'])
        k=N.array(mydata.data['Qy'])
        l=N.array(mydata.data['Qz'])
        A=N.array([o1,o2,o3]).T
        a_arr=[]
        b_arr=[]
        for i in range(len(h)):
            hkl=N.array([h[i],k[i],l[i]])
            sol=N.linalg.solve(A,hkl)
            a=sol[0]
            b=sol[1]
            a_arr.append(a)
            b_arr.append(b)
            
        
        if eflag=='weird':
            Qx=N.concatenate((Qx,a_arr))
            Qy=N.concatenate((Qy,b_arr))
        else:
            Qx=N.concatenate((Qx,N.array(mydata.data['Qx'])))
            Qy=N.concatenate((Qy,N.array(mydata.data['Qy'])))
            Qz=N.concatenate((Qz,N.array(mydata.data['Qz'])))
        Counts=N.concatenate((Counts,N.array(mydata.data['Counts'])*mon0/mon))
    if eflag=='hhl':
        xa,ya,za=prep_data2(Qx,Qz,Counts)
    elif eflag=='hkk':
        xa,ya,za=prep_data2(Qy,Qx,Counts)
    elif eflag=='hkh':
        xa,ya,za=prep_data2(Qx,Qy,Counts)
    elif eflag=='weird':
        xa,ya,za=prep_data2(Qy,Qx,Counts)
        
    return xa,ya,za
Exemplo n.º 6
0
def readmeshfiles(mydirectory, myfilebase, myend, eflag="hhl"):
    myfilebaseglob = myfilebase + "*." + myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    # SU.printr(flist)
    mydatareader = readicp.datareader()
    Qx = N.array([])
    Qy = N.array([])
    Qz = N.array([])

    Counts = N.array([])
    # mon0=240000.0
    mon0 = 65000.0
    for currfile in flist:
        print currfile
        mydata = mydatareader.readbuffer(currfile)
        mon = mydata.header["count_info"]["monitor"]

        o1 = N.array([mydata.header["orient1"]["h"], mydata.header["orient1"]["k"], mydata.header["orient1"]["l"]])
        o2 = N.array([mydata.header["orient2"]["h"], mydata.header["orient2"]["k"], mydata.header["orient2"]["l"]])
        o3 = N.cross(o1, o2)
        h = N.array(mydata.data["Qx"])
        k = N.array(mydata.data["Qy"])
        l = N.array(mydata.data["Qz"])
        A = N.array([o1, o2, o3]).T
        a_arr = []
        b_arr = []
        for i in range(len(h)):
            hkl = N.array([h[i], k[i], l[i]])
            sol = N.linalg.solve(A, hkl)
            a = sol[0]
            b = sol[1]
            a_arr.append(a)
            b_arr.append(b)

        if eflag == "weird":
            Qx = N.concatenate((Qx, a_arr))
            Qy = N.concatenate((Qy, b_arr))
        else:
            Qx = N.concatenate((Qx, N.array(mydata.data["Qx"])))
            Qy = N.concatenate((Qy, N.array(mydata.data["Qy"])))
            Qz = N.concatenate((Qz, N.array(mydata.data["Qz"])))
        Counts = N.concatenate((Counts, N.array(mydata.data["Counts"]) * mon0 / mon))
    if eflag == "hhl":
        xa, ya, za = prep_data2(Qx, Qz, Counts)
    elif eflag == "hkk":
        xa, ya, za = prep_data2(Qy, Qx, Counts)
    elif eflag == "hkh":
        xa, ya, za = prep_data2(Qx, Qy, Counts)
    elif eflag == "weird":
        xa, ya, za = prep_data2(Qy, Qx, Counts)

    return xa, ya, za
Exemplo n.º 7
0
def readmeshfiles(mydirectory,myfilebase,myend):
    myfilebaseglob=myfilebase+'*.'+myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readicp.datareader()
    Qx=N.array([])
    Qy=N.array([])
    Qz=N.array([])
    Counts=N.array([])
    for currfile in flist:
        print currfile
        mydata=mydatareader.readbuffer(currfile)
        Qx=N.concatenate((Qx,N.array(mydata.data['Qx'])))
        Qy=N.concatenate((Qy,N.array(mydata.data['Qy'])))
        Qz=N.concatenate((Qz,N.array(mydata.data['Qz'])))
        Counts=N.concatenate((Counts,N.array(mydata.data['Counts'])))
    xa,ya,za=prep_data2(Qx,Qy,Counts);
    return xa,ya,za
Exemplo n.º 8
0
def readmeshfiles(mydirectory,myfilebase,myend):
    myfilebaseglob=myfilebase+'*.'+myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readicp.datareader()
    Qx=N.array([])
    Qy=N.array([])
    Qz=N.array([])
    Counts=N.array([])
    a=N.array([3.943],'d')
    b=N.array([2.779],'d')
    for currfile in flist:
        print currfile
        mydata=mydatareader.readbuffer(currfile)
        Qx=N.concatenate((Qx,N.array(mydata.data['Qx'])*2*pi/a[0]))
        Qy=N.concatenate((Qy,N.array(mydata.data['Qy'])*2*pi/b[0]))
        Qz=N.concatenate((Qz,N.array(mydata.data['Qz'])))
        Counts=N.concatenate((Counts,N.array(mydata.data['Counts'])))
    xa,ya,za=prep_data2(Qx,Qy,Counts);
    print 'xa',xa.min(),xa.max()
    print 'qx',Qx.min(),Qx.max()
    print
    return xa,ya,za
Exemplo n.º 9
0
def readmeshfiles(mydirectory,myfilebase,myend):
    myfilebaseglob=myfilebase+'*.'+myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readicp.datareader()
    Qx=N.array([])
    Qy=N.array([])
    Qz=N.array([])
    Counts=N.array([])
    a=N.array([3.943],'d')
    b=N.array([2.779],'d')
    for currfile in flist:
        print currfile
        mydata=mydatareader.readbuffer(currfile)
        Qx=N.concatenate((Qx,N.array(mydata.data['Qx'])*2*pi/a[0]))
        Qy=N.concatenate((Qy,N.array(mydata.data['Qy'])*2*pi/b[0]))
        Qz=N.concatenate((Qz,N.array(mydata.data['Qz'])))
        Counts=N.concatenate((Counts,N.array(mydata.data['Counts'])))
    xa,ya,za=prep_data2(Qx,Qy,Counts);
    print 'xa',xa.min(),xa.max()
    print 'qx',Qx.min(),Qx.max()
    print 
    return xa,ya,za
Exemplo n.º 10
0
    mydict={}
    mydict['myarr']=g

    for k,v in mydict.iteritems():
        print k,v
        s='create table '+k
        s=s+'(%sid integer primary key'%(k)
        print s
        if isinstance(v,N.ndarray):
            print 'true'
            for i in N.arange(v.shape[0]):
                print v[i]

    #qbuffer
    myfilestr=r'c:\sqltest\\mnl1p004.ng5'
    mydatareader=readicp.datareader()
    mydata=mydatareader.readbuffer(myfilestr)
    print mydata.header['filename']

    #create our database
    #conn=sqlite3.connect(':memory:')
    conn=sqlite3.connect(mydatbstr)

    #create a table with our list of files
    s='create table catalog(file_id integer primary key, file_name varchar(12),sample_id integer)'
    sqlexecute(conn,s)
    print 'created catalog table'


    s='create table fields'
    s=s+'(field_id integer primary key, file_id integer, field_name varchar(20))'
Exemplo n.º 11
0
import numpy as N
import pylab
import os
from readicp import datareader

myfile = "./FILES/Mar27_2011/meshs006.bt9"
reader = datareader()
data = reader.readbuffer(myfile)

## data.data has keys E, min, Qx, Qy, Qz

print data.data['Qx']

#
#for root, dirs, files in os.walk('./FILES/Mar27_2011/'):
#	for fname in files:
#		print fname
Exemplo n.º 12
0
    mydict = {}
    mydict['myarr'] = g

    for k, v in mydict.iteritems():
        print k, v
        s = 'create table ' + k
        s = s + '(%sid integer primary key' % (k)
        print s
        if isinstance(v, N.ndarray):
            print 'true'
            for i in N.arange(v.shape[0]):
                print v[i]

    #qbuffer
    myfilestr = r'c:\sqltest\\mnl1p004.ng5'
    mydatareader = readicp.datareader()
    mydata = mydatareader.readbuffer(myfilestr)
    print mydata.header['filename']

    #create our database
    #conn=sqlite3.connect(':memory:')
    conn = sqlite3.connect(mydatbstr)

    #create a table with our list of files
    s = 'create table catalog(file_id integer primary key, file_name varchar(12),sample_id integer)'
    sqlexecute(conn, s)
    print 'created catalog table'

    s = 'create table fields'
    s = s + '(field_id integer primary key, file_id integer, field_name varchar(20))'
    sqlexecute(conn, s)