aind-dynamic-foraging-basic-analysis 0.4.3__py3-none-any.whl → 0.4.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.4.3"
3
+ __version__ = "0.4.4"
4
4
 
5
5
  from .metrics.foraging_efficiency import compute_foraging_efficiency # noqa: F401
6
6
  from .plot.plot_foraging_session import plot_foraging_session # noqa: F401
@@ -942,34 +942,123 @@ def plot_session_in_time_plotly( # noqa: C901 pragma: no cover
942
942
  y_main_top = params["curve_top"]
943
943
 
944
944
  # FIP channels (single-session only), normalised and stacked above the behavior panel
945
+ fip_unclipped_ids = []
946
+ fip_clipped_ids = []
945
947
  if df_fip is not None and len(sessions) == 1 and len(fip) > 0:
946
948
  fip_channels = fip
947
949
  present = set(df_fip["event"].unique())
948
- band = 0
950
+ band = 0.0
951
+ fip_gap = 0.5
949
952
  for channel in fip_channels:
950
953
  if channel not in present:
951
954
  continue
952
- bottom = params["curve_top"] + 0.1 + band
953
955
  C = df_fip.query("event == @channel").copy()
954
- d = C["data"].values - np.nanmin(C["data"].values)
955
- d = d / np.nanmax(d) + bottom
956
+ vals = C["data"].astype(float).to_numpy()
957
+ if vals.size == 0 or np.all(np.isnan(vals)):
958
+ continue
959
+ vmin = np.nanmin(vals)
960
+ vmax = np.nanmax(vals)
961
+ span = vmax - vmin
962
+ # avoid zero-span stacking problems for constant signals
963
+ if np.isnan(span) or span == 0:
964
+ span = 1.0
965
+
966
+ # place this channel so its minimum maps to `base`, preserving original scale
967
+ base = params["curve_top"] + 0.1 + band
968
+ offset = base - vmin
969
+ d = vals + offset
970
+
956
971
  color = get_fip_color(channel)
972
+ custom = np.stack([C.timestamps.values, vals], axis=-1)
973
+ hover = f"%{{customdata[0]:.2f}}s %{{customdata[1]:.3f}} <extra>{channel}</extra>"
974
+
975
+ fip_unclipped_ids.append(len(fig.data))
957
976
  fig.add_trace(
958
977
  go.Scattergl(
959
978
  x=C.timestamps.values + last_off,
960
979
  y=d,
980
+ customdata=custom,
981
+ mode="lines",
982
+ hovertemplate=hover,
983
+ line=dict(color=color),
984
+ name=channel,
985
+ ),
986
+ row=1,
987
+ col=1,
988
+ )
989
+
990
+ # clipped version: clip raw values to 1st–99th percentile, same y-offset
991
+ p01, p99 = np.nanpercentile(vals, 1), np.nanpercentile(vals, 99)
992
+ vals_clipped = np.clip(vals, p01, p99)
993
+ d_clipped = vals_clipped + offset
994
+ fip_clipped_ids.append(len(fig.data))
995
+ fig.add_trace(
996
+ go.Scattergl(
997
+ x=C.timestamps.values + last_off,
998
+ y=d_clipped,
999
+ customdata=custom,
961
1000
  mode="lines",
1001
+ hovertemplate=hover,
962
1002
  line=dict(color=color),
963
1003
  name=channel,
1004
+ visible=False,
1005
+ showlegend=False,
964
1006
  ),
965
1007
  row=1,
966
1008
  col=1,
967
1009
  )
968
- yticks.append(bottom + 0.5)
969
- ylabels.append(channel)
970
- band += 1
971
- y_main_top = bottom + 1.0
972
1010
 
1011
+ # use three ticks: bottom (vmin), center (channel name), top (vmax)
1012
+ yticks.extend([base - vmin, base + span / 2.0, base + span])
1013
+ ylabels.extend(
1014
+ [
1015
+ "0.0",
1016
+ f"{channel.split('_dff')[0]}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
1017
+ f"{vmax:.2f}",
1018
+ ]
1019
+ )
1020
+
1021
+ # advance band by the display span (not raw span) plus a small gap to avoid overlap
1022
+ band += span + fip_gap
1023
+ y_main_top = base + span + 0.25
1024
+
1025
+ # Toggle button to switch FIP traces between full range and 1–99% clipped
1026
+ if fip_unclipped_ids:
1027
+ n_all = len(fig.data)
1028
+ vis_full = [True] * n_all
1029
+ vis_clip = [True] * n_all
1030
+ for idx in fip_clipped_ids:
1031
+ vis_full[idx] = False
1032
+ for idx in fip_unclipped_ids:
1033
+ vis_clip[idx] = False
1034
+ for idx in fip_clipped_ids:
1035
+ vis_clip[idx] = True
1036
+
1037
+ fig.update_layout(
1038
+ updatemenus=[
1039
+ dict(
1040
+ type="buttons",
1041
+ direction="right",
1042
+ x=1.0,
1043
+ y=1.0,
1044
+ xanchor="right",
1045
+ yanchor="top",
1046
+ showactive=True,
1047
+ buttons=[
1048
+ dict(
1049
+ label="FIP: full range",
1050
+ method="restyle",
1051
+ args=[{"visible": vis_full}],
1052
+ ),
1053
+ dict(
1054
+ label="FIP: clip 1–99%",
1055
+ method="restyle",
1056
+ args=[{"visible": vis_clip}],
1057
+ ),
1058
+ ],
1059
+ )
1060
+ ]
1061
+ )
973
1062
  # Thick vertical lines marking session boundaries (both panels)
974
1063
  for b in boundaries:
975
1064
  for row in (1, 2):
@@ -1012,7 +1101,7 @@ def plot_session_in_time_plotly( # noqa: C901 pragma: no cover
1012
1101
  # Title pinned to the very top-left so it clears the legend below it.
1013
1102
  title=dict(text=title or "Session Scroller", x=0.0, xanchor="left", y=0.98, yanchor="top"),
1014
1103
  showlegend=True,
1015
- height=620,
1104
+ height=620 + (50 * len(fip) if df_fip is not None and len(fip) > 0 else 0),
1016
1105
  width=1000,
1017
1106
  template="simple_white",
1018
1107
  # Legend outside, top-left, horizontal, compact entries (narrow box).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aind-dynamic-foraging-basic-analysis
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: Generated from aind-library-template
5
5
  Author: Allen Institute for Neural Dynamics
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
- aind_dynamic_foraging_basic_analysis/__init__.py,sha256=yFwtNyfxrbBfjwuan3c0LIXYDVCbS-93Y17Hg5aH8H0,410
1
+ aind_dynamic_foraging_basic_analysis/__init__.py,sha256=igIqt40ZJYDqlkIoif_kcuV-4Pj6kFrEm8VOx-hK38g,410
2
2
  aind_dynamic_foraging_basic_analysis/data_model/foraging_session.py,sha256=7PFHfEIXP3QcjFS9Fk88S7PzBBYnUYw81WBjjEu_UKo,3536
3
3
  aind_dynamic_foraging_basic_analysis/licks/annotation.py,sha256=04NKOxqGS1B06WDPH_9Pu1rgyDq1LwvXbc0YDLIx6Io,13305
4
4
  aind_dynamic_foraging_basic_analysis/licks/lick_analysis.py,sha256=WqaDbAinxmkRpGez92kBoc4YpyuLbDBNEOfq06bbXhY,20333
@@ -11,11 +11,11 @@ aind_dynamic_foraging_basic_analysis/metrics/snr_kurtosis.py,sha256=F7SJ2zwleMPd
11
11
  aind_dynamic_foraging_basic_analysis/metrics/trial_metrics.py,sha256=OxJvxz1XssEFJ5Nrnlqqgx9UsftbzTDonFIE65azLKM,13220
12
12
  aind_dynamic_foraging_basic_analysis/plot/plot_fip.py,sha256=Lkw9YafpB6Kv3-pnZ663mc83o16tYNnekRqhb4TD2Ss,26962
13
13
  aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session.py,sha256=06OEfIZTtE6zEH1iQLTrzadwxGB5rntlSyh8KPhFfEs,16914
14
- aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session_plotly.py,sha256=5KQnDbBXCpUUMz4iYPV56ihpTgxXz-EnawWGeVD69ek,39213
14
+ aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session_plotly.py,sha256=5Av4pzD2W5ptg5RIyv7BOsO8YOHsWEhRWpziJOqlWrM,42549
15
15
  aind_dynamic_foraging_basic_analysis/plot/plot_session_scroller.py,sha256=_3vYP7zBkiq9psR1ph_cuNhOzvV3emdco2wnmO5ud5A,18255
16
16
  aind_dynamic_foraging_basic_analysis/plot/style.py,sha256=9OE22zVQR39FBt4mfdRFA43YbqXwhQF71VBSiFP65Qk,2649
17
- aind_dynamic_foraging_basic_analysis-0.4.3.dist-info/licenses/LICENSE,sha256=U0Y7B3gZJHXpjJVLgTQjM8e_c8w4JJpLgGhIdsoFR1Y,1092
18
- aind_dynamic_foraging_basic_analysis-0.4.3.dist-info/METADATA,sha256=I1SEwHBOlKjhq3Ajg39PCPyl_q4WgpD_exHQfpaczpM,9876
19
- aind_dynamic_foraging_basic_analysis-0.4.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
20
- aind_dynamic_foraging_basic_analysis-0.4.3.dist-info/top_level.txt,sha256=gc5fvvd3cR7uvCHkTaSx-TcC4JmKMt9dBYMPncEO8VY,37
21
- aind_dynamic_foraging_basic_analysis-0.4.3.dist-info/RECORD,,
17
+ aind_dynamic_foraging_basic_analysis-0.4.4.dist-info/licenses/LICENSE,sha256=U0Y7B3gZJHXpjJVLgTQjM8e_c8w4JJpLgGhIdsoFR1Y,1092
18
+ aind_dynamic_foraging_basic_analysis-0.4.4.dist-info/METADATA,sha256=ect9pxumrB2s14wOadpuuErWF5OMaiGM2EFjfBXBnyk,9876
19
+ aind_dynamic_foraging_basic_analysis-0.4.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
20
+ aind_dynamic_foraging_basic_analysis-0.4.4.dist-info/top_level.txt,sha256=gc5fvvd3cR7uvCHkTaSx-TcC4JmKMt9dBYMPncEO8VY,37
21
+ aind_dynamic_foraging_basic_analysis-0.4.4.dist-info/RECORD,,