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:
-
imshow
–Display an array or DataWrapper in a new
ArrayViewer
window. -
run_app
–Start the active GUI application event loop.
ArrayViewer #
ArrayViewer(
data: Any | DataWrapper = 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_model
must be an array orDataWrapper
... and kwargs will be ignored. -
**kwargs
#Unpack[ArrayDisplayModelKwargs]
, default:{}
) –Keyword arguments to pass to the
ArrayDisplayModel
constructor. Ifdisplay_model
is 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
56 57 58 59 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 |
|
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
212 213 214 215 216 217 218 219 220 221 |
|
close #
close() -> None
Close the viewer.
Source code in src/ndv/controllers/_array_viewer.py
208 209 210 |
|
hide #
hide() -> None
Hide the viewer.
Source code in src/ndv/controllers/_array_viewer.py
204 205 206 |
|
show #
show() -> None
Show the viewer.
Source code in src/ndv/controllers/_array_viewer.py
200 201 202 |
|
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
129 130 131 132 133 134 135 136 137 138 139 140 |
|
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.
-
dims
(tuple[Hashable, ...]
) –Return the dimension labels for the data.
-
dtype
(dtype
) –Return the dtype for the data.
Source code in src/ndv/models/_data_wrapper.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
axis_map cached
property
#
Mapping of ALL valid axis keys to normalized, positive integer keys.
clear_cache #
clear_cache() -> None
Clear any cached properties.
Source code in src/ndv/models/_data_wrapper.py
288 289 290 291 |
|
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
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 |
|
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
215 216 217 218 219 220 221 222 223 224 225 226 |
|
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
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
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
122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
normalize_axis_key #
Return positive index for axis
(which can be +/- int or str label).
Source code in src/ndv/models/_data_wrapper.py
276 277 278 279 280 281 282 283 284 285 286 |
|
sizes #
Return the sizes of the dimensions.
Source code in src/ndv/models/_data_wrapper.py
208 209 210 |
|
summary_info #
summary_info() -> str
Return info label with information about the data.
Source code in src/ndv/models/_data_wrapper.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
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
100 101 102 103 104 105 106 107 |
|
imshow #
imshow(
data: Any | DataWrapper,
/,
display_model: ArrayDisplayModel = ...,
) -> ArrayViewer
imshow(
data: Any | DataWrapper,
/,
**kwargs: Unpack[ArrayDisplayModelKwargs],
) -> ArrayViewer
imshow(
data: Any | DataWrapper,
/,
display_model: ArrayDisplayModel | None = None,
**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.
-
kwargs
#Unpack[ArrayDisplayModelKwargs]
, default:{}
) –Additional keyword arguments used to create the
ArrayDisplayModel
.
Returns:
-
ArrayViewer
–The
ArrayViewer
instance.
Source code in src/ndv/util.py
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 53 54 55 |
|
run_app #
run_app() -> None
Start the active GUI application event loop.
Source code in src/ndv/views/_app.py
312 313 314 |
|