f68169304f61e5bd08f22d5d4624caa9af986a27
[hooke.git] / hooke / plugin / tccd.py
1 # Copyright (C) 2009-2010 Massimo Sandal <devicerandom@gmail.com>
2 #                         W. Trevor King <wking@drexel.edu>
3 #
4 # This file is part of Hooke.
5 #
6 # Hooke is free software: you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
10 #
11 # Hooke is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
14 # Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with Hooke.  If not, see
18 # <http://www.gnu.org/licenses/>.
19
20 """General utilities for TCCD stuff
21 """
22
23 class generaltccdCommands(object):
24
25     def plotmanip_threshold(self, plot, current, customvalue=False):
26         '''
27         Cuts from the plot everything below the threshold.
28         Set the threshold with "set tccd_threshold"
29         '''
30
31         if current.curve.experiment != 'smfluo':
32             return plot
33
34         if not self.config['tccd_threshold'] and (not customvalue):
35             return plot
36
37         if customvalue:
38             thresh=customvalue
39         else:
40             thresh=self.config['tccd_threshold']
41
42         for set in plot.vectors:
43             newy=[]
44             for value in set[1]:
45                 if abs(value) < thresh:
46                     newy.append(0)
47                 else:
48                     newy.append(value)
49
50             set[1]=newy
51
52         return plot
53
54
55     def plotmanip_coincident(self,plot,current, customvalue=False):
56         '''
57         Shows only coincident events
58         '''
59         if current.curve.experiment != 'smfluo':
60             return plot
61
62         if not self.config['tccd_coincident'] and (not customvalue):
63             return plot
64
65         newred=[]
66         newblue=[]
67         for index in range(len(plot.vectors[0][1])):
68             if abs(plot.vectors[0][1][index])>self.config['tccd_threshold'] and abs(plot.vectors[1][1][index])>self.config['tccd_threshold']:
69                 newred.append(plot.vectors[0][1][index])
70                 newblue.append(plot.vectors[1][1][index])
71             else:
72                 newred.append(0)
73                 newblue.append(0)
74
75         plot.vectors[0][1]=newred
76         plot.vectors[1][1]=newblue
77
78         return plot