Skip to content

spaces

ngtools.spaces

Utilities to manipulate spaces (ng.CoordinateSpace) in neuroglancer.

Functions:

Name Description
convert_space

Convert units of a coordinate space.

normalize_space

Ensure that dimensions have SI units (without prefix).

name_compact2full

Convert a compact axis name ("RAS") to a list of full axis names (["anterior", "posterior", "superior"]).

space_is_compatible

Check whether two standard spaces can map to/from each other.

space_to_name

Get neurospace name from spatial axis names.

Attributes:

Name Type Description
default CoordinateSpace

Default display space ("xyz").

defaultnames list[str]

List of all default orientations ("xyz", "zyx", etc).

defaultspaces dict[str, CoordinateSpace]

Mapping to all neuroglancer standard spaces (xyz, zyx, etc).

letter2full dict[str, str]

Mapping from short to long axis names.

neuronames list[str]

List of all existing neuroimaging orientations ("ras", "lpi", etc).

neurospaces dict[str, CoordinateSpace]

Mapping to all known neuroimaging-oriented spaced (RAS, LPI, etc), as well as all neuroglancer standard spaces (xyz, zyx, etc).

neurotransforms dict[tuple[str, str], CoordinateSpaceTransform]

Mapping to transforms between neuroimaging spaces. The keys are either pairs of str, or pairs of ng.CoordinateSpace instances from the neurospaces dictionary.

name_compact2full

name_compact2full(name)

Convert compact axes name to long list of names.

Examples:

compact2full("ras") -> ["right", "anterior", "posterior"] compact2full("xyz") -> ["x", "y", "z"]

space_is_compatible

space_is_compatible(src, dst)

Check whether two spaces can map to/from each other.

True if both spaces describe the same set of 3 axes.

convert_space

convert_space(space, units='base', *, names=None)

Convert units of a coordinate space.

Example

Ensure that all axes have SI unit (without prefix)

new_space = convert_space(space)
# or
new_space = convert_space(space, "base")
# or
new_space = convert_space(space, ["m", "s", "hz", "rad/s"])
# or
new_space = normalize_space(space)

Ensure that spatial axes have millimeter unit

new_space = convert_space(space, "mm")

Ensure that specific axes have specific unit

new_space = convert_space(space, {"x": "mm", "y": "mm", "t": "ms"})
# or
new_space = convert_space(space, {("x", "y"): "mm", "t": "ms"})
# or
new_space = convert_space(space, {("x", "y", "t"): ["mm", "ms"]})

See also: normalize_space.

Parameters:

Name Type Description Default
space CoordinateSpace

Coordinate space to convert.

required
units str | list[str] | dict[str | tuple[str], str | list[str]]

Output unit(s).

  • If "base", convert all units to their zero-exponent basis ({"m", "s", "hz", "rad/s"}).
  • If a dictionary, it should map axis name(s) to target unit(s).
'base'
names str | list[str] | dict[str, str] | None

Name(s) of axis to convert. If None, all axes that have compatible units. Cannot be used if units is a dictionary.

None

Returns:

Name Type Description
space CoordinateSpace

Converted coordinate space.

normalize_space

normalize_space(space)

Ensure that dimensions have SI units (without prefix).

See also: convert_space.

space_to_name

space_to_name(space, compact=False)

Get spatial axis name from coordinate space.