Skip to content

Commit 0107e49

Browse files
committed
Merge branch 'han_bug_fix'
2 parents cc77a49 + 43f4563 commit 0107e49

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
A streamlit app for browsing foraging behavior sessions in AIND.
44

55
## The app
6-
- The one running on ECS: https://foraging-behavior-browser.allenneuraldynamics-test.org/
6+
- The one running on ECS: https://foraging-behavior-browser.allenneuraldynamics.org/
77
- If you see a window "Select a certificate for authentication", just click "Cancel".
88
- To debug, use this [Code Ocean capsule](https://codeocean.allenneuraldynamics.org/capsule/3373065/tree?cw=true)
9-
- See also a streamlit app for ephys sessions https://foraging-ephys-browser.allenneuraldynamics-test.org/ ([Git repo](https://github.com/AllenNeuralDynamics/foraging-ephys-browser/))
9+
- See also a streamlit app for ephys sessions https://foraging-ephys-browser.allenneuraldynamics.org/ ([Git repo](https://github.com/AllenNeuralDynamics/foraging-ephys-browser/))
1010

1111
## Sharing a contextual app
1212
Starting from this [PR](https://github.com/AllenNeuralDynamics/foraging-behavior-browser/pull/25), the URL contains (part of) the session state of the app. Meaning that the user can "query" pre-set filters and plot settings in the URL. On the other hand, after interacting with the app, the URL is automatically updated to reflect the user interactions, and the user can then copy and paste the URL to share/save the new context. Essentially, this becomes a cool way of sharing a data analysis.
1313

1414
For example, this URL show all plots of mouse 699982
1515

16-
> https://foraging-behavior-browser.allenneuraldynamics-test.org/?filter_subject_id=699982&session_plot_mode=all+sessions+filtered+from+sidebar&tab_id=tab_session_inspector
16+
> https://foraging-behavior-browser.allenneuraldynamics.org/?filter_subject_id=699982&session_plot_mode=all+sessions+filtered+from+sidebar&tab_id=tab_session_inspector
1717
1818
![image](https://github.com/AllenNeuralDynamics/foraging-behavior-browser/assets/24734299/4389e251-1305-4a85-8936-7e5d737f8408)
1919

2020

2121
and this URL will show exactly the plot below. Note the filters and plot settings are preserved.
2222

23-
> https://foraging-behavior-browser.allenneuraldynamics-test.org/Old_mice?filter_subject_id=HH&filter_session=1.0&filter_session=81.0&filter_finished_trials=825.6&filter_finished_trials=1872.0&filter_foraging_eff=0.793295&filter_foraging_eff=1.2966&filter_task=coupled_block_baiting&filter_photostim_location=None&tab_id=tab_session_x_y&x_y_plot_xname=foraging_eff&x_y_plot_yname=finished_trials&x_y_plot_group_by=subject_id&x_y_plot_if_show_dots=True&x_y_plot_if_aggr_each_group=True&x_y_plot_aggr_method_group=linear+fit&x_y_plot_if_aggr_all=False&x_y_plot_aggr_method_all=mean+%2B%2F-+sem&x_y_plot_smooth_factor=5&x_y_plot_if_use_x_quantile_group=False&x_y_plot_q_quantiles_group=20&x_y_plot_if_use_x_quantile_all=False&x_y_plot_q_quantiles_all=20&x_y_plot_dot_size=21&x_y_plot_dot_opacity=0.4&x_y_plot_line_width=3.5&auto_training_history_x_axis=session&auto_training_history_sort_by=progress_to_graduated&auto_training_history_sort_order=descending
23+
> https://foraging-behavior-browser.allenneuraldynamics.org/Old_mice?filter_subject_id=HH&filter_session=1.0&filter_session=81.0&filter_finished_trials=825.6&filter_finished_trials=1872.0&filter_foraging_eff=0.793295&filter_foraging_eff=1.2966&filter_task=coupled_block_baiting&filter_photostim_location=None&tab_id=tab_session_x_y&x_y_plot_xname=foraging_eff&x_y_plot_yname=finished_trials&x_y_plot_group_by=subject_id&x_y_plot_if_show_dots=True&x_y_plot_if_aggr_each_group=True&x_y_plot_aggr_method_group=linear+fit&x_y_plot_if_aggr_all=False&x_y_plot_aggr_method_all=mean+%2B%2F-+sem&x_y_plot_smooth_factor=5&x_y_plot_if_use_x_quantile_group=False&x_y_plot_q_quantiles_group=20&x_y_plot_if_use_x_quantile_all=False&x_y_plot_q_quantiles_all=20&x_y_plot_dot_size=21&x_y_plot_dot_opacity=0.4&x_y_plot_line_width=3.5&auto_training_history_x_axis=session&auto_training_history_sort_by=progress_to_graduated&auto_training_history_sort_order=descending
2424
2525
<img width="1664" alt="image" src="https://github.com/AllenNeuralDynamics/foraging-behavior-browser/assets/24734299/2eaa7697-01cc-4eb3-bd0c-7d91c1eb64e0">
2626

code/Home.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
pass
6161

6262

63+
# Inhibit the deprecated user warning from streamlit 1.45.1
64+
# https://discuss.streamlit.io/t/can-not-find-cause-of-st-experimental-user-deprecation-warning/111680
65+
def no_op(*args, **kwargs):
66+
"""This function replaces the original one and does not perform any action."""
67+
pass
68+
st.user_info.maybe_show_deprecated_user_warning = no_op
69+
70+
6371
def _trainer_mapper(trainer):
6472
user_mapper = {
6573
'Avalon Amaya': ['Avalon'],
@@ -693,6 +701,6 @@ def add_main_tabs():
693701
st.markdown('# Something went wrong! :scream: ')
694702
st.markdown('## :bulb: Please follow these steps to troubleshoot:')
695703
st.markdown('#### 1. Reload the page')
696-
st.markdown('#### 2. Click this original URL https://foraging-behavior-browser.allenneuraldynamics-test.org/')
704+
st.markdown('#### 2. Click this original URL https://foraging-behavior-browser.allenneuraldynamics.org/')
697705
st.markdown('#### 3. Report your bug here: https://github.com/AllenNeuralDynamics/foraging-behavior-browser/issues (paste your URL and screenshoots)')
698706
raise e

code/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__ver__ = 'v3.2.1'
1+
__ver__ = 'v2025.11.13'

code/util/plot_autotrain_manager.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ def plot_manager_all_progress_bokeh_source(
5050
on=["subject_id", "session"],
5151
how="inner",
5252
)
53+
df_to_draw = df_to_draw.copy()
5354

54-
df_to_draw["color"] = df_to_draw["current_stage_actual"].map(stage_color_mapper)
55-
df_to_draw["edge_color"] = ( # Use grey edge to indicate stage without suggestion
55+
df_to_draw.loc[:, "color"] = df_to_draw["current_stage_actual"].map(stage_color_mapper)
56+
df_to_draw.loc[:, "edge_color"] = ( # Use grey edge to indicate stage without suggestion
5657
df_to_draw["current_stage_suggested"].map(stage_color_mapper).fillna("#d3d3d3")
5758
)
5859

5960
# Convert session_date to string for URL generation
60-
df_to_draw["session_date_str"] = df_to_draw["session_date"].astype(str)
61-
df_to_draw["imgs_1"] = df_to_draw.apply(
61+
df_to_draw.loc[:, "session_date_str"] = df_to_draw["session_date"].astype(str)
62+
df_to_draw.loc[:, "imgs_1"] = df_to_draw.apply(
6263
lambda x: get_s3_public_url(
6364
subject_id=x["subject_id"],
6465
session_date=x["session_date_str"],
@@ -67,7 +68,7 @@ def plot_manager_all_progress_bokeh_source(
6768
),
6869
axis=1,
6970
)
70-
df_to_draw["imgs_2"] = df_to_draw.apply(
71+
df_to_draw.loc[:, "imgs_2"] = df_to_draw.apply(
7172
lambda x: get_s3_public_url(
7273
subject_id=x["subject_id"],
7374
session_date=x["session_date_str"],
@@ -80,13 +81,13 @@ def plot_manager_all_progress_bokeh_source(
8081

8182
# --- Remove rows with NaN in color or edge_color ---
8283
# to fix a bug where non-normalized stages appears in the autotrain table
83-
df_to_draw = df_to_draw.dropna(subset=["color", "edge_color"])
84+
df_to_draw = df_to_draw.dropna(subset=["color", "edge_color"]).copy()
8485

8586
# --- Filter recent days ---
86-
df_to_draw['session_date'] = pd.to_datetime(df_to_draw['session_date'])
87+
df_to_draw.loc[:, 'session_date'] = pd.to_datetime(df_to_draw['session_date'])
8788
if not if_use_filtered_data and x_axis == 'date' and recent_days is not None:
8889
date_start = datetime.today() - pd.Timedelta(days=recent_days)
89-
df_to_draw = df_to_draw.query('session_date >= @date_start')
90+
df_to_draw = df_to_draw.query('session_date >= @date_start').copy()
9091

9192
# Sort subjects
9293
if sort_by == "subject_id":
@@ -114,26 +115,29 @@ def plot_manager_all_progress_bokeh_source(
114115
else:
115116
raise ValueError("Invalid sort_by value.")
116117

118+
df_to_draw = df_to_draw.copy()
119+
117120
# Select x
118121
if x_axis == 'session':
119-
df_to_draw["x"] = df_to_draw['session']
122+
df_to_draw.loc[:, "x"] = df_to_draw['session']
120123
elif x_axis == 'date':
121-
df_to_draw["x"] = df_to_draw['session_date']
124+
df_to_draw.loc[:, "x"] = df_to_draw['session_date']
122125
elif x_axis == 'relative_date':
123126
# groupby subject_id and all subtracted by the min date of each subject
124-
df_to_draw["x"] = (
127+
df_to_draw.loc[:, "x"] = (
125128
df_to_draw.groupby("subject_id")["session_date"]
126129
.transform(lambda x: x - x.min())
127130
.dt.days
128131
)
129132

130-
df_to_draw["session_date"] = df_to_draw["session_date"].dt.strftime('%Y-%m-%d')
133+
# Convert session_date to string format AFTER x-axis calculations
134+
df_to_draw.loc[:, "session_date"] = df_to_draw["session_date"].dt.strftime('%Y-%m-%d')
131135

132136
# --- Reorder subjects ---
133137
df_subjects = []
134138

135139
for n, subject_id in enumerate(subject_ids):
136-
df_subject = df_to_draw[df_to_draw['subject_id'] == subject_id]
140+
df_subject = df_to_draw[df_to_draw['subject_id'] == subject_id].copy()
137141
df_subject["y"] = len(subject_ids) - n
138142
df_subjects.append(df_subject)
139143

code/util/streamlit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def add_dot_property_mapper():
698698

699699
return size_mapper, size_mapper_range, size_mapper_gamma
700700

701-
@st.fragment(run_every=5)
701+
@st.fragment()
702702
def data_selector():
703703

704704
with st.expander(f'Session selector', expanded=True):
@@ -1177,7 +1177,7 @@ def _add_agg(df_this, x_name, y_name, group, aggr_method, if_use_x_quantile, q_q
11771177

11781178
def add_footnote():
11791179
st.markdown('---')
1180-
st.markdown(f'#### AIND Behavior Team @ 2025 {__ver__}')
1180+
st.markdown(f'#### Han Hou @ AIND Behavior Team\n{__ver__}')
11811181
st.markdown('[bug report / feature request](https://github.com/AllenNeuralDynamics/foraging-behavior-browser/issues)')
11821182

11831183

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
streamlit==1.41.1
1+
streamlit==1.45.1
22
streamlit-aggrid==0.3.5
33
streamlit-bokeh3-events==0.1.4
44
streamlit_dynamic_filters==0.1.9

0 commit comments

Comments
 (0)