1 # Copyright (C) 2009-2010 Allen Chen
2 # Massimo Sandal <devicerandom@gmail.com>
3 # W. Trevor King <wking@drexel.edu>
5 # This file is part of Hooke.
7 # Hooke is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation, either
10 # version 3 of the License, or (at your option) any later version.
12 # Hooke is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with Hooke. If not, see
19 # <http://www.gnu.org/licenses/>.
21 """Driver for mcs fluorescence files
24 from .. import curve as lhc
25 from .. import libhooke as lh
28 class mcsDriver(lhc.Driver):
30 def __init__(self, filename):
32 Open the RED (A) ones; the BLUE (D) mirror ones will be automatically opened
34 #obtain name of blue files
36 if othername[-8]=='a': #fixme: how to make it general? (maybe should not be in driverspace but in environment...)
39 othername=''.join(oth)
40 self.filename=filename
41 self.othername=othername
43 #print self.filename, self.othername
45 self.filedata=open(filename,'rb')
46 self.reddata=self.filedata.read()
49 self.filebluedata=open(othername,'rb') #open also the blue ones
50 self.bluedata=self.filebluedata.read()
51 self.filebluedata.close()
54 self.experiment = 'smfluo'
57 if self.filename[-3:].lower()=='mcs':
64 self.filebluedata.close()
67 def default_plots(self):
68 red_data=self.read_file(self.reddata)
69 blue_data=self.read_file(self.bluedata)
70 blue_data=[-1*float(item) for item in blue_data] #visualize blue as "mirror" of red
72 main_plot=lhc.PlotObject()
73 main_plot.add_set(range(len(red_data)),red_data)
74 main_plot.add_set(range(len(blue_data)),blue_data)
75 main_plot.normalize_vectors()
76 main_plot.units=['time','count'] #FIXME: if there's an header saying something about the time count, should be used
77 main_plot.destination=0
78 main_plot.title=self.filename
79 main_plot.colors=['red','blue']
83 def read_file(self, raw_data):
85 intervalsperfile=struct.unpack('h', raw_data[10:12])[0] #read in number of intervals in this file
86 #this data is contained in bit offset 10-12 in mcs file
87 #see http://docs.python.org/library/struct.html#module-struct for additional explanation
89 numbytes=len(raw_data) #data is stored in 4-byte chunks, starting with pos 256
90 for j in range(0,intervalsperfile): #read in all intervals in file
91 temp=raw_data[256+j*4:256+j*4+4] #data starts at byte offset 256
92 real_data.append(struct.unpack('i', temp)[0]) #[0] because it returns a 1-element tuple