Compute modules
Compute tasks for lab data processing and analysis.
This module provides compute task classes for running analyses on lab data. Tasks can be scheduled and run on dedicated containers using job schedulers.
Available compute tasks: - SpksCompute: Spike sorting using Kilosort/Phy via SPKS - DeeplabcutCompute: Animal pose estimation using DeepLabCut
Each compute task can be: - Scheduled to run on compute clusters via SLURM/PBS - Executed in isolated Singularity/Docker containers - Tracked and monitored through the database - Configured via user preferences
The compute tasks handle: - Input/output file management - Container and environment setup - Job scheduling and resource allocation - Progress tracking and error handling - Result storage and validation
BaseCompute
Base class for analysis compute jobs.
Subclasses implement specific analysis pipelines (spike sorting, cell
segmentation, pose estimation, etc.) by overriding _compute(). The
base class handles job claiming, file retrieval, status tracking, and
safe-exit cleanup.
Jobs are dispatched via place_tasks_in_queue() and consumed by worker
nodes running inside Apptainer containers. The worker calls
handle_compute() which instantiates the appropriate subclass and calls
compute().
Class Attributes
name : str or None
Short identifier used to select this class from the command line.
container : str
Apptainer container image name.
cuda : bool
Whether the container requires a GPU.
ec2 : dict
EC2 instance type presets ('small', 'large') for cloud runs.
| Parameters: |
|
|---|
See Also
labdata.compute.ephys.SpksCompute : Spike sorting with Kilosort. labdata.compute.suite2p.Suite2pCompute : Cell segmentation with Suite2p. labdata.compute.caiman.CaimanCompute : Cell segmentation with CaImAn. labdata.compute.pose.DeeplabcutCompute : Pose estimation with DeepLabCut.
Source code in labdata/compute/utils.py
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 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
__init__(job_id, project=None, allow_s3=None, keep_intermediate=False)
Executes a computation on a dataset, that can be remote or local. Uses a singularity/apptainer image if possible.
Source code in labdata/compute/utils.py
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 | |
compute()
This calls the compute function. If "use_s3" is true it will download the files from s3 when needed.
Source code in labdata/compute/utils.py
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
find_datasets(subject_name=None, session_name=None, dataset_name=None)
Find datasets to analyze, this function will search in the proper tables if datasets are available. Has to be implemented per Compute class since it varies.
Source code in labdata/compute/utils.py
652 653 654 655 656 657 | |
get_files(dset, allowed_extensions=[])
Gets the paths and downloads from S3 if needed.
Source code in labdata/compute/utils.py
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 | |
place_tasks_in_queue(datasets, task_cmd=None, force_submit=False, multisession=False)
Submit compute tasks for each dataset to the ComputeTask queue.
Delegates to _place_tasks_in_queue(). Override in subclasses to
customise submission logic (e.g. SpksCompute handles multi-probe).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in labdata/compute/utils.py
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 | |
register_safe_exit()
Register cleanup_function with safe_exit so it runs on abnormal termination.
Source code in labdata/compute/utils.py
498 499 500 501 | |
secondary_parse(secondary_arguments, parameter_number=None)
Parse secondary command-line arguments for this compute class.
Delegates to _secondary_parse() which subclasses override to add
algorithm-specific CLI options (e.g. motion correction flags, parameter
set selection, batch size).
| Parameters: |
|
|---|
Source code in labdata/compute/utils.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
set_job_status(job_status=None, job_log=None, job_waiting=0)
Update the status of this compute job in ComputeTask.
| Parameters: |
|
|---|
Source code in labdata/compute/utils.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
unregister_safe_exit()
Unregister the cleanup function when the job finishes normally.
Source code in labdata/compute/utils.py
503 504 505 506 | |
PopulateCompute
Bases: BaseCompute
Compute class that calls DataJoint populate() on an arbitrary table.
Useful for running DataJoint computed tables (dj.Computed /
dj.Imported) inside a container or on a remote worker without writing
a custom compute class. The target table, import module, number of
processes, and optional restriction are configured via secondary CLI
arguments.
Secondary arguments (passed after --)::
populate <table> [-i IMPORTS] [-p PROCESSES] [-r RESTRICTIONS] [-s]
Examples:
Queue a populate job for UnitMetrics on all sessions::
parse_analysis('populate', secondary_args=['populate', 'UnitMetrics'])
Source code in labdata/compute/utils.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
find_datasets()
Return None — PopulateCompute does not filter by dataset.
Source code in labdata/compute/utils.py
859 860 861 | |
SpksCompute
Bases: BaseCompute
Spike sorting compute class using the spks / Kilosort pipeline.
Runs Kilosort (via the spks wrapper) on each probe in turn. For
each probe the steps are:
- Locate
.ap.cbin(or.ap.bin) files assigned to the job. - Copy the file to the scratch directory.
- Run spike sorting (Kilosort 4 by default).
- Delete the raw file from scratch.
- Upload results (features, waveforms) to S3 and insert into
SpikeSortingandSpikeSorting.Unit.
Parameters used for sorting are stored in SpikeSortingParams and
matched across jobs so that identical parameter sets share a row.
Requires the labdata-spks Apptainer container and a CUDA GPU.
Source code in labdata/compute/ephys.py
4 5 6 7 8 9 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 | |
add_parameter_key()
Insert a SpikeSortingParams row for the current parameters if it does not exist.
Resolves or creates a parameter_set_num, inserts into
SpikeSortingParams, and raises ValueError if the dataset has
already been sorted with these parameters.
Source code in labdata/compute/ephys.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
extract_waveforms(udict, nchannels, results_folder, n_pre_samples, n_jobs, offsets)
Select spike indices and extract waveform snippets from the filtered binary.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in labdata/compute/ephys.py
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 | |
find_datasets(subject_name=None, session_name=None)
Searches for subjects and sessions in EphysRecording
Source code in labdata/compute/ephys.py
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 | |
place_tasks_in_queue(datasets, task_cmd=None, force_submit=False, multisession=False)
Submit one ComputeTask per probe per dataset.
Overrides BaseCompute.place_tasks_in_queue to split multi-probe
datasets into separate jobs (one job per probe_num) so each probe
can be sorted independently and in parallel.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in labdata/compute/ephys.py
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 | |
postprocess_and_insert(results_folder, probe_num, remove_duplicates=True, n_pre_samples=45)
Does the preprocessing for a spike sorting and inserts
Source code in labdata/compute/ephys.py
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 | |
prepare_results(results_folder, probe_num, remove_duplicates, n_pre_samples)
Parse Kilosort output and prepare structured dicts for database insertion.
Optionally removes duplicate spikes across shanks, then collects per-unit spike times, positions, amplitudes, and template features.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in labdata/compute/ephys.py
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 | |
DeeplabcutCompute
Bases: BaseCompute
Pose estimation compute class using DeepLabCut.
Supports two modes selected by parameters['mode']:
'train': Train a new DeepLabCut model from aPoseEstimationLabelSetand upload the trained model toPoseEstimationModel.'infer': Run inference with an existingPoseEstimationModelon aDatasetVideoand insert predictions intoPoseEstimation.
Requires the labdata-deeplabcut Apptainer container and a CUDA GPU.
Source code in labdata/compute/pose.py
4 5 6 7 8 9 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 | |
add_parameter_key()
Resolve or assign a PoseEstimationModel number for this job.
For mode='train', finds an existing model with the same parameters
and label set, or allocates the next available model number. For
mode='infer', uses parameters['model_num'] directly.
Source code in labdata/compute/pose.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
find_datasets(subject_name=None, session_name=None)
Searches for subjects and sessions
Source code in labdata/compute/pose.py
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 | |
CaimanCompute
Bases: Suite2pCompute
Cell segmentation compute class using CaImAn.
Works for both one-photon (miniscope) and two-photon datasets. Runs
inside the labdata-caiman Apptainer container (CPU-only).
The compute pipeline:
- Identify files and determine dataset type (
MiniscopeorTwoPhoton). - Copy the
zarr.zipstack to the scratch directory. - Run CaImAn CNMF/CNMF-E with the specified parameters.
- Delete memory-mapped intermediate files.
- Upload the HDF5 results file to S3 and insert into
CellSegmentation.
Parameters are stored in CellSegmentationParams (shared with
Suite2pCompute using the same part tables).
Source code in labdata/compute/caiman.py
4 5 6 7 8 9 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 | |
Suite2pCompute
Bases: BaseCompute
Cell segmentation compute class using Suite2p + FISSA.
Runs Suite2p on a two-photon or miniscope imaging dataset inside the
labdata-suite2p Apptainer container, followed by FISSA neuropil
decontamination. Results are written to an HDF5 analysis file and
inserted into CellSegmentation and its part tables.
Supports .zarr.zip, .sbx, and .tiff input files.
Parameters are stored in CellSegmentationParams and matched across
jobs so that identical parameter sets share a row.
Requires a CUDA GPU for Suite2p registration and detection.
Source code in labdata/compute/suite2p.py
4 5 6 7 8 9 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 | |
add_parameter_key()
Insert a CellSegmentationParams row for the current parameters if it does not exist.
Resolves or creates a parameter_set_num, inserts into
CellSegmentationParams, and raises ValueError if the dataset
has already been segmented with these parameters.
Source code in labdata/compute/suite2p.py
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 | |
find_datasets(subject_name=None, session_name=None)
Searches for subjects and sessions in TwoPhoton
Source code in labdata/compute/suite2p.py
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 | |
run_analysis(target, jobids, compute_obj, project=None)
Launch one or more analysis jobs on a specific execution target.
Selects the appropriate runner (local Apptainer, SLURM, EC2) based on
target and submits all jobids as separate tasks.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in labdata/compute/utils.py
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 | |
handle_compute(job_id, project=None)
Instantiate and return the correct compute object for a queued job.
Looks up the task_name for job_id in ComputeTask, resolves the
registered compute class via load_analysis_object(), and returns an
initialised instance ready to call compute().
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in labdata/compute/utils.py
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 | |