def printWordBlocks(words, colorText=True, wordsPerChannel=None): ''' Hex prints and colors words based on location. ''' c = colors() if colorText == True: c.enableColors() clkLocations, fadcLocations, otherLocations, dataLocations, areaLocations, lastBoardLocation, duplicates = getWordIndicies( words, wordsPerChannel=wordsPerChannel) for i, word in enumerate(words): hexed = '0x%08x' % word if i in clkLocations: print(c.pink(hexed), end=' ') elif i in fadcLocations: print(c.yellow(hexed), end=' ') elif i in otherLocations: print(c.blue(hexed), end=' ') elif i in dataLocations: print(c.cyan(hexed), end=' ') elif i in areaLocations: print(c.green(hexed), end=' ') elif i in lastBoardLocation: print(c.red(hexed), end=' ') else: print(hexed, end=' ') if (i + 1) % 8 == 0: print('')
def __init__(self, f, lower = None, upper = None, c = None): self.c = c if c is not None else colors() try: f.shape model = f except: try: model = np.load(f) except: print('Model is neither a npy file or npy array.') if len(model.shape) == 2: self.baseX = model[:, 0] self.baseY = model[:, 1] self.xLower = self.baseX[0] self.xUpper = self.baseX[-1] elif len(model.shape) == 1 and (upper and lower) is not None: self.baseY = model self.xLower = lower if lower is not None else print('Lower not set.') self.xUpper = upper if upper is not None else print('Upper not set.') self.baseX = np.linspace(self.xLower, self.xUpper, len(self.baseY)) else: print('You mixed parameters or something went wrong.') self.support = np.arange(len(self.baseX)) self.baseY = self.baseY/np.sum(self.baseY) self.drv = st.rv_discrete(a=self.xLower, b=self.xUpper, values=(self.support, self.baseY))
def hexPrintWords(self, words=None, colorText=False): def hexPrinter(words, c): for i, word in enumerate(words): hexed = '0x%08x' % word if hexed[0:6].lower() == '0xcafe': print(c.violet(hexed), end=' ') elif hexed[0:6].lower() == '0xfadc': print(c.yellow(hexed), end=' ') else: print(hexed, end=' ') if (i + 1) % 8 == 0: print('') print('\n') if colorText == True: c = colors() c.enableColors() else: c = colors() if words is not None: hexPrinter(words, c) elif self.words is not None: hexPrinter(self.words, c)
def __init__(self, f, lower = None, upper = None, c = None): self.c = c if c is not None else colors() try: f.shape model = f except: try: model = np.load(f) except: print('Model is neither a npy file or npy array.') if len(model.shape) == 2: self.baseX = model[:, 0] self.baseY = model[:, 1] self.xLower = self.baseX[0] self.xUpper = self.baseX[-1] elif len(model.shape) == 1 and (upper and lower) is not None: self.baseY = model self.xLower = lower if lower is not None else print('Lower not set.') self.xUpper = upper if upper is not None else print('Upper not set.') self.baseX = np.linspace(self.xLower, self.xUpper, len(self.baseY)) else: print('You mixed parameters or something went wrong.') try: self.baseY = self.baseY/(ini.quad(self.contPDF, self.xLower, self.xUpper)[0]) print('Setting bounds to ' + str(self.xLower) + ' and ' + str(self.xUpper)) st.rv_continuous.__init__(self, a = self.xLower, b = self.xUpper) except: print(self.c.red('Warning: Bounds were passed but not set.')) st.rv_continuous.__init__(self) self.baseX = np.linspace(0, 1, len(self.baseY)) self.contPDF = si.interp1d(self.baseX, self.baseY, kind='linear')
def parseFADCs(words, wordsPerChannel=None): boards = [] c = colors() c.enableColors() if wordsPerChannel is None: wordsPerChannel = extractWordsPerChannel(words) wordsPerChannel += 1 for i, word in enumerate(words): hexed = '0x%08x' % word if hexed[0:6].lower() == '0xfadc': startHeader = { '0xFADC': maskAndRShifter(words[i], first2ByteMask, first2ByteShift), 'Board Number': maskAndRShifter(words[i], third1ByteMask, third1ByteShift), 'Words Per Channel': maskAndRShifter(words[i], fourth1ByteMask, fourth1ByteShift) } eventHeader = { 'Misc. 6 bits': maskAndRShifter(words[i + 1], first6bMask, first6bShift), 'Event Count': maskAndRShifter(words[i + 1], last26bMask, last26bShift) } hitHeader = { 'Mode': maskAndRShifter(words[i + 2], first2bMask, first2bShift), 'HILO': maskAndRShifter(words[i + 2], first10bMask, first10bShift), 'Trigger Flags': maskAndRShifter(words[i + 2], second10bMask, second10bShift), 'Channel Hits': maskAndRShifter(words[i + 2], third10bMask, third10bShift) } #print('\n') #print('0x%08x' % words[i], end= ' ') #print('0x%08x' % words[i+1], end= ' ') #print('0x%08x' % words[i+2]) channel_words = [ words[i + 3 + wordsPerChannel * x:i + 3 + wordsPerChannel * (x + 1)] for x in range(10) ] #for things in channel_words: # for box, beep in enumerate(things): # printThis = '0x%08x' % beep # print(printThis, end = ' ') # if (box+1) % 8 == 0: # print('') # print('') channel_data = [wordsToADC(words[:-1]) for words in channel_words] area_words = [words[-1] for words in channel_words] area_data = [{ 'Channel Number': maskAndRShifter(area_words[x], first4bMask, first4bShift), 'Unused': maskAndRShifter(area_words[x], next12bMask, next12bShift), 'Pulse Area': maskAndRShifter(area_words[x], last16bMask, last16bShift), 'ADC': channel_data[x] } for x in range(10)] board = { 'Start Header': startHeader, 'Event Header': eventHeader, 'Hit Header': hitHeader, } for y in area_data: board['Channel ' + str(y['Channel Number'])] = y boards.append(board) lastBoardStatus = { 'Sync Pattern': maskAndRShifter(words[-1], first15bMask, first15bShift), 'CBLT Buf Size': maskAndRShifter(words[-1], last17bMask, last17bShift) } return boards