ndv #
Fast and flexible n-dimensional data viewer.
Modules:
-
controllers–Controllers are the primary public interfaces that wrap models & views.
-
data–Sample data for testing and examples.
-
models–Models for
ndv. -
util–Utility and convenience functions.
-
views–Wrappers around GUI & graphics frameworks.
Classes:
-
ArrayViewer–Viewer dedicated to displaying a single n-dimensional array.
-
DataWrapper–Interface for wrapping different array-like data types.
Functions:
-
call_later–Call
funcaftermsecmilliseconds. -
imshow–Display an array or DataWrapper in a new
ArrayViewerwindow. -
process_events–Force processing of events for the application.
-
run_app–Start the active GUI application event loop.
-
set_canvas_backend–Sets the preferred canvas backend. Cannot be set after the GUI is running.
-
set_gui_backend–Sets the preferred GUI backend. Cannot be set after the GUI is running.
ArrayViewer #
ArrayViewer(
data: Any | DataWrapper = None,
/,
*,
viewer_options: ArrayViewerModel
| ArrayViewerModelKwargs
| None = None,
display_model: ArrayDisplayModel | None = None,
**kwargs: Unpack[ArrayDisplayModelKwargs],
)
Viewer dedicated to displaying a single n-dimensional array.
This wraps a model and sview into a single object, and defines the public API.
See also
ndv.imshow - a convenience function that constructs and shows an ArrayViewer.
Future plans
In the future, ndv would like to support multiple, layered data sources with coordinate transforms. We reserve the name Viewer for a more fully featured viewer. ArrayViewer assumes you're viewing a single array.
Parameters:
-
(data#DataWrapper | Any, default:None) –Data to be displayed.
-
(display_model#ArrayDisplayModel, default:None) –Just the display model to use. If provided,
data_or_modelmust be an array orDataWrapper... and kwargs will be ignored. -
(**kwargs#Unpack[ArrayDisplayModelKwargs], default:{}) –Keyword arguments to pass to the
ArrayDisplayModelconstructor. Ifdisplay_modelis provided, these will be ignored.
Methods:
-
clone–Return a new ArrayViewer instance with the same data and display model.
-
close–Close the viewer.
-
hide–Hide the viewer.
-
show–Show the viewer.
-
widget–Return the native front-end widget.
Attributes:
-
data(Any) –Return data being displayed.
-
data_wrapper(Any) –Return data being displayed.
-
display_model(ArrayDisplayModel) –Return the current ArrayDisplayModel.
-
roi(RectangularROIModel | None) –Return ROI being displayed.
Source code in src/ndv/controllers/_array_viewer.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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 128 129 130 131 | |
display_model property writable #
display_model: ArrayDisplayModel
Return the current ArrayDisplayModel.
clone #
clone() -> ArrayViewer
Return a new ArrayViewer instance with the same data and display model.
Currently, this is a shallow copy. Modifying one viewer will affect the state of the other.
Source code in src/ndv/controllers/_array_viewer.py
229 230 231 232 233 234 235 236 237 238 | |
close #
close() -> None
Close the viewer.
Source code in src/ndv/controllers/_array_viewer.py
225 226 227 | |
hide #
hide() -> None
Hide the viewer.
Source code in src/ndv/controllers/_array_viewer.py
221 222 223 | |
show #
show() -> None
Show the viewer.
Source code in src/ndv/controllers/_array_viewer.py
217 218 219 | |
widget #
widget() -> Any
Return the native front-end widget.
Warning
If you directly manipulate the frontend widget, you're on your own . No guarantees can be made about synchronization with the model. It is exposed for embedding in an application, and for experimentation and custom use cases. Please open an issue if you have questions.
Source code in src/ndv/controllers/_array_viewer.py
135 136 137 138 139 140 141 142 143 144 145 146 | |
DataWrapper #
DataWrapper(data: 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.
This base class provides basic support for numpy-like array types. If the data supports getitem and shape attributes, it will work. If the data does not support getitem, the subclass MUST implement the isel method. If the data does not have a shape attribute, the subclass MUST implement the dims and coords properties.
Methods:
-
clear_cache–Clear any cached properties.
-
create–Create a DataWrapper instance for the given data.
-
guess_channel_axis–Return the (best guess) axis name for the channel dimension.
-
guess_z_axis–Return the (best guess) axis name for the z (3rd spatial) dimension.
-
isel–Return a slice of the data as a numpy array.
-
normalize_axis_key–Return positive index for
axis(which can be +/- int or str label). -
sizes–Return the sizes of the dimensions.
-
summary_info–Return info label with information about the data.
-
supports–Return True if this wrapper can handle the given object.
Attributes:
-
axis_map(Mapping[Hashable, int]) –Mapping of ALL valid axis keys to normalized, positive integer keys.
-
coords(Mapping[Hashable, Sequence]) –Return the coordinates for the data.
-
data(ArrayT) –Return the data being wrapped.
-
data_changed–Signal emitted when the data changes.
-
dims(tuple[Hashable, ...]) –Return the dimension labels for the data.
-
dims_changed–Signal to emit when the dimensions of the data change.
-
dtype(dtype) –Return the dtype for the data.
Source code in src/ndv/models/_data_wrapper.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
axis_map cached property #
Mapping of ALL valid axis keys to normalized, positive integer keys.
data_changed class-attribute instance-attribute #
data_changed = Signal()
Signal emitted when the data changes.
NOTE: It is up to data wrappers, or even end-users to emit this signal when the data object changes. We do not currently use object proxies to spy on mutation of the underlying data.
dims_changed class-attribute instance-attribute #
dims_changed = Signal()
Signal to emit when the dimensions of the data change.
NOTE: It is up to data wrappers, or even end-users to emit this signal when the dimensions/shape of the wrapped _data object changes.
clear_cache #
clear_cache() -> None
Clear any cached properties.
Source code in src/ndv/models/_data_wrapper.py
315 316 317 318 | |
create classmethod #
create(data: ArrayT) -> DataWrapper[ArrayT]
Create a DataWrapper instance for the given data.
This method will detect all subclasses of DataWrapper and check them in order of their PRIORITY class variable. The first subclass that supports the given data will be used to wrap it.
Tip
This means that you can subclass DataWrapper to handle new data types. Just make sure that your subclass is imported before calling create.
If no subclasses support the data, a NotImplementedError is raised.
If an instance of DataWrapper is passed in, it will be returned as-is.
Source code in src/ndv/models/_data_wrapper.py
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 | |
guess_channel_axis #
guess_channel_axis() -> Hashable | None
Return the (best guess) axis name for the channel dimension.
Source code in src/ndv/models/_data_wrapper.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
guess_z_axis #
guess_z_axis() -> Hashable | None
Return the (best guess) axis name for the z (3rd spatial) dimension.
Source code in src/ndv/models/_data_wrapper.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
isel #
Return a slice of the data as a numpy array.
index will look like (e.g.) {0: slice(0, 10), 1: 5}. The default implementation converts the index to a tuple of the same length as the self.dims, populating missing keys with slice(None), and then slices the data array using getitem.
Source code in src/ndv/models/_data_wrapper.py
147 148 149 150 151 152 153 154 155 156 157 158 159 | |
normalize_axis_key #
Return positive index for axis (which can be +/- int or str label).
Source code in src/ndv/models/_data_wrapper.py
303 304 305 306 307 308 309 310 311 312 313 | |
sizes #
Return the sizes of the dimensions.
Source code in src/ndv/models/_data_wrapper.py
233 234 235 | |
summary_info #
summary_info() -> str
Return info label with information about the data.
Source code in src/ndv/models/_data_wrapper.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
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 src/ndv/models/_data_wrapper.py
120 121 122 123 124 125 126 127 | |
call_later #
Call func after msec milliseconds.
This can be used to enqueue a function to be called after the current event loop iteration. For example, before calling run_app(), to ensure that the event loop is running before the function is called.
Parameters:
-
(msec#int) –The number of milliseconds to wait before calling
func. -
(func#Callable[[], None]) –The function to call.
Source code in src/ndv/views/_app.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
imshow #
imshow(
data: Any | DataWrapper,
/,
*,
viewer_options: ArrayViewerModel
| ArrayViewerModelKwargs
| None = ...,
display_model: ArrayDisplayModel = ...,
) -> ArrayViewer
imshow(
data: Any | DataWrapper,
/,
*,
viewer_options: ArrayViewerModel
| ArrayViewerModelKwargs
| None = ...,
**display_kwargs: Unpack[ArrayDisplayModelKwargs],
) -> ArrayViewer
imshow(
data: Any | DataWrapper,
/,
*,
viewer_options: ArrayViewerModel
| ArrayViewerModelKwargs
| None = None,
display_model: ArrayDisplayModel | None = None,
**display_kwargs: Unpack[ArrayDisplayModelKwargs],
) -> ArrayViewer
Display an array or DataWrapper in a new ArrayViewer window.
This convenience function creates an ArrayViewer instance populated with data, calls show() on it, and then runs the application.
Parameters:
-
(data#Any | DataWrapper) –The data to be displayed. Any ArrayLike object or an
ndv.DataWrapper. -
(display_model#ArrayDisplayModel | None, default:None) –The display model to use. If not provided, a new one will be created.
-
(viewer_options#ArrayViewerModel | ArrayViewerModelKwargs | None, default:None) –Either a
ArrayViewerModelor a dictionary of keyword arguments used to create one. See docs forArrayViewerModelfor options. -
(**display_kwargs#Unpack[ArrayDisplayModelKwargs], default:{}) –Additional keyword arguments used to create the
ArrayDisplayModel. (Generally, this is used instead of passing adisplay_modeldirectly.)
Returns:
-
ArrayViewer–The
ArrayViewerinstance.
Source code in src/ndv/util.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
process_events #
process_events() -> None
Force processing of events for the application.
Source code in src/ndv/views/_app.py
342 343 344 | |
run_app #
run_app() -> None
Start the active GUI application event loop.
Source code in src/ndv/views/_app.py
347 348 349 | |
set_canvas_backend #
set_canvas_backend(
backend: Literal["pygfx", "vispy"] | None = None,
) -> None
Sets the preferred canvas backend. Cannot be set after the GUI is running.
Source code in src/ndv/views/_app.py
227 228 229 230 231 232 233 234 | |
set_gui_backend #
set_gui_backend(
backend: Literal["jupyter", "qt", "wx"] | None = None,
) -> None
Sets the preferred GUI backend. Cannot be set after the GUI is running.
Source code in src/ndv/views/_app.py
237 238 239 240 241 242 243 244 | |