- navis.xform(x, transform, affine_fallback=True, caching=True)¶
Apply transform(s) to data.
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
.unitsand node/soma radii. This works reasonably well with base 10 increments (e.g. nm -> um) but is off with odd changes in units.
x (Neuron/List | Volume/Trimesh | numpy.ndarray | pandas.DataFrame) – Data to transform. Dataframe must contain
['x', 'y', 'z']columns. Numpy array must be shape
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
True, 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 footprint
True= higher upfront cost, most definitely faster
Only applies if input is NeuronList and if transforms include H5 transform.
Copy of input with transformed coordinates.
- Return type:
same type as
>>> 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)
Higher level function that finds and applies a sequence of transforms to go from one template brain to another.