Skip to content

Commit

Permalink
Merge pull request #19 from AllenNeuralDynamics/plot_updates
Browse files Browse the repository at this point in the history
Plot updates
  • Loading branch information
alexpiet authored Sep 26, 2024
2 parents daf1f5f + b6ad25c commit 671448a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
)


def plot_session_scroller(nwb, ax=None, plot_bouts=False): # noqa: C901 pragma: no cover
def plot_session_scroller( # noqa: C901 pragma: no cover
nwb, ax=None, plot_bouts=False, processing="bright"
):
"""
Creates an interactive plot of the session.
Plots left/right licks/rewards, and go cues
Expand Down Expand Up @@ -77,14 +79,30 @@ def plot_session_scroller(nwb, ax=None, plot_bouts=False): # noqa: C901 pragma:
"right_reward_top": 0.75,
"go_cue_bottom": 0,
"go_cue_top": 1,
"G_1_preprocessed_bottom": 1,
"G_1_preprocessed_top": 2,
"G_2_preprocessed_bottom": 2,
"G_2_preprocessed_top": 3,
"R_1_preprocessed_bottom": 3,
"R_1_preprocessed_top": 4,
"R_2_preprocessed_bottom": 4,
"R_2_preprocessed_top": 5,
"G_1_dff-bright_bottom": 1,
"G_1_dff-bright_top": 2,
"G_2_dff-bright_bottom": 2,
"G_2_dff-bright_top": 3,
"R_1_dff-bright_bottom": 3,
"R_1_dff-bright_top": 4,
"R_2_dff-bright_bottom": 4,
"R_2_dff-bright_top": 5,
"G_1_dff-poly_bottom": 1,
"G_1_dff-poly_top": 2,
"G_2_dff-poly_bottom": 2,
"G_2_dff-poly_top": 3,
"R_1_dff-poly_bottom": 3,
"R_1_dff-poly_top": 4,
"R_2_dff-poly_bottom": 4,
"R_2_dff-poly_top": 5,
"G_1_dff-exp_bottom": 1,
"G_1_dff-exp_top": 2,
"G_2_dff-exp_bottom": 2,
"G_2_dff-exp_top": 3,
"R_1_dff-exp_bottom": 3,
"R_1_dff-exp_top": 4,
"R_2_dff-exp_bottom": 4,
"R_2_dff-exp_top": 5,
}
yticks = [
(params["left_lick_top"] - params["left_lick_bottom"]) / 2 + params["left_lick_bottom"],
Expand All @@ -99,24 +117,51 @@ def plot_session_scroller(nwb, ax=None, plot_bouts=False): # noqa: C901 pragma:

if fip_df is not None:
fip_channels = [
"G_2_preprocessed",
"G_1_preprocessed",
"R_2_preprocessed",
"R_1_preprocessed",
"G_2_dff-{}".format(processing),
"G_1_dff-{}".format(processing),
"R_2_dff-{}".format(processing),
"R_1_dff-{}".format(processing),
]
present_channels = fip_df["event"].unique()
for index, channel in enumerate(fip_channels):
if channel in present_channels:
yticks.append(
(params[channel + "_top"] - params[channel + "_bottom"]) / 2
(params[channel + "_top"] - params[channel + "_bottom"]) * 1
+ params[channel + "_bottom"]
)
ylabels.append(channel)
color = FIP_COLORS.get(channel, "k")
ycolors.append(color)
C = fip_df.query("event == @channel").copy()
C["data"] = C["data"] - C["data"].min()
C["data"] = C["data"].values / C["data"].max()
d_min = C["data"].min()
d_max = C["data"].max()
d_range = d_max - d_min
t1 = 0.25
t2 = 0.5
t3 = 0.75
p1 = d_min + t1 * d_range
p2 = d_min + t2 * d_range
p3 = d_min + t3 * d_range
yticks.append(
params[channel + "_bottom"]
+ (params[channel + "_top"] - params[channel + "_bottom"]) * t1
)
yticks.append(
params[channel + "_bottom"]
+ (params[channel + "_top"] - params[channel + "_bottom"]) * t2
)
yticks.append(
params[channel + "_bottom"]
+ (params[channel + "_top"] - params[channel + "_bottom"]) * t3
)
ylabels.append(str(round(p1, 3)))
ylabels.append(str(round(p2, 3)))
ylabels.append(str(round(p3, 3)))
ycolors.append("darkgray")
ycolors.append("darkgray")
ycolors.append("darkgray")
C["data"] = C["data"] - d_min
C["data"] = C["data"].values / (d_max - d_min)
C["data"] += params[channel + "_bottom"]
ax.plot(C.timestamps.values, C.data.values, color)
ax.axhline(params[channel + "_bottom"], color="k", linewidth=0.5, alpha=0.25)
Expand Down Expand Up @@ -226,6 +271,10 @@ def plot_session_scroller(nwb, ax=None, plot_bouts=False): # noqa: C901 pragma:
ax.set_ylim(0, 5)
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
if fip_df is not None:
ax.set_title(nwb.session_id + ", FIP processing: {}".format(processing))
else:
ax.set_title(nwb.session_id)
plt.tight_layout()

def on_key_press(event):
Expand Down
24 changes: 18 additions & 6 deletions src/aind_dynamic_foraging_basic_analysis/plot/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@
# Colorscheme for FIP channels
FIP_COLORS = {
"G_1": "g",
"G_1_preprocessed": "g",
"G_1_dff-bright": "g",
"G_1_dff-exp": "g",
"G_1_dff-poly": "g",
"G_2": "darkgreen",
"G_2_preprocessed": "darkgreen",
"G_2_dff-bright": "darkgreen",
"G_2_dff-exp": "darkgreen",
"G_2_dff-poly": "darkgreen",
"R_1": "r",
"R_1_preprocessed": "r",
"R_1_dff-bright": "r",
"R_1_dff-exp": "r",
"R_1_dff-poly": "r",
"R_2": "darkred",
"R_2_preprocessed": "darkred",
"R_2_dff-bright": "darkred",
"R_2_dff-exp": "darkred",
"R_2_dff-poly": "darkred",
"Iso_1": "gray",
"Iso_1_preprocessed": "gray",
"Iso_1_dff-bright": "gray",
"Iso_1_dff-exp": "gray",
"Iso_1_dff-poly": "gray",
"Iso_2": "k",
"Iso_2_preprocessed": "k",
"Iso_2_dff-bright": "k",
"Iso_2_dff-exp": "k",
"Iso_2_dff-poly": "k",
"goCue_start_time": "b",
"left_lick_time": "m",
"right_lick_time": "r",
Expand Down

0 comments on commit 671448a

Please sign in to comment.