Skip to content

Commit fb290f3

Browse files
committed
add sections to inventory
1 parent f08f25a commit fb290f3

File tree

1 file changed

+61
-55
lines changed

1 file changed

+61
-55
lines changed

code/pages/0_Data inventory.py

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ def app():
443443
def add_venn_diagrms(df_merged):
444444

445445
cols = st.columns([2, 1])
446-
cols[0].markdown("## Venn diagrams from presets")
446+
cols[0].markdown("## Issues in dynamic foraging data inventory")
447+
cols[0].markdown("#### [Github discussion](https://github.com/AllenNeuralDynamics/aind-behavior-blog/discussions/851)")
447448
with cols[1].expander("Time view settings", expanded=True):
448449
cols_1 = st.columns([1, 1])
449450
if_separate_plots = cols_1[0].checkbox("Separate in subplots", value=True)
@@ -453,65 +454,70 @@ def add_venn_diagrms(df_merged):
453454
time_period = cols_1[1].selectbox(
454455
"Bin size",
455456
["Daily", "Weekly", "Monthly", "Quarterly"],
456-
index=1,
457-
)
458-
459-
for i_venn, venn_preset in enumerate(VENN_PRESET):
460-
# -- Venn diagrams --
461-
st.markdown(f"### ({i_venn+1}). {venn_preset['name']}")
462-
fig, notes = generate_venn(
463-
df_merged,
464-
venn_preset
465-
)
466-
for note in notes:
467-
st.markdown(note)
468-
469-
cols = st.columns([1, 1])
470-
with cols[0]:
471-
st.pyplot(fig, use_container_width=True)
472-
473-
# -- Show and download df for this Venn --
474-
circle_columns = [c_s["column"] for c_s in venn_preset["circle_settings"]]
475-
# Show histogram over time for the columns and patches in preset
476-
df_this_preset = df_merged[circle_columns]
477-
# Filter out rows that have at least one True in this Venn
478-
df_this_preset = df_this_preset[df_this_preset.any(axis=1)]
479-
480-
# Create a new column to indicate sessions in patches specified by patch_ids like ["100", "101", "110", "111"]
481-
for patch_setting in venn_preset.get("patch_settings", []):
482-
idx = _filter_df_by_patch_ids(
483-
df_this_preset[circle_columns],
484-
patch_setting["patch_ids"]
485-
)
486-
df_this_preset.loc[idx, str(patch_setting["patch_ids"])] = True
487-
488-
# Join in other extra columns
489-
df_this_preset = df_this_preset.join(
490-
df_merged[[col for col in df_merged.columns if col not in META_COLUMNS]], how="left"
457+
index=0,
491458
)
459+
460+
st.markdown("---")
461+
for section in VENN_PRESET:
462+
section_name, section_contents = section["section_name"], section["section_contents"]
463+
st.markdown(f"## {section_name}")
464+
st.markdown("---")
465+
for i_venn, venn_preset in enumerate(section_contents):
466+
# -- Venn diagrams --
467+
st.markdown(f"### ({i_venn+1}). {venn_preset['name']}")
468+
fig, notes = generate_venn(
469+
df_merged,
470+
venn_preset
471+
)
472+
for note in notes:
473+
st.markdown(note)
474+
475+
cols = st.columns([1, 1])
476+
with cols[0]:
477+
st.pyplot(fig, use_container_width=True)
478+
479+
# -- Show and download df for this Venn --
480+
circle_columns = [c_s["column"] for c_s in venn_preset["circle_settings"]]
481+
# Show histogram over time for the columns and patches in preset
482+
df_this_preset = df_merged[circle_columns]
483+
# Filter out rows that have at least one True in this Venn
484+
df_this_preset = df_this_preset[df_this_preset.any(axis=1)]
485+
486+
# Create a new column to indicate sessions in patches specified by patch_ids like ["100", "101", "110", "111"]
487+
for patch_setting in venn_preset.get("patch_settings", []):
488+
idx = _filter_df_by_patch_ids(
489+
df_this_preset[circle_columns],
490+
patch_setting["patch_ids"]
491+
)
492+
df_this_preset.loc[idx, str(patch_setting["patch_ids"])] = True
492493

493-
with cols[0]:
494-
download_df(
495-
df_this_preset,
496-
label="Download as CSV for this Venn diagram",
497-
file_name=f"df_{venn_preset['name']}.csv",
494+
# Join in other extra columns
495+
df_this_preset = df_this_preset.join(
496+
df_merged[[col for col in df_merged.columns if col not in META_COLUMNS]], how="left"
498497
)
499-
with st.expander(f"Show dataframe, n = {len(df_this_preset)}"):
500-
st.write(df_this_preset)
501498

502-
with cols[1]:
503-
# -- Show histogram over time --
504-
fig = plot_histogram_over_time(
505-
df=df_this_preset.reset_index(),
506-
venn_preset=venn_preset,
507-
time_period=time_period,
508-
if_sync_y_limits=if_sync_y_limits,
509-
if_separate_plots=if_separate_plots,
510-
)
511-
override_plotly_theme(fig, font_size_scale=0.9)
512-
st.plotly_chart(fig, use_container_width=True)
499+
with cols[0]:
500+
download_df(
501+
df_this_preset,
502+
label="Download as CSV for this Venn diagram",
503+
file_name=f"df_{venn_preset['name']}.csv",
504+
)
505+
with st.expander(f"Show dataframe, n = {len(df_this_preset)}"):
506+
st.write(df_this_preset)
507+
508+
with cols[1]:
509+
# -- Show histogram over time --
510+
fig = plot_histogram_over_time(
511+
df=df_this_preset.reset_index(),
512+
venn_preset=venn_preset,
513+
time_period=time_period,
514+
if_sync_y_limits=if_sync_y_limits,
515+
if_separate_plots=if_separate_plots,
516+
)
517+
override_plotly_theme(fig, font_size_scale=0.9)
518+
st.plotly_chart(fig, use_container_width=True)
513519

514-
st.markdown("---")
520+
st.markdown("---")
515521

516522
# --- User-defined Venn diagram ---
517523
# Multiselect for selecting queries up to three

0 commit comments

Comments
 (0)