pept.tracking.SamplesCondition#
- class pept.tracking.SamplesCondition(*conditions)[source]#
Bases:
Reducer
Select only samples satisfying multiple conditions, given as a string, a function or list thereof; e.g.
Condition("sample_size > 30")
selects all samples with a sample size larger than 30.Filter signature:
PointData -> SamplesCondition.fit_sample -> PointData LineData -> SamplesCondition.fit_sample -> LineData
This is different to a Condition, which selects individual points; for SamplesCondition, each sample will be passed through the conditions.
Conditions can be defined as Python code using the following variables:
sample - this is the full PointData or LineData, e.g. only keep samples with more than 30 points with “len(sample.points) > 30”.
data - this is the raw NumPy array of data wrapped by a PointData or LineData, e.g. only keep samples which have all X coordinates beyond 100 with SamplesCondition(“np.all(data[:, 1] > 100)”).
sample_size - this is a shorthand for the number of data points, e.g. only keep samples with more than 30 points with “sample_size > 30”.
Conditions can also be Python functions:
>>> def high_velocity_filter(sample): >>> return np.all(sample["v"] > 5)
>>> from pept.tracking import SamplesCondition >>> filtered = SamplesCondition(high_velocity_filter).fit(point_data)
Methods
__init__
(*conditions)copy
([deep])Create a deep copy of an instance of this class, including all inner attributes.
fit
(samples)load
(filepath)Load a saved / pickled PEPTObject object from filepath.
save
(filepath)Save a PEPTObject instance as a binary pickle object.
Attributes
- property conditions#
- copy(deep=True)#
Create a deep copy of an instance of this class, including all inner attributes.
- static load(filepath)#
Load a saved / pickled PEPTObject object from filepath.
Most often the full object state was saved using the .save method.
- Parameters
- filepath
filename
orfile
handle
If filepath is a path (rather than file handle), it is relative to where python is called.
- filepath
- 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
- filepath
filename
orfile
handle
If filepath is a path (rather than file handle), it is relative to where python is called.
- filepath
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")