pept.tracking.Reorient#
- class pept.tracking.Reorient(dimensions='xyz', basis=None, origin=None)[source]#
Bases:
Reducer
Rotate a dataset such that it is oriented according to its principal axes.
Reducer signature:
PointData -> Reorient.fit -> PointData list[PointData] -> Reorient.fit -> PointData np.ndarray -> Reorient.fit -> PointData
By default, this reducer reorients the points such that the axis along which it is most spread out (e.g. lengthwise in a pipe) becomes the X-axis. The input argument dimensions sets this - the default “xyz” can be changed to e.g. “zyx” so that the longest data axis becomes the Z-axis.
The reducer also sets three attributes on the returned PointData: - origin: the origin relative to which the initial data was rotated. - basis: the principal components - or change of basis 3x3 matrix. - eigenvalues: how spread out the data is in each initial dimension.
If you’d like to reorient a second dataset to the same basis as a first one, set the basis and origin arguments.
New in pept-0.5.0
Examples
Reorient a dataset by aligning the longest principal component (e.g. lengthwise in a pipe) to the X-axis:
>>> import pept.tracking as pt >>> data = PointData(...) >>> reoriented = pt.Reorient().fit(data)
Reorient it such that the longest principal component (e.g. vertical in a mixer) becomes the Z-axis:
>>> reoriented = pt.Reorient("zyx").fit(data)
Reorient a second dataset to the same orientation basis as the first one:
>>> reoriented2 = pt.Reorient( >>> basis = reoriented.attrs["basis"], >>> origin = reoriented.attrs["origin"], >>> ).fit(other_data)
Methods
__init__
([dimensions, basis, origin])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.
- 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")