Session-Level Plots¶
Functions for creating detailed visualizations of individual behavioral sessions.
LickPlot(animal_id, session, conds_split=['response_port'], state_start='PreTrial', stim_table=None, color_rew_pun=False, difficulty=None, period=None, save_path=None, **kwargs)
¶
Generate lick plots for animal behavior analysis.
Creates subplot grids showing lick patterns across different conditions, with customizable filtering by difficulty, period, and response port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal. |
required |
session
|
int
|
Session number or identifier. |
required |
conds_split
|
List[str]
|
Conditions to split data by. Defaults to ["response_port"]. |
['response_port']
|
state_start
|
str
|
Starting state for analysis. Defaults to "PreTrial". |
'PreTrial'
|
stim_table
|
DataJoint table
|
Stimulus table to use. Defaults to None. |
None
|
color_rew_pun
|
bool
|
Whether to color by reward/punishment. Defaults to False. |
False
|
difficulty
|
int
|
Specific difficulty level to filter. Defaults to None. |
None
|
period
|
str
|
Specific period to filter. Defaults to None. |
None
|
**kwargs
|
Additional parameters for plot customization. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Tuple |
Tuple[Any, Any]
|
(selected_trials, condition) data for further analysis |
Example
data, cond = LickPlot(123, 1, difficulty=2, period="sample")
Source code in src/ethopy_analysis/plots/session.py
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 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
|
calculate_proximity_duration(animal_id, session, ports=None)
¶
Calculate duration of proximity sensor activations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
ports
|
Optional[List]
|
Optional list of ports to analyze |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with proximity duration data |
Source code in src/ethopy_analysis/plots/session.py
difficultyPlot(animal_id, session, save_path=None, params=None)
¶
Create a comprehensive difficulty plot for an animal session.
Generates a visualization showing trial outcomes (reward, punish, abort) across different difficulty levels over time. The plot includes color-coded markers for different response ports and trial states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal. |
required |
session
|
int
|
Session number or identifier. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
Function creates and displays a matplotlib plot |
Example
difficultyPlot(123, 1)
Source code in src/ethopy_analysis/plots/session.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
find_diff_trials(key_animal_session, diff)
¶
Find trials with specific difficulty level for a given animal session.
This function identifies trials that match a specific difficulty level for either MatchToSample or MatchPort experiment types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_animal_session
|
dict
|
Dictionary containing animal_id and session keys |
required |
diff
|
int
|
Difficulty level to filter trials |
required |
Returns:
Type | Description |
---|---|
Any
|
DataJoint query object: Trials matching the specified difficulty level |
Raises:
Type | Description |
---|---|
ValueError
|
If experiment class is not MatchToSample or MatchPort |
Example
key = {'animal_id': 123, 'session': 1} trials = find_diff_trials(key, difficulty=2)
Source code in src/ethopy_analysis/plots/session.py
find_ready_times_state(states_check_tr, proximities)
¶
Find ready times based on proximity sensor data during specific states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states_check_tr
|
DataFrame
|
DataFrame with state information including start_time and stop_time |
required |
proximities
|
DataFrame
|
DataFrame with proximity sensor data |
required |
Returns:
Type | Description |
---|---|
List[float]
|
List of ready time durations |
Source code in src/ethopy_analysis/plots/session.py
get_state_times(animal_id, session)
¶
Get state timing information for an animal session.
Retrieves trial states and calculates start and stop times for each state by using the next state's start time as the current state's stop time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: DataFrame with columns: - 'start_time': Start time of each state - 'stop_time': Stop time of each state (next state's start time) - Other columns from trial states data |
Example
state_times = get_state_times(123, 1) print(state_times[['state', 'start_time', 'stop_time']])
Source code in src/ethopy_analysis/plots/session.py
group_column_times(df, start_times, stop_times, time_id=None, column='port')
¶
Group events by time periods and specified column values.
Processes time-series data by grouping events within specified time periods and counting occurrences by a specified column (e.g., port number).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame containing time-series data with 'time' column |
required |
start_times
|
array - like
|
Start times for each period to analyze |
required |
stop_times
|
array - like
|
Stop times for each period to analyze |
required |
time_id
|
array - like
|
Custom IDs for each time period. Defaults to None (uses period index). |
None
|
column
|
str
|
Column name to group by. Defaults to "port". |
'port'
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: DataFrame with columns: - 'id': Period identifier - column: Values from the specified grouping column - 'event_count': Number of events in this period/column combination - 'timings': List of actual event times |
Example
start_times = [0, 1000, 2000] stop_times = [500, 1500, 2500] result = group_column_times(lick_data, start_times, stop_times)
Source code in src/ethopy_analysis/plots/session.py
liquidsPlot(animal_id, days=15, save_path=None)
¶
plot liquid delivered per day
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
|
required |
days
|
int
|
how many days before to plot. Defaults to 15. |
15
|
Source code in src/ethopy_analysis/plots/session.py
perf_difficulty(animal_id, session)
¶
Calculate performance across different difficulty levels for an animal session.
This function retrieves trial experiment conditions and states for a given animal and session, then calculates the performance for each unique difficulty level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal. |
required |
session
|
int
|
Session number or identifier. |
required |
Returns:
Type | Description |
---|---|
Tuple[List, List]
|
Tuple[List, List]: A tuple containing: - uniq_diffs (List): List of unique difficulty levels - diffs_perf (List[float]): List of performance values for each difficulty |
Example
difficulties, performances = perf_difficulty(123, 1) print(f"Difficulty levels: {difficulties}") print(f"Performances: {performances}")
Source code in src/ethopy_analysis/plots/session.py
plot_first_lick_after(animal_id, session, state='Response', sub_state='', save_path=None, **kwargs)
¶
Plot histogram of first lick times after a specific state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
state
|
str
|
State after which to measure first lick times |
'Response'
|
sub_state
|
str
|
Optional sub-state filter |
''
|
**kwargs
|
Additional arguments passed to plt.hist() |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing first lick data |
Source code in src/ethopy_analysis/plots/session.py
plot_licks_state(animal_id, session, check_state='InterTrial', state_select='Reward', save_path=None, **kwargs)
¶
Analyze licking behavior at specific states for selected trial types. Creates a histogram showing lick counts per port during a specified state, filtered to include only trials of a specific outcome type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
check_state
|
str
|
State to analyze licks during |
'InterTrial'
|
state_select
|
str
|
Trial type to include (e.g., "Reward", "Punish") |
'Reward'
|
**kwargs
|
Additional arguments passed to plt.hist() |
{}
|
Source code in src/ethopy_analysis/plots/session.py
plot_licks_time(animal_id, session, bins=50, save_path=None)
¶
Plot lick counts over time by port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
bins
|
int
|
Number of time bins |
50
|
Source code in src/ethopy_analysis/plots/session.py
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 |
|
plot_proximities_dur(animal_id, session, ports=[], save_path=None, **kwargs)
¶
Plot histogram of proximity durations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
ports
|
List[int]
|
List of port IDs to plot. If empty, plots all ports |
[]
|
**kwargs
|
Additional arguments passed to plt.hist() |
{}
|
Source code in src/ethopy_analysis/plots/session.py
plot_states_in_time(animal_id, session, seconds=30, save_path=None)
¶
Plot trial states over time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
seconds
|
int
|
Time bin size in seconds |
30
|
Source code in src/ethopy_analysis/plots/session.py
plot_trial_time(animal_id, session, trials, display_tables=True, port=3, save_path=None)
¶
Plot timeline of trial events including states, licks, and proximity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
trials
|
List[int]
|
List of trial indices to plot |
required |
display_tables
|
bool
|
Whether to print data tables |
True
|
port
|
int
|
Port number for proximity data |
3
|
Returns:
Type | Description |
---|---|
Tuple[DataFrame, DataFrame, Any]
|
Tuple of (trial_states, trial_licks, trial_prox) DataFrames |
Source code in src/ethopy_analysis/plots/session.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
|
plot_trials(trial_df, params, **kwargs)
¶
Plot trial data with difficulty levels and visual offset.
Creates a scatter plot of trials showing difficulty levels with a visual offset to prevent overlapping points. The offset is calculated based on trial bins to create a staggered appearance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trial_df
|
DataFrame
|
DataFrame containing trial data with columns: - 'difficulty': Difficulty levels for each trial - 'trial_idx': Trial indices |
required |
params
|
dict
|
Parameters dictionary containing: - 'trial_bins': Number of trial bins for offset calculation - 'range': Range multiplier for offset calculation |
required |
**kwargs
|
Additional keyword arguments passed to plt.scatter |
{}
|
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
Function creates a matplotlib scatter plot |
Example
params = {'trial_bins': 10, 'range': 0.9} plot_trials(trial_df, params, s=10, c='red')
Source code in src/ethopy_analysis/plots/session.py
plot_valid_proximity_state(animal_id, session, state='Trial', save_path=None)
¶
Plot histogram of valid proximity durations for a specific state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
state
|
str
|
State to analyze proximity for |
'Trial'
|
Source code in src/ethopy_analysis/plots/session.py
roll_time(timestamps, binaries, seconds_offset=60)
¶
Group binary events into time bins.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamps
|
ndarray
|
Array of timestamps |
required |
binaries
|
ndarray
|
Array of binary values |
required |
seconds_offset
|
int
|
Bin size in seconds |
60
|
Returns:
Type | Description |
---|---|
Series
|
Series with summed binary values per time bin |
Source code in src/ethopy_analysis/plots/session.py
select_trials(df, state)
¶
Filter trials based on their state.
Filters a DataFrame to include only trials that match a specific state. If an empty string is provided, returns all trials.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame containing trial data with 'state' and 'trial_idx' columns |
required |
state
|
str
|
State to filter by (e.g., 'Reward', 'Punish'). Empty string returns all trials. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Filtered DataFrame containing only trials with matching state |
Example
reward_trials = select_trials(trials_df, 'Reward') all_trials = select_trials(trials_df, '')
Source code in src/ethopy_analysis/plots/session.py
valid_ready_state(animal_id, session, state='PreTrial')
¶
Calculate valid ready times for a specific state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animal_id
|
int
|
Unique identifier for the animal |
required |
session
|
int
|
Session number or identifier |
required |
state
|
str
|
State to analyze ready times for |
'PreTrial'
|
Returns:
Type | Description |
---|---|
Series
|
Series with ready times grouped by trial |