Skip to content

calc_avg_point_coords

jaybgager edited this page Sep 25, 2026 · 1 revision

This function gets the average point coordinates from a list of point coordinates. Useful for calculating the center mass of point clouds, commonly required when generating line annotation endpoints to visualize split edits which are typically associated with multiple points per operation.

Arguments:

  • points (list of lists of integers, mandatory)
    • a list of point coords to be included in the average
    • each point coord should be a list of integers (e.g. [1,2,3])
    • although intended for 3D space, any number of coordinates should work as long as all coords have the same number of dimensions
  • exact_value (boolean, optional, default=False)
    • by default, this function rounds the average coords to integers
    • toggling this option to True will return them as exact floats instead

Returns:

  • avg_point (list of integers)
    • the average values for each dimension in the coordinate list (e.g. [Xavg,Yavg,Zavg])

Examples

Let's say you wanted to get the average point coordinates of these 5 point annotations in the brain_and_nerve_cord abdominal ganglion.

Default Behavior

By default, this function returns the average coordinates as integers (intended for use with neuroglancer).

INPUT:

import tracertools as tt

point_coords = [
    [100713, 246315, 5113],
    [91940, 251937, 5793],
    [92076, 244805, 6015],
    [95390, 242043, 5273],
    [99324, 243448, 6116],
]

average_coords = tt.calc_avg_point_coords(
    points = point_coords,
)

print(average_coords)

OUTPUT:

[95889, 245710, 5662]

Looking at the position of the resulting point it does indeed appear to be in the center of all the others.

Exact Value Reporting

If you toggle the exact_value argument to True, you can get the exact coordinates as floats.

INPUT:

import tracertools as tt

point_coords = [
    [100713, 246315, 5113],
    [91940, 251937, 5793],
    [92076, 244805, 6015],
    [95390, 242043, 5273],
    [99324, 243448, 6116],
]

average_coords = tt.calc_avg_point_coords(
    points = point_coords,
    exact_value = True,
)

print(average_coords)

OUTPUT:

[95888.6, 245709.6, 5662.0]

Clone this wiki locally