aind-dynamic-foraging-basic-analysis 0.2.3__py3-none-any.whl → 0.2.4__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.3"
3
+ __version__ = "0.2.4"
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
@@ -20,12 +20,18 @@ PHOTOSTIM_EPOCH_MAPPING = {
20
20
  "whole trial": "blue",
21
21
  }
22
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}
28
+
23
29
 
24
30
  def moving_average(a, n=3):
25
31
  """Compute moving average of a list or array."""
26
32
  ret = np.nancumsum(a, dtype=float)
27
33
  ret[n:] = ret[n:] - ret[:-n]
28
- return ret[n - 1:] / n
34
+ return ret[(n - 1):] / n
29
35
 
30
36
 
31
37
  def plot_foraging_session( # noqa: C901
@@ -313,3 +319,152 @@ def plot_foraging_session( # noqa: C901
313
319
  ax.remove()
314
320
 
315
321
  return ax_choice_reward.get_figure(), [ax_choice_reward, ax_reward_schedule]
322
+
323
+
324
+ def plot_session_scroller(df_events, ax=None, adjust_time=True): # pragma: no cover
325
+ """
326
+ Creates an interactive plot of the session.
327
+ Plots left/right licks/rewards, and go cues
328
+
329
+ pressing "left arrow" scrolls backwards in time
330
+ pressing "right arrow" scrolls forwards in time
331
+ pressing "up arrow" zooms out, in time
332
+ pressing "down arrow" zooms in, in time
333
+
334
+ df_events, is a tidy dataframe of session events generated by
335
+ aind_dynamic_foraging_data_utils.nwb_utils.create_events_df
336
+
337
+ ax is a pyplot figure axis. If None, a new figure is created
338
+
339
+ adjust_time (bool). If True, resets time=0 to the first event of the session
340
+
341
+ EXAMPLE:
342
+ df_events = nwb_utils.create_events_df(nwb_object)
343
+ plot_foraging_session.plot_session_scroller(df_events)
344
+ """
345
+ if ax is None:
346
+ fig, ax = plt.subplots(figsize=(15, 3))
347
+
348
+ if adjust_time:
349
+ df_events = df_events.copy()
350
+ df_events["timestamps"] = df_events["timestamps"] - df_events.iloc[0]["timestamps"]
351
+
352
+ xmin = df_events.iloc[0]["timestamps"]
353
+ xmax = xmin + 20
354
+ ax.set_xlim(xmin, xmax)
355
+
356
+ params = {
357
+ "left_lick_bottom": 0,
358
+ "left_lick_top": 0.25,
359
+ "right_lick_bottom": 0.75,
360
+ "right_lick_top": 1,
361
+ "left_reward_bottom": 0.25,
362
+ "left_reward_top": 0.5,
363
+ "right_reward_bottom": 0.5,
364
+ "right_reward_top": 0.75,
365
+ "go_cue_bottom": 0,
366
+ "go_cue_top": 1,
367
+ }
368
+ yticks = [
369
+ (params["left_lick_top"] - params["left_lick_bottom"]) / 2 + params["left_lick_bottom"],
370
+ (params["right_lick_top"] - params["right_lick_bottom"]) / 2 + params["right_lick_bottom"],
371
+ (params["left_reward_top"] - params["left_reward_bottom"]) / 2
372
+ + params["left_reward_bottom"],
373
+ (params["right_reward_top"] - params["right_reward_bottom"]) / 2
374
+ + params["right_reward_bottom"],
375
+ ]
376
+ ylabels = ["left licks", "right licks", "left reward", "right reward"]
377
+
378
+ left_licks = df_events.query('event == "left_lick_time"')
379
+ left_times = left_licks.timestamps.values
380
+ ax.vlines(
381
+ left_times,
382
+ params["left_lick_bottom"],
383
+ params["left_lick_top"],
384
+ alpha=1,
385
+ linewidth=2,
386
+ color="k",
387
+ )
388
+
389
+ right_licks = df_events.query('event == "right_lick_time"')
390
+ right_times = right_licks.timestamps.values
391
+ ax.vlines(
392
+ right_times,
393
+ params["right_lick_bottom"],
394
+ params["right_lick_top"],
395
+ alpha=1,
396
+ linewidth=2,
397
+ color="k",
398
+ )
399
+
400
+ left_reward_deliverys = df_events.query('event == "left_reward_delivery_time"')
401
+ left_times = left_reward_deliverys.timestamps.values
402
+ ax.vlines(
403
+ left_times,
404
+ params["left_reward_bottom"],
405
+ params["left_reward_top"],
406
+ alpha=1,
407
+ linewidth=2,
408
+ color="r",
409
+ )
410
+
411
+ right_reward_deliverys = df_events.query('event == "right_reward_delivery_time"')
412
+ right_times = right_reward_deliverys.timestamps.values
413
+ ax.vlines(
414
+ right_times,
415
+ params["right_reward_bottom"],
416
+ params["right_reward_top"],
417
+ alpha=1,
418
+ linewidth=2,
419
+ color="r",
420
+ )
421
+
422
+ go_cues = df_events.query('event == "goCue_start_time"')
423
+ go_cue_times = go_cues.timestamps.values
424
+ ax.vlines(
425
+ go_cue_times,
426
+ params["go_cue_bottom"],
427
+ params["go_cue_top"],
428
+ alpha=0.75,
429
+ linewidth=1,
430
+ color="b",
431
+ )
432
+
433
+ # Clean up plot
434
+ ax.set_yticks(yticks)
435
+ ax.set_yticklabels(ylabels, fontsize=STYLE["axis_ticks_fontsize"])
436
+ colors = ["k", "k", "r", "r"]
437
+ for tick, color in zip(ax.get_yticklabels(), colors):
438
+ tick.set_color(color)
439
+ ax.set_xlabel("time (s)", fontsize=STYLE["axis_fontsize"])
440
+ ax.set_ylim(0, 1)
441
+ ax.spines["top"].set_visible(False)
442
+ ax.spines["right"].set_visible(False)
443
+ plt.tight_layout()
444
+
445
+ def on_key_press(event):
446
+ """
447
+ Define interaction resonsivity
448
+ """
449
+ x = ax.get_xlim()
450
+ xmin = x[0]
451
+ xmax = x[1]
452
+ xStep = (xmax - xmin) / 4
453
+ if event.key == "<" or event.key == "," or event.key == "left":
454
+ xmin -= xStep
455
+ xmax -= xStep
456
+ elif event.key == ">" or event.key == "." or event.key == "right":
457
+ xmin += xStep
458
+ xmax += xStep
459
+ elif event.key == "up":
460
+ xmin -= xStep
461
+ xmax += xStep
462
+ elif event.key == "down":
463
+ xmin += xStep * (2 / 3)
464
+ xmax -= xStep * (2 / 3)
465
+ ax.set_xlim(xmin, xmax)
466
+ plt.draw()
467
+
468
+ kpid = fig.canvas.mpl_connect("key_press_event", on_key_press) # noqa: F841
469
+
470
+ return fig, ax
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aind-dynamic-foraging-basic-analysis
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Generated from aind-library-template
5
5
  Author: Allen Institute for Neural Dynamics
6
6
  License: MIT
@@ -0,0 +1,10 @@
1
+ aind_dynamic_foraging_basic_analysis/__init__.py,sha256=ti2seCRcOdLN6XHXb1oId4MB7ghsQp5ScK7kSEs889k,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=xvOCDutonCDmPBfzeVL49pkV_nqsTiLZPxT5Obn5s6w,16388
6
+ aind_dynamic_foraging_basic_analysis-0.2.4.dist-info/LICENSE,sha256=U0Y7B3gZJHXpjJVLgTQjM8e_c8w4JJpLgGhIdsoFR1Y,1092
7
+ aind_dynamic_foraging_basic_analysis-0.2.4.dist-info/METADATA,sha256=4cqyS-byYZFLPvZ3GxO7JiJ6MaE3T7aixFMmvNmp-ps,6715
8
+ aind_dynamic_foraging_basic_analysis-0.2.4.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
9
+ aind_dynamic_foraging_basic_analysis-0.2.4.dist-info/top_level.txt,sha256=gc5fvvd3cR7uvCHkTaSx-TcC4JmKMt9dBYMPncEO8VY,37
10
+ aind_dynamic_foraging_basic_analysis-0.2.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (73.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- aind_dynamic_foraging_basic_analysis/__init__.py,sha256=pzXja6QJMzGyrEjymtaqBJc9MIUFJDi-0uTzCmP62II,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=X-gLffs8tau2Eeh_fF8tlU-KDkYiyRrtbO_jZnTyPxo,11580
6
- aind_dynamic_foraging_basic_analysis-0.2.3.dist-info/LICENSE,sha256=U0Y7B3gZJHXpjJVLgTQjM8e_c8w4JJpLgGhIdsoFR1Y,1092
7
- aind_dynamic_foraging_basic_analysis-0.2.3.dist-info/METADATA,sha256=5lXBY3eJw6ZyU2k4QySUXIanpWkbe5whu4ZjG8WpjYY,6715
8
- aind_dynamic_foraging_basic_analysis-0.2.3.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
9
- aind_dynamic_foraging_basic_analysis-0.2.3.dist-info/top_level.txt,sha256=gc5fvvd3cR7uvCHkTaSx-TcC4JmKMt9dBYMPncEO8VY,37
10
- aind_dynamic_foraging_basic_analysis-0.2.3.dist-info/RECORD,,