import%20marimo%0A%0A__generated_with%20%3D%20%220.26.0%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Analysing%20Training%20Village%20data%20with%20lecilab-behavior-analysis%0A%0A%20%20%20%20This%20notebook%20goes%20through%20the%20main%20analyses%20of%20the%20package%2C%20from%20the%0A%20%20%20%20data%20saved%20by%20the%20village%20to%20the%20figures%20of%20the%20daily%20reports%3A%0A%0A%20%20%20%201.%20load%20the%20trials%20of%20a%20mouse%20and%20prepare%20them%2C%0A%20%20%20%202.%20a%20first%20look%3A%20trials%20and%20performance%20per%20day%2C%0A%20%20%20%203.%20the%20ready-made%20figures%20(training%20history%2C%20one%20session)%2C%0A%20%20%20%204.%20psychometric%20curves%20and%20their%20fit%2C%0A%20%20%20%205.%20win-stay%20%2F%20lose-switch%2C%20by%20session%2C%20through%20training%20and%20by%20mouse%2C%0A%20%20%20%206.%20the%20settings%20of%20each%20session%2C%20and%20how%20they%20changed%20through%20training%2C%0A%20%20%20%207.%20your%20own%20figure%2C%20made%20of%20panels%2C%0A%20%20%20%208.%20styles%3A%20for%20a%20paper%2C%20or%20with%20every%20number.%0A%0A%20%20%20%20It%20runs%20on%20the%20sample%20data%20of%20the%20package%20(%60sample_data%60%3A%20four%20mice%20of%0A%20%20%20%20the%20project%20COT_cannula_data%2C%20their%20first%20three%20months%20of%20training%2C%0A%20%20%20%20from%20habituation%20to%20the%20multisensory%20task).%20To%20use%20your%20data%2C%20set%0A%20%20%20%20%60USE_SAMPLE_DATA%60%20to%20%60False%60%20and%20choose%20the%20project%20and%20mice%20in%20the%20next%20cell.%0A%0A%20%20%20%20Open%20it%20with%20%60marimo%20edit%20notebooks%2Ftutorial.py%60%20(from%20the%20root%20of%20the%0A%20%20%20%20repository).%20Every%20plot%20of%20the%20package%2C%20with%20its%20code%2C%20is%20in%20the%0A%20%20%20%20%5Bgallery%5D(https%3A%2F%2Flearningcircuitslab.github.io%2Flecilab-behavior-analysis%2Fgallery.html).%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20where%20the%20data%20is%3A%20the%20sample%20data%20of%20the%20package%2C%20or%20a%20project%20of%20the%20data%20folder%0A%20%20%20%20USE_SAMPLE_DATA%20%3D%20True%0A%20%20%20%20PROJECT%20%3D%20%22COT_cannula_data%22%20%20%23%20a%20folder%20of%20the%20data%20folder%20(lecilab_behavior_analysis.io.server.get_outpath)%0A%20%20%20%20MOUSE%20%3D%20%22NUO003%22%20%20%23%20the%20mouse%20of%20the%20figures%0A%20%20%20%20MICE%20%3D%20%5B%22NUO001%22%2C%20%22NUO002%22%2C%20%22NUO003%22%2C%20%22NUO009%22%5D%20%20%23%20the%20mice%20compared%20in%20section%205%0A%20%20%20%20return%20MICE%2C%20MOUSE%2C%20PROJECT%2C%20USE_SAMPLE_DATA%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%201.%20Load%20and%20prepare%20the%20trials%0A%0A%20%20%20%20The%20village%20saves%20one%20row%20per%20trial%20in%0A%20%20%20%20%60%3Cdata%20folder%3E%2F%3Cproject%3E%2Fsessions%2F%3Cmouse%3E%2F%3Cmouse%3E.csv%60.%0A%20%20%20%20%60load_project_trials%60%20reads%20it%20and%20**prepares**%20it%20(%60preprocessing.prepare%60)%3A%0A%20%20%20%20it%20reads%20old%20and%20new%20data%20formats%20the%20same%20way%20(see%0A%20%20%20%20%60data_format_changes.py%60)%20and%20adds%20every%20column%20the%20analyses%20use%3A%20the%0A%20%20%20%20day%20(%60year_month_day%60)%2C%20the%20trial%20number%20through%20training%20(%60total_trial%60)%2C%0A%20%20%20%20the%20first%20choice%2C%20misses%2C%20early%20pokeouts%2C%20reaction%20times%2C%20center%20holds...%0A%20%20%20%20It%20also%20adds%20the%20performance%20through%20trials%20(%60performance_w%60).%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(MOUSE%2C%20PROJECT%2C%20USE_SAMPLE_DATA%2C%20mo)%3A%0A%20%20%20%20import%20pandas%20as%20pd%0A%0A%20%20%20%20from%20lecilab_behavior_analysis.io.loading%20import%20load_project_logs%2C%20load_project_trials%0A%0A%20%20%20%20%23%20the%20data%20folder%3A%20sample_data%20(next%20to%20this%20notebook)%2C%20or%20the%20one%20of%20this%20computer%20(None)%0A%20%20%20%20root%20%3D%20mo.notebook_dir().parent%20%2F%20%22sample_data%22%20if%20USE_SAMPLE_DATA%20else%20None%0A%20%20%20%20trials%20%3D%20load_project_trials(PROJECT%2C%20%5BMOUSE%5D%2C%20root%3Droot)%0A%20%20%20%20%23%20the%20events%20and%20the%20sessions%20summaries%20of%20the%20setups%20(with%20the%20settings%20of%20each%20session)%0A%20%20%20%20events%2C%20summary%2C%20_%20%3D%20load_project_logs(PROJECT%2C%20root%3Droot)%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20f%22**%7Blen(trials)%7D%20trials**%20of%20%7BMOUSE%7D%2C%20from%20%7Btrials%5B'date'%5D.min()%3A%25Y-%25m-%25d%7D%20to%20%7Btrials%5B'date'%5D.max()%3A%25Y-%25m-%25d%7D%22%0A%20%20%20%20)%0A%20%20%20%20return%20events%2C%20load_project_trials%2C%20pd%2C%20root%2C%20summary%2C%20trials%0A%0A%0A%40app.cell%0Adef%20_(trials)%3A%0A%20%20%20%20trials%5B%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22date%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22session%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22trial%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22current_training_stage%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22correct_side%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22first_choice%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22correct%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22reaction_time%22%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%5D.head()%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%202.%20A%20first%20look%3A%20trials%20and%20performance%20per%20day%0A%0A%20%20%20%20Timeouts%20(%60correct%60%20empty)%20count%20as%20errors%20in%20the%20performance%0A%20%20%20%20(%60data_format_changes.correct_as_number%60).%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(trials)%3A%0A%20%20%20%20import%20lecilab_behavior_analysis.data_format_changes%20as%20dfc%0A%0A%20%20%20%20_per_day%20%3D%20trials.assign(correct_number%3Dtrials%5B%22correct%22%5D.apply(dfc.correct_as_number))%0A%20%20%20%20per_day%20%3D%20_per_day.groupby(%22year_month_day%22).agg(%0A%20%20%20%20%20%20%20%20trials%3D(%22trial%22%2C%20%22size%22)%2C%0A%20%20%20%20%20%20%20%20sessions%3D(%22session%22%2C%20%22nunique%22)%2C%0A%20%20%20%20%20%20%20%20performance%3D(%22correct_number%22%2C%20lambda%20c%3A%20round(c.mean()%20*%20100%2C%201))%2C%0A%20%20%20%20%20%20%20%20stages%3D(%22current_training_stage%22%2C%20lambda%20s%3A%20%22%2C%20%22.join(sorted(s.unique())))%2C%0A%20%20%20%20)%0A%20%20%20%20per_day%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%203.%20The%20ready-made%20figures%0A%0A%20%20%20%20%60figures.subject_progress%60%20is%20the%20training%20history%20of%20the%20daily%20report%3A%0A%20%20%20%20calendar%2C%20training%20times%2C%20performance%2C%20trials%20and%20water%20per%20day%2C%0A%20%20%20%20performance%20by%20trial%20type%2C%20bias%2C%20win-stay%20%2F%20lose-switch%2C%20center%20port%2C%0A%20%20%20%20reaction%20times%2C%20and%20engagement%20(from%20the%20events%20of%20the%20setup).%20Each%0A%20%20%20%20panel%20that%20cannot%20be%20drawn%20shows%20why%20instead%20of%20stopping%20the%20figure%3B%0A%20%20%20%20%60problems%60%20lists%20them.%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(events%2C%20trials)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.figures%20import%20session_summary%2C%20subject_progress%0A%0A%20%20%20%20history%2C%20problems%20%3D%20subject_progress(trials%2C%20perf_window%3D100%2C%20events_df%3Devents)%0A%20%20%20%20history%0A%20%20%20%20return%20problems%2C%20session_summary%0A%0A%0A%40app.cell%0Adef%20_(problems)%3A%0A%20%20%20%20problems%20%20%23%20the%20panels%20that%20could%20not%20be%20drawn%20(none%2C%20hopefully)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20trials)%3A%0A%20%20%20%20day_picker%20%3D%20mo.ui.dropdown(options%3Dsorted(trials%5B%22year_month_day%22%5D.unique())%2C%20value%3D%222025-11-08%22%2C%20label%3D%22Day%22)%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%60figures.session_summary%60%20is%20one%20day%3A%20performance%2C%20choices%2C%20center%0A%20%20%20%20port%2C%20timing%2C%20and%20a%20psychometric%20panel%20per%20stimulus%20modality.%0A%0A%20%20%20%20%7Bday_picker%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(day_picker%2C)%0A%0A%0A%40app.cell%0Adef%20_(day_picker%2C%20session_summary%2C%20trials)%3A%0A%20%20%20%20day%20%3D%20trials%5Btrials%5B%22year_month_day%22%5D%20%3D%3D%20day_picker.value%5D%0A%20%20%20%20_figure%2C%20_%20%3D%20session_summary(day%2C%20perf_window%3D50)%0A%20%20%20%20_figure%0A%20%20%20%20return%20(day%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%204.%20Psychometric%20curves%0A%0A%20%20%20%20%60get_performance_by_difficulty_ratio%60%20adds%2C%20for%20each%20trial%2C%20the%20value%20of%0A%20%20%20%20its%20stimulus%20(%60visual_stimulus_ratio%60%3A%20brightness%20ratio%20of%20the%20ports%2C%0A%20%20%20%20positive%20when%20the%20left%20one%20is%20brighter%3B%20%60total_evidence_strength%60%20for%20the%0A%20%20%20%20cloud%20of%20tones)%20and%20the%20first%20choice%20as%20a%20number%20(1%20left%2C%200%20right).%0A%20%20%20%20%60psychometric_plot%60%20draws%20the%20choices%20and%20a%20lapse%20logistic%20fit%3B%0A%20%20%20%20%60psychometric_curve_fitting_params%60%20gives%20the%20parameters%20of%20that%20same%20fit%0A%20%20%20%20(on%20the%20log%20of%20the%20brightness%20ratio%2C%20as%20the%20plot).%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(trials)%3A%0A%20%20%20%20from%20matplotlib%20import%20pyplot%20as%20plt%0A%0A%20%20%20%20from%20lecilab_behavior_analysis.metrics.choices%20import%20get_performance_by_difficulty_ratio%0A%20%20%20%20from%20lecilab_behavior_analysis.models.psychometric%20import%20psychometric_curve_fitting_params%0A%20%20%20%20from%20lecilab_behavior_analysis.plots%20import%20psychometric_plot%0A%0A%20%20%20%20%23%20the%20trials%20of%20the%20visual%20task%20with%20easy%20to%20hard%20stimuli%0A%20%20%20%20visual%20%3D%20get_performance_by_difficulty_ratio(trials%5Btrials%5B%22current_training_stage%22%5D%20%3D%3D%20%22TwoAFC_visual_hard%22%5D)%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots(figsize%3D(4%2C%203.5))%0A%20%20%20%20if%20len(visual)%3A%0A%20%20%20%20%20%20%20%20psychometric_plot(visual%2C%20x%3D%22visual_stimulus_ratio%22%2C%20y%3D%22first_choice_numeric%22%2C%20ax%3D_ax%2C%20valueType%3D%22discrete%22)%0A%20%20%20%20%20%20%20%20_%2C%20(lapse_left%2C%20lapse_right%2C%20slope%2C%20bias)%20%3D%20psychometric_curve_fitting_params(%0A%20%20%20%20%20%20%20%20%20%20%20%20visual%2C%20x%3D%22visual_stimulus_ratio%22%2C%20y%3D%22first_choice_numeric%22%2C%20valueType%3D%22discrete%22%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20print(f%22lapses%3A%20left%20%7Blapse_left%3A.2f%7D%2C%20right%20%7Blapse_right%3A.2f%7D%3B%20slope%20%7Bslope%3A.2f%7D%3B%20bias%20(log%20ratio)%20%7Bbias%3A.2f%7D%22)%0A%20%20%20%20_fig%0A%20%20%20%20return%20(plt%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%205.%20Win-stay%20%2F%20lose-switch%0A%0A%20%20%20%20After%20a%20correct%20trial%2C%20does%20the%20mouse%20choose%20the%20same%20side%20again%0A%20%20%20%20(win-stay)%3F%20After%20an%20error%2C%20does%20it%20choose%20the%20other%20side%0A%20%20%20%20(lose-switch)%3F%20%60get_win_stay_lose_switch_df%60%20gives%20both%20probabilities%0A%20%20%20%20for%20each%20group%20of%20trials%3A%20%60by%3D%22session%22%60%20(a%20point%20per%20session)%2C%0A%20%20%20%20%60by%3D%22subject%22%60%20(a%20point%20per%20mouse%2C%20with%20the%20trials%20of%20several%20mice)%2C%0A%20%20%20%20%60by%3D%22year_month_day%22%60%2C%20or%20%60by%3D%22trial_group%22%60%20(through%20training%2C%20after%0A%20%20%20%20%60add_trial_group_column%60).%20%60win_stay_lose_switch_plot%60%20draws%20them%20in%0A%20%20%20%20the%20square%3A%20chance%20is%200.5%2C%20and%20the%20strategy%20is%20on%20the%20top%20right.%20The%0A%20%20%20%20third%20plot%20loads%20the%20trials%20of%20several%20mice%20to%20compare%20them.%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(MICE%2C%20PROJECT%2C%20day%2C%20load_project_trials%2C%20plt%2C%20root%2C%20trials)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.metrics.choices%20import%20add_trial_group_column%2C%20get_win_stay_lose_switch_df%0A%20%20%20%20from%20lecilab_behavior_analysis.plots%20import%20win_stay_lose_switch_plot%0A%0A%20%20%20%20_fig%2C%20(_by_session%2C%20_through_training%2C%20_by_mouse)%20%3D%20plt.subplots(1%2C%203%2C%20figsize%3D(15%2C%204))%0A%20%20%20%20%23%20a%20point%20per%20session%20of%20the%20day%0A%20%20%20%20win_stay_lose_switch_plot(get_win_stay_lose_switch_df(day%2C%20by%3D%22session%22)%2C%20hue%3D%22session%22%2C%20ax%3D_by_session)%0A%20%20%20%20%23%20through%20training%3A%2020%20groups%20of%20trials%2C%20from%20dark%20to%20yellow%0A%20%20%20%20_groups%20%3D%20get_win_stay_lose_switch_df(add_trial_group_column(trials%2C%20n_groups%3D20)%2C%20by%3D%22trial_group%22)%0A%20%20%20%20win_stay_lose_switch_plot(_groups%2C%20hue%3D%22trial_group%22%2C%20trajectory%3DTrue%2C%20ax%3D_through_training)%0A%20%20%20%20%23%20a%20point%20per%20mouse%0A%20%20%20%20_mice%20%3D%20load_project_trials(PROJECT%2C%20MICE%2C%20root%3Droot)%0A%20%20%20%20win_stay_lose_switch_plot(get_win_stay_lose_switch_df(_mice%2C%20by%3D%22subject%22)%2C%20hue%3D%22subject%22%2C%20ax%3D_by_mouse)%0A%20%20%20%20_fig.tight_layout()%0A%20%20%20%20_fig%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**The%20bias%20triangle%20works%20the%20same%20way.**%20%60get_bias_evolution_df%60%0A%20%20%20%20gives%2C%20for%20each%20group%2C%20how%20often%20the%20mouse%20alternated%0A%20%20%20%20(%60alternating_bias%60)%20and%20repeated%20to%20the%20right%20minus%20to%20the%20left%0A%20%20%20%20(%60left_right_bias%60)%3B%20%60bias_triangle_plot%60%20draws%20a%20point%20per%20group%0A%20%20%20%20(or%20a%20trajectory).%20A%20mouse%20that%20chooses%20at%20random%20is%20in%20the%20circle.%0A%0A%20%20%20%20**The%20cohort%2C%20as%20in%20the%20overview%20of%20the%20daily%20report.**%0A%20%20%20%20%60reports.overview%60%20has%20the%20cells%20of%20the%20overview%20tab%3A%20the%20strategies%0A%20%20%20%20of%20each%20mouse%20in%20the%20last%2048%20hours%2C%20the%20performance%20of%20the%20cohort%0A%20%20%20%20through%20the%20trials%20of%20each%20training%20stage%2C%20and%20when%20the%20box%20was%20used%2C%0A%20%20%20%20with%20who%20follows%20whom%20(an%20arrow%20from%20A%20to%20B%3A%20B%20started%20a%20session%20right%0A%20%20%20%20after%20A).%20Each%20mouse%20has%20the%20same%20colour%20in%20all%20of%20them.%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(MICE%2C%20PROJECT%2C%20load_project_trials%2C%20root)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.reports%20import%20overview%0A%0A%20%20%20%20cohort%20%3D%20load_project_trials(PROJECT%2C%20MICE%2C%20root%3Droot%2C%20window%3D50)%0A%20%20%20%20overview.strategies_figure(cohort%2C%20hours%3D48)%0A%20%20%20%20return%20cohort%2C%20overview%0A%0A%0A%40app.cell%0Adef%20_(cohort%2C%20overview)%3A%0A%20%20%20%20overview.stage_performance_figure(cohort%2C%20bin_size%3D100)%0A%0A%0A%40app.cell%0Adef%20_(cohort%2C%20overview)%3A%0A%20%20%20%20overview.box_occupancy_figure(cohort)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**The%20online%20plot.**%20While%20a%20mouse%20does%20the%20task%2C%20the%20village%20shows%0A%20%20%20%20%60plots.online.OnlineSessionFigure%60%2C%20updated%20after%20every%20trial%20with%20the%0A%20%20%20%20raw%20trials%20of%20the%20session%20so%20far.%20Here%20it%20is%20with%20one%20session%20of%20the%0A%20%20%20%20chosen%20day%2C%20as%20it%20looked%20at%20its%20last%20trial.%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(day)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.plots.online%20import%20OnlineSessionFigure%0A%0A%20%20%20%20_online%20%3D%20OnlineSessionFigure()%0A%20%20%20%20_online.update(day%5Bday%5B%22session%22%5D%20%3D%3D%20day%5B%22session%22%5D.iloc%5B0%5D%5D)%0A%20%20%20%20_online.fig%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%206.%20The%20settings%20of%20each%20session%0A%0A%20%20%20%20The%20village%20saves%20the%20settings%20of%20every%20session%20(training%20stage%2C%0A%20%20%20%20difficulties%2C%20punishment%2C%20reward...)%20in%20the%20%60settings%60%20column%20of%20the%0A%20%20%20%20%60sessions_summary.csv%60%20of%20each%20setup.%20%60io.settings.session_settings_table%60%0A%20%20%20%20makes%20a%20table%20with%20one%20row%20per%20session%3B%20%60changing_settings%60%20lists%20those%0A%20%20%20%20that%20changed%20at%20some%20point.%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(MOUSE%2C%20summary)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.io%20import%20settings%20as%20session_settings%0A%0A%20%20%20%20settings_table%20%3D%20session_settings.session_settings_table(summary%2C%20MOUSE)%0A%20%20%20%20changing%20%3D%20session_settings.changing_settings(settings_table)%0A%20%20%20%20settings_table%5B%5B%22date%22%2C%20%22task%22%5D%20%2B%20changing%5D%0A%20%20%20%20return%20changing%2C%20session_settings%2C%20settings_table%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20session_settings%2C%20settings_table)%3A%0A%20%20%20%20%23%20the%20settings%20of%20one%20session%2C%20the%20changes%20since%20the%20previous%20session%20first%0A%20%20%20%20_row%20%3D%203%0A%20%20%20%20_text%20%3D%20session_settings.format_session_settings(%0A%20%20%20%20%20%20%20%20session_settings.row_settings(settings_table.iloc%5B_row%5D)%2C%0A%20%20%20%20%20%20%20%20previous%3Dsession_settings.row_settings(settings_table.iloc%5B_row%20-%201%5D)%2C%0A%20%20%20%20%20%20%20%20title%3Df%22NUO003%2C%20session%20of%20%7Bsettings_table%5B'date'%5D.iloc%5B_row%5D%7D%22%2C%0A%20%20%20%20)%0A%20%20%20%20mo.md(f%22%60%60%60text%5Cn%7B_text%7D%5Cn%60%60%60%22)%0A%0A%0A%40app.cell%0Adef%20_(changing%2C%20mo)%3A%0A%20%20%20%20setting_picker%20%3D%20mo.ui.multiselect(%0A%20%20%20%20%20%20%20%20options%3Dchanging%2C%0A%20%20%20%20%20%20%20%20value%3D%5Bn%20for%20n%20in%20(%22current_training_stage%22%2C%20%22punishment%22%2C%20%22hard_trials_on%22)%20if%20n%20in%20changing%5D%2C%0A%20%20%20%20%20%20%20%20label%3D%22Settings%20to%20show%22%2C%0A%20%20%20%20)%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20**How%20the%20settings%20and%20the%20choices%20changed%2C%20session%20by%20session.**%0A%20%20%20%20%60metrics.choices.get_choices_by_difficulty_matrix%60%20gives%20the%20proportion%0A%20%20%20%20of%20left%20choices%20by%20correct%20side%20and%20difficulty%20in%20each%20session%20(a%0A%20%20%20%20psychometric%20curve%20per%20session)%3B%20%60plots.training_matrix_plot%60%20draws%20it%0A%20%20%20%20with%20the%20chosen%20settings%20as%20rows%20above%20it.%0A%0A%20%20%20%20%7Bsetting_picker%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(setting_picker%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20day_picker%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20session_settings%2C%0A%20%20%20%20setting_picker%2C%0A%20%20%20%20settings_table%2C%0A%20%20%20%20trials%2C%0A)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.metrics.choices%20import%20get_choices_by_difficulty_matrix%0A%20%20%20%20from%20lecilab_behavior_analysis.plots%20import%20training_matrix_plot%0A%0A%20%20%20%20p_left%2C%20n_trials%2C%20sessions%20%3D%20get_choices_by_difficulty_matrix(trials)%0A%20%20%20%20_rows%20%3D%20session_settings.settings_for_sessions(settings_table%2C%20p_left.columns%2C%20list(setting_picker.value))%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots(figsize%3D(10%2C%204.5))%0A%20%20%20%20training_matrix_plot(p_left%2C%20sessions%2C%20_rows%2C%20highlight_day%3Dday_picker.value%2C%20ax%3D_ax)%0A%20%20%20%20_fig%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%207.%20Your%20own%20figure%2C%20made%20of%20panels%0A%0A%20%20%20%20The%20ready-made%20figures%20are%20layouts%20of%20**panels**%3A%20small%20functions%20that%0A%20%20%20%20draw%20one%20plot%20from%20the%20prepared%20trials%20(%60data.df%60).%20A%20panel%20lists%20the%0A%20%20%20%20columns%20it%20needs%2C%20and%20raises%20%60NotApplicable%60%20when%20there%20is%20nothing%20to%0A%20%20%20%20show.%20%60render%60%20draws%20a%20layout%20and%20never%20stops%20because%20of%20one%20panel.%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(pd%2C%20trials)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.figures%20import%20FigureData%2C%20Layout%2C%20Row%2C%20panel%2C%20render%0A%20%20%20%20from%20lecilab_behavior_analysis.figures%20import%20panels%20as%20p%0A%0A%20%20%20%20%40panel(%22trials%20per%20day%22%2C%20needs%3D%7B%22year_month_day%22%7D)%0A%20%20%20%20def%20trials_per_day(data%2C%20ax)%3A%0A%20%20%20%20%20%20%20%20_counts%20%3D%20data.df.groupby(%22year_month_day%22).size()%0A%20%20%20%20%20%20%20%20ax.bar(pd.to_datetime(_counts.index)%2C%20_counts.values)%0A%20%20%20%20%20%20%20%20ax.set_ylabel(%22Trials%22)%0A%0A%20%20%20%20_layout%20%3D%20Layout(%0A%20%20%20%20%20%20%20%20%5BRow(%5B(p.subject_summary%2C%201)%2C%20(trials_per_day%2C%202)%5D)%2C%20Row(%5B(p.subject_performance%2C%201)%5D)%5D%2C%20width%3D12%2C%20height%3D6%0A%20%20%20%20)%0A%20%20%20%20own_figure%2C%20_%20%3D%20render(_layout%2C%20FigureData(trials%2C%20perf_window%3D100))%0A%20%20%20%20own_figure%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%208.%20Styles%0A%0A%20%20%20%20Every%20figure%20can%20be%20drawn%20in%20another%20style%3A%20%60%22report%22%60%20(the%20default)%2C%0A%20%20%20%20%60%22publication%22%60%20(only%20the%20data%2C%20colour-blind-safe%20colours%2C%20fonts%20for%20a%0A%20%20%20%20paper)%20or%20%60%22full%22%60%20(also%20the%20number%20of%20trials%20of%20each%20point%20and%20the%0A%20%20%20%20fitted%20parameters)%2C%20with%20any%20palette%20(%60%22default%22%60%2C%20%60%22colorblind%22%60%2C%0A%20%20%20%20%60%22grayscale%22%60).%20Each%20training%20stage%20has%20the%20colour%20of%20its%20modality.%0A%20%20%20%20%60set_style%60%20changes%20the%20style%20of%20everything%20after%20it.%0A%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20_(day%2C%20session_summary)%3A%0A%20%20%20%20from%20lecilab_behavior_analysis.style%20import%20get_style%0A%0A%20%20%20%20_figure%2C%20_%20%3D%20session_summary(day%2C%20perf_window%3D50%2C%20style%3Dget_style(%22full%22%2C%20palette%3D%22colorblind%22))%0A%20%20%20%20_figure%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20DOCS%20%3D%20%22https%3A%2F%2Flearningcircuitslab.github.io%2Flecilab-behavior-analysis%22%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%20Where%20next%0A%0A%20%20%20%20-%20The%20%5Bgallery%5D(%7BDOCS%7D%2Fgallery.html)%3A%20every%20plot%2C%20with%20its%20code.%0A%20%20%20%20-%20%5BStyles%5D(%7BDOCS%7D%2Fstyles.html)%3A%20the%20styles%20and%20palettes%2C%20and%20how%20to%20use%20them%20in%20your%20plots.%0A%20%20%20%20-%20The%20%5BAPI%5D(%7BDOCS%7D%2Fapi_index.html)%3A%20every%20function%2C%20by%20topic%0A%20%20%20%20%20%20(%60io%60%2C%20%60preprocessing%60%2C%20%60metrics%60%2C%20%60models%60%2C%20%60plots%60%2C%20%60figures%60%2C%20%60reports%60).%0A%20%20%20%20-%20%60data_format_changes.py%60%3A%20how%20old%20and%20new%20data%20formats%20are%20read.%0A%20%20%20%20%22%22%22)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
8bc2598cc92abca07e292ec9b845562a