pept.tracking.Centroids#

class pept.tracking.Centroids(error=False, cluster_size=False, weight=True)[source]#

Bases: Filter

Compute the geometric centroids of a list of samples of points.

Filter signature:

      PointData -> Centroids.fit_sample -> PointData
list[PointData] -> Centroids.fit_sample -> PointData
  numpy.ndarray -> Centroids.fit_sample -> PointData

This filter can be used right after pept.tracking.SplitLabels, e.g.:

>>> (SplitLabels() + Centroids()).fit(points)

If error = True, append a measure of error on the computed centroid as the standard deviation in distances from centroid to all points. It is saved in an extra column “error”.

If cluster_size = True, append the number of points used for each centroid in an extra column “cluster_size” - unless weight = True, in which case it is the sum of weights.

If weight = True and there is a column “weight” in the PointData, compute weighted centroids and standard deviations (if error = True) and the sum of weights (if cluster_size = True). The “weight” column is removed in the output centroid.

__init__(error=False, cluster_size=False, weight=True)[source]#

Methods

__init__([error, cluster_size, weight])

copy([deep])

Create a deep copy of an instance of this class, including all inner attributes.

fit(samples[, executor, max_workers, verbose])

Apply self.fit_sample (implemented by subclasses) according to the execution policy.

fit_sample(points)

load(filepath)

Load a saved / pickled PEPTObject object from filepath.

save(filepath)

Save a PEPTObject instance as a binary pickle object.

fit_sample(points)[source]#
copy(deep=True)#

Create a deep copy of an instance of this class, including all inner attributes.

fit(samples, executor='joblib', max_workers=None, verbose=True)#

Apply self.fit_sample (implemented by subclasses) according to the execution policy. Simply return a list of processed samples. If you need a reduction step (e.g. stack all processed samples), apply it in the subclass.

static load(filepath)#

Load a saved / pickled PEPTObject object from filepath.

Most often the full object state was saved using the .save method.

Parameters
filepathfilename or file handle

If filepath is a path (rather than file handle), it is relative to where python is called.

Returns
pept.PEPTObject subclass instance

The loaded object.

Examples

Save a LineData instance, then load it back:

>>> lines = pept.LineData([[1, 2, 3, 4, 5, 6, 7]])
>>> lines.save("lines.pickle")
>>> lines_reloaded = pept.LineData.load("lines.pickle")
save(filepath)#

Save a PEPTObject instance as a binary pickle object.

Saves the full object state, including inner attributes, in a portable binary format. Load back the object using the load method.

Parameters
filepathfilename or file handle

If filepath is a path (rather than file handle), it is relative to where python is called.

Examples

Save a LineData instance, then load it back:

>>> lines = pept.LineData([[1, 2, 3, 4, 5, 6, 7]])
>>> lines.save("lines.pickle")
>>> lines_reloaded = pept.LineData.load("lines.pickle")