Animal-Level Plots¶
Functions for creating visualizations that analyze animal behavior across multiple sessions.
find_uniq_pos(arr)
¶
Find unique values and their starting positions in a list.
Helper function that identifies unique consecutive values in a list and returns both the unique values and their starting positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
List
|
Input list to analyze for unique consecutive values. |
required |
Returns:
| Type | Description |
|---|---|
List
|
A tuple containing: |
List[int]
|
|
Tuple[List, List[int]]
|
|
Source code in src/ethopy_analysis/plots/animal.py
plot_animal_weight(weight_df, animal_id=None, count_from=5, thresholds=(0.7, 0.8, 0.9), save_path=None)
¶
Plot the weight of an animal over time with water deprivation limits.
Creates a line plot of every weight measurement, with a horizontal line for each fraction of the reference weight, so weight loss can be tracked against the humane endpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight_df
|
DataFrame
|
DataFrame of weight measurements with columns: - 'timestamp': Time of the measurement - 'weight': Weight in grams - 'animal_id': Animal identifier (used if animal_id is None) |
required |
animal_id
|
Optional[int]
|
The animal identifier, used for the title. Taken from the DataFrame if None. |
None
|
count_from
|
int
|
Index of the measurement used as the reference weight, counted from the first one. Adjust it to the start of water deprivation. Defaults to 5. |
5
|
thresholds
|
Tuple[float, ...]
|
Fractions of the reference weight to draw as limit lines. Defaults to (0.7, 0.8, 0.9). |
(0.7, 0.8, 0.9)
|
save_path
|
Optional[str]
|
Path to save the plot image. If None, plot is not saved. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Figure, Axes]
|
Tuple of the figure and axes of the plot. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the DataFrame is empty or has fewer than count_from + 1 measurements. |
Source code in src/ethopy_analysis/plots/animal.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
plot_performance_liquid(animal_id, animal_sessions, xaxis='session', save_path=None)
¶
Plot performance vs liquid reward consumption over sessions.
Creates a dual-axis plot showing both behavioral performance and liquid reward consumption across sessions. This helps identify relationships between motivation (liquid consumption) and task performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier to analyze. |
required |
animal_sessions
|
DataFrame
|
DataFrame containing session information with columns: - 'session': Session identifiers - 'session_tmst': Session timestamps (required if xaxis='date') |
required |
xaxis
|
str
|
X-axis format, either 'session' for session IDs or 'date' for timestamps. Defaults to 'session'. |
'session'
|
save_path
|
Optional[str]
|
Path to save the plot image. If None, plot is not saved. |
None
|
Source code in src/ethopy_analysis/plots/animal.py
plot_session_date(animal_id, min_trials=0, save_path=None)
¶
Plot sessions per date to visualize training schedule.
Creates a bar chart showing the number of sessions conducted on each date for a specific animal. This helps visualize training consistency and patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier to analyze. |
required |
min_trials
|
int
|
Minimum number of trials required per session to include in analysis. Sessions with fewer trials will be excluded. Defaults to 0. |
0
|
save_path
|
Optional[str]
|
Path to save the plot image. If None, plot is not saved. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[date, List[int]]
|
Dictionary mapping each date to a list of session IDs conducted on that date. |
Source code in src/ethopy_analysis/plots/animal.py
plot_session_performance(animal_id, sessions, perf_func, save_path=None)
¶
Plot session performance over time with protocol visualization.
Creates a line plot showing performance across sessions, with colored background regions indicating different experimental protocols. This helps visualize how performance changes over time and across different task conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier to analyze. |
required |
sessions
|
List[int]
|
List of session IDs to include in the analysis. |
required |
perf_func
|
callable
|
Function that calculates performance for a given animal_id and session. Should have signature: perf_func(animal_id: int, session: int) -> float |
required |
save_path
|
Optional[str]
|
Path to save the plot image. If None, plot is not saved. |
None
|
Returns:
| Type | Description |
|---|---|
List[float]
|
List of performance values for each session, in the same order as input sessions. |
Source code in src/ethopy_analysis/plots/animal.py
plot_trial_per_session(animal_id, min_trials=2, save_path=None)
¶
Plot the distribution of trials per session.
Creates a bar chart showing the number of trials completed in each session for a specific animal. This helps assess session length consistency and identify potential issues with session termination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animal_id
|
int
|
The animal identifier to analyze. |
required |
min_trials
|
int
|
Minimum number of trials required per session to include in analysis. Sessions with fewer trials will be excluded. Defaults to 2. |
2
|
save_path
|
Optional[str]
|
Path to save the plot image. If None, plot is not saved. |
None
|