Esempio n. 1
0
 def insert_file(self,myfilestr=r'c:\sqltest\\mnl1p004.ng5'):
     mydatareader=readncnr.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=='detector':
                     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
Esempio n. 2
0
    def insert_file(self, myfilestr=r'c:\sqltest\\mnl1p004.ng5'):
        mydatareader = readncnr.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 == 'detector':
                        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
Esempio n. 3
0
def read_order_files(flist):
#    myfilebaseglob=myfilebase+'*.'+myend
#    print myfilebaseglob
#    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readncnr.datareader()
    H=[]#N.array([])
    I=[]#N.array([])
    Ierr=[]#N.array([])
    monlist=[]
    count=0
    mon0=5.0e4
    a4list=[]
    for currfile in flist:
        #print currfile
        mydata=mydatareader.readbuffer(currfile)
        #if count==0:
        #    #mon0=mydata.header['count_info']['monitor']
        #    mon0=5.0e4
        mon=mydata.metadata['count_info']['monitor']
        if count==0:
            mon0=mon
        #print count, mon0,mon
        #temp=N.concatenate((temp,N.array(mydata.data['temp'])))
        H.append(N.array(mydata.data['magfield'],'float64'))
        psd_detectors=mydata.metadata['count_info']['AnalyzerDetectorDevicesOfInterest'.lower()]
        psd_arr=[]
        a4_center=[]
        a4=N.array(mydata.data['a4'],'float64')
        for psd in psd_detectors:
            psd_arr.append(N.array(mydata.data[psd],'float64'))
            a4_center.append(a4)
        #print 'loop done'
        psd_arr=N.array(psd_arr,'float64')
        effs=N.tile(psd_channel_efficiency,(1,psd_arr.shape[1]))
        Ierr.append(N.sqrt(psd_arr)*effs*mon0/mon)

        #print 'psdarr shape ',psd_arr.shape
        #print 'new shape ',N.tile(psd_channel_efficiency,(1,psd_arr.shape[1])).shape
        psd_arr=psd_arr*effs*mon0/mon
        a4_center_arr=N.array(a4_center)
        #print psd_arr.shape
        #print a4_center_arr.shape
        #print psd_a4_offset
        #print N.tile(psd_a4_offset,(1,a4.shape[0])).shape
        a4_corrected=a4_center_arr+N.tile(psd_a4_offset,(1,a4.shape[0]))
        #print a4_corrected
        a4list.append(a4_corrected)
        #It=N.array(N.array(mydata.data['detector']),'float64')
        #Iterr=N.sqrt(It)
        monlist.append(mon)
        I.append(psd_arr)
        #Ierr.append(N.sqrt(psd_arr))
        count=count+1
    return N.array(H),N.array(I),N.array(Ierr),N.array(monlist),N.array(a4list)
Esempio n. 4
0
def readmeshfiles_direct(mydirectory,myfilebase,myend):
    myfilebaseglob=myfilebase+'*.'+myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readncnr.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 Qx,Qz,Counts
Esempio n. 5
0
def readmeshfiles(mydirectory, myfilebase, myend):
    myfilebaseglob = myfilebase + "*." + myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    # SU.printr(flist)
    mydatareader = readncnr.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["detector"])))
    xa, ya, za = prep_data2(Qx, Qy, Counts)
    return xa, ya, za
Esempio n. 6
0
def readmeshfiles_direct(mydirectory, myfilebase, myend):
    myfilebaseglob = myfilebase + '*.' + myend
    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob, ))
    #SU.printr(flist)
    mydatareader = readncnr.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 Qx, Qz, Counts
Esempio n. 7
0
def read_order_files(mydirectory,myfilebase,myend):
    myfilebaseglob=myfilebase+'*.'+myend
#    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
    #SU.printr(flist)
    mydatareader=readncnr.datareader()
    temp=[]#N.array([])
    I=[]#N.array([])
    Ierr=[]#N.array([])
    monlist=[]
    count=0
    mon0=5.0e4
    for currfile in flist:
        #print currfile
        mydata=mydatareader.readbuffer(currfile)
        #if count==0:
        #    #mon0=mydata.header['count_info']['monitor']
        #    mon0=5.0e4
        mon=mydata.metadata['count_info']['monitor']
        #print count, mon0,mon
        #temp=N.concatenate((temp,N.array(mydata.data['temp'])))
        temp.append(N.array(mydata.data['temp'],'float64'))
        It=N.array(N.array(mydata.data['counts']),'float64')
        Iterr=N.sqrt(It)
        #It=It*mon0/mon
        monlist.append(mon)
        I.append(It)
        Ierr.append(Iterr)
        #Iterr=Iterr*mon0/mon
        #I=N.concatenate((I,It))
        #Ierr=N.concatenate((Ierr,Iterr))
        #print I
        #print Iterr
    #xa,ya,za=prep_data2(Qx,Qy,Counts);
        count=count+1
    return temp,I,Ierr,monlist
def read_order_files(mydirectory, myfilebase, myend):
    myfilebaseglob = myfilebase + '*.' + myend
    #    print myfilebaseglob
    flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob, ))
    #SU.printr(flist)
    mydatareader = readncnr.datareader()
    temp = []  #N.array([])
    I = []  #N.array([])
    Ierr = []  #N.array([])
    monlist = []
    count = 0
    mon0 = 5.0e4
    for currfile in flist:
        #print currfile
        mydata = mydatareader.readbuffer(currfile)
        #if count==0:
        #    #mon0=mydata.header['count_info']['monitor']
        #    mon0=5.0e4
        mon = mydata.metadata['count_info']['monitor']
        #print count, mon0,mon
        #temp=N.concatenate((temp,N.array(mydata.data['temp'])))
        temp.append(N.array(mydata.data['temp'], 'float64'))
        It = N.array(N.array(mydata.data['counts']), 'float64')
        Iterr = N.sqrt(It)
        #It=It*mon0/mon
        monlist.append(mon)
        I.append(It)
        Ierr.append(Iterr)
        #Iterr=Iterr*mon0/mon
        #I=N.concatenate((I,It))
        #Ierr=N.concatenate((Ierr,Iterr))
        #print I
        #print Iterr
        #xa,ya,za=prep_data2(Qx,Qy,Counts);
        count = count + 1
    return temp, I, Ierr, monlist
Esempio n. 9
0
        mydirectory=r'c:\BiFeO3xtal\Oct9_2007'
        myfilebase='bfo_spinflip_he3flip51585'
        myfilebase2='bfo_spinflip51579'
        myfilebase3='bfo_spinflip51583'
        myend='bt7'
        data={}
        #pm
        myfilebaseglob=myfilebase+'*.'+myend
        print myfilebaseglob
        flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
        myfilestr=flist[0]
        Counts=N.array([],'float64')
        monlist=[]
        timestamp={}
        mydatareader=readncnr.datareader()
        mydata=mydatareader.readbuffer(myfilestr)
        S1=N.array(mydata.data['a3'][1:])
        S2=N.array(mydata.data['a4'][1:])
        A2=N.array(mydata.data['a5'][1:])*2
        M2=N.array(mydata.data['a2'][1:])
        Counts_pm=N.concatenate((Counts,N.array(mydata.data['detector'][1:])))
        H_pm,K_pm,L_pm,E_pm,Q_pm,Ei_pm,Ef_pm=mylattice.SpecWhere(myradians(M2),myradians(S1),myradians(S2),myradians(A2),setup)
        monlist.append(mydata.data['monitor'][0])
        Counts_pm=Counts_pm[:-1]
        H_pm=H_pm[:-1]
        K_pm=K_pm[:-1]
        L_pm=L_pm[:-1]
        E_pm=E_pm[:-1]
        Q_pm=Q_pm[:-1]
        Ei_pm=Ei_pm[:-1]