organoid_tracker.core.position_collection module

class organoid_tracker.core.position_collection.PositionCollection(positions: Iterable[Position] = ())

Bases: object

add(position: Position)

Adds a position, optionally with the given shape. The position must have a time point specified.

add_data_from_time_point_dict(time_point: TimePoint, positions: List[Position], metadata_dict: Dict[str, List[Optional[Union[float, int, str, bool, List[float], List[int], List[str], List[bool]]]]])

Adds a time point with positions and metadata. The metadata dictionary must contain lists of the same length as the positions list. The position and metadata lists must be in the same order, and the position list must not contain any duplicates.

This method is kind of low-level, and is mostly used for loading data from files. It’s faster than just calling set_position_data for every position. However, note that for speed reasons, this method does not check the positions list for duplicates.

add_positions(other: PositionCollection)
add_positions_data(data_name: str, data_set: Dict[Position, Union[float, int, str, bool, List[float], List[int], List[str], List[bool]]])

Bulk-addition of position data. Should be faster that adding everything individually.

contains_position(position: Position) bool

Returns whether the given position is part of the experiment.

copy() PositionCollection

Creates a copy of this positions collection. Changes made to the copy will not affect this instance and vice versa.

count_positions(*, time_point: Optional[TimePoint])

Counts the number of positions at the given time point. If notime point is given, positions of all available time points will be counted.

create_time_point_dict(time_point: TimePoint, positions: List[Position]) Dict[str, List[Optional[Union[float, int, str, bool, List[float], List[int], List[str], List[bool]]]]]

Creates a dictionary of metadata lists for a given time point. The metadata lists are empty. This is useful for creating a new time point with the same positions as an existing time point, but with no metadata.

delete_data_with_name(data_name: str)

Deletes the data with the given key, for all positions in the experiment.

detach_all_for_time_point(time_point: TimePoint)

Removes all positions for a given time point, if any.

detach_position(position: Position)

Removes a position from a time point. Does nothing if the position is not in this collection.

find_all_data_names() Set[str]

Finds all data_names

find_all_data_of_position(position: Position) Iterable[Tuple[str, Union[float, int, str, bool, List[float], List[int], List[str], List[bool]]]]

Finds all stored data of a given position.

find_all_positions_with_data(data_name: str) Iterable[Tuple[Position, Union[float, int, str, bool, List[float], List[int], List[str], List[bool]]]]

Gets a dictionary of all positions with the given data marker. Do not modify the returned dictionary.

first_time_point() Optional[TimePoint]

Gets the first time point that contains positions, or None if there are no positions stored.

first_time_point_number() Optional[int]

Gets the first time point that contains positions, or None if there are no positions stored.

get_data_names_and_types() Dict[str, Type]

Gets all data names that are currently in use, along with their type. The type will be str, float, bool, list, or object. (The type int is never returned, for ints float is returned instead. This is done so that users don’t have to worry about storing their numbers with the correct type.)

get_position_data(position: Position, data_name: str) Optional[Union[float, int, str, bool, List[float], List[int], List[str], List[bool]]]

Gets the attribute of the position with the given name. Returns None if not found.

has_position_data() bool

Gets whether there is any position metadata stored here.

has_position_data_with_name(data_name: str) bool

Returns whether there is position metadata stored for the given data name.

has_positions() bool

Returns True if there are any positions stored here.

highest_z() Optional[int]

Returns the lowest z in use, or None if there are no positions in this collection.

last_time_point() Optional[TimePoint]

Gets the last time point (inclusive) that contains positions, or None if there are no positions stored.

last_time_point_number() Optional[int]

Gets the last time point (inclusive) that contains positions, or None if there are no positions stored.

lowest_z() Optional[int]

Returns the lowest z in use, or None if there are no positions in this collection.

merge_data(other: PositionCollection)

Adds all positions and metadata of the other collection to this collection.

move_in_time(time_point_delta: int)

Moves all data with the given time point delta.

move_position(old_position: Position, new_position: Position)

Moves a position, keeping its shape. Does nothing if the position is not in this collection. Raises a value error if the time points the provided positions are None or if they do not match.

nearby_z(z: int) Iterable[Position]

Returns all positions (for any time point) for which round(position.z) == z.

of_time_point(time_point: TimePoint) AbstractSet[Position]

Returns all positions for a given time point. Returns an empty set if that time point doesn’t exist.

of_time_point_and_z(time_point: TimePoint, z_min: Optional[int] = None, z_max: Optional[int] = None) Iterable[Position]

Gets all positions that are nearby the given min to max z, inclusive.

set_position_data(position: Position, data_name: str, value: Optional[Union[float, int, str, bool, List[float], List[int], List[str], List[bool]]])

Adds or overwrites the given attribute for the given position. Set value to None to delete the attribute.

Does nothing if the position does not exist. Use self.add(…) to add a position.

If the data_name is ‘id’ or starts with “__”, a ValueError is raised. This requirement was necessary for the old save system, so as long as OrganoidTracker still supports writing to the old format, this restriction remains in place.

time_points() Iterable[TimePoint]

Returns all time points from self.first_time_point() to self.last_time_point().