organoid_tracker.core.spline module

class organoid_tracker.core.spline.Spline

Bases: object

A curve (curved line) trough the positions. This can be used to measure how far the positions are along this curve.

An offset specifies the zero-point of the axis. A checkpoint (relative to the offset) specifies some point after which a newregion starts. For example, in intestinal organoids this is used to mark the boundary between the crypt and the villus.

add_point(x: float, y: float, z: float)

Adds a new point to the path.

copy() Spline

Returns a copy of this path. Changes to this path will not affect the copy and vice versa.

from_position_on_axis(path_position: float) Tuple[float, float, float] | None

Given a path position, this returns the corresponding x, y and z coordinates. Returns None for positions outside of the line.

get_direction_marker() str

Returns a char thar represents the general direction of this path: “>”, “<”, “^” or “v”. The (0,0) coord is assumed to be in the top left.

get_interpolation_2d() Tuple[List[float], List[float]]

Returns a (cached) list of x and y values that are used for interpolation.

get_interpolation_3d() Tuple[List[float], List[float], List[float]]

Returns a (cached) list of x, y and z values that are used for interpolation.

get_offset() float

Gets the offset used in calls to get_path_position_2d and path_position_to_xy. Note that these methods apply the offset automatically, so except for saving/loading purposes there should be no need to call this method.

get_points_2d() Tuple[List[float], List[float]]

Gets all explicitly added points (no interpolation) without the z coord.

get_points_3d() Tuple[List[float], List[float], List[float]]

Gets all explicitly added points (no interpolation) including the z coord.

get_z() int

Gets the average Z coord of this path. Raises ValueError if the path has no points.

length() float

Gets the length of the spline.

move_points(delta: Position)

Translates all points in this path with the specified amount.

remove_point(x: float, y: float)

Removes the point that is (within 1 px) at the given coords. Does nothing if there is no such point.

set_offset(offset: float)

Manually sets the offset used in calls to get_path_position_2d and path_position_to_xy. See also update_offset_for_positions.

to_position_on_axis(position: Position) SplinePosition | None

Interprets this spline as an axis. Gets the closest position on this axis and the distance to the axis, both in pixels. Returns None if this spline has fewer than 2 points.

update_offset_for_positions(positions: Iterable[Position])

Updates the offset of this spline such that the lowest path position that is ever returned by get_path_position_2d is exactly 0.

class organoid_tracker.core.spline.SplineCollection

Bases: object

Holds the paths of all time points in an experiment.

add_spline(time_point: TimePoint, path: Spline, spline_id: int | None) int

Adds a new spline to the given time point. If another spline with that id already exists in the time point, it is overwritten. If spline_id is None, a new id will be assigned. The spline_id is then returned.

all_splines() Iterable[Tuple[int, TimePoint, Spline]]

Gets all paths. Note that a single time point can have multiple paths.

exists(path: Spline, time_point: TimePoint) bool

Returns True if the path exists in this path collection at the given time point, False otherwise.

first_time_point() TimePoint | None

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

first_time_point_number() int | None

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

get_marker_name(axis_id: int) str | None

Gets the marker of the data axes with the given id.

get_marker_names() Iterable[Tuple[int, str]]

Gets all registered axis markers as (id, name).

get_spline(time_point: TimePoint, spline_id: int) Spline | None

Gets the spline with the given id and time point. Returns None if not found.

has_splines() bool

Returns True if there are any paths stored in this collection.

is_axis(spline_id: int) bool

Returns true if the spline with the given id is an axis.

last_time_point() TimePoint | None

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

last_time_point_number() int | None

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

move_in_time(time_point_delta: int)

Moves all splines the specified amount of time points in time.

of_time_point(time_point: TimePoint) Iterable[Tuple[int, Spline]]

Gets the data axes of the time point along with their id, or an empty collection if that time point has no paths defined.

reference_time_point(number: TimePoint | None = None) TimePoint | None

Gets or sets the reference time point number. The reference time point is used to define the “original” axis on which a point resides. Returns None when getting the time point number if there are no data axes provided.

remove_spline(time_point: TimePoint, spline_to_remove: Spline)

Removes the given data axis from the given time point. Does nothing if the data axis is not used for the given time point.

set_marker(axis_id: int, axis_marker: Marker | None)

Sets the marker of the specified data axes across all time points. High-level version of set_marker_name. If the marker has the extra data “is_axis”: true, then the spline will be used as an axis.

set_marker_name(axis_id: int, axis_marker: str | None, is_data_axis: bool)

Sets the marker of the specified data axes across all time points

time_points() Iterable[TimePoint]

Gets all time points with data axes in them, from first to last.

to_position_on_original_axis(links: Links, position: Position) SplinePosition | None

Gets the position on the axis that was closest in the first time point this position appeared. In this way, every position is assigned to a single axis, and will never switch to another axis during its lifetime.

to_position_on_spline(position: Position, only_axis=False) SplinePosition | None
update_for_changed_positions(time_point: TimePoint, new_positions: Iterable[Position])

If the positions of a time point have changed, this method must be called to update the zero point of all axes.

class organoid_tracker.core.spline.SplinePosition(axis: Spline, pos: float, distance: float, time_point: TimePoint)

Bases: object

Records a position projected on a spline: both the spline, its id, the position on the spline and the distance to the spline are recorded.

calculate_angle(position: Position, resolution: ImageResolution) float

Calculates the angle from this point on the data axis to the given position.

distance: float
pos: float
spline: Spline
spline_id: int
time_point: TimePoint