ListOfFragments#

Warning

The code reference is a work in progress and may contain inconsistencies.

class idtrackerai.ListOfFragments(fragments: list[Fragment], id_images_file_paths: list[Path], number_of_animals: int)[source]#

Contains all the instances of the class Fragment.

__init__(fragments: list[Fragment], id_images_file_paths: list[Path], number_of_animals: int) None[source]#

Initialize the ListOfFragments manually from a list of Fragment. This method should only be called from from_fragmented_blobs(). You can load a ListOfFragments from a file by using the method load().

Parameters:
  • fragments (list[Fragment]) – List of instances of the class Fragment.

  • id_images_file_paths (list[Path]) – List of paths to the files where the identification images are stored.

  • number_of_animals (int) – Number of animals in the video

id_to_exclusive_roi: ndarray#

Maps identities (from 0 to n_animals-1) to their exclusive ROI (-1 meaning no ROI)

classmethod load(file_path: Path | str, reconnect: bool = True, verbose: bool = True) ListOfFragments[source]#

Loads a previously saved list of fragments (see save()) from a JSON file

Parameters:
  • file_path (Path | str) – Path to the JSON file containing

  • reconnect (bool, optional) – If True, the Fragments.coexisting_individual_fragments attribute, which is not saved in the JSON file, is computed and populated, by default True

Returns:

Loaded instance

Return type:

ListOfFragments

classmethod from_fragmented_blobs(all_blobs: Iterable[Blob], number_of_animals: int, id_images_file_paths: list[Path]) ListOfFragments[source]#

Generate a list of instances of Fragment collecting all the fragments in the video.

Parameters:
  • all_blobs (Iterable[Blob]) – An iterable of the blob objects which have to be sorted by Blob.frame_number, for example ListOfBlobs.all_blobs.

  • number_of_animals (int) – Number of animals to track as defined by the user

  • id_images_file_paths (list[Path]) – List of paths to the files where the identification images are stored.

Returns:

The List of Fragments computed from the blobs.

Return type:

ListOfFragments

save(file_path: Path | str) None[source]#

Save the list of fragments into a JSON file

Parameters:

file_path (Path | str) – Path where the instance of the object will be stored.

get_connectivity(min_fragment_length: int = 4) float[source]#

Computes the connectivity of the fragments.

reset(roll_back_to: Literal['fragmentation', 'accumulation']) None[source]#

Resets all the fragment to a given processing step.

Parameters:

roll_back_to (str) – Name of the step at which the fragments should be reset. It can be ‘fragmentation’, ‘accumulation’ or

See also

Fragment.reset()

property n_images_in_global_fragments: int#

Number of images available in global fragments (without repetitions)

property ratio_of_images_used_for_training: float#

Returns the ratio of images used for training over the number of available images

build_exclusive_rois() dict[str, set[int]][source]#

Builds id_to_exclusive_roi and returns a more readable version intended to be saved in Session.identities_groups

compute_P2_vectors() None[source]#

Computes the P2_vector associated to every individual fragment. See Fragment.compute_P2_vector()

get_fragments_to_identify() Iterator[Fragment][source]#

Yields all the Fragment instances left non identified after the cascade of training and identification protocols sorted by the certainty computed with P2. See :attr:Fragment.certainty_P2`

Yields:

Iterator[Fragment] – Non identified Fragments sorted by P2 certainty

update_id_images_dataset() None[source]#

Updates the identification images files with the identity assigned to each fragment during the tracking process.

get_ordered_list_of_fragments(scope: Literal['to_the_past', 'to_the_future'], specific_frame: int) list[Fragment][source]#

Sorts the fragments starting from the frame number first_frame_first_global_fragment. According to scope the sorting is done either “to the future” of “to the past” with respect to first_frame_first_global_fragment

Parameters:
  • scope (str) – either “to_the_past” or “to_the_future”

  • first_frame_first_global_fragment (int) – frame number corresponding to the first frame in which all the individual fragments coexist in the first global fragment using in an iteration of the fingerprint protocol cascade

Returns:

list of sorted fragments

Return type:

list

load_images_in_memory(condition: Callable[[Fragment], bool] | None = None)[source]#

Loads Fragment’s images in memory from id_images_file_paths. It only takes into account the fragments satisfying the given condition. Used outside idtracker.ai

connect_coexisting_fragments(verbose=True) None[source]#

Populates Fragment.coexisting_individual_fragments

manage_accumulable_non_accumulable_fragments(accumulable_global_fragments: list[GlobalFragment], non_accumulable_global_fragments: list[GlobalFragment])[source]#

Gets the unique identifiers associated to individual fragments that can be accumulated.

Parameters:

list_of_global_fragments (ListOfGlobalFragments) – Object collecting the global fragment objects (instances of the class GlobalFragment) detected in the entire video.

get_stats() dict[str, int][source]#

Collects the following counters from the fragments.

  • fragments

  • crossing_fragments

  • individual_fragments

  • individual_fragments_not_in_a_global_fragment

  • accumulable_individual_fragments

  • not_accumulable_individual_fragments

  • globally_accumulated_individual_fragments

  • partially_accumulated_individual_fragments

  • blobs

  • crossing_blobs

  • individual_blobs

  • individual_blobs_not_in_a_global_fragment

  • accumulable_individual_blobs

  • not_accumulable_individual_blobs

  • globally_accumulated_individual_blobs

  • partially_accumulated_individual_blobs

Returns:

Dictionary with the counters mentioned above

Return type:

dict

update_blobs(all_blobs: Iterable[Blob]) None[source]#

Updates the blobs objects generated from the video with the attributes computed for each fragment

Parameters:

all_blobs (Iterable[Blob]) – All blobs to be updated

get_next_fragment_to_identify()[source]#

Get next fragment to identify

Deprecated since version 6.0.0: Use get_fragments_to_identify() instead

get_number_of_unidentified_individual_fragments()[source]#

Get number of unidentified individual fragments

Deprecated since version 6.0.0: See get_stats() to get the same information

property ratio_of_images_used_for_pretraining#

Ratio of images used for pretraining

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_individual_fragments_not_in_a_glob_fragment#

Number of individual fragments not in a glob fragment

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_accumulable_individual_fragments#

Number of accumulable individual fragments

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_not_accumulable_individual_fragments#

Number of not accumulable individual fragments

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_blobs#

Number of blobs

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_crossing_blobs#

Number of crossing blobs

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_individual_blobs#

Number of individual blobs

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_individual_blobs_not_in_a_global_fragment#

Number of individual blobs not in a global fragment

Deprecated since version 6.0.0: See get_stats() to get the same information

property fragments_not_accumulated#

Fragments not accumulated

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_globally_accumulated_individual_fragments#

Number of globally accumulated individual fragments

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_partially_accumulated_individual_fragments#

Number of partially accumulated individual fragments

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_accumulable_individual_blobs#

Number of accumulable individual blobs

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_not_accumulable_individual_blobs#

Number of not accumulable individual blobs

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_globally_accumulated_individual_blobs#

Number of globally accumulated individual blobs

Deprecated since version 6.0.0: See get_stats() to get the same information

property number_of_partially_accumulated_individual_blobs#

Number of partially accumulated individual blobs

Deprecated since version 6.0.0: See get_stats() to get the same information