navis.xform¶
- navis.xform(x, transform, affine_fallback=True, caching=True)[source]¶
Apply transform(s) to data.
Notes
For Neurons only: whether there is a change in units during transformation (e.g. nm -> um) is inferred by comparing distances between x/y/z coordinates before and after transform. This guesstimate is then used to convert
.units
and node/soma radii. This works reasonably well with base 10 increments (e.g. nm -> um) but is off with odd changes in units.- Parameters:
x (Neuron/List | Volume/Trimesh | numpy.ndarray | pandas.DataFrame) – Data to transform. Dataframe must contain
['x', 'y', 'z']
columns. Numpy array must be shape(N, 3)
.transform (Transform/Sequence or list thereof) – Either a single transform or a transform sequence.
affine_fallback (bool) – In same cases the non-rigid transformation of points can fail - for example if points are outside the deformation field. If that happens, they will be returned as
NaN
. Unlessaffine_fallback
isTrue
, in which case we will apply only the rigid affine part of the transformation to at least get close to the correct coordinates.caching (bool) –
If True, will (pre-)cache data for transforms whenever possible. Depending on the data and the type of transforms this can tremendously speed things up at the cost of increased memory usage:
False
= no upfront cost, lower memory footprintTrue
= higher upfront cost, most definitely faster
Only applies if input is NeuronList and if transforms include H5 transform.
- Returns:
Copy of input with transformed coordinates.
- Return type:
same type as
x
Examples
>>> import navis >>> # Example neurons are in 8nm voxel space >>> nl = navis.example_neurons() >>> # Make a simple Affine transform to go from voxel to nanometers >>> import numpy as np >>> M = np.diag([8, 8, 8, 8]) >>> tr = navis.transforms.AffineTransform(M) >>> # Apply the transform >>> xf = navis.xform(nl, tr)
See also
navis.xform_brain()
Higher level function that finds and applies a sequence of transforms to go from one template brain to another.