Skip to content

axis ¤

Classes:

Name Description
Axis
AxisDescrLike
AxisInfo

Attributes:

Name Type Description
AxisId

An axis identifier, e.g. 'batch', 'channel', 'z', 'y', 'x'

AxisLetter
AxisLike
BatchSize
PerAxis
S
T

AxisLetter module-attribute ¤

AxisLetter = Literal['b', 'i', 't', 'c', 'z', 'y', 'x']

AxisLike module-attribute ¤

AxisLike = Union[_AxisLikePlain, AxisDescrLike, v0_5.AnyAxis, 'Axis']

BatchSize module-attribute ¤

BatchSize = int

S module-attribute ¤

S = TypeVar('S', bound=str)

T module-attribute ¤

T = TypeVar('T')

Axis dataclass ¤

Axis(id: AxisId, type: Literal['batch', 'channel', 'index', 'space', 'time'])

Methods:

Name Description
__post_init__
create

Attributes:

Name Type Description
id AxisId
type Literal['batch', 'channel', 'index', 'space', 'time']

id instance-attribute ¤

id: AxisId

type instance-attribute ¤

type: Literal['batch', 'channel', 'index', 'space', 'time']

__post_init__ ¤

__post_init__()
Source code in src/bioimageio/core/axis.py
61
62
63
64
65
def __post_init__(self):
    if self.type == "batch":
        self.id = AxisId("batch")
    elif self.type == "channel":
        self.id = AxisId("channel")

create classmethod ¤

create(axis: AxisLike) -> Axis
Source code in src/bioimageio/core/axis.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@classmethod
def create(cls, axis: AxisLike) -> Axis:
    if isinstance(axis, cls):
        return axis

    if isinstance(axis, (AxisId, str)):
        axis_id = axis
        axis_type = _guess_axis_type(str(axis))
    else:
        if hasattr(axis, "type"):
            axis_type = axis.type
        else:
            axis_type = _guess_axis_type(str(axis))

        if hasattr(axis, "id"):
            axis_id = axis.id
        else:
            axis_id = axis

    return Axis(id=AxisId(axis_id), type=axis_type)

AxisDescrLike ¤

Bases: Protocol


              flowchart TD
              bioimageio.core.axis.AxisDescrLike[AxisDescrLike]

              

              click bioimageio.core.axis.AxisDescrLike href "" "bioimageio.core.axis.AxisDescrLike"
            

Attributes:

Name Type Description
id _AxisLikePlain
type Literal['batch', 'channel', 'index', 'space', 'time']

id instance-attribute ¤

id: _AxisLikePlain

type instance-attribute ¤

type: Literal['batch', 'channel', 'index', 'space', 'time']

AxisInfo dataclass ¤

AxisInfo(id: AxisId, type: Literal['batch', 'channel', 'index', 'space', 'time'], maybe_singleton: bool)

Bases: Axis


              flowchart TD
              bioimageio.core.axis.AxisInfo[AxisInfo]
              bioimageio.core.axis.Axis[Axis]

                              bioimageio.core.axis.Axis --> bioimageio.core.axis.AxisInfo
                


              click bioimageio.core.axis.AxisInfo href "" "bioimageio.core.axis.AxisInfo"
              click bioimageio.core.axis.Axis href "" "bioimageio.core.axis.Axis"
            

Methods:

Name Description
__post_init__
create

Attributes:

Name Type Description
id AxisId
maybe_singleton bool
type Literal['batch', 'channel', 'index', 'space', 'time']

id instance-attribute ¤

id: AxisId

maybe_singleton instance-attribute ¤

maybe_singleton: bool

type instance-attribute ¤

type: Literal['batch', 'channel', 'index', 'space', 'time']

__post_init__ ¤

__post_init__()
Source code in src/bioimageio/core/axis.py
61
62
63
64
65
def __post_init__(self):
    if self.type == "batch":
        self.id = AxisId("batch")
    elif self.type == "channel":
        self.id = AxisId("channel")

create classmethod ¤

create(axis: AxisLike, maybe_singleton: Optional[bool] = None) -> AxisInfo
Source code in src/bioimageio/core/axis.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@classmethod
def create(cls, axis: AxisLike, maybe_singleton: Optional[bool] = None) -> AxisInfo:
    if isinstance(axis, AxisInfo):
        return axis

    axis_base = super().create(axis)
    if maybe_singleton is None:
        if not isinstance(axis, v0_5.AxisBase):
            maybe_singleton = True
        else:
            if axis.size is None:
                maybe_singleton = True
            elif isinstance(axis.size, int):
                maybe_singleton = axis.size == 1
            elif isinstance(axis.size, v0_5.SizeReference):
                maybe_singleton = (
                    True  # TODO: check if singleton is ok for a `SizeReference`
                )
            elif isinstance(
                axis.size, (v0_5.ParameterizedSize, v0_5.DataDependentSize)
            ):
                try:
                    maybe_size_one = axis.size.validate_size(
                        1
                    )  # TODO: refactor validate_size() to have boolean func here
                except ValueError:
                    maybe_singleton = False
                else:
                    maybe_singleton = maybe_size_one == 1
            else:
                assert_never(axis.size)

    return AxisInfo(
        id=axis_base.id, type=axis_base.type, maybe_singleton=maybe_singleton
    )