forked from haesleinhuepf/napari-skimage-regionprops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added function for loading CSV files into label layer properties
- Loading branch information
1 parent
cfb2c11
commit 80ed208
Showing
2 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
from ._table import add_table, get_table, TableWidget | ||
from ._regionprops import regionprops, regionprops_table, regionprops_table_all_frames | ||
from ._parametric_images import visualize_measurement_on_labels | ||
from napari_plugin_engine import napari_hook_implementation | ||
from ._load_csv import load_csv | ||
|
||
try: | ||
from ._version import version as __version__ | ||
except ImportError: | ||
__version__ = "0.4.1" | ||
|
||
from napari_plugin_engine import napari_hook_implementation | ||
|
||
|
||
@napari_hook_implementation | ||
def napari_experimental_provide_function(): | ||
return [regionprops_table, visualize_measurement_on_labels] | ||
return [regionprops_table, visualize_measurement_on_labels, load_csv] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import napari | ||
import numpy as np | ||
from napari_tools_menu import register_function | ||
|
||
@register_function(menu="Measurement > Load from CSV (nsr)") | ||
def load_csv(csv_filename:"magicgui.types.PathLike", labels_layer:napari.layers.Labels, viewer:napari.Viewer=None): | ||
"""Save contents of a CSV file into a given layer's properties""" | ||
import pandas as pd | ||
# load region properties from csv file | ||
reg_props = pd.read_csv(csv_filename) | ||
try: | ||
edited_reg_props = reg_props.drop(["Unnamed: 0"], axis=1) | ||
except KeyError: | ||
edited_reg_props = reg_props | ||
|
||
if "label" not in edited_reg_props.keys().tolist(): | ||
label_column = pd.DataFrame( | ||
{"label": np.array(range(1, (len(edited_reg_props) + 1)))} | ||
) | ||
edited_reg_props = pd.concat([label_column, edited_reg_props], axis=1) | ||
|
||
if hasattr(labels_layer, "properties"): | ||
labels_layer.properties = edited_reg_props | ||
if hasattr(labels_layer, "features"): | ||
labels_layer.features = edited_reg_props | ||
|
||
from ._table import add_table | ||
add_table(labels_layer, viewer) |