Changeset 471 for sans/utils/bt5/bt5plot2/usans.py
- Timestamp:
- Jan 30, 2009 2:39:07 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/utils/bt5/bt5plot2/usans.py
r466 r471 1 1 #!/usr/bin/python 2 2 3 #import Tkinter as Tk 4 5 def numeric_compare(x, y): 6 x = float(x) 7 y = float(y) 8 9 if x < y: 10 return - 1 11 elif x == y: 12 return 0 13 else: # x>y 14 return 1 3 import os 4 import sys 15 5 16 6 def isBT5Data(fileName): … … 27 17 else: 28 18 inputfile.close() 19 return 0 20 21 def numeric_compare(x, y): 22 x = float(x) 23 y = float(y) 24 25 if x < y: 26 return - 1 27 elif x == y: 29 28 return 0 29 else: # x>y 30 return 1 30 31 31 32 def getBT5DataFromFile(fileName): 33 ''' 34 Takes a filename and returns a dictionary of the detector values 35 keyed by varying value (ususally A2 or A5) 36 ''' 37 detdata = {} 38 metadata = {} 39 motlist = [] 40 41 if isBT5Data(fileName): 42 43 #print "File: ",fileName 44 inputfile = open(fileName, "r") 45 46 inputdata = inputfile.readlines() 47 48 mdtmp = inputdata[0].replace("'", "") 49 mdtmp = mdtmp.split() 32 def GetBT5DirList(): 33 """Function to parse the directory listing of the current working directory 34 and create a list of filenames that are BT5 data files""" 35 36 dirlist = os.listdir(os.getcwd()) 50 37 51 #Sundry metadata about run settings 52 (metadata['filename'], metadata['datetime'], 53 metadata['mon'], metadata['prefactor'], 54 metadata['base'], metadata['numpnts'], 55 metadata['type']) = (mdtmp[0], ' '.join(mdtmp[1:5]), float(mdtmp[6]), int(mdtmp[7]), mdtmp[8], int(mdtmp[9]), mdtmp[10]) 38 bt5list = [ x for x in dirlist if (x.find('.bt5') > 0 and isBT5Data(x))] 56 39 57 #Comment string 58 metadata['title'] = inputdata[2].strip() 59 60 #Start, step and end values for motors 1-6 61 motlist.append(inputdata[5].split()[1:]) 62 motlist.append(inputdata[6].split()[1:]) 63 motlist.append(inputdata[7].split()[1:]) 64 motlist.append(inputdata[8].split()[1:]) 65 motlist.append(inputdata[9].split()[1:]) 66 motlist.append(inputdata[10].split()[1:]) 67 metadata['motorvals'] = motlist 68 69 for index in range(13, len(inputdata), 2): 70 detdata[float(inputdata[index].split()[0])] = inputdata[index + 1].split(',') 71 72 for key in detdata.keys(): 73 for val in range(0, len(detdata[key])): 74 detdata[key][val] = int(detdata[key][val]) 75 76 inputfile.close() 77 return detdata, metadata 78 79 else: 80 return 0,0 81 82 def printBT5DetData(detdata): 83 ''' 84 Print the contents of the file in a formatted fashion 85 86 Takes a dictionary of data as provided by getBT5DataFromFile() and prints out the contents 87 in a formatted fashion 88 ''' 89 motorvals = detdata.keys() 90 motorvals.sort(cmp=numeric_compare) 91 92 for motorval in motorvals: 93 str = repr(motorval) + ":" 94 str += "\tMon: " + repr(detdata[motorval][0]) 95 str += "\tDet 1-5: " + repr(detdata[motorval][2]) 96 str += "\t" + repr(detdata[motorval][1]) 97 str += "\t" + repr(detdata[motorval][4]) 98 str += "\t" + repr(detdata[motorval][5]) 99 str += "\t" + repr(detdata[motorval][6]) 100 str += "\tTrans: " + repr(detdata[motorval][3]) 101 print str 102 103 return 0 104 105 def getAlignVals(data, motorval): 106 ''' 107 Return the values we record in the logbook for a given motor position 108 109 Takes a dictionary as provided by getBT5DataFromFile and returns a dictionary with 110 keys Central, Trans and Sum 111 ''' 112 alignvals = {} 113 114 alignvals['Central'] = data[motorval][1] 115 alignvals['Trans'] = data[motorval][3] 116 alignvals['Sum'] = data[motorval][1] + data[motorval][2] + data[motorval][4] + data[motorval][5] + data[motorval][6] 117 return alignvals 118 119 def maxDetCount(data, detector): 120 ''' 121 Return the maximum value and corresponding motor position for a given detector 122 123 Takes a dictionary as provided by getBT5DataFromFile() and returns a dictionary with 124 keys Position and Value 125 ''' 126 maxpos = '' 127 maxval = 0 128 result = {} 129 130 mvals = data.keys() 131 det = {'1':2, '2':1, '3':4, '4':5, '5':6}[repr(detector)] 132 133 for mval in mvals: 134 if data[mval][det] > maxval: 135 maxval = data[mval][det] 136 maxpos = mval 137 138 result['Position'] = maxpos 139 result['Value'] = maxval 140 141 return result 142 143 144 40 return bt5list 145 41 146 42 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.