Ignore:
Timestamp:
Nov 11, 2008 1:49:10 PM (14 years ago)
Author:
ajj
Message:

updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/utils/bt5/bt5plot2/usans.py

    r438 r441  
    33#import Tkinter as Tk 
    44 
    5 def numeric_compare(x,y): 
    6         x = float(x) 
    7         y = float(y)     
     5def numeric_compare(x, y): 
     6    x = float(x) 
     7    y = float(y)     
    88 
    9         if x < y: 
    10                 return -1 
    11         elif x==y: 
    12                 return 0 
    13         else: # x>y 
    14                 return 1  
     9    if x < y: 
     10        return - 1 
     11    elif x == y: 
     12        return 0 
     13    else: # x>y 
     14        return 1  
    1515 
    1616def getBT5DataFromFile(fileName): 
    17         ''' 
    18         Takes a filename and returns a dictionary of the detector values 
    19         keyed by varying value (ususally A2 or A5) 
    20         ''' 
    21         detdata = {} 
     17    ''' 
     18    Takes a filename and returns a dictionary of the detector values 
     19    keyed by varying value (ususally A2 or A5) 
     20    ''' 
     21    detdata = {} 
     22    metadata = {} 
     23    motlist = [] 
     24     
     25    inputfile = open(fileName, "r") 
    2226 
    23         inputfile = open(fileName, "r") 
     27    inputdata = inputfile.readlines() 
    2428 
    25         inputdata = inputfile.readlines() 
     29    mdtmp = inputdata[0].replace("'","") 
     30    mdtmp = mdtmp.split() 
     31     
     32    #Sundry metadata about run settings 
     33    (metadata['filename'], metadata['datetime'], 
     34    metadata['mon'],metadata['prefactor'], 
     35    metadata['base'],metadata['numpnts'], 
     36    metadata['type']) = (mdtmp[0],' '.join(mdtmp[1:5]),mdtmp[6],mdtmp[7],mdtmp[8],mdtmp[9],mdtmp[10]) 
     37     
     38    #Comment string 
     39    metadata['title'] = inputdata[2].strip() 
     40     
     41    #Start, step and end values for motors 1-6 
     42    motlist.append(inputdata[5].split()[1:]) 
     43    motlist.append(inputdata[6].split()[1:]) 
     44    motlist.append(inputdata[7].split()[1:]) 
     45    motlist.append(inputdata[8].split()[1:]) 
     46    motlist.append(inputdata[9].split()[1:]) 
     47    motlist.append(inputdata[10].split()[1:])  
     48    metadata['motorvals'] = motlist 
     49     
     50    for index in range(13, len(inputdata), 2): 
     51        detdata[inputdata[index].split()[0]] = inputdata[index + 1].split(',')     
    2652 
    27         for index in range(13,len(inputdata),2): 
    28                 detdata[inputdata[index].split()[0]] = inputdata[index+1].split(',')     
     53    for key in detdata.keys(): 
     54        for val in range(0, len(detdata[key])): 
     55            detdata[key][val] = int(detdata[key][val]) 
    2956 
    30         for key in detdata.keys(): 
    31                 for val in range(0,len(detdata[key])): 
    32                         detdata[key][val] = int(detdata[key][val]) 
    33  
    34         inputfile.close() 
    35         return detdata 
     57    inputfile.close() 
     58    return detdata,metadata 
    3659 
    3760def printBT5DetData(detdata): 
    38         ''' 
    39         Print the contents of the file in a formatted fashion 
     61    ''' 
     62    Print the contents of the file in a formatted fashion 
    4063 
    41         Takes a dictionary of data as provided by getBT5DataFromFile() and prints out the contents 
    42         in a formatted fashion 
    43         ''' 
    44         motorvals = detdata.keys() 
    45         motorvals.sort(cmp=numeric_compare) 
     64    Takes a dictionary of data as provided by getBT5DataFromFile() and prints out the contents 
     65    in a formatted fashion 
     66    ''' 
     67    motorvals = detdata.keys() 
     68    motorvals.sort(cmp=numeric_compare) 
    4669 
    47         for motorval in motorvals: 
    48                 str = motorval+":" 
    49                 str += "\tMon: "+repr(detdata[motorval][0]) 
    50                 str += "\tDet 1-5: "+repr(detdata[motorval][2]) 
    51                 str += "\t"+repr(detdata[motorval][1]) 
    52                 str += "\t"+repr(detdata[motorval][4]) 
    53                 str += "\t"+repr(detdata[motorval][5]) 
    54                 str += "\t"+repr(detdata[motorval][6]) 
    55                 str += "\tTrans: "+repr(detdata[motorval][3]) 
    56                 print str 
     70    for motorval in motorvals: 
     71        str = motorval + ":" 
     72        str += "\tMon: " + repr(detdata[motorval][0]) 
     73        str += "\tDet 1-5: " + repr(detdata[motorval][2]) 
     74        str += "\t" + repr(detdata[motorval][1]) 
     75        str += "\t" + repr(detdata[motorval][4]) 
     76        str += "\t" + repr(detdata[motorval][5]) 
     77        str += "\t" + repr(detdata[motorval][6]) 
     78        str += "\tTrans: " + repr(detdata[motorval][3]) 
     79        print str 
    5780 
    58         return 0 
     81    return 0 
    5982 
    60 def getAlignVals(data,motorval): 
    61         ''' 
    62         Return the values we record in the logbook for a given motor position 
     83def getAlignVals(data, motorval): 
     84    ''' 
     85    Return the values we record in the logbook for a given motor position 
    6386 
    64         Takes a dictionary as provided by getBT5DataFromFile and returns a dictionary with  
    65         keys Central, Trans and Sum 
    66         ''' 
    67         alignvals = {} 
     87    Takes a dictionary as provided by getBT5DataFromFile and returns a dictionary with  
     88    keys Central, Trans and Sum 
     89    ''' 
     90    alignvals = {} 
    6891 
    69         alignvals['Central'] = data[motorval][1] 
    70         alignvals['Trans'] = data[motorval][3] 
    71         alignvals['Sum'] = data[motorval][1]+data[motorval][2]+data[motorval][4]+data[motorval][5]+data[motorval][6]     
    72         return alignvals 
     92    alignvals['Central'] = data[motorval][1] 
     93    alignvals['Trans'] = data[motorval][3] 
     94    alignvals['Sum'] = data[motorval][1] + data[motorval][2] + data[motorval][4] + data[motorval][5] + data[motorval][6]      
     95    return alignvals 
    7396 
    74 def maxDetCount(data,detector): 
    75         ''' 
    76         Return the maximum value and corresponding motor position for a given detector 
    77          
    78         Takes a dictionary as provided by getBT5DataFromFile() and returns a dictionary with 
    79         keys Position and Value 
    80         '''      
    81         maxpos = '' 
    82         maxval = 0 
    83         result = {} 
     97def maxDetCount(data, detector): 
     98    ''' 
     99    Return the maximum value and corresponding motor position for a given detector 
     100     
     101    Takes a dictionary as provided by getBT5DataFromFile() and returns a dictionary with 
     102    keys Position and Value 
     103    '''     
     104    maxpos = '' 
     105    maxval = 0 
     106    result = {} 
    84107 
    85         mvals = data.keys() 
    86         det = {'1':2, '2':1, '3':4, '4':5, '5':6}[repr(detector)] 
     108    mvals = data.keys() 
     109    det = {'1':2, '2':1, '3':4, '4':5, '5':6}[repr(detector)] 
    87110 
    88         for mval in mvals: 
    89                 if data[mval][det] > maxval: 
    90                         maxval = data[mval][det]                 
    91                         maxpos = mval 
    92          
    93         result['Position'] = maxpos 
    94         result['Value'] = maxval 
     111    for mval in mvals: 
     112        if data[mval][det] > maxval: 
     113            maxval = data[mval][det]         
     114            maxpos = mval 
     115     
     116    result['Position'] = maxpos 
     117    result['Value'] = maxval 
    95118 
    96         return result    
     119    return result     
    97120 
    98          
    99          
     121     
     122     
    100123 
    101124if __name__ == '__main__': 
    102         import sys 
    103         data = getBT5DataFromFile(sys.argv[1]) 
    104         printBT5DetData(data) 
     125    import sys 
     126    data,metadata = getBT5DataFromFile(sys.argv[1]) 
     127    printBT5DetData(data) 
    105128 
    106         maxinfo =  maxDetCount(data,2) 
    107         print maxinfo 
    108         avals = getAlignVals(data,maxinfo['Position']) 
    109         print avals 
     129    maxinfo = maxDetCount(data, 2) 
     130    print maxinfo 
     131    avals = getAlignVals(data, maxinfo['Position']) 
     132    print avals 
Note: See TracChangeset for help on using the changeset viewer.