30
30
from time import strptime
31
31
32
32
class DAMrealtime ():
33
- def __init__ (self , path , email = None , useEnvironmental = False ):
33
+ def __init__ (self , path , email = None , useEnvironmental = False , folderName = 'DAMSystem3Data' ):
34
34
'''
35
35
'''
36
36
37
- #self.path = os.path.join(path, 'DAMSystem3Data')
38
- self .path = os .path .join (path , 'videoDAM' )
37
+ self .path = os .path .join (path , folderName )
39
38
40
39
if useEnvironmental :
41
40
self .flymon_path = os .path .join (path , 'flymons' )
@@ -113,19 +112,40 @@ def getAsleep(self, filename, interval=5):
113
112
lastlines = fh .read ().split ('\n ' )[ - (2 + interval_for_dead ) : - 2 ]
114
113
fh .close ()
115
114
116
- isSDMonitor = lastlines [- 1 ][5 ]
117
- #monitorNumber = lastlines[-1][6]
118
-
115
+ header = lastlines [0 ].split ('\t ' )
116
+ trackType = int (header [5 ])
117
+ #isSDMonitor = int(header[6])
118
+ #monitorNumber = int(header[7])
119
+
119
120
activity = np .array ( [ line .split ('\t ' )[10 :] for line in lastlines ], dtype = np .int )
120
121
121
- # dead because they didn't move for the past 30 mins
122
- dead = ( activity .sum (axis = 0 ) == 0 ) * 1
123
- # didn't move in the past 5
124
- asleep = ( activity [- interval :].sum (axis = 0 ) == 0 ) * 1
125
- # did move in the past 5
126
- awake = ( activity [- interval :].sum (axis = 0 ) != 0 ) * 1
127
- # asleep but not dead
128
- sleepDep = asleep - dead
122
+ if trackType == 0 : #Actual Distance
123
+
124
+ dead_threshold = 50
125
+ asleep_threshold = 10 * interval
126
+
127
+ dead = ( activity .sum (axis = 0 ) <= dead_threshold ) * 1
128
+ asleep = ( activity [- interval :].sum (axis = 0 ) <= asleep_threshold ) * 1
129
+ awake = ( activity [- interval :].sum (axis = 0 ) > asleep_threshold ) * 1
130
+ sleepDep = asleep - dead
131
+
132
+
133
+ elif trackType == 1 : #Virtual Beam Crossing
134
+
135
+ dead_threshold = 50
136
+ asleep_threshold = 10 * interval
137
+
138
+ # dead because they didn't move for the past 30 mins
139
+ dead = ( activity .sum (axis = 0 ) <= dead_threshold ) * 1
140
+ # didn't move in the past 5
141
+ asleep = ( activity [- interval :].sum (axis = 0 ) <= asleep_threshold ) * 1
142
+ # did move in the past 5
143
+ awake = ( activity [- interval :].sum (axis = 0 ) > asleep_threshold ) * 1
144
+ # asleep but not dead
145
+ sleepDep = asleep - dead
146
+
147
+ elif trackType == 2 : # Position of flies
148
+ sleepDep = 0
129
149
130
150
return sleepDep
131
151
@@ -138,7 +158,8 @@ def deprive(self, fname, interval=5):
138
158
connected on serial port
139
159
'''
140
160
141
- monitor = int (os .path .split (fname )[1 ].split ('.' )[0 ][- 2 :])
161
+ monitor = int ( filter (lambda x : x .isdigit (), os .path .split (fname )[1 ] ) )
162
+
142
163
flies = self .getAsleep (fname , interval )
143
164
cmd = ['M %02d %02d' % (monitor , channel + 1 ) for (channel ,sleeping ) in enumerate (flies ) if sleeping ]
144
165
0 commit comments