ndv.v1 #
Here to allow access to the original (legacy) version of NDViewer.
Warning
This module should not be used for new code. It will be removed in a future release.
Classes:
-
DataWrapper
–Interface for wrapping different array-like data types.
-
NDViewer
–A viewer for ND arrays.
Functions:
-
imshow
–Display an array or DataWrapper in a new NDViewer window.
DataWrapper #
DataWrapper(data: ArrayT)
Bases: Generic[ArrayT]
Interface for wrapping different array-like data types.
DataWrapper.create
is a factory method that returns a DataWrapper instance for the given data type. If your datastore type is not supported, you may implement a new DataWrapper subclass to handle your data type. To do this, import and subclass DataWrapper, and (minimally) implement the supports and isel methods. Ensure that your class is imported before the DataWrapper.create method is called, and it will be automatically detected and used to wrap your data.
Methods:
-
guess_channel_axis
–Return the (best guess) axis name for the channel dimension.
-
isel
–Select a slice from a data store using (possibly) named indices.
-
isel_async
–Asynchronous version of isel.
-
sizes
–Return a mapping of {dimkey: size} for the data.
-
summary_info
–Return info label with information about the data.
-
supports
–Return True if this wrapper can handle the given object.
Source code in ndv/v1/_old_data_wrapper.py
102 103 |
|
guess_channel_axis #
guess_channel_axis() -> Any | None
Return the (best guess) axis name for the channel dimension.
Source code in ndv/v1/_old_data_wrapper.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
isel abstractmethod
#
isel(indexers: Indices) -> ndarray
Select a slice from a data store using (possibly) named indices.
This follows the xarray-style indexing, where indexers is a mapping of dimension names to indices or slices. Subclasses should implement this method to return a numpy array.
Source code in ndv/v1/_old_data_wrapper.py
119 120 121 122 123 124 125 126 127 |
|
isel_async #
Asynchronous version of isel.
Source code in ndv/v1/_old_data_wrapper.py
129 130 131 132 133 |
|
sizes #
sizes() -> Sizes
Return a mapping of {dimkey: size} for the data.
The default implementation uses the shape attribute of the data, and tries to find dimension names in the dims
, names
, or labels
attributes. (dims
is used by xarray, names
is used by torch, etc...). If no labels are found, the dimensions are just named by their integer index.
Source code in ndv/v1/_old_data_wrapper.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
summary_info #
summary_info() -> str
Return info label with information about the data.
Source code in ndv/v1/_old_data_wrapper.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
supports abstractmethod
classmethod
#
Return True if this wrapper can handle the given object.
Any exceptions raised by this method will be suppressed, so it is safe to directly import necessary dependencies without a try/except block.
Source code in ndv/v1/_old_data_wrapper.py
109 110 111 112 113 114 115 116 117 |
|
NDViewer #
NDViewer(
data: DataWrapper | Any | None = None,
*,
colormaps: Iterable[ColorStopsLike] | None = None,
parent: QWidget | None = None,
channel_axis: DimKey | None = None,
channel_mode: ChannelMode | str = MONO,
)
Bases: QWidget
A viewer for ND arrays.
This widget displays a single slice from an ND array (or a composite of slices in different colormaps). The widget provides sliders to select the slice to display, and buttons to control the display mode of the channels.
An important concept in this widget is the "index". The index is a mapping of dimensions to integers or slices that define the slice of the data to display. For example, a numpy slice of [0, 1, 5:10]
would be represented as {0: 0, 1: 1, 2: slice(5, 10)}
, but dimensions can also be named, e.g. {'t': 0, 'c': 1, 'z': slice(5, 10)}
. The index is used to select the data from the datastore, and to determine the position of the sliders.
The flow of data is as follows:
- The user sets the data using the
set_data
method. This will set the number and range of the sliders to the shape of the data, and display the first slice. - The user can then use the sliders to select the slice to display. The current slice is defined as a
Mapping
of{dim -> int|slice}
and can be retrieved with the_dims_sliders.value()
method. To programmatically set the current position, use thesetIndex
method. This will set the values of the sliders, which in turn will trigger the display of the new slice via the_update_data_for_index
method. _update_data_for_index
is an asynchronous method that retrieves the data for the given index from the datastore (using_isel
) and queues the_on_data_slice_ready
method to be called when the data is ready. The logic for extracting data from the datastore is defined in_data_wrapper.py
, which handles idiosyncrasies of different datastores (e.g. xarray, tensorstore, etc)._on_data_slice_ready
is called when the data is ready, and updates the image. Note that if the slice is multidimensional, the data will be reduced to 2D using max intensity projection (and double-clicking on any given dimension slider will turn it into a range slider allowing a projection to be made over that dimension).- The image is displayed on the canvas, which is an object that implements the
PCanvas
protocol (mostly, it has anadd_image
method that returns a handle to the added image that can be used to update the data and display). This small abstraction allows for various backends to be used (e.g. vispy, pygfx, etc).
Parameters:
-
data
#Any
, default:None
) –The data to display. This can be any duck-like ND array, including numpy, dask, xarray, jax, tensorstore, zarr, etc. You can add support for new datastores by subclassing
DataWrapper
and implementing the required methods. SeeDataWrapper
for more information. -
parent
#QWidget
, default:None
) –The parent widget of this widget.
-
channel_axis
#Hashable
, default:None
) –The axis that represents the channels in the data. If not provided, this will be guessed from the data.
-
channel_mode
#ChannelMode
, default:MONO
) –The initial mode for displaying the channels. If not provided, this will be set to ChannelMode.MONO.
Methods:
-
eventFilter
–Event filter installed on the canvas to handle mouse events.
-
refresh
–Refresh the canvas.
-
set_channel_mode
–Set the mode for displaying the channels.
-
set_current_index
–Set the index of the displayed image.
-
set_data
–Set the datastore, and, optionally, the sizes of the data.
-
set_ndim
–Set the number of dimensions to display.
-
set_roi
–Set the properties of the ROI overlaid on the displayed data.
-
set_visualized_dims
–Set the dimensions that will be visualized.
Attributes:
-
data
(Any
) –Return the data backing the view.
-
data_wrapper
(DataWrapper | None
) –Return the DataWrapper object around the datastore.
-
dims_sliders
(DimsSliders
) –Return the DimsSliders widget.
Source code in ndv/v1/_old_viewer.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
data_wrapper property
#
data_wrapper: DataWrapper | None
Return the DataWrapper object around the datastore.
eventFilter #
eventFilter(
obj: QObject | None, event: QEvent | None
) -> bool
Event filter installed on the canvas to handle mouse events.
Source code in ndv/v1/_old_viewer.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
|
refresh #
refresh() -> None
Refresh the canvas.
Source code in ndv/v1/_old_viewer.py
420 421 422 423 |
|
set_channel_mode #
Set the mode for displaying the channels.
In "composite" mode, the channels are displayed as a composite image, using self._channel_axis as the channel axis. In "grayscale" mode, each channel is displayed separately. (If mode is None, the current value of the channel_mode_picker button is used)
Parameters:
-
mode
#ChannelMode | str | None
, default:None
) –The mode to set, must be one of 'composite' or 'mono'.
Source code in ndv/v1/_old_viewer.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
set_current_index #
set_current_index(index: Indices | None = None) -> None
Set the index of the displayed image.
index
is a mapping of dimensions to integers or slices that define the slice of the data to display. For example, a numpy slice of [0, 1, 5:10]
would be represented as {0: 0, 1: 1, 2: slice(5, 10)}
, but dimensions can also be named, e.g. {'t': 0, 'c': 1, 'z': slice(5, 10)}
if the data has named dimensions.
Note, calling .set_current_index()
with no arguments will force the widget to redraw the current slice.
Source code in ndv/v1/_old_viewer.py
425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
set_data #
set_data(
data: DataWrapper | Any,
*,
initial_index: Indices | None = None,
) -> None
Set the datastore, and, optionally, the sizes of the data.
Properties
data : DataWrapper | Any The data to display. This can be any duck-like ND array, including numpy, dask, xarray, jax, tensorstore, zarr, etc. You can add support for new datastores by subclassing DataWrapper
and implementing the required methods. If a DataWrapper
instance is passed, it is used directly. See DataWrapper
for more information. initial_index : Indices | None The initial index to display. This is a mapping of dimensions to integers or slices that define the slice of the data to display. If not provided, the initial index will be set to the middle of the data.
Source code in ndv/v1/_old_viewer.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
set_ndim #
set_ndim(ndim: Literal[2, 3]) -> None
Set the number of dimensions to display.
Source code in ndv/v1/_old_viewer.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
set_roi #
set_roi(
vertices: list[tuple[float, float]] | None = None,
color: Any = None,
border_color: Any = None,
) -> None
Set the properties of the ROI overlaid on the displayed data.
Properties
vertices : list[tuple[float, float]] | None The vertices of the ROI. color : str, tuple, list, array, Color, or int The fill color. Can be any "ColorLike". border_color : str, tuple, list, array, Color, or int The border color. Can be any "ColorLike".
Source code in ndv/v1/_old_viewer.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
set_visualized_dims #
set_visualized_dims(dims: Iterable[DimKey]) -> None
Set the dimensions that will be visualized.
This dims will NOT have sliders associated with them.
Source code in ndv/v1/_old_viewer.py
355 356 357 358 359 360 361 362 363 364 |
|
imshow #
imshow(
data: Any | DataWrapper,
cmap: Any | None = None,
*,
channel_mode: Literal[
"mono", "composite", "auto"
] = "auto",
) -> NDViewer
Display an array or DataWrapper in a new NDViewer window.
Parameters:
-
data
#Any | DataWrapper
) –The data to be displayed. If not a DataWrapper, it will be wrapped in one.
-
cmap
#Any | None
, default:None
) –The colormap(s) to use for displaying the data.
-
channel_mode
#Literal['mono', 'composite']
, default:'auto'
) –The initial mode for displaying the channels. By default "mono" will be used unless a cmap is provided, in which case "composite" will be used.
Returns:
-
NDViewer
–The viewer window.
Source code in ndv/v1/_util.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|