A configurable features table widget for Napari.
Project description
Configurable Features Table for Napari
This plugin is similar to Napari's built-in features table widget, but optimized for usage with 2D and 3D Labels layers. It offers extra options to:
- Sort table values.
- Hide or show table columns.
- Colorize
Labelsbased on feature values, with different color maps. - Connect your own callback functions to customize what happens when users click on a table row.
- Connect your own featurizer functions that run automatically when the data in the
Labelschanges and update the displayed table.
The content of the table is a graphical view of the features attribute of a Labels layer.
Displaying the table
Open the table from Plugins > Features Table in Napari.
The table displays features from the currently selected layer in the layers list. It will automatically update when the layer selection changes. If multiple layers are selected, only features from the first selected layer will be displayed.
Connecting featurizer functions
By default, the table displays a label column for the selected Labels layer, along with any pre-existing features that can be matched with the label column (they should be in Pandas DataFrame format with at least a 'label' column).
You can customize the behaviour of the plugin to update features automatically when a new Labels layer is selected, or when its data changes, based on a featurizer function that you provide. Featurizer functions will receive as input the labels layer data as a Numpy array, and should return a Pandas DataFrame with at least a label column, along with any other feature columns.
For example, the following code extends the behaviour of the table to display the area (or volume) of objects:
import napari
import pandas as pd
from skimage.measure import regionprops_table
from napari_label_focus import ConfigurableFeaturesTableWidget
# Write an "area" featurizer
def area_featurizer(labels: np.ndarray) -> pd.DataFrame:
return pd.DataFrame(regionprops_table(labels, properties=["label", "area"]))
if __name__ == "__main__":
viewer = napari.Viewer()
widget = ConfigurableFeaturesTableWidget(viewer, featurizer_functs=[area_featurizer])
viewer.window.add_dock_widget(widget)
napari.run()
If more than one featurizer function is provided, these functions will be run one by one and the results will be merged into a single features DataFrame.
Controlling what clicking on a table row does
By default, clicking on a table row selects the corresponding label in the Labels layer. This behaviour can be extended by adding callback functions to the table_click_callbacks parameter of the table widget. The callback functions receive a selection context object with references to the viewer, selected layer, selected table row, and the table itself.
For example:
import napari
from napari_label_focus import ConfigurableFeaturesTableWidget, SelectionContext
def print_selection_context(ctx: SelectionContext):
print(f"Napari viewer: {ctx.viewer}")
print(f"Selected layer: {ctx.selected_layer}")
print(f"Selected table row: {ctx.selected_table_idx}")
print(f"Features table: {ctx.features_table}")
if __name__ == "__main__":
viewer = napari.Viewer()
widget = ConfigurableFeaturesTableWidget(viewer, table_click_callbacks=[print_selection_context])
viewer.window.add_dock_widget(widget)
napari.run()
In this case, the function print_selection_context gets called whenever users click on a table row.
Installation
You can install napari-label-focus via [pip]:
pip install napari-label-focus
Contributing
Contributions are very welcome.
License
This software is distributed under the terms of the BSD-3 license.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file napari_label_focus-0.2.3.tar.gz.
File metadata
- Download URL: napari_label_focus-0.2.3.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0daab658034455e8eaa473c53e9c5fb4b52610a2c287459f1ec91841e0c6a3b3
|
|
| MD5 |
72901cf043fad2edcd2c106551d23ac2
|
|
| BLAKE2b-256 |
9543f829d4e984af421a830427f63eab45be83da7d0c7830aded9a2290f1b161
|
File details
Details for the file napari_label_focus-0.2.3-py3-none-any.whl.
File metadata
- Download URL: napari_label_focus-0.2.3-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faf164d54d16e3ca640dd76996e4e296cec2fded909dd51600dcf60045b54ce7
|
|
| MD5 |
aac52d02952f36ddbf8c000ac3e54ad1
|
|
| BLAKE2b-256 |
043f7705a6c86ed148c9db1ece854740e4a1ca231f034b029198d070757ceac7
|