Data Analysis¶
Functions for analyzing behavioral data and calculating performance metrics.
Data analysis functions for Ethopy experiments.
This module provides functions to analyze behavioral data, calculate performance metrics, and generate session summaries.
get_performance(animal_id, session, trials=None)
¶
Calculate performance as the ratio of reward trials to total decisive trials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
Animal identifier |
required |
session
|
int
|
Session identifier |
required |
trials
|
Optional[List[int]]
|
List of trial indices to filter by. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[float]
|
Optional[float]: Performance ratio (0-1), or None if no decisive trials found |
Note
Decisive trials are those with state 'Reward' or 'Punish'. Performance is calculated as: count_reward_trials / (count_reward_trials + count_punish_trials)
Source code in src/ethopy_analysis/data/analysis.py
get_port_exit_to_lick_latency(animal_id, session, state='Trial', port=3)
¶
Calculate the time from leaving a proximity sensor to the first lick.
Measures how quickly the animal responds (licks) after moving away from
the center port, combining data from
:func:~ethopy_analysis.data.loaders.get_first_port_exit_after_state and
:func:~ethopy_analysis.data.loaders.get_first_lick_after_state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier. |
required |
session
|
int
|
The session number. |
required |
state
|
str
|
State used as the reference for both off-position
and first-lick searches. Defaults to |
'Trial'
|
port
|
int
|
Proximity port monitored for the off-position
event. Defaults to |
3
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: One row per trial that has both an off-position event and
a subsequent lick. Columns: |
Source code in src/ethopy_analysis/data/analysis.py
session_summary(animal_id, session)
¶
Print a comprehensive summary of a session including metadata and performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier |
required |
session
|
int
|
The session number |
required |
Prints
- Animal ID and session number
- User name and setup information
- Session start time and duration
- Experiment, stimulus, and behavior classes
- Task filename and the code version records for the session
- Session performance and number of trials
Source code in src/ethopy_analysis/data/analysis.py
trials_per_session(animal_id, min_trials=2, format='df')
¶
Returns the number of trials per session
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier |
required |
min_trials
|
int
|
Minimum number of trials to include session. Defaults to 2. |
2
|
format
|
str
|
Return format, either "df" for DataFrame or "dj" for DataJoint expression. Defaults to "df". |
'df'
|
Returns:
| Type | Description |
|---|---|
|
Union[pd.DataFrame, Any]: DataFrame with trials_count column if format="df", DataJoint expression if format="dj" |
Source code in src/ethopy_analysis/data/analysis.py
weight_check(animal_id, count_from=5, weight_days=8, weight_percentage=0.7, weight_df=None)
¶
Check the weight of an animal against its water deprivation reference weight.
Prints a warning if the last weight is below weight_percentage of the
reference weight, or if the animal has not been weighted for more than
weight_days days.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier |
required |
count_from
|
int
|
Index of the weight measurement used as the reference weight, counted from the first one, after sorting by timestamp. Adjust it to the start of water deprivation. Defaults to 5. |
5
|
weight_days
|
int
|
Maximum accepted number of days since the last weighting. Defaults to 8. |
8
|
weight_percentage
|
float
|
Minimum accepted fraction of the reference weight. Defaults to 0.7. |
0.7
|
weight_df
|
DataFrame
|
Weight measurements as returned by get_mouse_weight. Fetched from the database if None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
reference_weight, last_weight, percentage, days_since_last, below_threshold and overdue |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the animal has no weight measurements or fewer than count_from + 1 of them. |