-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample4.texw
More file actions
164 lines (129 loc) · 5.17 KB
/
example4.texw
File metadata and controls
164 lines (129 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
In this example, we illustrate the possibility of programming
new data analysis methods in Python.
We are going to investigate durations of intervals between
subsequent visits of mice to a corner.
The assumption here is that the distribution of such intervals
is a measure of
interactions between the mice. In this example we will just calculate the
measure without discussing it much, but we believe that such
measure, or a variant of it, would be useful in studying social behaviors
or social structure of the group. In particular, one could study which
mice follow which, and therefore look into potential modulation
of learning or cognitive abilities by such behaviors as following
or imitation.
We want to plot histograms of interval durations
for each corner separately, and we restrict the analysis to just one phase: \emph{Place Pref 3 dark}.
Such analysis would be very hard or impossible to perform using Analyzer, and requires the use of some kind of programming
language, which is the main reason we include it in the paper. Below we show that the analysis in
Python using PyMICE is quite straightforward.
<<echo=False,results='hidden'>>=
import warnings
warnings.simplefilter("ignore")
import pymice as pm
data = pm.Loader('C57_AB/2012-08-31 11.58.22.zip')
timeline = pm.Timeline('C57_AB/timeline.ini')
import matplotlib.pyplot as plt
import numpy as np
def setUpAxes(ax):
setUpAxisX(ax)
setUpAxisY(ax)
drawReferenceIntervals(ax)
addLogHistMethod(ax)
def setUpAxisX(ax):
ax.set_xscale('log')
ax.set_xlim(0.05, 5000)
ax.set_xticks([0.1, 1, 10, 100, 1000])
ax.xaxis.set_ticks_position('bottom')
ax.xaxis.set_tick_params(direction='out', which='both')
def setUpAxisY(ax):
ax.set_ylim(0, 70)
ax.set_yticks([0, 20, 40, 60])
ax.yaxis.set_ticks_position('left')
ax.yaxis.set_tick_params(direction='out', which='both')
def drawReferenceIntervals(ax):
ax.axvline(1, ls=':', color='k')
ax.axvline(60, ls=':', color='k')
ax.axvline(3600, ls=':', color='k')
def addLogHistMethod(ax):
def logHist(self, xs):
self.hist(xs, bins=np.logspace(-2, 4, 30))
ax.logHist = logHist.__get__(ax, ax.__class__)
class DecoratedAxes(object):
def __enter__(self):
fig, axes = plt.subplots(4, 2, figsize=(13, 8))
for axRow in axes:
for ax in axRow:
setUpAxes(ax)
for i, axRow in enumerate(axes, 1):
axRow[0].set_ylabel("corner #{}".format(i))
for i, ax in enumerate(axes[0], 1):
ax.set_title("cage #{}".format(i))
for axRow in axes[:-1]:
for ax in axRow:
ax.set_xticklabels([])
ax.xaxis.set_ticks_position('none')
for ax in axes[-1]:
ax.set_xlabel('intervisit interval [s]')
for axRow in axes:
for ax in axRow[1:]:
ax.set_yticklabels([])
ax.yaxis.set_ticks_position('none')
return axes
def __exit__(self, type, value, traceback):
plt.show()
#self.__ax.legend(loc='lower right')
#self.__ax.autoscale_view()
#self.__fig.autofmt_xdate()
@
We begin by selecting all visits performed during the phase.
The \code{order} parameter of the \code{.getVisits()} method
makes the returned sequence ordered with respect to the
\code{.Start} attribute.
<<echo=True,results='hidden'>>=
start, end = timeline.getTimeBounds('Place Pref 3 dark')
visits = data.getVisits(start=start, end=end, order='Start')
@
This list contains visits performed to all corners of the cage.
Next we need to extract subsequences of visits
performed \textbf{to the same corner} in the same cage.
\begin{samepage}
<<>>=
def getSubsequence(visits, cage, corner):
return [v for v in visits
if v.Cage == cage and v.Corner == corner]
@
\end{samepage}
Since the order of the subsequence is preserved, it is then easy to determine
intervisit intervals.
\begin{samepage}
<<>>=
def getIntervisitIntervals(visits):
return [(b.Start - a.End)
for (a, b) in zip(visits[:-1], visits[1:])]
@
\end{samepage}
The histograms are shown in \fig{figureIntervisitIntervals}.
As in the previous examples, the details of plot generation are hidden. The
full code is available at \url{https://github.com/Neuroinflab/PyMICE_SM/blob/examples/example4.py}.
<<echo=False,results='hidden',fig=True,include=False,name='Figure'>>=
def toSeconds(intervals):
return [x.total_seconds() for x in intervals]
with DecoratedAxes() as axes:
for corner, axRow in enumerate(axes, 1):
for cage, ax in enumerate(axRow, 1):
cornerVisits = getSubsequence(visits, cage, corner)
intervals = getIntervisitIntervals(cornerVisits)
ax.logHist(toSeconds(intervals))
@
%htbp
\begin{figure*}
\includegraphics[width=0.75\textwidth]{figures/example4_Figure_1.pdf}
\caption{
{\bf Frequencies of intervisit intervals in the analyzed phase.}
Histograms are plotted for each corner of each cage separately.
The bins are equally spaced in a logarithmic scale.
The dotted vertical lines represents intervals of one second,
minute and hour (from left to right, respectively).
}
\label{figureIntervisitIntervals}
\end{figure*}