pept.tracking.Minpoints#

class pept.tracking.Minpoints(num_lines, max_distance, cutoffs=None, append_indices=False)[source]#

Bases: LineDataFilter

Transform LoRs (a pept.LineData instance) into minpoints (a pept.PointData instance) for clustering, in parallel.

Given a sample of lines, the minpoints are the minimum distance points (MDPs) for every possible combination of num_lines lines that satisfy the following conditions:

  1. Are within the cutoffs.

  2. Are closer to all the constituent LoRs than max_distance.

Under typical usage, the Minpoints class is initialised with a pept.LineData instance, automatically calculating the minpoints from the samples of lines. The Minpoints class inherits from pept.PointData, such that once the cutpoints have been computed, all the methods from the parent class pept.PointData can be used on them (such as visualisation functionality).

For more control over the operations, pept.tracking.peptml.find_minpoints can be used - it receives a generic numpy array of LoRs (one ‘sample’) and returns a numpy array of cutpoints.

See also

pept.LineData

Encapsulate LoRs for ease of iteration and plotting.

pept.tracking.peptml.HDBSCANClusterer

Efficient, parallel HDBSCAN-based clustering of cutpoints.

pept.scanners.ParallelScreens

Read in and initialise a pept.LineData instance from parallel screens PET/PEPT detectors.

pept.utilities.read_csv

Fast CSV file reading into numpy arrays.

Examples

Compute the minpoints for a LineData instance for all triplets of lines that are less than 0.1 from those lines:

>>> line_data = pept.LineData(example_data)
>>> minpts = peptml.Minpoints(line_data, 3, 0.1)

Compute the minpoints for a single sample:

>>> sample = line_data[0]
>>> cutpts_sample = peptml.find_minpoints(sample, 3, 0.1)
Attributes
line_datainstance of pept.LineData

The LoRs for which the cutpoints will be computed. It must be an instance of pept.LineData.

num_linesint

The number of lines in each combination of LoRs used to compute the MDP. This function considers every combination of num_lines from the input sample_lines. It must be smaller or equal to the number of input lines sample_lines.

max_distancefloat

The maximum allowed distance between an MDP and its constituent lines. If any distance from the MDP to one of its lines is larger than max_distance, the MDP is thrown away. A good starting value would be 0.1 mm for small tracers and/or clean data, or 0.2 mm for larger tracers and/or noisy data.

cutoffslist-like of length 6

A list (or equivalent) of the cutoff distances for every axis, formatted as [x_min, x_max, y_min, y_max, z_min, z_max]. Only the minpoints which fall within these cutoff distances are considered. The default is None, in which case they are automatically computed using pept.tracking.peptml.get_cutoffs.

__init__(num_lines, max_distance, cutoffs=None, append_indices=False)[source]#

Minpoints class constructor.

Parameters
num_linesint

The number of lines in each combination of LoRs used to compute the MDP. This function considers every combination of num_lines from the input sample_lines. It must be smaller or equal to the number of input lines sample_lines.

max_distancefloat

The maximum allowed distance between an MDP and its constituent lines. If any distance from the MDP to one of its lines is larger than max_distance, the MDP is thrown away. A good starting value would be 0.1 mm for small tracers and/or clean data, or 0.2 mm for larger tracers and/or noisy data.

cutoffslist-like of length 6, optional

A list (or equivalent) of the cutoff distances for every axis, formatted as [x_min, x_max, y_min, y_max, z_min, z_max]. Only the minpoints which fall within these cutoff distances are considered. The default is None, in which case they are automatically computed using pept.tracking.peptml.get_cutoffs.

append_indicesbool, default False

If set to True, the indices of the individual LoRs that were used to compute each minpoint are also appended to the returned array.

Raises
TypeError

If line_data is not an instance of pept.LineData.

ValueError

If 2 <= num_lines <= len(sample_lines) is not satisfied.

ValueError

If cutoffs is not a one-dimensional array with values formatted as [min_x, max_x, min_y, max_y, min_z, max_z].

Methods

__init__(num_lines, max_distance[, cutoffs, ...])

Minpoints class constructor.

copy([deep])

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

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

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

fit_sample(sample_lines)

load(filepath)

Load a saved / pickled PEPTObject object from filepath.

save(filepath)

Save a PEPTObject instance as a binary pickle object.

Attributes

append_indices

cutoffs

max_distance

num_lines

copy(deep=True)#

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

fit(line_data, 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")
property num_lines#
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")
property max_distance#
property cutoffs#
property append_indices#
fit_sample(sample_lines)[source]#