4 driver for mcs fluorescence files
6 Massimo Sandal, Allen Chen (c) 2009
9 from .. import libhookecurve as lhc
10 from .. import libhooke as lh
13 class mcsDriver(lhc.Driver):
15 def __init__(self, filename):
17 Open the RED (A) ones; the BLUE (D) mirror ones will be automatically opened
19 #obtain name of blue files
21 if othername[-8]=='a': #fixme: how to make it general? (maybe should not be in driverspace but in environment...)
24 othername=''.join(oth)
25 self.filename=filename
26 self.othername=othername
28 #print self.filename, self.othername
30 self.filedata=open(filename,'rb')
31 self.reddata=self.filedata.read()
34 self.filebluedata=open(othername,'rb') #open also the blue ones
35 self.bluedata=self.filebluedata.read()
36 self.filebluedata.close()
39 self.experiment = 'smfluo'
42 if self.filename[-3:].lower()=='mcs':
49 self.filebluedata.close()
52 def default_plots(self):
53 red_data=self.read_file(self.reddata)
54 blue_data=self.read_file(self.bluedata)
55 blue_data=[-1*float(item) for item in blue_data] #visualize blue as "mirror" of red
57 main_plot=lhc.PlotObject()
58 main_plot.add_set(range(len(red_data)),red_data)
59 main_plot.add_set(range(len(blue_data)),blue_data)
60 main_plot.normalize_vectors()
61 main_plot.units=['time','count'] #FIXME: if there's an header saying something about the time count, should be used
62 main_plot.destination=0
63 main_plot.title=self.filename
64 main_plot.colors=['red','blue']
68 def read_file(self, raw_data):
70 intervalsperfile=struct.unpack('h', raw_data[10:12])[0] #read in number of intervals in this file
71 #this data is contained in bit offset 10-12 in mcs file
72 #see http://docs.python.org/library/struct.html#module-struct for additional explanation
74 numbytes=len(raw_data) #data is stored in 4-byte chunks, starting with pos 256
75 for j in range(0,intervalsperfile): #read in all intervals in file
76 temp=raw_data[256+j*4:256+j*4+4] #data starts at byte offset 256
77 real_data.append(struct.unpack('i', temp)[0]) #[0] because it returns a 1-element tuple