Skip to content

Commit

Permalink
Catch errors & provide default colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
jluethi committed Jul 23, 2024
1 parent b50e8a0 commit e5c9e51
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/napari_feature_visualization/feature_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ def get_feature_choices(*args):
except OSError:
return [""]
else:
df = pd.DataFrame(widget.label_layer.value.properties)
return list(df.columns)
try:
df = pd.DataFrame(widget.label_layer.value.properties)
return list(df.columns)
except AttributeError:
return [""]

# set feature and label_column "default choices"
# to be a function that gets the column names of the
Expand Down Expand Up @@ -70,7 +73,10 @@ def switch_feature_load_mode(event):
@widget.feature.changed.connect
def update_rescaling(event):
if widget.load_features_from.value == "CSV File":
df = get_df(widget.DataFrame.value)
if widget.DataFrame.value != pathlib.Path("."):
df = get_df(widget.DataFrame.value)
else:
df = pd.DataFrame()
else:
df = pd.DataFrame(widget.label_layer.value.properties)

Expand Down Expand Up @@ -144,6 +150,7 @@ def feature_vis(
label_properties = {feature: np.round(properties_array, decimals=2)}

colormap = dict(zip(site_df["label"], colors))
colormap[None] = [0.0, 0.0, 0.0, 0.0]
# If in napari >= 0.4.19, use DirectLabelColormap
try:
from napari.utils.colormaps import DirectLabelColormap
Expand Down

0 comments on commit e5c9e51

Please sign in to comment.