Skip to content

brainhops.datamodel.axes

Axes of a coordinate system, such as a spatial or a time axis.

Attributes

R module-attribute

A left-to-right anatomical axis (coordinates increase toward the right).

LR module-attribute

A left-to-right anatomical axis (coordinates increase toward the right).

L module-attribute

A right-to-left anatomical axis (coordinates increase toward the left).

RL module-attribute

A right-to-left anatomical axis (coordinates increase toward the left).

A module-attribute

A posterior-to-anterior anatomical axis (increasing toward the front).

PA module-attribute

A posterior-to-anterior anatomical axis (increasing toward the front).

P module-attribute

An anterior-to-posterior anatomical axis (increasing toward the back).

AP module-attribute

An anterior-to-posterior anatomical axis (increasing toward the back).

S module-attribute

An inferior-to-superior anatomical axis (increasing toward the top).

IS module-attribute

An inferior-to-superior anatomical axis (increasing toward the top).

I module-attribute

A superior-to-inferior anatomical axis (increasing toward the bottom).

SI module-attribute

A superior-to-inferior anatomical axis (increasing toward the bottom).

Classes

Axis magic

Axis(
    name: str | bytes | None = None,
    type: AxisType | str | bytes | None = None,
    unit: Unit | None = None,
    discrete: bool | int | str | None = None,
    orientation: Orientation | None = None,
)

Bases: DataModelBase

One axis of a coordinate system or of a grid.

An axis names its type, such as "space" or "time", and may carry a unit, an orientation, and whether it is discrete.

Each field that is None is unknown. A plain Axis(), whose fields are all None, is an axis about which nothing is known. It is the placeholder that fills a position no description covers. An instance of a subclass that sets a field, such as a SpaceAxis, whose type is "space", is not unknown -- although its unit, which it leaves unspecified by default, is.

Equality (==) is strict: two axes are equal when they are of the same class and every field is equal. compatible_with is the looser question of whether two descriptions could be of the same axis.

Fields

Field Type Default Notes
name str \| None None converted
type brainhops.datamodel.enums.AxisType \| str \| None None converted
unit brainhops.datamodel.units.Unit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.Orientation \| None None converted

Attributes

name class-attribute instance-attribute
name: str | None = None

The name of the axis, such as "x" or "y".

type class-attribute instance-attribute
type: AxisType | str | None = None

The type of the axis, such as "space" or "time".

unit class-attribute instance-attribute
unit: Unit | None = None

The unit in which coordinates are measured along the axis.

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

orientation class-attribute instance-attribute
orientation: Orientation | None = None

The orientation of the axis, if it has one.

This is useful to indicate that the direction of coordinates along the axis has a particular meaning, such as "left-to-right" for an anatomical axis.

Methods:

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

SpaceAxis magic

SpaceAxis(
    name: str | bytes | None = None,
    type: Literal[space] = "space",
    unit: SpaceUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: Orientation | None = None,
)

Bases: Axis

An axis that measures a spatial dimension.

Its unit is a unit of space, an index unit (the axis indexes an array), or unspecified (None, the default). Any other unit is refused by the type of the field. The unit is not what an axis is selected on, so Axis(type="space", unit="s") builds a SpaceAxis, which refuses the second, rather than quietly falling back to a generic Axis.

Fields

Field Type Default Notes
name str \| None None converted
type Literal['space'] 'space' converted
unit brainhops.datamodel.units.SpaceUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.Orientation \| None None converted

Attributes

name class-attribute instance-attribute
name: str | None = None

The name of the axis, such as "x" or "y".

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

orientation class-attribute instance-attribute
orientation: Orientation | None = None

The orientation of the axis, if it has one.

This is useful to indicate that the direction of coordinates along the axis has a particular meaning, such as "left-to-right" for an anatomical axis.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

TimeAxis magic

TimeAxis(
    name: str | bytes | None = None,
    type: Literal[time] = "time",
    unit: TimeUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: Orientation | None = None,
)

Bases: Axis

An axis that measures time.

Its unit is a unit of time, an index unit (the axis indexes an array), or unspecified (None, the default). Any other unit is refused.

Fields

Field Type Default Notes
name str \| None None converted
type Literal['time'] 'time' converted
unit brainhops.datamodel.units.TimeUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.Orientation \| None None converted

Attributes

name class-attribute instance-attribute
name: str | None = None

The name of the axis, such as "x" or "y".

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

orientation class-attribute instance-attribute
orientation: Orientation | None = None

The orientation of the axis, if it has one.

This is useful to indicate that the direction of coordinates along the axis has a particular meaning, such as "left-to-right" for an anatomical axis.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

ChannelAxis magic

ChannelAxis(
    name: str | bytes | None = None,
    type: Literal[channel] = "channel",
    unit: Unit | None = None,
    discrete: bool | int | str | None = None,
    orientation: Orientation | None = None,
)

Bases: Axis

An axis that enumerates channels, such as color or feature channels.

Fields

Field Type Default Notes
name str \| None None converted
type Literal['channel'] 'channel' converted
unit brainhops.datamodel.units.Unit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.Orientation \| None None converted

Attributes

name class-attribute instance-attribute
name: str | None = None

The name of the axis, such as "x" or "y".

unit class-attribute instance-attribute
unit: Unit | None = None

The unit in which coordinates are measured along the axis.

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

orientation class-attribute instance-attribute
orientation: Orientation | None = None

The orientation of the axis, if it has one.

This is useful to indicate that the direction of coordinates along the axis has a particular meaning, such as "left-to-right" for an anatomical axis.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

DisplacementAxis magic

DisplacementAxis(
    name: str | bytes | None = None,
    type: Literal[displacement] = "displacement",
    unit: Unit | None = None,
    discrete: bool | int | str | None = None,
    orientation: Orientation | None = None,
)

Bases: Axis

An axis that carries the components of a displacement vector.

A field of displacements names its spatial axes together with exactly one axis of this type. That axis enumerates the displacement components stored at each grid point.

Fields

Field Type Default Notes
name str \| None None converted
type Literal['displacement'] 'displacement' converted
unit brainhops.datamodel.units.Unit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.Orientation \| None None converted

Attributes

name class-attribute instance-attribute
name: str | None = None

The name of the axis, such as "x" or "y".

unit class-attribute instance-attribute
unit: Unit | None = None

The unit in which coordinates are measured along the axis.

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

orientation class-attribute instance-attribute
orientation: Orientation | None = None

The orientation of the axis, if it has one.

This is useful to indicate that the direction of coordinates along the axis has a particular meaning, such as "left-to-right" for an anatomical axis.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

CoordinateAxis magic

CoordinateAxis(
    name: str | bytes | None = None,
    type: Literal[coordinate] = "coordinate",
    unit: Unit | None = None,
    discrete: bool | int | str | None = None,
    orientation: Orientation | None = None,
)

Bases: Axis

An axis that carries the components of a coordinate vector.

A field of coordinates names its spatial axes together with exactly one axis of this type. That axis enumerates the coordinate components stored at each grid point.

Fields

Field Type Default Notes
name str \| None None converted
type Literal['coordinate'] 'coordinate' converted
unit brainhops.datamodel.units.Unit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.Orientation \| None None converted

Attributes

name class-attribute instance-attribute
name: str | None = None

The name of the axis, such as "x" or "y".

unit class-attribute instance-attribute
unit: Unit | None = None

The unit in which coordinates are measured along the axis.

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

orientation class-attribute instance-attribute
orientation: Orientation | None = None

The orientation of the axis, if it has one.

This is useful to indicate that the direction of coordinates along the axis has a particular meaning, such as "left-to-right" for an anatomical axis.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

LeftToRightAxis magic

LeftToRightAxis(
    name: str | bytes = "left-to-right",
    type: Literal[space] = "space",
    unit: SpaceUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: LeftToRight = LeftToRight(),
)

Bases: AnatomicalAxis

A spatial axis oriented from left to right.

Fields

Field Type Default Notes
name str 'left-to-right' converted
type Literal['space'] 'space' converted, validated
unit brainhops.datamodel.units.SpaceUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.LeftToRight LeftToRight() converted

Attributes

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

RightToLeftAxis magic

RightToLeftAxis(
    name: str | bytes = "right-to-left",
    type: Literal[space] = "space",
    unit: SpaceUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: RightToLeft = RightToLeft(),
)

Bases: AnatomicalAxis

A spatial axis oriented from right to left.

Fields

Field Type Default Notes
name str 'right-to-left' converted
type Literal['space'] 'space' converted, validated
unit brainhops.datamodel.units.SpaceUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.RightToLeft RightToLeft() converted

Attributes

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

AnteriorToPosteriorAxis magic

AnteriorToPosteriorAxis(
    name: str | bytes = "anterior-to-posterior",
    type: Literal[space] = "space",
    unit: SpaceUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: AnteriorToPosterior = AnteriorToPosterior(),
)

Bases: AnatomicalAxis

A spatial axis oriented from anterior to posterior.

Fields

Field Type Default Notes
name str 'anterior-to-posterior' converted
type Literal['space'] 'space' converted, validated
unit brainhops.datamodel.units.SpaceUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.AnteriorToPosterior AnteriorToPosterior() converted

Attributes

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

PosteriorToAnteriorAxis magic

PosteriorToAnteriorAxis(
    name: str | bytes = "posterior-to-anterior",
    type: Literal[space] = "space",
    unit: SpaceUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: PosteriorToAnterior = PosteriorToAnterior(),
)

Bases: AnatomicalAxis

A spatial axis oriented from posterior to anterior.

Fields

Field Type Default Notes
name str 'posterior-to-anterior' converted
type Literal['space'] 'space' converted, validated
unit brainhops.datamodel.units.SpaceUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.PosteriorToAnterior PosteriorToAnterior() converted

Attributes

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

InferiorToSuperiorAxis magic

InferiorToSuperiorAxis(
    name: str | bytes = "inferior-to-superior",
    type: Literal[space] = "space",
    unit: SpaceUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: InferiorToSuperior = InferiorToSuperior(),
)

Bases: AnatomicalAxis

A spatial axis oriented from inferior to superior.

Fields

Field Type Default Notes
name str 'inferior-to-superior' converted
type Literal['space'] 'space' converted, validated
unit brainhops.datamodel.units.SpaceUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.InferiorToSuperior InferiorToSuperior() converted

Attributes

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

SuperiorToInferiorAxis magic

SuperiorToInferiorAxis(
    name: str | bytes = "superior-to-inferior",
    type: Literal[space] = "space",
    unit: SpaceUnit | IndexUnit | None = None,
    discrete: bool | int | str | None = None,
    orientation: SuperiorToInferior = SuperiorToInferior(),
)

Bases: AnatomicalAxis

A spatial axis oriented from superior to inferior.

Fields

Field Type Default Notes
name str 'superior-to-inferior' converted
type Literal['space'] 'space' converted, validated
unit brainhops.datamodel.units.SpaceUnit \| brainhops.datamodel.units.IndexUnit \| None None converted
discrete bool \| None None converted
orientation brainhops.datamodel.orientation.SuperiorToInferior SuperiorToInferior() converted

Attributes

discrete class-attribute instance-attribute
discrete: bool | None = None

Whether the axis is discrete, as opposed to continuous.

Here discrete means that the axis has no particular order, and therefore does not come with a continuous coordinates system.

Methods:

from_dict classmethod
from_dict(other: Mapping, *args, **kwargs) -> Self

Create an instance of the class from a dictionary-like object.

Only keys in the dictionary that match keyword-like fields of this class, or the keywords its constructor takes without storing them (its InitVars, such as the matrix= of an Affine), will be used. Other keys are ignored, but see from_other, which refuses them.

Additional positional and/or keyword arguments can be provided, and will take precedence over the values in the dictionary.

A key naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: a dictionary that sets it to anything other than None or the value of this class is refused with a ValueError.

from_instance classmethod
from_instance(other: Self, *args, **kwargs) -> Self

Create an instance of the class from an instance of a similar class.

Only attributes of the other instance that match keyword-like fields of this class will be used. An attribute that is None is unset, and leaves the default of this class in place.

Additional positional and/or keyword arguments can be provided, and will take precedence over the attributes in the instance.

Unless the other instance is already an instance of this class, an attribute naming a field that this class fixes (a field that cannot be passed to its constructor) is checked instead of used: an instance that sets it to anything other than None or the value of this class is refused with a ValueError. A generic Axis whose orientation is right-to-left, for example, cannot be read as a LeftToRightAxis.

from_other classmethod
from_other(other: Any, *args, **kwargs) -> Self

Create an instance of the class from any object that can be interpreted as a dictionary, or an instance of a similar class, or an arguments to be passed to the constructor.

A similar class is this class or one of its parents within the data model, or another member of a polymorphic family this class belongs to: calling a polymorphic class such as Axis builds the subclass its arguments select, so a "generic" axis is usually an instance of a sibling (a RightToLeftAxis, a TimeAxis) rather than of a parent. Any other object, including an instance of a parent that is not a data model (such as a plain object), is passed to the constructor.

Unlike from_dict, a dictionary with a key that matches no field of this class is refused with a TypeError naming the keys, so that a misspelt key is not silently dropped.

compatible_with
compatible_with(other: Axis) -> bool

Whether self and other could describe the same axis.

Two axes are compatible when every field that is set (not None) on both of them is equal. A field that is None on either side is unknown there, and matches anything. In particular, the unknown Axis() is compatible with every axis.

The relation is symmetric, but it is not transitive: Axis() is compatible with both Axis(name="x") and Axis(name="y"), which are not compatible with each other.

Example

>>> Axis(name="x").compatible_with(Axis(name="x", unit="mm"))
True
>>> Axis(name="x").compatible_with(Axis(name="y"))
False
>>> SpaceAxis(unit="mm").compatible_with(Axis(unit="micrometer"))
False

Parameters:

Name Type Description Default
other Axis

The axis to compare with.

required

Returns:

Type Description
bool

Whether no field is known on both sides with different values.

Raises:

Type Description
TypeError

If other is not an Axis.

merge_with
merge_with(other: Axis) -> Axis

Combine what self and other know about the same axis.

Each field of the result is the value set on either side, or None if neither side sets it. The two axes must be compatible_with: a field that both set must be set to the same value.

The result is an instance of the more derived of the two classes, so merging an Axis with a SpaceAxis gives a SpaceAxis. Merging with the unknown Axis() returns an axis equal to the other side.

Example

>>> Axis(name="x").merge_with(SpaceAxis(unit="micrometer"))
SpaceAxis(name='x', unit='micrometer')
>>> Axis(name="x").merge_with(Axis(name="y"))
Traceback (most recent call last):
  ...
ValueError: Cannot merge axes that disagree on name: 'x' != 'y'.

Parameters:

Name Type Description Default
other Axis

The other description of the same axis.

required

Returns:

Type Description
Axis

A new axis that carries every field known on either side.

Raises:

Type Description
TypeError

If other is not an Axis.

ValueError

If a field is set on both sides to different values, or if neither class derives from the other, so that no class can hold what both sides know.

__repr__ generated
__repr__()

Show the instance as the call that would build it again.

__eq__ generated
__eq__(other)

Compare field by field with another instance of the same class.

AxisError

Bases: ValueError

Raised when a list of axes cannot be read as a vector field.

A vector field names its grid axes together with exactly one vector axis, of type displacement or coordinate. A list that names no vector axis, more than one, or one of each type, is refused with this error.

Functions:

vector_axis

vector_axis(axes: Sequence[Any] | None) -> tuple[str, int]

Return the type and position of the single vector axis of a field.

A vector field lists every grid axis together with exactly one vector axis. The vector axis is either a displacement axis or a coordinate axis, and it carries the components of the vector stored at each grid point. This function returns a pair of the vector axis type, one of "displacement" or "coordinate", and its index in axes.

A list of axes that names no vector axis, more than one vector axis, or both a displacement axis and a coordinate axis, is refused with an AxisError.