qc.camera¶
CameraTestSuite ¶
CameraTestSuite(
data_stream: Camera,
*,
expected_fps: Optional[int] = None,
clock_jitter_s: float = 0.0001,
start_time_s: Optional[float] = None,
stop_time_s: Optional[float] = None,
saturation_bounds: tuple[
Optional[int], Optional[int]
] = (5, 250),
)
Bases: Suite
Test suite for validating camera data integrity.
Provides tests for validating video and metadata integrity according to the AIND file format specification for behavior videos.
For more details, see: https://github.com/AllenNeuralDynamics/aind-file-standards/blob/ce0aa517a40064d1ac9764d42c9efe4ae5c61f7b/file_formats/behavior_videos.md
Attributes:
| Name | Type | Description |
|---|---|---|
data_stream |
Camera
|
The Camera data stream to test. |
expected_fps |
Optional expected frames per second for validation. |
|
clock_jitter_s |
Maximum allowed time difference between frame timestamps, in seconds. |
|
start_time_s |
Optional expected start time for validation, in seconds. |
|
stop_time_s |
Optional expected stop time for validation, in seconds. |
Examples:
from contraqctor.contract.camera import Camera, CameraParams
from contraqctor.qc.camera import CameraTestSuite
from contraqctor.qc.base import Runner
# Create and load a camera data stream
params = CameraParams(path="recordings/session1/")
camera_stream = Camera("front_camera", reader_params=params).load()
# Create test suite with validation parameters
suite = CameraTestSuite(
camera_stream,
expected_fps=30,
start_time_s=10.0,
stop_time_s=310.0
)
# Run tests
runner = Runner().add_suite(suite)
results = runner.run_all_with_progress()
Initialize the camera test suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_stream
|
Camera
|
The Camera data stream to test. |
required |
expected_fps
|
Optional[int]
|
Optional expected frames per second for validation. |
None
|
clock_jitter_s
|
float
|
Maximum allowed time difference between frame timestamps, in seconds. |
0.0001
|
start_time_s
|
Optional[float]
|
Optional expected start time for validation, in seconds. |
None
|
stop_time_s
|
Optional[float]
|
Optional expected stop time for validation, in seconds. |
None
|
saturation_bounds
|
tuple[Optional[int], Optional[int]]
|
Pixel intensity bounds to check for saturation (min, max). |
(5, 250)
|
Source code in src/contraqctor/qc/camera.py
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 | |
description
property
¶
name
property
¶
name: str
Get the name of the test suite.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the test suite class. |
test_metadata_shape ¶
test_metadata_shape()
Checks if the metadata DataFrame has the expected shape. Including headers.
Source code in src/contraqctor/qc/camera.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
test_check_dropped_frames ¶
test_check_dropped_frames()
Check if there are dropped frames in the metadata DataFrame.
Source code in src/contraqctor/qc/camera.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
test_match_expected_fps ¶
test_match_expected_fps()
Check if the frames per second (FPS) of the video metadata matches the expected FPS.
Source code in src/contraqctor/qc/camera.py
123 124 125 126 127 128 129 130 131 132 133 134 | |
test_is_start_bounded ¶
test_is_start_bounded()
Check if the start time of the video is bounded by the provided start time.
Source code in src/contraqctor/qc/camera.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
test_is_stop_bounded ¶
test_is_stop_bounded()
Check if the stop time of the video is bounded by the provided stop time.
Source code in src/contraqctor/qc/camera.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
test_video_frame_count ¶
test_video_frame_count()
Check if the number of frames in the video matches the number of rows in the metadata DataFrame.
Source code in src/contraqctor/qc/camera.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
test_histogram_and_create_asset ¶
test_histogram_and_create_asset()
Checks the histogram of the video and ensures color is well distributed. It also saves an asset with a single frame of the video and color histogram.
Source code in src/contraqctor/qc/camera.py
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 | |
test_create_pixel_saturation_visualizer ¶
test_create_pixel_saturation_visualizer()
Creates a visualization highlighting saturated and underexposed pixels in the video frame.
Source code in src/contraqctor/qc/camera.py
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 | |
get_tests ¶
Find all methods starting with 'test'.
Yields:
| Name | Type | Description |
|---|---|---|
ITest |
ITest
|
Test methods found in the suite. |
Source code in src/contraqctor/qc/base.py
350 351 352 353 354 355 356 357 358 | |
pass_test ¶
pass_test() -> Result
pass_test(
result: Any = None,
message: Optional[str] = None,
*,
context: Optional[Any] = None,
) -> Result
Create a passing test result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
The value to include in the test result. |
None
|
message
|
Optional[str]
|
Optional message describing why the test passed. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with PASSED status. |
Source code in src/contraqctor/qc/base.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 | |
warn_test ¶
warn_test() -> Result
warn_test(
result: Any = None,
message: Optional[str] = None,
*,
context: Optional[Any] = None,
) -> Result
Create a warning test result.
Creates a result with WARNING status, or FAILED if warnings are elevated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
The value to include in the test result. |
None
|
message
|
Optional[str]
|
Optional message describing the warning. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with WARNING or FAILED status. |
Source code in src/contraqctor/qc/base.py
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 | |
fail_test ¶
fail_test() -> Result
fail_test(
result: Optional[Any] = None,
message: Optional[str] = None,
*,
context: Optional[Any] = None,
) -> Result
Create a failing test result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Optional[Any]
|
The value to include in the test result. |
None
|
message
|
Optional[str]
|
Optional message describing why the test failed. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with FAILED status. |
Source code in src/contraqctor/qc/base.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
skip_test ¶
skip_test() -> Result
Create a skipped test result.
Creates a result with SKIPPED status, or FAILED if skips are elevated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Optional[str]
|
Optional message explaining why the test was skipped. |
None
|
context
|
Optional[Any]
|
Optional contextual data for the test result. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
A Result object with SKIPPED or FAILED status. |
Source code in src/contraqctor/qc/base.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | |
setup_suite ¶
setup_suite() -> None
Run once before any test method in the suite.
Mimics :meth:unittest.TestCase.setUpClass. Override this to perform
expensive or failure-prone preparation — e.g. loading a data stream's
.data — a single time for the whole suite, rather than in __init__
(which is not protected by exception handling) or in :meth:setup (which
re-runs before every test).
The :class:Runner invokes this inside an exception-handling block. If it
raises, every test in the suite is reported as an error instead of being
run, and :meth:teardown_suite is not called. Suite construction and
test discovery are unaffected.
Source code in src/contraqctor/qc/base.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
teardown_suite ¶
teardown_suite() -> None
Run once after all test methods in the suite have run.
Mimics :meth:unittest.TestCase.tearDownClass. Only invoked if
:meth:setup_suite completed successfully.
Source code in src/contraqctor/qc/base.py
730 731 732 733 734 735 736 | |
setup ¶
setup() -> None
Run before each test method.
Mimics :meth:unittest.TestCase.setUp. This method can be overridden by
subclasses to implement setup logic that runs before each test. For work
that should happen only once for the whole suite, override
:meth:setup_suite instead.
Source code in src/contraqctor/qc/base.py
738 739 740 741 742 743 744 745 746 | |
teardown ¶
teardown() -> None
Run after each test method.
Mimics :meth:unittest.TestCase.tearDown. This method can be overridden
by subclasses to implement teardown logic that runs after each test. For
work that should happen only once for the whole suite, override
:meth:teardown_suite instead.
Source code in src/contraqctor/qc/base.py
748 749 750 751 752 753 754 755 756 | |
run_test ¶
Run a single test method and yield its results.
Handles setup, test execution, result processing, and teardown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_method
|
ITest
|
The test method to run. |
required |
Yields:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Result objects produced by the test method. |
Source code in src/contraqctor/qc/base.py
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 | |
run_all ¶
Run all test methods in the suite.
Runs :meth:setup_suite once, then all test methods in sequence, then
:meth:teardown_suite. If :meth:setup_suite raises, every test is
yielded as an error result and no tests are run.
Yields:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Result objects produced by all test methods. |
Source code in src/contraqctor/qc/base.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |