results¶
One run's outputs: the results file deeperfly run writes and a reader reads.
A run's file holds one group per stage, the arrays inventory.STAGE_ARRAYS declares
under the names every reference uses, and nothing derived. The file describes the work
it came from: the run config, the skeleton and the initial calibration verbatim, the
geometry, the videos, the frame rate, the deeperfly that wrote it, per stage the
fingerprint that says its arrays are valid (ADR-0035), and when it was last written.
A run covers a frame set (ADR-0082): every array with a T axis is dense over the
absolute frame index, and each stage group's covered (T,) mask says which frames
hold values; a frame never written holds the array's fill value
(fill_value). An array without T is rewritten
whole by every write, so the last one wins. The file is only appended to or refused,
never overwritten for other video, and shapes are checked on write against the
inventory. Every per-animal array leads with N (ADR-0052).
Results ¶
Read/write access to one run's results file, as a context manager.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
The file on disk. |
|
views |
tuple[str, ...]
|
View names, in the |
keypoints |
tuple[str, ...]
|
Keypoint names, in the |
n_frames |
The recording's frame count, the |
|
animals |
How many animals the run tracked, the |
Source code in src/deeperfly/results.py
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 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 786 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 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | |
frame_sizes
property
¶
Per view, the (height, width) of the video frames the run read.
videos
property
¶
Per video, the files the run read, relative to the project folder.
Relative to that folder also for a --out run, whose results lie outside it.
written
property
¶
The unix time of the last write to any stage, or 0 if none was written.
__enter__ ¶
__exit__ ¶
__init__ ¶
Wrap an already-open file; use create or open instead.
Source code in src/deeperfly/results.py
axes ¶
The declared axes of a "stage/array" reference, e.g. ("T", "K", 3).
Source code in src/deeperfly/results.py
begin_stage ¶
Make stage's group ready for frames written under fingerprint.
A group of the same fingerprint is kept with its coverage; one of another is dropped, since none of its frames are valid now, and a fresh one covering nothing takes its place. Returns whether a stored group was dropped.
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in src/deeperfly/results.py
calibration ¶
The run's calibration: the one bundle adjustment solved, else the initial.
A solved one records, as refined_from, the project calibration its starting
parameters were copied from, when they name one (ADR-0086): the copy the
solve keeps (write_frames), not the
file's, which a later invocation may have copied from another.
Source code in src/deeperfly/results.py
close ¶
covered ¶
(T,) bool: the frames stage has written; all false if it never ran.
Source code in src/deeperfly/results.py
create
classmethod
¶
create(
path: str | Path,
*,
project: str,
views: Sequence[str],
keypoints: Sequence[str],
n_frames: int,
animals: int = 1,
config_text: str = "",
calibration_text: str | None = None,
skeleton_text: str = "",
videos: Mapping[str, Sequence[str | Path]]
| None = None,
fps: float | None = None,
frame_sizes: Mapping[str, tuple[int, int]]
| None = None,
force: bool = False,
) -> Results
Start a results file, or reopen one that already describes this recording.
A file for the same views, keypoints, frame count and format is reopened for
append, which is what lets a run grow and keep its matching stages; one
describing other work is refused unless force. config_text,
skeleton_text and calibration_text are stored verbatim, the skeleton
being the only place a reader finds the edges and the calibration a
Calibration document of the parameters
the run started from (ADR-0086; None stores none, as a pose2d-only run
does). videos are each video's files and frame_sizes each view's frame.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a file is there, describes other work, and not |
Source code in src/deeperfly/results.py
drop_stage ¶
Delete a stage's group, so the next run recomputes it.
fingerprint ¶
The fingerprint recorded for stage, or None if it never ran.
Source code in src/deeperfly/results.py
has ¶
initial_calibration ¶
The camera parameters the run started from, or None if it stores none.
names ¶
The attrs.names labelling an array's named axis, if it has one.
open
classmethod
¶
open(
path: str | Path,
mode: str = "r",
*,
locking: bool | None = None,
rdcc_nbytes: int | None = None,
) -> Results
Open an existing results file (read-only by default).
locking=None opens a reader without HDF5's file lock and a writer with it;
rdcc_nbytes is the chunk cache, READ_CACHE_BYTES by default.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file is not a results file, or another format version, so its arrays would be read under the wrong layout. |
Source code in src/deeperfly/results.py
provenance ¶
What a stage's group records: its fingerprint, when, how long, by whom.
Raises:
| Type | Description |
|---|---|
KeyError
|
If the stage has written nothing. |
Source code in src/deeperfly/results.py
read ¶
read_animal ¶
One animal's copy of an array, with the leading N axis peeled off.
read_animal("pose3d/points", 0) is (T, K, 3) however many animals were
tracked; an array about the recording has no N and comes back whole.
Raises:
| Type | Description |
|---|---|
IndexError
|
If the file holds no animal |
KeyError
|
If the file holds no such array. |
Source code in src/deeperfly/results.py
read_frame ¶
An array at one frame, its T axis dropped; instance also drops N.
An array without N ignores instance, and one without T comes back
whole.
Raises:
| Type | Description |
|---|---|
KeyError
|
If the file holds no such array. |
IndexError
|
If the frame, or the animal, is not in the file. |
Source code in src/deeperfly/results.py
read_frames ¶
An array at the given frames only, in the order given, T kept.
Read one stretch at a time, so only the chunks holding those frames are
decompressed; an array without T comes back whole.
Raises:
| Type | Description |
|---|---|
KeyError
|
If the file holds no such array. |
IndexError
|
If a frame is outside |
Source code in src/deeperfly/results.py
read_rig ¶
Read back a stored rig ("views", or "bundle_adjustment/views").
Source code in src/deeperfly/results.py
replace ¶
Overwrite a stored array in place with one of the same shape.
A repair (swap_animals), not a stage's write: the fingerprint and provenance stand, so a rerun still skips the stage.
Raises:
| Type | Description |
|---|---|
KeyError
|
If the file holds no such array. |
ValueError
|
If |
Source code in src/deeperfly/results.py
same_config ¶
Whether text is the stored run config, apart from name and frames.
Compared as parsed TOML, so layout and comments do not count; the name and the frame set are what may differ between invocations of one run (ADR-0082). Text that does not parse is compared verbatim.
Source code in src/deeperfly/results.py
select ¶
Read an array and keep only the named keypoints and views, in stored order.
points and views are the run config's selectors, applied along the
reference's K and V axes; an array without the axis ignores its selector.
Raises:
| Type | Description |
|---|---|
KeyError
|
If the file holds no such array. |
ConfigError
|
If a selector matches nothing. |
Source code in src/deeperfly/results.py
skeleton ¶
The stored skeleton, parsed: the topology behind keypoints.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file stores no skeleton, or the text no longer parses. |
Source code in src/deeperfly/results.py
stages ¶
stamp_duration ¶
Record how long stage took, beside its fingerprint.
stamp_written ¶
Record that the run was written at when (unix time, default now).
uncover ¶
Mark frames of stage as not written, so a later run recomputes them.
The arrays keep their values; a stage that never ran is left alone.
Source code in src/deeperfly/results.py
write_frames ¶
write_frames(
stage: str,
arrays: Mapping[str, ndarray],
frames: Sequence[int] | ndarray,
*,
names: Mapping[str, Sequence[str]] | None = None,
rig: Rig | None = None,
) -> None
Write a stage's arrays at frames, mark them covered, stamp written.
frames are increasing absolute indices, and every array with a T axis
holds exactly those frames along it; the file's copy is dense over T, and
a frame never written keeps the array's fill value. An array without T is
rewritten whole. names labels an array's named axis (ik/angles) and
rig stores the geometry beside the arrays (bundle_adjustment/views), the
group keeping a copy of the file's calibration, the one it derives from.
Raises:
| Type | Description |
|---|---|
KeyError
|
If the stage was not begun, or an array name is not declared. |
ValueError
|
If an array's shape disagrees with the declaration or with
what the file already holds, or |
IndexError
|
If a frame is outside |
Source code in src/deeperfly/results.py
write_rig ¶
Store the geometry the run used, at the file's top level.
write_stage ¶
write_stage(
stage: str,
arrays: Mapping[str, ndarray],
*,
fingerprint: str,
names: Mapping[str, Sequence[str]] | None = None,
rig: Rig | None = None,
) -> None
Replace stage's group with arrays over every frame, fingerprinted.
Replaced, not updated, so an array a stage stopped producing does not linger:
a fresh begin_stage and one
write_frames over the whole T
axis, which marks every frame covered.
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If an array's shape disagrees with the declaration. |
Source code in src/deeperfly/results.py
stretches ¶
The maximal contiguous ranges of a frame set, as (start, stop) slices.
frames is unioned and sorted first, so [5, 0, 1, 2, 7, 6] is
[(0, 3), (5, 8)], and a stepped range is one stretch per frame.
Source code in src/deeperfly/results.py
swap_animals ¶
Exchange two animals of a run's results over [start, stop), and drop the rest.
Every pose2d array with an animal axis is exchanged, and every downstream group
deleted, since its fingerprint still matches the config. The run's written is
stamped, so the swapped run wins precedence where it covers a frame (ADR-0083).
stop=None runs to the end. Returns the stage groups deleted, in pipeline order.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file holds one animal, a slot is not one of its animals, the two slots are the same, or the range is empty. |