aind-dynamic-foraging-basic-analysis 0.2.5__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aind_dynamic_foraging_basic_analysis/__init__.py +1 -1
- aind_dynamic_foraging_basic_analysis/lick_analysis.py +4 -1
- aind_dynamic_foraging_basic_analysis/plot/plot_fip.py +223 -0
- aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session.py +7 -22
- aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session_plotly.py +199 -0
- aind_dynamic_foraging_basic_analysis/plot/style.py +35 -0
- {aind_dynamic_foraging_basic_analysis-0.2.5.dist-info → aind_dynamic_foraging_basic_analysis-0.3.0.dist-info}/METADATA +2 -1
- aind_dynamic_foraging_basic_analysis-0.3.0.dist-info/RECORD +13 -0
- {aind_dynamic_foraging_basic_analysis-0.2.5.dist-info → aind_dynamic_foraging_basic_analysis-0.3.0.dist-info}/WHEEL +1 -1
- aind_dynamic_foraging_basic_analysis-0.2.5.dist-info/RECORD +0 -10
- {aind_dynamic_foraging_basic_analysis-0.2.5.dist-info → aind_dynamic_foraging_basic_analysis-0.3.0.dist-info}/LICENSE +0 -0
- {aind_dynamic_foraging_basic_analysis-0.2.5.dist-info → aind_dynamic_foraging_basic_analysis-0.3.0.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Load packages."""
|
|
2
|
+
|
|
2
3
|
import os
|
|
3
4
|
import numpy as np
|
|
4
5
|
import matplotlib.pyplot as plt
|
|
@@ -300,7 +301,9 @@ def cal_metrics(data):
|
|
|
300
301
|
ref_kernel = np.convolve(ref, kernel)
|
|
301
302
|
finish_kernel = np.convolve(finish.astype(float), kernel)
|
|
302
303
|
finish_kernel = np.divide(finish_kernel, ref_kernel)
|
|
303
|
-
finish_kernel = finish_kernel[
|
|
304
|
+
finish_kernel = finish_kernel[
|
|
305
|
+
int(0.5 * len(kernel)) : -int(0.5 * len(kernel)) # noqa: E203
|
|
306
|
+
]
|
|
304
307
|
all_go_no_rwd = tbl_trials.loc[
|
|
305
308
|
(tbl_trials["animal_response"] != 2)
|
|
306
309
|
& (tbl_trials["rewarded_historyL"] == 0)
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tools for plotting FIP data
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from aind_dynamic_foraging_data_utils import alignment as an
|
|
9
|
+
from aind_dynamic_foraging_data_utils import nwb_utils as nu
|
|
10
|
+
from aind_dynamic_foraging_basic_analysis.plot.style import STYLE, FIP_COLORS
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def plot_fip_psth_compare_alignments(nwb, alignments, channel, tw=[-4, 4]):
|
|
14
|
+
"""
|
|
15
|
+
Compare the same FIP channel aligned to multiple event types
|
|
16
|
+
nwb, nwb object for the session
|
|
17
|
+
alignments, either a list of event types in df_events, or a dictionary
|
|
18
|
+
whose keys are event types and values are a list of timepoints
|
|
19
|
+
channel, (str) the name of the FIP channel
|
|
20
|
+
tw, time window for the PSTH
|
|
21
|
+
|
|
22
|
+
EXAMPLE
|
|
23
|
+
*******************
|
|
24
|
+
plot_fip_psth_compare_alignments(nwb,['left_reward_delivery_time',
|
|
25
|
+
'right_reward_delivery_time'],'G_1_preprocessed')
|
|
26
|
+
"""
|
|
27
|
+
if not hasattr(nwb, "fip_df"):
|
|
28
|
+
print("You need to compute the fip_df first")
|
|
29
|
+
print("running `nwb.fip_df = create_fib_df(nwb,tidy=True)`")
|
|
30
|
+
nwb.fip_df = nu.create_fib_df(nwb, tidy=True)
|
|
31
|
+
if not hasattr(nwb, "df_events"):
|
|
32
|
+
print("You need to compute the df_events first")
|
|
33
|
+
print("run `nwb.df_events = create_events_df(nwb)`")
|
|
34
|
+
nwb.df_events = nu.create_events_df(nwb)
|
|
35
|
+
|
|
36
|
+
if channel not in nwb.fip_df["event"].values:
|
|
37
|
+
print("channel {} not in fip_df".format(channel))
|
|
38
|
+
|
|
39
|
+
if isinstance(alignments, list):
|
|
40
|
+
align_dict = {}
|
|
41
|
+
for a in alignments:
|
|
42
|
+
if a not in nwb.df_events["event"].values:
|
|
43
|
+
print("{} not found in the events table".format(a))
|
|
44
|
+
return
|
|
45
|
+
else:
|
|
46
|
+
align_dict[a] = nwb.df_events.query("event == @a")["timestamps"].values
|
|
47
|
+
elif isinstance(alignments, dict):
|
|
48
|
+
align_dict = alignments
|
|
49
|
+
else:
|
|
50
|
+
print(
|
|
51
|
+
"alignments must be either a list of events in nwb.df_events, "
|
|
52
|
+
+ "or a dictionary where each key is an event type, "
|
|
53
|
+
+ "and the value is a list of timepoints"
|
|
54
|
+
)
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
align_label = "Time (s)"
|
|
58
|
+
|
|
59
|
+
fig, ax = plt.subplots()
|
|
60
|
+
for alignment in align_dict:
|
|
61
|
+
etr = fip_psth_inner_compute(nwb, align_dict[alignment], channel, True, tw)
|
|
62
|
+
fip_psth_inner_plot(ax, etr, FIP_COLORS.get(alignment, "k"), alignment)
|
|
63
|
+
|
|
64
|
+
plt.legend()
|
|
65
|
+
ax.set_xlabel(align_label, fontsize=STYLE["axis_fontsize"])
|
|
66
|
+
ax.set_ylabel("df/f", fontsize=STYLE["axis_fontsize"])
|
|
67
|
+
ax.spines["top"].set_visible(False)
|
|
68
|
+
ax.spines["right"].set_visible(False)
|
|
69
|
+
ax.set_xlim(tw)
|
|
70
|
+
ax.axvline(0, color="k", alpha=0.2)
|
|
71
|
+
ax.tick_params(axis="both", labelsize=STYLE["axis_ticks_fontsize"])
|
|
72
|
+
plt.tight_layout()
|
|
73
|
+
return fig, ax
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def plot_fip_psth_compare_channels(
|
|
77
|
+
nwb,
|
|
78
|
+
align,
|
|
79
|
+
tw=[-4, 4],
|
|
80
|
+
channels=[
|
|
81
|
+
"G_1_preprocessed",
|
|
82
|
+
"G_2_preprocessed",
|
|
83
|
+
"R_1_preprocessed",
|
|
84
|
+
"R_2_preprocessed",
|
|
85
|
+
"Iso_1_preprocessed",
|
|
86
|
+
"Iso_2_preprocessed",
|
|
87
|
+
],
|
|
88
|
+
):
|
|
89
|
+
"""
|
|
90
|
+
TODO, need to censor by next event
|
|
91
|
+
todo, clean up plots
|
|
92
|
+
todo, figure out a modular system for comparing alignments, and channels
|
|
93
|
+
todo, annotate licks into bouts, start of bout, etc
|
|
94
|
+
|
|
95
|
+
align should either be a string of the name of an event type in nwb.df_events,
|
|
96
|
+
or a list of timepoints
|
|
97
|
+
EXAMPLE
|
|
98
|
+
********************
|
|
99
|
+
plot_fip_psth(nwb, 'goCue_start_time')
|
|
100
|
+
"""
|
|
101
|
+
if not hasattr(nwb, "fip_df"):
|
|
102
|
+
print("You need to compute the fip_df first")
|
|
103
|
+
print("running `nwb.fip_df = create_fib_df(nwb,tidy=True)`")
|
|
104
|
+
nwb.fip_df = nu.create_fib_df(nwb, tidy=True)
|
|
105
|
+
if not hasattr(nwb, "df_events"):
|
|
106
|
+
print("You need to compute the df_events first")
|
|
107
|
+
print("run `nwb.df_events = create_events_df(nwb)`")
|
|
108
|
+
nwb.df_events = nu.create_events_df(nwb)
|
|
109
|
+
|
|
110
|
+
if isinstance(align, str):
|
|
111
|
+
if align not in nwb.df_events["event"].values:
|
|
112
|
+
print("{} not found in the events table".format(align))
|
|
113
|
+
return
|
|
114
|
+
align_timepoints = nwb.df_events.query("event == @align")["timestamps"].values
|
|
115
|
+
align_label = "Time from {} (s)".format(align)
|
|
116
|
+
else:
|
|
117
|
+
align_timepoints = align
|
|
118
|
+
align_label = "Time (s)"
|
|
119
|
+
|
|
120
|
+
fig, ax = plt.subplots()
|
|
121
|
+
|
|
122
|
+
colors = [FIP_COLORS.get(c, "k") for c in channels]
|
|
123
|
+
for dex, c in enumerate(channels):
|
|
124
|
+
if c in nwb.fip_df["event"].values:
|
|
125
|
+
etr = fip_psth_inner_compute(nwb, align_timepoints, c, True, tw)
|
|
126
|
+
fip_psth_inner_plot(ax, etr, colors[dex], c)
|
|
127
|
+
else:
|
|
128
|
+
print("No data for channel: {}".format(c))
|
|
129
|
+
|
|
130
|
+
plt.legend()
|
|
131
|
+
ax.set_xlabel(align_label, fontsize=STYLE["axis_fontsize"])
|
|
132
|
+
ax.set_ylabel("df/f", fontsize=STYLE["axis_fontsize"])
|
|
133
|
+
ax.spines["top"].set_visible(False)
|
|
134
|
+
ax.spines["right"].set_visible(False)
|
|
135
|
+
ax.set_xlim(tw)
|
|
136
|
+
ax.axvline(0, color="k", alpha=0.2)
|
|
137
|
+
ax.tick_params(axis="both", labelsize=STYLE["axis_ticks_fontsize"])
|
|
138
|
+
plt.tight_layout()
|
|
139
|
+
return fig, ax
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def fip_psth_inner_plot(ax, etr, color, label):
|
|
143
|
+
"""
|
|
144
|
+
helper function that plots an event triggered response
|
|
145
|
+
ax, the pyplot axis to plot on
|
|
146
|
+
etr, the dataframe that contains the event triggered response
|
|
147
|
+
color, the line color to plot
|
|
148
|
+
label, the label for the etr
|
|
149
|
+
"""
|
|
150
|
+
ax.fill_between(etr.index, etr.data - etr["sem"], etr.data + etr["sem"], color=color, alpha=0.2)
|
|
151
|
+
ax.plot(etr.index, etr.data, color, label=label)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def fip_psth_inner_compute(nwb, align_timepoints, channel, average, tw=[-1, 1]):
|
|
155
|
+
"""
|
|
156
|
+
helper function that computes the event triggered response
|
|
157
|
+
nwb, nwb object for the session of interest, should have fip_df attribute
|
|
158
|
+
align_timepoints, an iterable list of the timepoints to compute the ETR aligned to
|
|
159
|
+
channel, what channel in the fip_df dataframe to use
|
|
160
|
+
average(bool), whether to return the average, or all individual traces
|
|
161
|
+
tw, time window before and after each event
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
data = nwb.fip_df.query("event == @channel")
|
|
165
|
+
etr = an.event_triggered_response(
|
|
166
|
+
data,
|
|
167
|
+
"timestamps",
|
|
168
|
+
"data",
|
|
169
|
+
align_timepoints,
|
|
170
|
+
t_start=tw[0],
|
|
171
|
+
t_end=tw[1],
|
|
172
|
+
output_sampling_rate=40,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
if average:
|
|
176
|
+
mean = etr.groupby("time").mean()
|
|
177
|
+
sem = etr.groupby("time").sem()
|
|
178
|
+
mean["sem"] = sem["data"]
|
|
179
|
+
return mean
|
|
180
|
+
return etr
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def plot_histogram(nwb, preprocessed=True, edge_percentile=2):
|
|
184
|
+
"""
|
|
185
|
+
Generates a histogram of values of each FIP channel
|
|
186
|
+
preprocessed (Bool), if True, uses the preprocessed channel
|
|
187
|
+
edge_percentile (float), displays only the (2, 100-2) percentiles of the data
|
|
188
|
+
|
|
189
|
+
EXAMPLE
|
|
190
|
+
***********************
|
|
191
|
+
plot_histogram(nwb)
|
|
192
|
+
"""
|
|
193
|
+
if not hasattr(nwb, "fip_df"):
|
|
194
|
+
print("You need to compute the fip_df first")
|
|
195
|
+
print("running `nwb.fip_df = create_fib_df(nwb,tidy=True)`")
|
|
196
|
+
nwb.fip_df = nu.create_fib_df(nwb, tidy=True)
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
fig, ax = plt.subplots(3, 2, sharex=True)
|
|
200
|
+
channels = ["G", "R", "Iso"]
|
|
201
|
+
mins = []
|
|
202
|
+
maxs = []
|
|
203
|
+
for i, c in enumerate(channels):
|
|
204
|
+
for j, count in enumerate(["1", "2"]):
|
|
205
|
+
if preprocessed:
|
|
206
|
+
dex = c + "_" + count + "_preprocessed"
|
|
207
|
+
else:
|
|
208
|
+
dex = c + "_" + count
|
|
209
|
+
df = nwb.fip_df.query("event == @dex")
|
|
210
|
+
ax[i, j].hist(df["data"], bins=1000, color=FIP_COLORS.get(dex, "k"))
|
|
211
|
+
ax[i, j].spines["top"].set_visible(False)
|
|
212
|
+
ax[i, j].spines["right"].set_visible(False)
|
|
213
|
+
if preprocessed:
|
|
214
|
+
ax[i, j].set_xlabel("df/f")
|
|
215
|
+
else:
|
|
216
|
+
ax[i, j].set_xlabel("f")
|
|
217
|
+
ax[i, j].set_ylabel("count")
|
|
218
|
+
ax[i, j].set_title(dex)
|
|
219
|
+
mins.append(np.percentile(df["data"].values, edge_percentile))
|
|
220
|
+
maxs.append(np.percentile(df["data"].values, 100 - edge_percentile))
|
|
221
|
+
ax[0, 0].set_xlim(np.min(mins), np.max(maxs))
|
|
222
|
+
fig.suptitle(nwb.session_id)
|
|
223
|
+
plt.tight_layout()
|
|
@@ -12,26 +12,18 @@ from aind_dynamic_foraging_basic_analysis.data_model.foraging_session import (
|
|
|
12
12
|
ForagingSessionData,
|
|
13
13
|
PhotostimData,
|
|
14
14
|
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"whole trial": "blue",
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
"""
|
|
24
|
-
Define a dictionary of plotting styles
|
|
25
|
-
This allows rapid regeneration of figures
|
|
26
|
-
"""
|
|
27
|
-
STYLE = {"axis_ticks_fontsize": 12, "axis_fontsize": 16}
|
|
15
|
+
from aind_dynamic_foraging_basic_analysis.plot.style import (
|
|
16
|
+
STYLE,
|
|
17
|
+
PHOTOSTIM_EPOCH_MAPPING,
|
|
18
|
+
FIP_COLORS,
|
|
19
|
+
)
|
|
28
20
|
|
|
29
21
|
|
|
30
22
|
def moving_average(a, n=3):
|
|
31
23
|
"""Compute moving average of a list or array."""
|
|
32
24
|
ret = np.nancumsum(a, dtype=float)
|
|
33
25
|
ret[n:] = ret[n:] - ret[:-n]
|
|
34
|
-
return ret[(n - 1):] / n
|
|
26
|
+
return ret[(n - 1) :] / n # noqa: E203
|
|
35
27
|
|
|
36
28
|
|
|
37
29
|
def plot_foraging_session( # noqa: C901
|
|
@@ -416,14 +408,7 @@ def plot_session_scroller( # noqa: C901 pragma: no cover
|
|
|
416
408
|
+ params[channel + "_bottom"]
|
|
417
409
|
)
|
|
418
410
|
ylabels.append(channel)
|
|
419
|
-
|
|
420
|
-
color = "g"
|
|
421
|
-
elif "G_2" in channel:
|
|
422
|
-
color = "darkgreen"
|
|
423
|
-
elif "R_1" in channel:
|
|
424
|
-
color = "r"
|
|
425
|
-
elif "R_2" in channel:
|
|
426
|
-
color = "darkred"
|
|
411
|
+
color = FIP_COLORS.get(channel, "k")
|
|
427
412
|
ycolors.append(color)
|
|
428
413
|
C = fip_df.query("event == @channel").copy()
|
|
429
414
|
C["data"] = C["data"] - C["data"].min()
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""Interactive plotly figures that can be used in the Streamlit app as well as
|
|
2
|
+
Jupyter Notebook
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import plotly.graph_objects as go
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def plot_session_in_time_plotly( # noqa: C901 pragma: no cover
|
|
9
|
+
df_events, adjust_time=True, fip_df=None
|
|
10
|
+
):
|
|
11
|
+
"""A plotly version of plot_foraging_session.plot_session_scroller
|
|
12
|
+
|
|
13
|
+
Creates a plot of the session in time (not in trial).
|
|
14
|
+
Plots left/right licks/rewards, and go cues as vertical lines from bottom to top.
|
|
15
|
+
|
|
16
|
+
df_events: A tidy dataframe of session events.
|
|
17
|
+
|
|
18
|
+
fip_df is a tidy dataframe of FIP measurements generated by
|
|
19
|
+
aind_dynamic_foraging_data_utils.nwb_utils.create_fib_df(tidy=True)
|
|
20
|
+
|
|
21
|
+
adjust_time (bool): If True, resets time=0 to the first event of the session.
|
|
22
|
+
|
|
23
|
+
EXAMPLE:
|
|
24
|
+
df_events = nwb_utils.create_events_df(nwb_object)
|
|
25
|
+
fip_df = nwb_utils.create_fib_df(nwb_object, tidy=True)
|
|
26
|
+
plot_foraging_session_plotly.plot_session_events_plotly(df_events)
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
if adjust_time:
|
|
30
|
+
start_time = df_events.iloc[0]["timestamps"]
|
|
31
|
+
df_events = df_events.copy()
|
|
32
|
+
df_events["timestamps"] = df_events["timestamps"] - start_time
|
|
33
|
+
|
|
34
|
+
if fip_df is not None:
|
|
35
|
+
fip_df = fip_df.copy()
|
|
36
|
+
fip_df["timestamps"] = fip_df["timestamps"] - start_time
|
|
37
|
+
|
|
38
|
+
xmin = df_events.iloc[0]["timestamps"]
|
|
39
|
+
xmax = df_events.iloc[-1]["timestamps"]
|
|
40
|
+
|
|
41
|
+
params = {
|
|
42
|
+
"left_lick": 0.125,
|
|
43
|
+
"right_lick": 0.875,
|
|
44
|
+
"left_reward": 0.375,
|
|
45
|
+
"right_reward": 0.625,
|
|
46
|
+
"go_cue_bottom": 0,
|
|
47
|
+
"go_cue_top": 1,
|
|
48
|
+
"G_1_preprocessed_bottom": 1,
|
|
49
|
+
"G_1_preprocessed_top": 2,
|
|
50
|
+
"G_2_preprocessed_bottom": 2,
|
|
51
|
+
"G_2_preprocessed_top": 3,
|
|
52
|
+
"R_1_preprocessed_bottom": 3,
|
|
53
|
+
"R_1_preprocessed_top": 4,
|
|
54
|
+
"R_2_preprocessed_bottom": 4,
|
|
55
|
+
"R_2_preprocessed_top": 5,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
yticks = [
|
|
59
|
+
params["left_lick"],
|
|
60
|
+
params["right_lick"],
|
|
61
|
+
params["left_reward"],
|
|
62
|
+
params["right_reward"],
|
|
63
|
+
]
|
|
64
|
+
ylabels = ["left licks", "right licks", "left reward", "right reward"]
|
|
65
|
+
ycolors = ["k", "k", "r", "r"]
|
|
66
|
+
|
|
67
|
+
fig = go.Figure()
|
|
68
|
+
|
|
69
|
+
# Add FIP traces
|
|
70
|
+
if fip_df is not None:
|
|
71
|
+
fip_channels = [
|
|
72
|
+
"G_2_preprocessed",
|
|
73
|
+
"G_1_preprocessed",
|
|
74
|
+
"R_2_preprocessed",
|
|
75
|
+
"R_1_preprocessed",
|
|
76
|
+
]
|
|
77
|
+
present_channels = fip_df["event"].unique()
|
|
78
|
+
for index, channel in enumerate(fip_channels):
|
|
79
|
+
if channel in present_channels:
|
|
80
|
+
yticks.append(
|
|
81
|
+
(params[channel + "_top"] - params[channel + "_bottom"]) / 2
|
|
82
|
+
+ params[channel + "_bottom"]
|
|
83
|
+
)
|
|
84
|
+
ylabels.append(channel)
|
|
85
|
+
if "G_1" in channel:
|
|
86
|
+
color = "green"
|
|
87
|
+
elif "G_2" in channel:
|
|
88
|
+
color = "darkgreen"
|
|
89
|
+
elif "R_1" in channel:
|
|
90
|
+
color = "red"
|
|
91
|
+
elif "R_2" in channel:
|
|
92
|
+
color = "darkred"
|
|
93
|
+
ycolors.append(color)
|
|
94
|
+
C = fip_df.query("event == @channel").copy()
|
|
95
|
+
C["data"] = C["data"] - C["data"].min()
|
|
96
|
+
C["data"] = C["data"].values / C["data"].max()
|
|
97
|
+
C["data"] += params[channel + "_bottom"]
|
|
98
|
+
|
|
99
|
+
# Plot the data using go.Scattergl
|
|
100
|
+
fig.add_trace(
|
|
101
|
+
go.Scattergl(
|
|
102
|
+
x=C.timestamps.values,
|
|
103
|
+
y=C.data.values,
|
|
104
|
+
mode="lines",
|
|
105
|
+
line=dict(color=color),
|
|
106
|
+
name=channel,
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Add a horizontal reference line (axhline equivalent)
|
|
111
|
+
fig.add_trace(
|
|
112
|
+
go.Scattergl(
|
|
113
|
+
x=[C.timestamps.min(), C.timestamps.max()],
|
|
114
|
+
y=[params[channel + "_bottom"], params[channel + "_bottom"]],
|
|
115
|
+
mode="lines",
|
|
116
|
+
line=dict(color="black", width=1, dash="solid"),
|
|
117
|
+
showlegend=False,
|
|
118
|
+
hoverinfo="skip",
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
left_licks = df_events.query('event == "left_lick_time"')
|
|
123
|
+
left_times = left_licks.timestamps.values
|
|
124
|
+
fig.add_trace(
|
|
125
|
+
go.Scattergl(
|
|
126
|
+
x=left_times,
|
|
127
|
+
y=[params["left_lick"]] * len(left_times),
|
|
128
|
+
mode="markers",
|
|
129
|
+
marker=dict(symbol="line-ns", line_color="black", size=10, line_width=2),
|
|
130
|
+
name="Left Lick",
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
right_licks = df_events.query('event == "right_lick_time"')
|
|
135
|
+
right_times = right_licks.timestamps.values
|
|
136
|
+
fig.add_trace(
|
|
137
|
+
go.Scattergl(
|
|
138
|
+
x=right_times,
|
|
139
|
+
y=[params["right_lick"]] * len(right_times),
|
|
140
|
+
mode="markers",
|
|
141
|
+
marker=dict(symbol="line-ns", line_color="black", size=10, line_width=2),
|
|
142
|
+
name="Right Lick",
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
left_reward_deliverys = df_events.query('event == "left_reward_delivery_time"')
|
|
147
|
+
left_times = left_reward_deliverys.timestamps.values
|
|
148
|
+
fig.add_trace(
|
|
149
|
+
go.Scattergl(
|
|
150
|
+
x=left_times,
|
|
151
|
+
y=[params["left_reward"]] * len(left_times),
|
|
152
|
+
mode="markers",
|
|
153
|
+
marker=dict(symbol="line-ns", size=10, line_color="red", line_width=3),
|
|
154
|
+
name="Left Reward",
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
right_reward_deliverys = df_events.query('event == "right_reward_delivery_time"')
|
|
159
|
+
right_times = right_reward_deliverys.timestamps.values
|
|
160
|
+
fig.add_trace(
|
|
161
|
+
go.Scattergl(
|
|
162
|
+
x=right_times,
|
|
163
|
+
y=[params["right_reward"]] * len(right_times),
|
|
164
|
+
mode="markers",
|
|
165
|
+
marker=dict(symbol="line-ns", size=10, line_color="red", line_width=3),
|
|
166
|
+
name="Right Reward",
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
go_cues = df_events.query('event == "goCue_start_time"')
|
|
171
|
+
go_cue_times = go_cues.timestamps.values
|
|
172
|
+
for n, time in enumerate(go_cue_times):
|
|
173
|
+
fig.add_trace(
|
|
174
|
+
go.Scattergl(
|
|
175
|
+
x=[time, time],
|
|
176
|
+
y=[params["go_cue_bottom"], params["go_cue_top"]],
|
|
177
|
+
mode="lines",
|
|
178
|
+
line=dict(color="blue", width=0.3),
|
|
179
|
+
legendgroup="Go Cue group",
|
|
180
|
+
showlegend=(n == 0),
|
|
181
|
+
name="Go Cue",
|
|
182
|
+
hovertemplate=f"Go Cue, Trial {n+1}<extra></extra>",
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
fig.update_layout(
|
|
187
|
+
title="Session Scroller",
|
|
188
|
+
xaxis_title="Time (s)",
|
|
189
|
+
yaxis=dict(
|
|
190
|
+
tickvals=yticks,
|
|
191
|
+
ticktext=ylabels,
|
|
192
|
+
),
|
|
193
|
+
xaxis=dict(range=[xmin, xmax]),
|
|
194
|
+
showlegend=True,
|
|
195
|
+
height=800,
|
|
196
|
+
width=1300,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
return fig
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines a dictionary of styles
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# General plotting style
|
|
6
|
+
STYLE = {"axis_ticks_fontsize": 12, "axis_fontsize": 16}
|
|
7
|
+
|
|
8
|
+
# Colorscheme for photostim
|
|
9
|
+
PHOTOSTIM_EPOCH_MAPPING = {
|
|
10
|
+
"after iti start": "cyan",
|
|
11
|
+
"before go cue": "cyan",
|
|
12
|
+
"after go cue": "green",
|
|
13
|
+
"whole trial": "blue",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
# Colorscheme for FIP channels
|
|
17
|
+
FIP_COLORS = {
|
|
18
|
+
"G_1": "g",
|
|
19
|
+
"G_1_preprocessed": "g",
|
|
20
|
+
"G_2": "darkgreen",
|
|
21
|
+
"G_2_preprocessed": "darkgreen",
|
|
22
|
+
"R_1": "r",
|
|
23
|
+
"R_1_preprocessed": "r",
|
|
24
|
+
"R_2": "darkred",
|
|
25
|
+
"R_2_preprocessed": "darkred",
|
|
26
|
+
"Iso_1": "gray",
|
|
27
|
+
"Iso_1_preprocessed": "gray",
|
|
28
|
+
"Iso_2": "k",
|
|
29
|
+
"Iso_2_preprocessed": "k",
|
|
30
|
+
"goCue_start_time": "b",
|
|
31
|
+
"left_lick_time": "m",
|
|
32
|
+
"right_lick_time": "r",
|
|
33
|
+
"left_reward_delivery_time": "b",
|
|
34
|
+
"right_reward_delivery_time": "r",
|
|
35
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: aind-dynamic-foraging-basic-analysis
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Generated from aind-library-template
|
|
5
5
|
Author: Allen Institute for Neural Dynamics
|
|
6
6
|
License: MIT
|
|
@@ -11,6 +11,7 @@ License-File: LICENSE
|
|
|
11
11
|
Requires-Dist: numpy
|
|
12
12
|
Requires-Dist: scipy
|
|
13
13
|
Requires-Dist: matplotlib
|
|
14
|
+
Requires-Dist: plotly
|
|
14
15
|
Requires-Dist: pandas
|
|
15
16
|
Requires-Dist: pynwb
|
|
16
17
|
Requires-Dist: aind-ephys-utils
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
aind_dynamic_foraging_basic_analysis/__init__.py,sha256=CJo5C4AvgEygUeRKFNBsBn1cC9PlkAQmKOxGY6O2YwE,194
|
|
2
|
+
aind_dynamic_foraging_basic_analysis/foraging_efficiency.py,sha256=9IhMqQo_aU_RFsDu8D2P3-Qu3J72bo7sASC3dkUQ2YE,8634
|
|
3
|
+
aind_dynamic_foraging_basic_analysis/lick_analysis.py,sha256=tgFqowzXHMRW2aCXhDi5SFE3Lfj_VMuMG1QPggkW9WE,20158
|
|
4
|
+
aind_dynamic_foraging_basic_analysis/data_model/foraging_session.py,sha256=7PFHfEIXP3QcjFS9Fk88S7PzBBYnUYw81WBjjEu_UKo,3536
|
|
5
|
+
aind_dynamic_foraging_basic_analysis/plot/plot_fip.py,sha256=mvzFK48WY5KIfkl7odjVQulJ9F3wM-VNRdk3A8fjZ_Y,7968
|
|
6
|
+
aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session.py,sha256=9_l5dUZtQnaOwEMkridwe3EKg9V9u4oDcGzsvIOixKU,18256
|
|
7
|
+
aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session_plotly.py,sha256=wE-kl1W6KZjaMX08bjawWfSuse6KW6YNSxDbdph3XK0,6715
|
|
8
|
+
aind_dynamic_foraging_basic_analysis/plot/style.py,sha256=vmrUdlCWeTDH9XJJKz7UBTchKlIP_8lhagjtwjjBPEc,823
|
|
9
|
+
aind_dynamic_foraging_basic_analysis-0.3.0.dist-info/LICENSE,sha256=U0Y7B3gZJHXpjJVLgTQjM8e_c8w4JJpLgGhIdsoFR1Y,1092
|
|
10
|
+
aind_dynamic_foraging_basic_analysis-0.3.0.dist-info/METADATA,sha256=I0ttIuhUN5tmuIlgjmsPja5FRJRtQpt4_4yPlC9H3UA,6737
|
|
11
|
+
aind_dynamic_foraging_basic_analysis-0.3.0.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
|
|
12
|
+
aind_dynamic_foraging_basic_analysis-0.3.0.dist-info/top_level.txt,sha256=gc5fvvd3cR7uvCHkTaSx-TcC4JmKMt9dBYMPncEO8VY,37
|
|
13
|
+
aind_dynamic_foraging_basic_analysis-0.3.0.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
aind_dynamic_foraging_basic_analysis/__init__.py,sha256=I1u00VHqldy7ddxEBVq9TkN98RDSTHPdQVeF7N-Dgj8,194
|
|
2
|
-
aind_dynamic_foraging_basic_analysis/foraging_efficiency.py,sha256=9IhMqQo_aU_RFsDu8D2P3-Qu3J72bo7sASC3dkUQ2YE,8634
|
|
3
|
-
aind_dynamic_foraging_basic_analysis/lick_analysis.py,sha256=Du6sP-Dfr6hBdRS98gc9Gp_kOq5TV_L80pDyj2WYctQ,20120
|
|
4
|
-
aind_dynamic_foraging_basic_analysis/data_model/foraging_session.py,sha256=7PFHfEIXP3QcjFS9Fk88S7PzBBYnUYw81WBjjEu_UKo,3536
|
|
5
|
-
aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session.py,sha256=e_JNb-dTlX4XfZsPlJ7eabT69_Z179-JrlqvZTwNi6Y,18666
|
|
6
|
-
aind_dynamic_foraging_basic_analysis-0.2.5.dist-info/LICENSE,sha256=U0Y7B3gZJHXpjJVLgTQjM8e_c8w4JJpLgGhIdsoFR1Y,1092
|
|
7
|
-
aind_dynamic_foraging_basic_analysis-0.2.5.dist-info/METADATA,sha256=hO3k4XkH9qNz0-cM39su4TvF3oLdewHZBJ5AargtjrY,6715
|
|
8
|
-
aind_dynamic_foraging_basic_analysis-0.2.5.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
|
|
9
|
-
aind_dynamic_foraging_basic_analysis-0.2.5.dist-info/top_level.txt,sha256=gc5fvvd3cR7uvCHkTaSx-TcC4JmKMt9dBYMPncEO8VY,37
|
|
10
|
-
aind_dynamic_foraging_basic_analysis-0.2.5.dist-info/RECORD,,
|
|
File without changes
|