15
15
from ._reducer import ReducerType
16
16
17
17
if TYPE_CHECKING :
18
- from collections .abc import Mapping
18
+ from collections .abc import Hashable , Mapping # noqa: F401
19
+ from typing import Callable # noqa: F401
19
20
20
21
import cmap
22
+ import numpy .typing as npt # noqa: F401 # used for mkdocstrings
21
23
22
24
from ._lut_model import AutoscaleType
23
25
24
26
class LutModelKwargs (TypedDict , total = False ):
27
+ """Keyword arguments for `LUTModel`."""
28
+
25
29
visible : bool
26
30
cmap : cmap .Colormap | cmap ._colormap .ColorStopsLike
27
31
clims : tuple [float , float ] | None
28
32
gamma : float
29
33
autoscale : AutoscaleType
30
34
31
35
class ArrayDisplayModelKwargs (TypedDict , total = False ):
36
+ """Keyword arguments for `ArrayDisplayModel`."""
37
+
32
38
visible_axes : tuple [AxisKey , AxisKey , AxisKey ] | tuple [AxisKey , AxisKey ]
33
39
current_index : Mapping [AxisKey , Union [int , slice ]]
34
40
channel_mode : "ChannelMode" | Literal ["grayscale" , "composite" , "color" , "rgba" ]
@@ -106,40 +112,50 @@ def is_multichannel(self) -> bool:
106
112
class ArrayDisplayModel (NDVModel ):
107
113
"""Model of how to display an array.
108
114
109
- In the following types, `AxisKey` can be either an integer index or a string label.
115
+ An `ArrayDisplayModel` is used to specify how to display a multi-dimensional array.
116
+ It specifies which axes are visible, how to reduce along axes that are not visible,
117
+ how to display channels, and how to apply lookup tables to channels. It is
118
+ typically paired with a [`ndv.DataWrapper`][] in order to resolve axis keys and
119
+ slice data.
120
+
121
+ !!! info
122
+
123
+ In the following types, `Hashable` is used to refer to a type that will
124
+ typically be either an integer index or a string label for an axis.
110
125
111
126
Attributes
112
127
----------
113
- visible_axes : tuple[AxisKey , ...]
128
+ visible_axes : tuple[Hashable , ...]
114
129
Ordered list of axes to visualize, from slowest to fastest.
115
- e.g. ('z ', -2, -1)
116
- current_index : Mapping[AxisKey , int | Slice ]
130
+ e.g. `('Z ', -2, -1)`
131
+ current_index : Mapping[Hashable , int | slice ]
117
132
The currently displayed position/slice along each dimension.
118
133
e.g. {0: 0, 'time': slice(10, 20)}
119
134
Not all axes need be present, and axes not present are assumed to
120
135
be slice(None), meaning it is up to the controller of this model to restrict
121
136
indices to an efficient range for retrieval.
122
137
If the number of non-singleton axes is greater than `n_visible_axes`,
123
- then reducers are used to reduce the data along the remaining axes.
124
- NOTE: In terms of requesting data, there is a slight "delocalization" of state
125
- here in that we probably also want to avoid requesting data for channel
126
- positions that are not visible.
127
- reducers : Mapping[AxisKey | None, ReducerType]
128
- Callable to reduce data along axes remaining after slicing.
138
+ then `reducers` are used to reduce the data along the remaining axes.
139
+ reducers : Mapping[Hashable | None, numpy.ufunc]
140
+ Function used to reduce data along axes remaining after slicing.
129
141
Ideally, the ufunc should accept an `axis` argument.
130
- (TODO: what happens if not?)
142
+ *(TODO: what happens if not?)*
143
+ default_reducer : numpy.ufunc
144
+ Default reducer to use when no reducer is specified for an axis. By default,
145
+ this is [`numpy.max`][].
131
146
channel_mode : ChannelMode
132
147
How to display channel information:
133
- - `GRAYSCALE`: ignore channel axis, use `default_lut`
134
- - `COMPOSITE`: display all channels as a composite image, using `luts`
135
- - `COLOR`: display a single channel at a time, using `luts`
136
- - `RGBA`: display as an RGB image, using `default_lut` (except for cmap)
148
+
149
+ - `GRAYSCALE`: ignore channel axis, use `default_lut`
150
+ - `COMPOSITE`: display all channels as a composite image, using `luts`
151
+ - `COLOR`: display a single channel at a time, using `luts`
152
+ - `RGBA`: display as an RGB image, using `default_lut` (except for cmap)
137
153
138
154
If `channel_mode` is set to anything other than `GRAYSCALE`, then `channel_axis`
139
155
must be set to a valid axis; if no `channel_axis` is set, at the time of
140
- display, the `DataWrapper` MAY guess the `channel_axis`, and set it on the
141
- model.
142
- channel_axis : AxisKey | None
156
+ display, the [ `DataWrapper`][ndv.DataWrapper] MAY guess the `channel_axis`,
157
+ and set it on the model.
158
+ channel_axis : Hashable | None
143
159
The dimension index or name of the channel dimension.
144
160
The implication of setting channel_axis is that *all* elements along the channel
145
161
dimension are shown, with different LUTs applied to each channel.
@@ -151,18 +167,24 @@ class ArrayDisplayModel(NDVModel):
151
167
Values are `LUT` objects that specify how to display the channel.
152
168
The special key `None` is used to represent a fallback LUT for all channels,
153
169
and is used when `channel_axis` is None. It should always be present
170
+ default_lut : LUTModel
171
+ Default lookup table to use when no `LUTModel` is specified for a channel in
172
+ `luts`.
154
173
"""
155
174
156
175
visible_axes : TwoOrThreeAxisTuple = (- 2 , - 1 )
176
+ # NOTE: In terms of requesting data, there is a slight "delocalization" of state
177
+ # here in that we probably also want to avoid requesting data for channel
178
+ # positions that are not visible.
157
179
current_index : IndexMap = Field (default_factory = IndexMap , frozen = True )
158
180
159
- channel_mode : ChannelMode = ChannelMode .GRAYSCALE
160
- channel_axis : Optional [AxisKey ] = None
161
-
162
181
# map of axis to reducer (function that can reduce dimensionality along that axis)
163
182
reducers : Reducers = Field (default_factory = Reducers , frozen = True )
164
183
default_reducer : ReducerType = "numpy.max" # type: ignore [assignment] # FIXME
165
184
185
+ channel_mode : ChannelMode = ChannelMode .GRAYSCALE
186
+ channel_axis : Optional [AxisKey ] = None
187
+
166
188
# map of index along channel axis to LUTModel object
167
189
luts : LutMap = Field (default_factory = _default_luts )
168
190
default_lut : LUTModel = Field (default_factory = LUTModel , frozen = True )
0 commit comments