vodex.annotation
This module provides the classes for constructing time annotations for imaging data.
'TimeLabel', 'Labels', 'Cycle', 'Timeline', and 'Annotation' classes help to construct and store time annotations. The 'TimeLabel' class stores information about specific time-located events during the experiment, such as a specific condition described by a group and label. The 'Labels' class stores information about a group of time labels, such as temperature, light, sound, image on the screen, drug, or behavior. The 'Cycle' class stores and preprocesses information about repeated cycles of labels, useful for creating annotations for periodic conditions. The 'Timeline' class stores and preprocesses information about the sequence of labels, useful for creating annotations for non-periodic conditions. Finally, the 'Annotation' class stores and preprocesses information about the time annotation of the experiment; it uses either the 'Cycle' or 'Timeline' classes to initialize the annotation.
Annotation
Time annotation of the experiment.
Either frame_to_label_dict or n_frames need to be provided to infer the number of frames. If both are provided , they need to agree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labels |
Labels
|
Labels used to build the annotation |
required |
info |
str
|
a short description of the annotation |
None
|
frame_to_label |
List[TimeLabel]
|
what label it is for each frame |
required |
frame_to_cycle |
List[int]
|
what cycle it is for each frame |
None
|
cycle |
Cycle
|
for annotation from cycles keeps the cycle |
None
|
n_frames |
int
|
total number of frames, will be inferred from frame_to_label if not provided |
required |
Source code in src/vodex/annotation.py
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 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 |
|
cycle_info()
Creates and returns a description of a cycle.
Returns:
Type | Description |
---|---|
str
|
human-readable information about the cycle. |
Source code in src/vodex/annotation.py
from_cycle(n_frames, labels, cycle, info=None)
classmethod
Creates an Annotation object from Cycle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_frames |
int
|
total number of frames, must be provided |
required |
labels |
Labels
|
Labels used to build the annotation |
required |
cycle |
Cycle
|
the cycle to create annotation from |
required |
info |
str
|
a short description of the annotation |
None
|
Returns: (Annotation): Annotation object
Source code in src/vodex/annotation.py
from_df(n_frames, df, timing_conversion=None, is_cycle=False, info=None)
classmethod
Creates an Annotation object from a dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_frames |
int
|
total number of frames, must be provided |
required |
df |
DataFrame
|
dataframe with columns 'frame' and 'label' |
required |
timing_conversion |
Optional[dict]
|
a dictionary to convert the timing of the annotation. For example, if you want to convert the timing from frames to seconds, and you were recording at 30 frames per second, you can use timing_conversion = {'frames': 1, 'seconds': 1/30} You can list multiple units in the dictionary, and the timing will be converted to all of them, for example if there are also 10 frames per volume, you can use: timing_conversion = {'frames': 1, 'seconds': 1/30, 'volumes': 1/10} You must include 'frames' in the dictionary! The value of frames does not have to be 1, but it must be consistent with the other units. the rest of the values. for example this is valid for the example above: timing_conversion = {'frames': 10, 'seconds': 1/3, 'volumes': 1}. If timing_conversion is None, then the timing is not converted and 'duration_frames' must be provided in the dataframe. |
None
|
is_cycle |
bool
|
if True, the annotation is for a cycle |
False
|
info |
Optional[str]
|
a short description of the annotation |
None
|
Returns: (Annotation): Annotation object
Source code in src/vodex/annotation.py
from_timeline(n_frames, labels, timeline, info=None)
classmethod
Creates an Annotation object from Timeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_frames |
int
|
total number of frames, must be provided |
required |
labels |
Labels
|
Labels used to build the annotation |
required |
timeline |
Timeline
|
the timeline to create annotation from |
required |
info |
str
|
a short description of the annotation |
None
|
Returns: (Annotation): Annotation object
Source code in src/vodex/annotation.py
get_timeline()
Transforms frame_to_label to Timeline
Returns:
Type | Description |
---|---|
Timeline
|
timeline of the resulting annotation |
Source code in src/vodex/annotation.py
Cycle
Stores and preprocesses information about the repeated cycle of labels. Use it to create annotation when you have some periodic conditions. For example: light on , light off, light on, light off... will be made of list of labels [light_on, light_off] that repeat to cover the whole tie of the experiment. All labels must be from the same label group. Create multiple cycles to describe different label groups.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_order |
List[TimeLabel]
|
a list of labels in the right order in which they follow |
required |
duration |
Union[NDArray, List[int]]
|
duration of the corresponding labels, in frames (based on your imaging). Note that these are frames, not volumes ! |
required |
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
the name of the cycle, the same as the name of the grou p of the labels. |
label_order |
List[TimeLabel]
|
the order in which the labels follow in a cycle. |
duration |
List[int]
|
the duration of each label from the label_order ( in frames ) |
cycle_length |
int
|
the length of the cycle ( in frames ) |
per_frame_list |
List[TimeLabel]
|
mapping of frames to corresponding frames for one full cycle only. |
Source code in src/vodex/annotation.py
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 |
|
fit_cycles_to_frames(n_frames)
Create a list of cycle ids (what cycle iteration it is) corresponding to each frame in the range of n_frames
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_frames |
int
|
number of frames to fit cycle iterations to, must be >= 0. |
required |
Returns: cycle id per frame for each frame in range of n_frames
Source code in src/vodex/annotation.py
fit_frames(n_frames)
Calculates how many cycles you need to fully cover n_frames. Assumes the cycle starts at the beginning of the recording.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_frames |
int
|
number of frames to cover, must be >= 0. |
required |
Returns:
Type | Description |
---|---|
int
|
number of cycles (n_cycles) necessary to cover n_frames: |
int
|
n_cycles*self.cycle_length >= n_frames |
Source code in src/vodex/annotation.py
fit_labels_to_frames(n_frames)
Create a list of labels corresponding to each frame in the range of n_frames
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_frames |
int
|
number of frames to fit labels to, must be >= 0. |
required |
Returns:
Type | Description |
---|---|
List[TimeLabel]
|
labels per frame for each frame in range of n_frames |
Source code in src/vodex/annotation.py
from_df(df, timing_conversion=None)
classmethod
Create a Cycle object from a dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
dataframe to initialise the cycle. Must have columns 'group', 'name', optional column 'description'. Either column 'duration_frames' or duration column in any other unit and a timing_conversion dictionary to transform it to frames. For example if column 'duration_seconds' is present, the timing_conversion dictionary should be {'frames': 30, 'seconds': 1} if the recording was at 30 frames per second. |
required | |
timing_conversion |
Optional[dict]
|
a dictionary to convert the timing into a different unit. For example, if you want to convert the timing from frames to seconds, and you were recording at 30 frames per second, you can use timing_conversion = {'frames': 1, 'seconds': 1/30} You can list multiple units in the dictionary, and the timing will be converted to all of them, for example if there are also 10 frames per volume, you can use: timing_conversion = {'frames': 1, 'seconds': 1/30, 'volumes': 1/10} You must include 'frames' in the dictionary! The value of frames does not have to be 1, but it must be consistent with the other units. the rest of the values. for example this is valid for the example above: timing_conversion = {'frames': 10, 'seconds': 1/3, 'volumes': 1}. If timing_conversion is None, then the timing is not converted and 'duration_frames' must be provided in the dataframe. |
None
|
Returns: (Cycle): a Cycle object with labels and duration initialised from 'group', 'name', 'description' and duration fields of the dataframe. In the order in which they appear in the dataframe.
Source code in src/vodex/annotation.py
from_dict(d)
classmethod
Create a Cycle object from a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d |
dict
|
dictionary to initialize the cycle. |
required |
Returns:
Type | Description |
---|---|
Cycle
|
a Cycle object with label_order and duration initialized from 'label_order' and 'timing' fields of the dictionary. |
Source code in src/vodex/annotation.py
from_json(j)
classmethod
Create a Cycle object from a json string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
j |
json string to initialise the cycle |
required |
Returns:
Type | Description |
---|---|
Cycle
|
a Cycle object with label_order and duration initialised from 'label_order' and 'timing' fields of the json srting. |
Source code in src/vodex/annotation.py
to_df(timing_conversion=None)
Put all the information about a Cycle object into a dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timing_conversion |
Optional[dict]
|
a dictionary to convert the timing into a different unit. For example, if you want to convert the timing from frames to seconds, and you were recording at 30 frames per second, you can use timing_conversion = {'frames': 1, 'seconds': 1/30} You can list multiple units in the dictionary, and the timing will be converted to all of them, for example if there are also 10 frames per volume, you can use: timing_conversion = {'frames': 1, 'seconds': 1/30, 'volumes': 1/10} You must include 'frames' in the dictionary! The value of frames does not have to be 1, but it must be consistent with the other units. the rest of the values. for example this is valid for the example above: timing_conversion = {'frames': 10, 'seconds': 1/3, 'volumes': 1}. if timing_conversion is None, then the timing is not converted. if timing_conversion is not None, then the timing is converted and both the original and converted timing are added to the dataframe. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
a dataframe with columns 'timing', 'group', 'name' and 'description'. |
DataFrame
|
'timing' will be written in all the units in the timing_conversion dictionary, |
DataFrame
|
or just in frames, if timing_conversion is None. |
Source code in src/vodex/annotation.py
to_dict()
Put all the information about a Cycle object into a dictionary.
Returns:
Type | Description |
---|---|
dict
|
a dictionary with fields 'timing' and 'label_order' which store self.duration and self.label order. |
Source code in src/vodex/annotation.py
to_json()
Put all the information about a Cycle object into a json file.
Returns:
Type | Description |
---|---|
str
|
a json with fields 'timing' and 'label_order' which store self.duration and self.label order. |
Source code in src/vodex/annotation.py
Labels
Stores information about a group of time labels. Any specific aspect of the experiment that you want to document. For example: temperature|light|sound|image on the screen|drug|behaviour ... etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group |
the name of the group |
required | |
group_info |
description of what this group is about. Just for storing the information. |
None
|
|
state_names |
List[str]
|
the state names |
required |
state_info |
Optional[dict]
|
description of each individual state {state name : description}. Just for storing the information. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
group |
the name of the group |
|
group_info |
description of what this group is about. Just for storing the information. |
|
state_names |
the state names |
|
states |
list of states, each state as a TimeLabel object |
Source code in src/vodex/annotation.py
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 |
|
from_df(df, group=None)
classmethod
Create a Labels object from a dataframe. The dataframe must have columns 'group', 'name', optional column 'description'. 'group' column must be the same for all rows. 'name' columns contains the state names, state names can repeat and only the unique state names will be used. The descriptions are optional, if provided then the descriptions of the same state name must be the same or left empty.
Arg
df: the dataframe group: if not None, keep only the rows with this group name. Must be provided if there are multiple groups in the dataframe.
Returns: (Labels): a Labels object with attributes 'group', 'group_info', 'state_names', 'states' inferred and filled from the dataframe.
Source code in src/vodex/annotation.py
from_dict(d)
classmethod
Create a Labels object from a dictionary.
Returns:
Type | Description |
---|---|
Labels
|
a Labels object with attributes 'group', 'group_info', 'state_names', 'states' filled from the dictionary fields. |
Source code in src/vodex/annotation.py
TimeLabel
Stores information about a particular time-located event during the experiment: any specific condition, described by a group and the label. For example: group 'light', label 'on': the light was on; group 'light', label 'off': the light was off.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name for the time label. This is a unique identifier of the label. Different labels must have different names. Different labels are compared based on their names, so the same name means it is the same event. |
required |
description |
str
|
a detailed description of the label. This is to give you more info, but it is not used for anything else. |
None
|
group |
str
|
the group that the label belongs to. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
the name for the time label. This is a unique identifier of the label. Different labels must have different names. Different labels are compared based on their names, so the same name means it is the same event. |
description |
str
|
a detailed description of the label. This is to give you more info, but it is not used for anything else. |
group |
str
|
the group that the label belongs to. |
Source code in src/vodex/annotation.py
from_dict(d)
classmethod
Create a TimeLabel object from a dictionary.
Returns:
Type | Description |
---|---|
TimeLabel
|
a TimeLabel object with attributes 'name', 'group', 'description' filled from the dictionary fields. |
Source code in src/vodex/annotation.py
to_dict()
Put all the information about a TimeLabel object into a dictionary.
Returns:
Type | Description |
---|---|
dict
|
a dictionary with fields 'name', 'group', 'description' which store the corresponding attributes. |
Source code in src/vodex/annotation.py
Timeline
Information about the sequence of labels. Use it when you have non-periodic conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_order |
List[TimeLabel]
|
a list of labels in the right order in which they follow |
required |
duration |
Union[NDArray, List[int]]
|
duration of the corresponding labels, in frames (based on your imaging). Note that these are frames, not volumes ! |
required |
Source code in src/vodex/annotation.py
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 |
|
from_df(df, timing_conversion=None)
classmethod
Create a Timeline object from a dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
dataframe to initialise the timeline. Must have columns 'group', 'name', optional column 'description'. Either column 'duration_frames' or duration column in any other unit and a timing_conversion dictionary to transform it to frames. For example if column 'duration_seconds' is present, the timing_conversion dictionary should be {'frames': 30, 'seconds': 1} if the recording was at 30 frames per second. |
required | |
timing_conversion |
Optional[dict]
|
a dictionary to convert the timing into a different unit. For example, if you want to convert the timing from frames to seconds, and you were recording at 30 frames per second, you can use timing_conversion = {'frames': 1, 'seconds': 1/30} You can list multiple units in the dictionary, and the timing will be converted to all of them, for example if there are also 10 frames per volume, you can use: timing_conversion = {'frames': 1, 'seconds': 1/30, 'volumes': 1/10} You must include 'frames' in the dictionary! The value of frames does not have to be 1, but it must be consistent with the other units. the rest of the values. for example this is valid for the example above: timing_conversion = {'frames': 10, 'seconds': 1/3, 'volumes': 1}. If timing_conversion is None, then the timing is not converted and 'duration_frames' must be provided in the dataframe. |
None
|
Returns:
Type | Description |
---|---|
Timeline
|
a Timeline object with labels and duration initialised from 'group', 'name', 'description' and duration fields of the dataframe. In the order in which they appear in the dataframe. |
Source code in src/vodex/annotation.py
from_dict(d)
classmethod
Create a Timeline object from a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d |
dict
|
dictionary to initialize the timeline. |
required |
Returns:
Type | Description |
---|---|
Timeline
|
a Timeline object with label_order and duration initialized from 'label_order' and 'timing' fields of the dictionary. |
Source code in src/vodex/annotation.py
from_json(j)
classmethod
Create a Timeline object from a json string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
j |
json string to initialise the cycle |
required |
Returns:
Type | Description |
---|---|
Timeline
|
a Timeline object with label_order and duration initialised from 'label_order' and 'timing' fields of the json srting. |
Source code in src/vodex/annotation.py
get_label_per_frame()
A list of labels per frame for the duration of the experiment.
Returns:
Type | Description |
---|---|
List[TimeLabel]
|
labels per frame for the experiment. |
Source code in src/vodex/annotation.py
to_df(timing_conversion=None)
Put all the information about a Timeline object into a dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timing_conversion |
Optional[dict]
|
a dictionary to convert the timing into a different unit. For example, if you want to convert the timing from frames to seconds, and you were recording at 30 frames per second, you can use timing_conversion = {'frames': 1, 'seconds': 1/30} You can list multiple units in the dictionary, and the timing will be converted to all of them, for example if there are also 10 frames per volume, you can use: timing_conversion = {'frames': 1, 'seconds': 1/30, 'volumes': 1/10} You must include 'frames' in the dictionary! The value of frames does not have to be 1, but it must be consistent with the other units. the rest of the values. for example this is valid for the example above: timing_conversion = {'frames': 10, 'seconds': 1/3, 'volumes': 1}. if timing_conversion is None, then the timing is not converted. if timing_conversion is not None, then the timing is converted and both the original and converted timing are added to the dataframe. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
a dataframe with columns 'timing', 'group', 'name' and 'description'. |
DataFrame
|
'timing' will be written in all the units in the timing_conversion dictionary, |
DataFrame
|
or just in frames, if timing_conversion is None. |
Source code in src/vodex/annotation.py
to_dict()
Put all the information about a Timeline object into a dictionary.
Returns:
Type | Description |
---|---|
dict
|
a dictionary with fields 'label_order' and 'timing' . |
Source code in src/vodex/annotation.py
to_json()
Put all the information about a Timeline object into a json string.
Returns:
Type | Description |
---|---|
str
|
a json string with fields 'label_order' and 'timing' . |