pept.tracking.OptimizeWindow#

class pept.tracking.OptimizeWindow(ideal_elems, overlap=0.0, low=0.3, high=3)[source]#

Bases: Reducer

Automatically determine optimum adaptive time window to have an ideal number of elements per sample.

Reducer signature:

       LineData -> OptimizeWindow.fit -> LineData
 list[LineData] -> OptimizeWindow.fit -> LineData
      PointData -> OptimizeWindow.fit -> PointData
list[PointData] -> OptimizeWindow.fit -> PointData
  numpy.ndarray -> OptimizeWindow.fit -> PointData

The adaptive time window approach combines the advantages of fixed sample sizes and time windowing:

  • Time windows are robust to tracers moving in and out of the field of view, as they simply ignore the time slices where almost no LoRs are recorded.

  • Fixed sample sizes effectively adapt their spatio-temporal resolution, allowing for higher accuracy when tracers are passing through more active scanner regions.

All samples with more than ideal_elems are shortened, such that time windows are shrinked when the tracer activity permits. There exists an ideal time window such that most samples will have roughly ideal_elems, with a few higher activity ones that are shortened; OptimizeWindow finds this ideal time window for pept.AdaptiveWindow.

New in pept-0.5.1

Examples

Find an adaptive time window that is ideal for about 200 LoRs per sample:

>>> import pept
>>> import pept.tracking as pt
>>> lors = pept.LineData(...)
>>> lors = pt.OptimizeWindow(ideal_elems = 200).fit(lors)

OptimizeWindow can be used at the start of a pipeline; an optional overlap parameter can be used to define an overlap as a ratio to the ideal time window found. For example, if the ideal time window found is 100 ms, an overlap of 0.5 will result in an overlapping time interval of 50 ms:

>>> pipeline = pept.Pipeline([
>>>     pt.OptimizeWindow(200, overlap = 0.5),
>>>     pt.BirminghamMethod(0.5),
>>>     pt.Stack(),
>>> ])
__init__(ideal_elems, overlap=0.0, low=0.3, high=3)[source]#

Methods

__init__(ideal_elems[, overlap, low, high])

copy([deep])

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

evaluate(window)

fit(data)

load(filepath)

Load a saved / pickled PEPTObject object from filepath.

save(filepath)

Save a PEPTObject instance as a binary pickle object.

copy(deep=True)#

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

fit(data)[source]#
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")
evaluate(window)[source]#