aind-dynamic-foraging-basic-analysis 0.2.6__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.
@@ -1,6 +1,6 @@
1
1
  """Init package"""
2
2
 
3
- __version__ = "0.2.6"
3
+ __version__ = "0.3.0"
4
4
 
5
5
  from .foraging_efficiency import compute_foraging_efficiency # noqa: F401
6
6
  from .plot.plot_foraging_session import plot_foraging_session # noqa: F401
@@ -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[int(0.5 * len(kernel)): -int(0.5 * len(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,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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aind-dynamic-foraging-basic-analysis
3
- Version: 0.2.6
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,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (74.1.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- aind_dynamic_foraging_basic_analysis/__init__.py,sha256=Qg0Rfawo0JuRdGTLdWCzNu5URAopGjIOMNY2jEJ9pko,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_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/style.py,sha256=vmrUdlCWeTDH9XJJKz7UBTchKlIP_8lhagjtwjjBPEc,823
8
- aind_dynamic_foraging_basic_analysis-0.2.6.dist-info/LICENSE,sha256=U0Y7B3gZJHXpjJVLgTQjM8e_c8w4JJpLgGhIdsoFR1Y,1092
9
- aind_dynamic_foraging_basic_analysis-0.2.6.dist-info/METADATA,sha256=1g5OBig6QzfmhXb4cr5WkIVDjpvnEzTUcyYjXXUsu-g,6715
10
- aind_dynamic_foraging_basic_analysis-0.2.6.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
11
- aind_dynamic_foraging_basic_analysis-0.2.6.dist-info/top_level.txt,sha256=gc5fvvd3cR7uvCHkTaSx-TcC4JmKMt9dBYMPncEO8VY,37
12
- aind_dynamic_foraging_basic_analysis-0.2.6.dist-info/RECORD,,