Core Behavior module¶
Core behavior module handles behavioral variables, responses, and reward management.
This module provides the core functionality for managing animal behavior in experimental setups, including response tracking, reward delivery, and behavioral data logging. It interfaces with hardware components and maintains experiment state.
Activity
¶
Bases: Manual
DataJoint table for tracking behavioral responses.
Source code in src/ethopy/core/behavior.py
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 |
|
Lick
¶
Bases: Part
DataJoint table for licking.
Source code in src/ethopy/core/behavior.py
433 434 435 436 437 438 439 440 441 |
|
Position
¶
Bases: Part
DataJoint table for 2D possition timestamps.
Source code in src/ethopy/core/behavior.py
454 455 456 457 458 459 460 461 462 463 464 |
|
Proximity
¶
Bases: Part
DataJoint table for tracking proximity port information.
Source code in src/ethopy/core/behavior.py
421 422 423 424 425 426 427 428 429 430 431 |
|
Touch
¶
Bases: Part
DataJoint table for touch timestamps.
Source code in src/ethopy/core/behavior.py
443 444 445 446 447 448 449 450 451 452 |
|
BehActivity
dataclass
¶
Dataclass for tracking behavioral activity.
Attributes:
Name | Type | Description |
---|---|---|
port |
int
|
Port number where activity occurred |
type |
str
|
Type of activity (e.g., 'Lick', 'Touch') |
time |
int
|
Timestamp of activity |
in_position |
int
|
Position status |
loc_x |
int
|
X coordinate of activity |
loc_y |
int
|
Y coordinate of activity |
theta |
int
|
Angular position |
ready |
bool
|
Ready status |
reward |
bool
|
Whether activity was rewarded |
response |
bool
|
Whether activity was a valid response |
Source code in src/ethopy/core/behavior.py
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 |
|
__init__(**kwargs)
¶
Initialize the behavior object with the provided keyword arguments.
Source code in src/ethopy/core/behavior.py
390 391 392 393 394 395 |
|
BehCondition
¶
Bases: Manual
Datajoint table with a hash defining all the conditions.
Source code in src/ethopy/core/behavior.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
|
Trial
¶
Bases: Part
Datajoint table for keeping the hash for each trial.
Source code in src/ethopy/core/behavior.py
476 477 478 479 480 481 482 483 484 |
|
Behavior
¶
Manages behavioral variables and interactions in experimental setups.
This class handles all aspects of behavioral monitoring and control: - Response tracking and validation - Reward delivery and management - Behavioral data logging through logger module - Condition management and history tracking - Interface with hardware components through experiment module
Attributes:
Name | Type | Description |
---|---|---|
interface |
List[Any]
|
List of interface objects |
required_fields |
List[str]
|
Required fields for condition validation |
curr_cond |
List[Dict]
|
Current condition parameters |
response |
List[Any]
|
Current response data |
licked_port |
int
|
ID of the most recently licked port |
logging |
bool
|
Whether logging is enabled |
reward_amount |
Dict[int, float]
|
Reward amounts by port |
choice_history |
List[float]
|
History of animal choices |
reward_history |
List[float]
|
History of rewards given |
Source code in src/ethopy/core/behavior.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 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 351 352 353 354 355 356 357 358 |
|
__init__()
¶
Initialize the behavior class with default values.
Attributes:
Name | Type | Description |
---|---|---|
cond_tables |
List[str]
|
A list of condition table names. |
default_key |
Dict[str, Any]
|
A dictionary for default key-value pairs. |
interface |
Any
|
The interface object (initially None). |
required_fields |
List[str]
|
A list of required field names. |
curr_cond |
List[Dict[str, Any]]
|
A list of current trial conditions. |
response |
List[Any]
|
A list for storing responses. |
licked_port |
int
|
The port is that was licked. |
logging |
bool
|
A flag indicating if logging is enabled. |
reward_amount |
Dict[int, float]
|
A dictionary mapping port numbers to reward amounts. |
choice_history |
List[float]
|
A list of choice history values. |
reward_history |
List[float]
|
A list of reward history values. |
punish_history |
List[float]
|
A list of punishment history values. |
choices |
ndarray
|
An array of choices. |
response_queue |
Queue
|
A queue for storing responses with a maximum size of 4. |
last_lick |
Queue
|
The last lick event (initially None). |
params |
Queue
|
Parameters for the experiment (initially None). |
exp |
Queue
|
The experiment object (initially None). |
logger |
Queue
|
The logger object (initially None). |
Source code in src/ethopy/core/behavior.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
exit()
¶
Clean up and exit the behavior module.
Source code in src/ethopy/core/behavior.py
184 185 186 |
|
get_false_history(h=10)
¶
Get history of false responses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h
|
int
|
Number of trials to look back |
10
|
Returns:
Type | Description |
---|---|
float
|
Cumulative product of false responses |
Source code in src/ethopy/core/behavior.py
306 307 308 309 310 311 312 313 314 315 316 317 |
|
get_response(since=0, clear=True)
¶
Check for valid behavioral responses since a given time point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
since
|
int
|
Time reference point in milliseconds |
0
|
clear
|
bool
|
Whether to clear existing responses before checking |
True
|
Returns:
Type | Description |
---|---|
bool
|
Whether a valid response was detected |
Source code in src/ethopy/core/behavior.py
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 |
|
is_hydrated(rew=None)
¶
Check if animal has received enough reward.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rew
|
Optional[float]
|
Optional override for maximum reward amount |
None
|
Returns:
Type | Description |
---|---|
bool
|
Whether maximum reward threshold has been reached |
Source code in src/ethopy/core/behavior.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
is_licking(since=0, reward=False, clear=True)
¶
Check for licking activity since a given time point.
This method can be used in two ways: 1. To detect any licking activity since the given time 2. To check for rewarded licking (when reward=True) where only licks at reward ports count
Parameters:
Name | Type | Description | Default |
---|---|---|---|
since
|
int
|
Time reference point in milliseconds. Defaults to 0. |
0
|
reward
|
bool
|
Whether to only count licks at reward ports. Defaults to False. |
False
|
clear
|
bool
|
Whether to reset last_lick after checking. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
int
|
Port number of valid lick (0 if no valid lick detected) |
Source code in src/ethopy/core/behavior.py
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 |
|
is_ready(duration, since=0)
¶
Check if has been in position for a duration.
Source code in src/ethopy/core/behavior.py
109 110 111 |
|
is_sleep_time()
¶
Check if current time is within sleep period.
Returns:
Type | Description |
---|---|
bool
|
Whether current time is in sleep period |
Source code in src/ethopy/core/behavior.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
log_activity(activity_key)
¶
Log behavioral activity to the database.
Updates last_lick and licked_port variables, manages response queue, and logs the activity in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity_key
|
dict
|
Dictionary containing activity parameters |
required |
Returns:
Type | Description |
---|---|
int
|
Timestamp of the logged activity in milliseconds |
Source code in src/ethopy/core/behavior.py
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 |
|
log_reward(reward_amount)
¶
Log delivered reward to the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reward_amount
|
float
|
Amount of reward delivered |
required |
Source code in src/ethopy/core/behavior.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
make_conditions(conditions)
¶
Validate, update with default_key and generate hash for stimulus conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
List[Dict[str, Any]]
|
List of condition dictionaries |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dictionary containing processed conditions and metadata |
Source code in src/ethopy/core/behavior.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
prepare(condition)
¶
Prepare for a new trial with given conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition
|
Dict[str, Any]
|
Dictionary of trial conditions |
required |
Source code in src/ethopy/core/behavior.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|
punish()
¶
Punish action.
Source code in src/ethopy/core/behavior.py
181 182 |
|
reward()
¶
Reward action.
Source code in src/ethopy/core/behavior.py
177 178 179 |
|
setup(exp)
¶
Set up behavior.
Source code in src/ethopy/core/behavior.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
update_history(choice=np.nan, reward=np.nan, punish=np.nan)
¶
Update choice and reward history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
choice
|
float
|
Choice made (port number) |
nan
|
reward
|
float
|
Reward amount |
nan
|
punish
|
float
|
Punishment value |
nan
|
Source code in src/ethopy/core/behavior.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
Rewards
¶
Bases: Manual
DataJoint table for tracking reward trials.
Source code in src/ethopy/core/behavior.py
398 399 400 401 402 403 404 405 406 407 408 409 |
|