Registration API Reference¶
registration
¶
B2Registration
dataclass
¶
Bases: B2Session
Registration class for processing B2 (vrControl) session data.
This class handles the preprocessing and registration of behavioral and imaging data from vrControl experiments. It processes timeline data, behavioral data, imaging data (suite2p outputs), red cell identification, and creates mappings between behavioral and imaging data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mouse_name
|
str
|
Name of the mouse. |
required |
date_string
|
str
|
Date string in format "YYYY-MM-DD". |
required |
session_id
|
str
|
Session identifier. |
required |
opts
|
B2RegistrationOpts or dict
|
Registration options. If a dict, will be converted to B2RegistrationOpts. Default is B2RegistrationOpts(). |
B2RegistrationOpts()
|
Attributes:
| Name | Type | Description |
|---|---|---|
opts |
B2RegistrationOpts
|
Registration options. |
tl_file |
dict
|
Timeline data loaded from Timeline.mat file. |
vr_file |
dict
|
Behavioral data loaded from VRBehavior_trial.mat file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If session directory does not exist. |
Source code in vrAnalysis/registration/register.py
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 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 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | |
__init__(mouse_name, date_string, session_id, opts=B2RegistrationOpts())
¶
Initialize B2Registration object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mouse_name
|
str
|
Name of the mouse. |
required |
date_string
|
str
|
Date string in format "YYYY-MM-DD". |
required |
session_id
|
str
|
Session identifier. |
required |
opts
|
B2RegistrationOpts or dict
|
Registration options. If a dict, will be converted to B2RegistrationOpts. Default is B2RegistrationOpts(). |
B2RegistrationOpts()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If session directory does not exist. |
Source code in vrAnalysis/registration/register.py
convert_dense(data)
¶
Convert sparse or dense array to dense numpy array.
Truncates data to numTrials rows and converts sparse matrices to dense arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray or spmatrix
|
Input data, which may be sparse or dense. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Dense numpy array, truncated to numTrials rows and squeezed. |
Source code in vrAnalysis/registration/register.py
convert_rotary_encoder_to_position(rotaryEncoder, rigInfo)
¶
Convert rotary encoder counts to position in centimeters.
The rotary encoder is a counter with a large range that sometimes wraps around. This method handles wrap-around, computes cumulative movement, and scales to centimeters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotaryEncoder
|
ndarray
|
Rotary encoder counts from timeline. |
required |
rigInfo
|
DefaultRigInfo or similar
|
Rig information containing rotary encoder parameters. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Position in centimeters, shape (num_samples,). |
Source code in vrAnalysis/registration/register.py
create_index(time_stamps)
¶
Create index arrays for non-zero/non-NaN timestamps per trial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_stamps
|
ndarray
|
Timestamps as (numTrials x numSamples) dense numpy array. |
required |
Returns:
| Type | Description |
|---|---|
list of np.ndarray
|
List of index arrays, one per trial, indicating which samples have valid data (non-NaN or non-zero). |
Source code in vrAnalysis/registration/register.py
do_preprocessing()
¶
Run all preprocessing steps for the session.
Processes timeline data, behavioral data, imaging data, red cell identification, facecam data (placeholder), and creates mappings between behavioral and imaging data.
Notes
Processing steps are run in order: 1. Timeline processing 2. Behavior processing 3. Imaging processing 4. Red cell processing (if enabled) 5. Facecam processing (not yet implemented) 6. Behavior-to-imaging mapping
Source code in vrAnalysis/registration/register.py
get_timeline_var(var_name)
¶
Get a timeline variable by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var_name
|
str
|
Name of the timeline variable to retrieve. Can be "timestamps" or any hardware input name. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Timeline variable data as a 1D array. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If var_name is not a valid timeline variable name. |
Source code in vrAnalysis/registration/register.py
get_vr_data(data, nzindex)
¶
Extract valid data samples using index arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data array, shape (numTrials, numSamples). |
required |
nzindex
|
list of np.ndarray
|
List of index arrays, one per trial, indicating valid samples. |
required |
Returns:
| Type | Description |
|---|---|
list of np.ndarray
|
List of data arrays, one per trial, containing only valid samples. |
Source code in vrAnalysis/registration/register.py
load_behavior_structure()
¶
Load behavioral structure from VRBehavior_trial.mat file.
Loads the VRBehavior_trial.mat file produced by vrControl and stores it in self.vr_file. If rigInfo is missing, uses DefaultRigInfo as a fallback.
Notes
The behavior file contains trial-level and sample-level behavioral data including timestamps, positions, rewards, and licks. The file is expected to be named "{date}{session_id}{mouse_name}_VRBehavior_trial.mat".
Source code in vrAnalysis/registration/register.py
load_timeline_structure()
¶
Load timeline structure from Timeline.mat file.
Loads the Timeline.mat file produced by rigbox and stores it in self.tl_file. The file is expected to be named "{date}{session_id}{mouse_name}_Timeline.mat".
Notes
The timeline file contains raw DAQ data, timestamps, and hardware input measurements from the experimental rig.
Source code in vrAnalysis/registration/register.py
process_behavior()
¶
Process behavioral data from vrControl.
Processes behavioral data using the appropriate behavior processing function based on the vrBehaviorVersion option. Extracts trial-level and sample-level behavioral data and aligns timestamps to the timeline.
See Also
register_behavior : Dispatcher function for behavior processing.
Source code in vrAnalysis/registration/register.py
process_behavior_to_imaging()
¶
Create mapping from behavioral frames to imaging frames.
Computes the nearest imaging frame for each behavioral sample and saves the mapping to oneData.
Notes
This method is skipped if imaging is disabled in opts. The mapping is saved as "positionTracking.mpci" in oneData.
Source code in vrAnalysis/registration/register.py
process_facecam()
¶
Process facecam data.
Placeholder for facecam preprocessing. Not yet implemented.
Notes
This method currently only prints a message indicating that facecam preprocessing has not been implemented yet.
Source code in vrAnalysis/registration/register.py
process_imaging()
¶
Process imaging data from suite2p outputs.
Loads suite2p outputs, identifies available planes and outputs, handles frame count mismatches between suite2p and timeline, optionally recomputes deconvolution using OASIS, and saves imaging data to oneData format.
Raises:
| Type | Description |
|---|---|
ValueError
|
If imaging is requested but suite2p directory does not exist, or if required suite2p outputs are missing, or if frame count mismatches cannot be resolved. |
Notes
This method: - Identifies planes and available suite2p outputs - Checks for required outputs (stat, ops, F, Fneu, iscell, spks) - Handles frame count mismatches between suite2p and timeline - Optionally recomputes deconvolution using OASIS - Saves imaging data to oneData
Source code in vrAnalysis/registration/register.py
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 | |
process_red_cells()
¶
Process red cell features for identification.
Computes red cell features (dot product, Pearson correlation, phase correlation) using RedCellProcessing and saves them to oneData. Initializes red cell index and manual assignment arrays.
Notes
This method is skipped if imaging or redCellProcessing is disabled in opts, or if redcell output is not available in suite2p. The computed features are saved to oneData for later use in red cell identification.
Source code in vrAnalysis/registration/register.py
process_timeline()
¶
Process timeline data from rigbox.
Extracts timestamps, rotary encoder position, lick times, reward times, and trial start times from the Timeline.mat file. Processes photodiode signals to align trial starts with imaging frames.
Notes
This method: - Loads timeline structure from Timeline.mat - Converts rotary encoder to position - Detects licks and rewards - Processes photodiode signal to find trial start frames - Saves timeline data to oneData
Source code in vrAnalysis/registration/register.py
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 | |
register()
¶
Register the session by running all preprocessing steps.
This is the main entry point for registration. It runs all preprocessing steps (timeline, behavior, imaging, red cells, facecam, behavior-to-imaging) and saves session parameters.
See Also
do_preprocessing : Run all preprocessing steps. save_session_prms : Save session parameters to oneData.
Source code in vrAnalysis/registration/register.py
timeline_inputs(ignore_timestamps=False)
¶
Get list of available timeline input names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ignore_timestamps
|
bool
|
If True, return only hardware input names. If False, include "timestamps" as the first element. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
list of str
|
List of timeline input names. |
Source code in vrAnalysis/registration/register.py
RedCellProcessing
¶
Handle red cell processing for B2Registration sessions.
This class processes red cell data from suite2p outputs, computes features for identifying red cells (S2P, dot product, Pearson correlation, phase correlation), and provides methods for updating red cell indices based on cutoff criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b2session
|
B2Session
|
The B2Session object containing the session data. |
required |
um_per_pixel
|
float
|
Micrometers per pixel for spatial measurements. Default is 1.3. |
1.3
|
autoload
|
bool
|
If True, automatically load reference images and masks on initialization. Default is True. |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
b2session |
B2Session
|
The B2Session object containing the session data. |
feature_names |
list of str
|
Standard names of features used to determine red cell criterion. |
num_planes |
int
|
Number of imaging planes in the session. |
um_per_pixel |
float
|
Micrometers per pixel for spatial measurements. |
data_loaded |
bool
|
Whether reference images and masks have been loaded. |
reference |
list of np.ndarray
|
Reference images for each plane (loaded when data_loaded is True). |
lx, ly |
int
|
Dimensions of reference images. |
lam |
list of np.ndarray
|
Weights of each pixel in ROI masks. |
ypix, xpix |
list of np.ndarray
|
Pixel indices for each ROI mask. |
roi_plane_idx |
ndarray
|
Plane index for each ROI. |
red_s2p |
ndarray
|
Suite2p red cell values for each ROI. |
Source code in vrAnalysis/registration/redcell.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 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 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
__init__(b2session, um_per_pixel=1.3, autoload=True)
¶
Initialize RedCellProcessing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b2session
|
B2Session
|
The B2Session object containing the session data. |
required |
um_per_pixel
|
float
|
Micrometers per pixel for spatial measurements. Default is 1.3. |
1.3
|
autoload
|
bool
|
If True, automatically load reference images and masks on initialization. Default is True. |
True
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If redcell is not available in suite2p outputs. |
Source code in vrAnalysis/registration/redcell.py
centered_mask_stack(plane_idx=None, width=15, fill=0.0)
¶
Create a stack of ROI masks centered on each ROI.
Returns a stack of ROI masks cropped around each ROI centroid within a specified width. Mask values (lam) are placed at the appropriate positions in the centered stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plane_idx
|
int or array-like of int
|
Plane indices to process. If None, processes all planes. Default is None. |
None
|
width
|
float
|
Width in micrometers of the cropped region around each ROI centroid. Default is 15. |
15
|
fill
|
float
|
Value to use for background pixels outside the ROI mask. Should be 0.0 or np.nan. Default is 0.0. |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Stack of centered ROI masks, shape (num_rois, height, width), where height = width = 2 * round(width / um_per_pixel) + 1. |
Source code in vrAnalysis/registration/redcell.py
centered_reference_stack(plane_idx=None, width=15, fill=0.0, filtPrms=None)
¶
Create a stack of reference images centered on each ROI.
Returns a stack of reference images cropped around each ROI centroid within a specified width. Optionally applies a Butterworth filter to the reference images before cropping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plane_idx
|
int or array-like of int
|
Plane indices to process. If None, processes all planes. Default is None. |
None
|
width
|
float
|
Width in micrometers of the cropped region around each ROI centroid. Default is 15. |
15
|
fill
|
float
|
Value to use for background pixels outside the image bounds. Should be 0.0 or np.nan. Default is 0.0. |
0.0
|
filtPrms
|
tuple of 4 floats
|
Parameters for Butterworth filter: (lowcut, highcut, order, fs). If None, no filtering is applied. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Stack of centered reference images, shape (num_rois, height, width), where height = width = 2 * round(width / um_per_pixel) + 1. |
Source code in vrAnalysis/registration/redcell.py
compute_corr(plane_idx=None, width=20, lowcut=12, highcut=250, order=3, fs=512)
¶
Compute Pearson correlation between filtered reference and ROI masks.
Computes the Pearson correlation coefficient between each ROI mask and a Butterworth-filtered reference image within a cropped region around each ROI. This is used as a feature for identifying red cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plane_idx
|
int or array-like of int
|
Plane indices to process. If None, processes all planes. Default is None. |
None
|
width
|
float
|
Width in micrometers of the cropped region around each ROI centroid. Default is 20. |
20
|
lowcut
|
float
|
Low cutoff frequency for Butterworth bandpass filter in Hz. Default is 12. |
12
|
highcut
|
float
|
High cutoff frequency for Butterworth bandpass filter in Hz. Default is 250. |
250
|
order
|
int
|
Order of the Butterworth filter. Default is 3. |
3
|
fs
|
float
|
Sampling frequency for the filter in Hz. Default is 512. |
512
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Pearson correlation coefficients for each ROI, shape (num_rois,). |
Source code in vrAnalysis/registration/redcell.py
compute_dot(plane_idx=None, lowcut=12, highcut=250, order=3, fs=512)
¶
Compute normalized dot product between filtered reference and ROI masks.
Computes the dot product between each ROI mask and a Butterworth-filtered reference image. This is used as a feature for identifying red cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plane_idx
|
int or array-like of int
|
Plane indices to process. If None, processes all planes. Default is None. |
None
|
lowcut
|
float
|
Low cutoff frequency for Butterworth bandpass filter in Hz. Default is 12. |
12
|
highcut
|
float
|
High cutoff frequency for Butterworth bandpass filter in Hz. Default is 250. |
250
|
order
|
int
|
Order of the Butterworth filter. Default is 3. |
3
|
fs
|
float
|
Sampling frequency for the filter in Hz. Default is 512. |
512
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized dot product values for each ROI, shape (num_rois,). |
Source code in vrAnalysis/registration/redcell.py
compute_volume(plane_idx=None)
¶
Compute full-volume ROI masks for specified planes.
Creates a 3D array where each ROI mask is placed at its original position in the full image plane. This is useful for visualization or volume-based operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plane_idx
|
int or array-like of int
|
Plane indices to process. If None, processes all planes. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Volume array of ROI masks, shape (num_rois, ly, lx), where ly and lx are the dimensions of the reference images. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If any plane index is out of range. |
Source code in vrAnalysis/registration/redcell.py
create_centered_axis(numElements, scale=1)
¶
Create a centered axis array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numElements
|
int
|
Number of elements in the axis. |
required |
scale
|
float
|
Scaling factor for the axis. Default is 1. |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Centered axis array, shape (numElements,), with values ranging from -scale(numElements-1)/2 to scale(numElements-1)/2. |
Source code in vrAnalysis/registration/redcell.py
cropped_phase_correlation(plane_idx=None, width=40, eps=1000000.0, winFunc=lambda x: np.hamming(x.shape[-1]))
¶
Compute phase correlation of cropped masks with cropped reference images.
Returns the phase correlation of each ROI mask (cropped around the ROI centroid) with the corresponding cropped reference image. This is used as a feature for identifying red cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plane_idx
|
int or array-like of int
|
Plane indices to process. If None, processes all planes. Default is None. |
None
|
width
|
float
|
Width in micrometers of the cropped region around each ROI centroid. Default is 40. |
40
|
eps
|
float
|
Small value added to avoid division by zero in phase correlation. Default is 1e6. |
1000000.0
|
winFunc
|
callable or str
|
Window function to apply before computing phase correlation. If "hamming", uses Hamming window. Otherwise should be a callable that takes an array and returns a windowed array. Default is Hamming window. |
lambda x: hamming(shape[-1])
|
Returns:
| Name | Type | Description |
|---|---|---|
refStack |
ndarray
|
Stack of cropped reference images, shape (num_rois, height, width). |
maskStack |
ndarray
|
Stack of cropped ROI masks, shape (num_rois, height, width). |
pxcStack |
ndarray
|
Stack of phase correlation maps, shape (num_rois, height, width). |
phase_corr_values |
ndarray
|
Phase correlation values at the center of each correlation map, shape (num_rois,). This is the feature value used for red cell identification. |
Notes
The default parameters (width=40um, eps=1e6, and a Hamming window function) were tested on a few sessions and are subjective. Manual curation and parameter adjustment may be necessary for optimal results.
Source code in vrAnalysis/registration/redcell.py
get_roi_centroid(idx, mode='weightedmean')
¶
Get the centroid of an ROI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index of the ROI. |
required |
mode
|
str
|
Method for computing centroid. "weightedmean" uses pixel weights (lam), "median" uses median pixel coordinates. Default is "weightedmean". |
'weightedmean'
|
Returns:
| Name | Type | Description |
|---|---|---|
yc |
float
|
Y-coordinate of the centroid in pixels. |
xc |
float
|
X-coordinate of the centroid in pixels. |
Source code in vrAnalysis/registration/redcell.py
get_roi_in_plane_idx(idx)
¶
Get the index of an ROI within its own plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Global ROI index. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Index of the ROI within its plane (0-indexed within that plane). |
Source code in vrAnalysis/registration/redcell.py
get_roi_range(idx)
¶
Get the range (peak-to-peak) of x and y pixels for an ROI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index of the ROI. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
yr |
int
|
Range of y-pixels (peak-to-peak). |
xr |
int
|
Range of x-pixels (peak-to-peak). |
Source code in vrAnalysis/registration/redcell.py
getxref(xCenter)
¶
Get x-axis reference coordinates relative to a center point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xCenter
|
float
|
X-coordinate of the center point in pixels. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
X-axis coordinates in micrometers relative to xCenter, shape (lx,). |
Source code in vrAnalysis/registration/redcell.py
getyref(yCenter)
¶
Get y-axis reference coordinates relative to a center point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yCenter
|
float
|
Y-coordinate of the center point in pixels. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Y-axis coordinates in micrometers relative to yCenter, shape (ly,). |
Source code in vrAnalysis/registration/redcell.py
load_reference_and_masks()
¶
Load reference images and ROI masks from suite2p outputs.
Loads the mean image for channel 2 (red channel) for each plane, along with ROI mask data (lam, ypix, xpix) and ROI plane indices. Also loads suite2p red cell values and creates supporting variables for spatial measurements.
Raises:
| Type | Description |
|---|---|
AssertionError
|
If reference images do not all have the same shape. |
Source code in vrAnalysis/registration/redcell.py
one_name_feature_cutoffs(name)
¶
Generate oneData name for feature cutoff parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Feature name (e.g., "S2P", "dotProduct", "pearson", "phaseCorrelation"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
OneData name for the feature cutoff parameter, formatted as "parametersRed{Name}.minMaxCutoff" where {Name} is the capitalized feature name. |
Source code in vrAnalysis/registration/redcell.py
update_from_session(red_cell, force_update=False)
¶
Update red cell cutoffs from another session.
Copies red cell cutoff parameters from another RedCellProcessing object and applies them to this session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red_cell
|
RedCellProcessing
|
Another RedCellProcessing object to copy cutoffs from. |
required |
force_update
|
bool
|
If False, only allows copying from sessions with the same mouse name. If True, allows copying from any session. Default is False. |
False
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If red_cell is not a RedCellProcessing object, or if force_update is False and the mouse names don't match. |
Source code in vrAnalysis/registration/redcell.py
update_red_idx(s2p_cutoff=None, dot_product_cutoff=None, corr_coef_cutoff=None, phase_corr_cutoff=None)
¶
Update red cell index based on feature cutoff values.
Updates the red cell index by applying minimum and maximum cutoffs to each feature (S2P, dot product, Pearson correlation, phase correlation). Only features with non-NaN cutoff values are applied. The red cell index is updated to include only ROIs that meet all specified criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s2p_cutoff
|
array-like of float, length 2
|
[min, max] cutoff values for suite2p red cell feature. NaN values indicate the cutoff should not be applied. Default is None. |
None
|
dot_product_cutoff
|
array-like of float, length 2
|
[min, max] cutoff values for dot product feature. Default is None. |
None
|
corr_coef_cutoff
|
array-like of float, length 2
|
[min, max] cutoff values for Pearson correlation feature. Default is None. |
None
|
phase_corr_cutoff
|
array-like of float, length 2
|
[min, max] cutoff values for phase correlation feature. Default is None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any cutoff is not a numpy array or list, or if any cutoff does not have exactly 2 elements. |
Notes
Cutoff values are saved to oneData for future reference. The red cell index is updated in place and saved to oneData.
Source code in vrAnalysis/registration/redcell.py
behavior
¶
Behavior processing functions for B2Registration.
This module contains functions for processing behavioral data from different versions of the vrControl software. Each function processes behavior data to achieve the same results structure regardless of the data collection method.
BEHAVIOR_PROCESSING = {1: standard_behavior, 2: cr_hippocannula_behavior}
module-attribute
¶
Dictionary of behavior processing functions.
These reflect the different versions of the vrControl software that was used to collect the behavior data. Because the behavioral data was collected in different ways, we need to process it differently to achieve the same results structure.
Keys:
- 1: Standard behavior processing function.
- 2: CR hippocannula behavior processing function.
cr_hippocannula_behavior(b2registration)
¶
Process behavior data from CR hippocannula version of vrControl.
Extracts behavioral data from TRIAL and EXP structures, processes timestamps, positions, rewards, and licks, and saves them to oneData format. Aligns behavioral timestamps to the timeline using photodiode flips.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b2registration
|
B2Registration
|
The B2Registration object containing the session data to process. |
required |
Returns:
| Type | Description |
|---|---|
B2Registration
|
The B2Registration object with behavior data processed and saved. |
Notes
This function processes behavior data from the CR hippocannula version of vrControl. The data structure differs from the standard version, requiring different field names and processing steps.
Source code in vrAnalysis/registration/behavior.py
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 | |
register_behavior(b2registration, behavior_type)
¶
Register behavior for a given behavior type.
This is a dispatcher function that calls the appropriate behavior processing function based on the behavior type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b2registration
|
B2Registration
|
The B2Registration object containing the session data to process. |
required |
behavior_type
|
int
|
The behavior type to register. Must be a key in BEHAVIOR_PROCESSING. |
required |
Returns:
| Type | Description |
|---|---|
B2Registration
|
The B2Registration object with behavior registered. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If behavior_type is not supported. |
See Also
BEHAVIOR_PROCESSING : Dictionary mapping behavior types to processing functions.
Source code in vrAnalysis/registration/behavior.py
standard_behavior(b2registration)
¶
Process standard behavior data from vrControl.
Extracts behavioral data from trialInfo and expInfo structures, processes timestamps, positions, rewards, and licks, and saves them to oneData format. Aligns behavioral timestamps to the timeline using photodiode flips.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b2registration
|
B2Registration
|
The B2Registration object containing the session data to process. |
required |
Returns:
| Type | Description |
|---|---|
B2Registration
|
The B2Registration object with behavior data processed and saved. |
Notes
This function processes behavior data from the standard vrControl format. It extracts trial-level and sample-level behavioral data and aligns timestamps to the imaging timeline.
Source code in vrAnalysis/registration/behavior.py
19 20 21 22 23 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 | |
oasis
¶
oasis_deconvolution(fcorr, g, num_processes=cpu_count() - 1)
¶
Perform oasis deconvolution on a batch of fluorescence traces.
Processes fluorescence traces in parallel using multiple processes to compute deconvolved spike estimates using the OASIS algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fcorr
|
ndarray
|
The fluorescence traces to process, shape (num_rois, num_frames). |
required |
g
|
float
|
The g parameter for oasis deconvolution (decay constant). |
required |
num_processes
|
int
|
The number of processes to use for parallel processing. Default is cpu_count() - 1. |
cpu_count() - 1
|
Returns:
| Type | Description |
|---|---|
list of np.ndarray
|
List of deconvolved traces, one per ROI. Each trace has negative values clipped to zero. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fcorr is not a 2D array or if num_processes is less than 1. |
ImportError
|
If the oasis package cannot be imported. |