API#
data#
Reading the data of the Training Village projects for the dashboard.
A data folder has one folder per project, with the trials of each subject in <project>/sessions/<subject>/<subject>.csv (or .csv.gz), the logs of each setup in <project>/<setup>/ and the videos in <project>/videos/<subject>/. It is read with lecilab_behavior_analysis, as the daily reports (village-report-generator) do.
There can be several data folders (e.g. /storage and /archive on the cluster, with the same structure): see get_data_locations. The functions take the folder of the project (root); without it, the first data folder.
The trials of the last subjects opened are kept in memory, shared by everyone using the dashboard (up to CACHE_GB, see cache.py), and read again when their file changes.
- behavior_data_visualizer.data.clear_cache()[source]#
Forgets the data in memory (it is read again when needed).
- Return type:
None
- behavior_data_visualizer.data.day_trials(df, day)[source]#
Trials of one day (YYYY-MM-DD).
- Return type:
DataFrame
- behavior_data_visualizer.data.get_data_locations()[source]#
The data folders, in order, without repeats: the folders of BDV_DATA_PATHS if it is set, otherwise the one of lecilab_behavior_analysis and then FALLBACK_DATA_PATHS. Only those that exist.
- Return type:
List[Path]
- behavior_data_visualizer.data.get_data_path()[source]#
The first data folder, or None if there is none.
- Return type:
Path|None
- behavior_data_visualizer.data.get_list_of_projects(root=None)[source]#
Projects of a data folder: its folders with a sessions folder.
- Return type:
List[str]
- behavior_data_visualizer.data.is_data_location(root)[source]#
Whether root is one of the data folders (only those are read and served).
- Return type:
bool
- behavior_data_visualizer.data.load_events(project_name, root=None)[source]#
Events of every setup of a project (None if there are none). Do not modify it.
- Return type:
DataFrame|None
- behavior_data_visualizer.data.load_mouse_data(project_name, mouse_name, root=None)[source]#
Trials of a subject, prepared for analysis (preprocessing.prepare, with year_month_day, total_trial…), and its performance through trials (performance_w). Empty if there are none. Do not modify it: it is shared by every callback (copy it first).
- Return type:
DataFrame
- behavior_data_visualizer.data.load_session_settings(project_name, mouse_name, root=None)[source]#
The settings of every session of a mouse: one row per session (date, subject, task and one column per setting), read from the sessions summaries of the project (lecilab_behavior_analysis.io.settings). Empty if there are none. Do not modify it.
- Return type:
DataFrame
- behavior_data_visualizer.data.seconds_of_trial(df, session_date, trial_number)[source]#
Seconds from the start of the first trial of a session to the start of one of its trials.
- Return type:
float|None
- behavior_data_visualizer.data.summary_files(project_name, root=None)[source]#
The sessions_summary.csv of every setup of a project (lecilab_behavior_analysis.io.loading.find_setups).
- Return type:
List[Path]
- behavior_data_visualizer.data.trials_file(project_name, mouse_name, root=None)[source]#
<subject>.csv of a subject, or <subject>.csv.gz if there is no .csv.
- Return type:
Path|None
- behavior_data_visualizer.data.trials_per_day(df)[source]#
Number of trials of each day (index: YYYY-MM-DD).
- Return type:
Series
- behavior_data_visualizer.data.trials_up_to(df, day)[source]#
Trials up to the end of a day (YYYY-MM-DD).
- Return type:
DataFrame
- behavior_data_visualizer.data.video_folder(project_name, mouse_name, root=None)[source]#
Folder with the videos of a mouse (<project>/videos/<mouse>), or None if the folder is not a data folder, or the project or the mouse is not one of it (so that only videos of the data folders can be sent).
- Return type:
Path|None
figures#
Interactive (plotly) figures of the dashboard, and the figures of the daily report (matplotlib, from lecilab_behavior_analysis) as images.
- behavior_data_visualizer.figures.calendar_figure(trials_per_day, selected=None)[source]#
Days with trials, one column per week (Monday to Sunday from top to bottom), coloured by the number of trials. Clicking a day gives its date (YYYY-MM-DD) in clickData[“points”][0][“customdata”]. The selected day is framed in red.
- Return type:
Figure
- behavior_data_visualizer.figures.logistic_curve(trials)[source]#
Lapse logistic fitted to the trials: (x, P(left)) on 100 points, or None.
- Return type:
Tuple[ndarray,ndarray] |None
- behavior_data_visualizer.figures.matplotlib_to_uri(fig)[source]#
A matplotlib figure as a PNG data URI (for an html.Img), closing the figure.
- Return type:
str
- behavior_data_visualizer.figures.performance_figure(day_df, window=50)[source]#
Performance of a day through its trials (rolling window), coloured by modality, with a dashed line at each new session. Clicking a point gives (subject, task, session date, trial) in its customdata (to open the video).
- Return type:
Figure
- behavior_data_visualizer.figures.psychometric_figure(day_df, title=None)[source]#
One psychometric plot per modality of the trials (two in multisensory sessions). title: shown above (e.g. the trials used).
- Return type:
Figure
- behavior_data_visualizer.figures.psychometric_points(trials)[source]#
Proportion of left choices (p_left) and number of trials (n) at each x.
- Return type:
DataFrame
- behavior_data_visualizer.figures.psychometric_trials(df, modality)[source]#
Choices on the trials of one modality, as in the daily report (see lecilab_behavior_analysis.figures.panels.psychometric):
visual: by brightness ratio (+ left brighter),
auditory-cot: by evidence strength (6 bins),
auditory-local-wn: by sound level (+ left), 3 bins per side,
otherwise, or with only easy trials: by side and difficulty.
Returns (one row per trial, with x (the mean of its bin when binned) and choice (1 left, 0 right); x axis title; whether a logistic curve can be fitted). The trials are those of the modality that are not habituation and have a first choice.
- Return type:
Tuple[DataFrame,str,bool]
- behavior_data_visualizer.figures.report_problems(fig)[source]#
Panels of a report figure that could not be drawn.
- Return type:
List[str]
- behavior_data_visualizer.figures.training_matrix_figure(trials, settings_table=None, setting_names=None, selected_day=None)[source]#
How the choices and the settings changed through training, session by session: the proportion of left choices by correct side and difficulty (lecilab_behavior_analysis.metrics.choices.get_choices_by_difficulty_matrix) and, above it, a row per setting in setting_names (from settings_table, lecilab_behavior_analysis.io.settings), coloured by its value. The sessions of selected_day (YYYY-MM-DD) are framed. Clicking a cell gives the date of its session in its customdata.
- Return type:
Figure
- behavior_data_visualizer.figures.trial_by_trial_figure(day_df, window=20)[source]#
What happened on each trial of a day, as a barcode (one tick per trial):
stimulus left / right: the correct side, coloured by modality (darker for easier trials),
outcome: correct, incorrect or miss,
early pokeout: trials where the mouse left the center port too early.
Above, the performance and the early pokeouts (% of the last window trials). Dashed lines mark new sessions. Clicking a trial gives (subject, task, session date, trial) in its customdata (to open the video).
- Return type:
Figure
- behavior_data_visualizer.figures.trials_in_view(day_df, zoom)[source]#
Trials of the day whose total_trial is in the zoom range (all of them without zoom).
- Return type:
DataFrame
- behavior_data_visualizer.figures.zoom_range(relayout)[source]#
The trials shown after a zoom on a figure whose x axis is the trial (relayoutData of a dcc.Graph): (first, last), ZOOM_RESET when it goes back to all the trials (double click, autoscale), or None if the x axis did not change (e.g. only the size of the figure).
main#
Training Village Behavior Explorer: a dash app to look at the behavior of the mice of a project, day by day.
Choose a project and a mouse; the calendar shows its days with trials. Click a day to see its summary, its performance, its psychometric curves (one per stimulus modality) and what happened on each trial (stimulus, outcome, early pokeouts). Click a trial in the performance or in the trial-by-trial figure to watch the video from that trial. Zoom on some trials in either figure to see the same trials in the other one, and the psychometric curves of those trials only. The buttons draw the figures of the daily report: the session summary of the day and the training history up to it.
Run it with: behavior-explorer (or python behavior_data_visualizer/main.py), then open http://127.0.0.1:8050. One dashboard can be used by several people at the same time; http://127.0.0.1:8050/status shows its version and the data in memory. See behavior-explorer –help for the options. The data is read from the folder of lecilab_behavior_analysis (the LECILAB_DATA_PATH environment variable, or the folder of this computer).
- behavior_data_visualizer.main.chosen_project(trigger, values, locations)[source]#
The project chosen in the dropdown of one data folder ({“root”, “project”}, None if it was cleared) and the new values of every dropdown (the others cleared, so that only one project is selected).
- Return type:
tuple
- behavior_data_visualizer.main.code_version()[source]#
Commit of the code that is running (or the package version if it is not a git clone).
- Return type:
str
- behavior_data_visualizer.main.day_settings_text(table, mouse, day)[source]#
The settings of each session of a day, the changes since the previous session first.
- behavior_data_visualizer.main.day_text(day_df, mouse, day)[source]#
Summary of the trials of a day (as in the daily report).
- Return type:
str
- behavior_data_visualizer.main.location_name(location, locations)[source]#
The top folder of a data folder (“/storage” for /storage/training_village), or its full path if another data folder is under the same top folder.
- Return type:
str
- behavior_data_visualizer.main.main(argv=None)[source]#
Starts the dashboard (the behavior-explorer command).
- Return type:
None
- behavior_data_visualizer.main.mouse_of(loaded)[source]#
(project, mouse, data folder) of the selected mouse, for the functions of data.py.
- Return type:
tuple
- behavior_data_visualizer.main.port_is_free(host, port)[source]#
Whether nothing is listening on the port (as waitress checks it: free right after a restart).
- Return type:
bool
- behavior_data_visualizer.main.project_pickers(locations)[source]#
A project dropdown per data folder, titled with its top folder (its full path when hovering).
- Return type:
list
- behavior_data_visualizer.main.read_session_settings(loaded)[source]#
The settings of the sessions of the mouse (data.load_session_settings) and, if they could not be read, why (otherwise None). The rest of the dashboard keeps working without them.
- Return type:
tuple
- behavior_data_visualizer.main.report_image(title, figure_name, df, **kwargs)[source]#
A figure of the daily report (lecilab_behavior_analysis.figure_maker) as an image.
- behavior_data_visualizer.main.settings_options(table)[source]#
Options of the settings dropdown (those that change first, marked) and the ones shown by default.
- Return type:
tuple
- behavior_data_visualizer.main.status_text()[source]#
What is running: to check that a dashboard has the latest code and how much memory it uses.
- Return type:
str
- behavior_data_visualizer.main.triggered_id()[source]#
The id of the component that triggered the callback (None outside a callback).