From: devicerandom Date: Thu, 7 May 2009 11:25:23 +0000 (+0000) Subject: (mcs.py , generaltccd.py) added first version of TCCD driver and utilities X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f4cee7083bcbd84754b1411ac2e76eb8cbf2fbd0;p=hooke.git (mcs.py , generaltccd.py) added first version of TCCD driver and utilities --- diff --git a/generaltccd.py b/generaltccd.py new file mode 100644 index 0000000..70ad513 --- /dev/null +++ b/generaltccd.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +''' +generaltccd.py + +General utilities for TCCD stuff +''' + +class generaltccdCommands: + + def plotmanip_threshold(self, plot, current, customvalue=False): + ''' + Cuts from the plot everything below the threshold. + Set the threshold with "set tccd_threshold" + ''' + + if current.curve.experiment != 'smfluo': + return plot + + if not self.config['tccd_threshold'] and (not customvalue): + return plot + + if customvalue: + thresh=customvalue + else: + thresh=self.config['tccd_threshold'] + + for set in plot.vectors: + newy=[] + for value in set[1]: + if abs(value) < thresh: + newy.append(0) + else: + newy.append(value) + + set[1]=newy + + return plot + + + def plotmanip_coincident(self,plot,current, customvalue=False): + ''' + Shows only coincident events + ''' + if current.curve.experiment != 'smfluo': + return plot + + if not self.config['tccd_coincident'] and (not customvalue): + return plot + + newred=[] + newblue=[] + for index in range(len(plot.vectors[0][1])): + if abs(plot.vectors[0][1][index])>self.config['tccd_threshold'] and abs(plot.vectors[1][1][index])>self.config['tccd_threshold']: + newred.append(plot.vectors[0][1][index]) + newblue.append(plot.vectors[1][1][index]) + else: + newred.append(0) + newblue.append(0) + + plot.vectors[0][1]=newred + plot.vectors[1][1]=newblue + + return plot \ No newline at end of file diff --git a/hooke.conf b/hooke.conf index 439816d..5fe84ba 100755 --- a/hooke.conf +++ b/hooke.conf @@ -2,7 +2,7 @@ - + + + + diff --git a/mcs.py b/mcs.py new file mode 100644 index 0000000..7ddd892 --- /dev/null +++ b/mcs.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +''' +mcs.py + +driver for mcs fluorescence files + +Massimo Sandal, Allen Chen (c) 2009 +''' + +import libhookecurve as lhc +import libhooke as lh +import struct + +class mcsDriver(lhc.Driver): + + def __init__(self, filename): + ''' + Open the RED (A) ones; the BLUE (D) mirror ones will be automatically opened + ''' + #obtain name of blue files + othername=filename + if othername[-8]=='a': + oth=list(othername) + oth[-8]='d' + othername=''.join(oth) + self.filename=filename + self.othername=othername + + #print self.filename, self.othername + + self.filedata=open(filename,'rb') + self.reddata=self.filedata.read() + self.filedata.close() + + self.filebluedata=open(othername,'rb') #open also the blue ones + self.bluedata=self.filebluedata.read() + self.filebluedata.close() + + self.filetype = 'mcs' + self.experiment = 'smfluo' + + def is_me(self): + if self.filename[-3:]=='mcs': + return True + else: + return False + + def close_all(self): + self.filedata.close() + self.filebluedata.close() + + + def default_plots(self): + red_data=self.read_file(self.reddata) + blue_data=self.read_file(self.bluedata) + blue_data=[-1*float(item) for item in blue_data] #visualize blue as "mirror" of red + + main_plot=lhc.PlotObject() + main_plot.add_set(range(len(red_data)),red_data) + main_plot.add_set(range(len(blue_data)),blue_data) + main_plot.normalize_vectors() + main_plot.units=['time','count'] #FIXME: if there's an header saying something about the time count, should be used + main_plot.destination=0 + main_plot.title=self.filename + main_plot.colors=['red','blue'] + + return [main_plot] + + def read_file(self, raw_data): + real_data=[] + intervalsperfile=struct.unpack('h', raw_data[10:12])[0] #read in number of intervals in this file + #this data is contained in bit offset 10-12 in mcs file + #see http://docs.python.org/library/struct.html#module-struct for additional explanation + + numbytes=len(raw_data) #data is stored in 4-byte chunks, starting with pos 256 + for j in range(0,intervalsperfile): #read in all intervals in file + temp=raw_data[256+j*4:256+j*4+4] #data starts at byte offset 256 + real_data.append(struct.unpack('i', temp)[0]) #[0] because it returns a 1-element tuple + return real_data \ No newline at end of file