aind-dynamic-foraging-basic-analysis 0.2.3__py3-none-any.whl → 0.2.5__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.5"
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,212 @@ 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( # noqa: C901 pragma: no cover
325
+ df_events, ax=None, adjust_time=True, fip_df=None
326
+ ):
327
+ """
328
+ Creates an interactive plot of the session.
329
+ Plots left/right licks/rewards, and go cues
330
+
331
+ pressing "left arrow" scrolls backwards in time
332
+ pressing "right arrow" scrolls forwards in time
333
+ pressing "up arrow" zooms out, in time
334
+ pressing "down arrow" zooms in, in time
335
+
336
+ df_events, is a tidy dataframe of session events generated by
337
+ aind_dynamic_foraging_data_utils.nwb_utils.create_events_df
338
+
339
+ ax is a pyplot figure axis. If None, a new figure is created
340
+
341
+ adjust_time (bool). If True, resets time=0 to the first event of the session
342
+
343
+ fip_df is a tidy dataframe of FIP measurements generated by
344
+ aind_dynamic_foraging_data_utils.nwb_utils.create_fib_df(tidy=True)
345
+
346
+ EXAMPLES:
347
+ df_events = nwb_utils.create_events_df(nwb_object)
348
+ plot_foraging_session.plot_session_scroller(df_events)
349
+
350
+ df_events = nwb_utils.create_events_df(nwb_object)
351
+ fip_df = nwb_utils.create_fib_df(nwb_object, tidy=True)
352
+ plot_foraging_session.plot_session_scroller(df_events,fip_df=fip_df)
353
+ """
354
+ if ax is None:
355
+ if fip_df is None:
356
+ fig, ax = plt.subplots(figsize=(15, 3))
357
+ else:
358
+ fig, ax = plt.subplots(figsize=(15, 8))
359
+
360
+ if adjust_time:
361
+ start_time = df_events.iloc[0]["timestamps"]
362
+ df_events = df_events.copy()
363
+ df_events["timestamps"] = df_events["timestamps"] - start_time
364
+
365
+ if fip_df is not None:
366
+ fip_df = fip_df.copy()
367
+ fip_df["timestamps"] = fip_df["timestamps"] - start_time
368
+
369
+ xmin = df_events.iloc[0]["timestamps"]
370
+ xmax = xmin + 20
371
+ ax.set_xlim(xmin, xmax)
372
+
373
+ params = {
374
+ "left_lick_bottom": 0,
375
+ "left_lick_top": 0.25,
376
+ "right_lick_bottom": 0.75,
377
+ "right_lick_top": 1,
378
+ "left_reward_bottom": 0.25,
379
+ "left_reward_top": 0.5,
380
+ "right_reward_bottom": 0.5,
381
+ "right_reward_top": 0.75,
382
+ "go_cue_bottom": 0,
383
+ "go_cue_top": 1,
384
+ "G_1_preprocessed_bottom": 1,
385
+ "G_1_preprocessed_top": 2,
386
+ "G_2_preprocessed_bottom": 2,
387
+ "G_2_preprocessed_top": 3,
388
+ "R_1_preprocessed_bottom": 3,
389
+ "R_1_preprocessed_top": 4,
390
+ "R_2_preprocessed_bottom": 4,
391
+ "R_2_preprocessed_top": 5,
392
+ }
393
+ yticks = [
394
+ (params["left_lick_top"] - params["left_lick_bottom"]) / 2 + params["left_lick_bottom"],
395
+ (params["right_lick_top"] - params["right_lick_bottom"]) / 2 + params["right_lick_bottom"],
396
+ (params["left_reward_top"] - params["left_reward_bottom"]) / 2
397
+ + params["left_reward_bottom"],
398
+ (params["right_reward_top"] - params["right_reward_bottom"]) / 2
399
+ + params["right_reward_bottom"],
400
+ ]
401
+ ylabels = ["left licks", "right licks", "left reward", "right reward"]
402
+ ycolors = ["k", "k", "r", "r"]
403
+
404
+ if fip_df is not None:
405
+ fip_channels = [
406
+ "G_2_preprocessed",
407
+ "G_1_preprocessed",
408
+ "R_2_preprocessed",
409
+ "R_1_preprocessed",
410
+ ]
411
+ present_channels = fip_df["event"].unique()
412
+ for index, channel in enumerate(fip_channels):
413
+ if channel in present_channels:
414
+ yticks.append(
415
+ (params[channel + "_top"] - params[channel + "_bottom"]) / 2
416
+ + params[channel + "_bottom"]
417
+ )
418
+ ylabels.append(channel)
419
+ if "G_1" in channel:
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"
427
+ ycolors.append(color)
428
+ C = fip_df.query("event == @channel").copy()
429
+ C["data"] = C["data"] - C["data"].min()
430
+ C["data"] = C["data"].values / C["data"].max()
431
+ C["data"] += params[channel + "_bottom"]
432
+ ax.plot(C.timestamps.values, C.data.values, color)
433
+ ax.axhline(params[channel + "_bottom"], color="k", linewidth=0.5, alpha=0.25)
434
+
435
+ left_licks = df_events.query('event == "left_lick_time"')
436
+ left_times = left_licks.timestamps.values
437
+ ax.vlines(
438
+ left_times,
439
+ params["left_lick_bottom"],
440
+ params["left_lick_top"],
441
+ alpha=1,
442
+ linewidth=2,
443
+ color="k",
444
+ )
445
+
446
+ right_licks = df_events.query('event == "right_lick_time"')
447
+ right_times = right_licks.timestamps.values
448
+ ax.vlines(
449
+ right_times,
450
+ params["right_lick_bottom"],
451
+ params["right_lick_top"],
452
+ alpha=1,
453
+ linewidth=2,
454
+ color="k",
455
+ )
456
+
457
+ left_reward_deliverys = df_events.query('event == "left_reward_delivery_time"')
458
+ left_times = left_reward_deliverys.timestamps.values
459
+ ax.vlines(
460
+ left_times,
461
+ params["left_reward_bottom"],
462
+ params["left_reward_top"],
463
+ alpha=1,
464
+ linewidth=2,
465
+ color="r",
466
+ )
467
+
468
+ right_reward_deliverys = df_events.query('event == "right_reward_delivery_time"')
469
+ right_times = right_reward_deliverys.timestamps.values
470
+ ax.vlines(
471
+ right_times,
472
+ params["right_reward_bottom"],
473
+ params["right_reward_top"],
474
+ alpha=1,
475
+ linewidth=2,
476
+ color="r",
477
+ )
478
+
479
+ go_cues = df_events.query('event == "goCue_start_time"')
480
+ go_cue_times = go_cues.timestamps.values
481
+ ax.vlines(
482
+ go_cue_times,
483
+ params["go_cue_bottom"],
484
+ params["go_cue_top"],
485
+ alpha=0.75,
486
+ linewidth=1,
487
+ color="b",
488
+ )
489
+
490
+ # Clean up plot
491
+ ax.set_yticks(yticks)
492
+ ax.set_yticklabels(ylabels, fontsize=STYLE["axis_ticks_fontsize"])
493
+
494
+ for tick, color in zip(ax.get_yticklabels(), ycolors):
495
+ tick.set_color(color)
496
+ ax.set_xlabel("time (s)", fontsize=STYLE["axis_fontsize"])
497
+ if fip_df is None:
498
+ ax.set_ylim(0, 1)
499
+ else:
500
+ ax.set_ylim(0, 5)
501
+ ax.spines["top"].set_visible(False)
502
+ ax.spines["right"].set_visible(False)
503
+ plt.tight_layout()
504
+
505
+ def on_key_press(event):
506
+ """
507
+ Define interaction resonsivity
508
+ """
509
+ x = ax.get_xlim()
510
+ xmin = x[0]
511
+ xmax = x[1]
512
+ xStep = (xmax - xmin) / 4
513
+ if event.key == "<" or event.key == "," or event.key == "left":
514
+ xmin -= xStep
515
+ xmax -= xStep
516
+ elif event.key == ">" or event.key == "." or event.key == "right":
517
+ xmin += xStep
518
+ xmax += xStep
519
+ elif event.key == "up":
520
+ xmin -= xStep
521
+ xmax += xStep
522
+ elif event.key == "down":
523
+ xmin += xStep * (2 / 3)
524
+ xmax -= xStep * (2 / 3)
525
+ ax.set_xlim(xmin, xmax)
526
+ plt.draw()
527
+
528
+ kpid = fig.canvas.mpl_connect("key_press_event", on_key_press) # noqa: F841
529
+
530
+ 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.5
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=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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (74.0.0)
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,,