Skip to content

Commit

Permalink
use hash instead of expecting the ID to be integer
Browse files Browse the repository at this point in the history
  • Loading branch information
uermel committed Aug 29, 2024
1 parent ce940d2 commit 0c1c380
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/napari_cryoet_data_portal/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@

def _annotation_color(annotation: Annotation) -> np.ndarray:
"""Maps an annotation to a color based on its object_id."""
try:
object_id = int(annotation.object_id.split(":")[-1])
except RuntimeError as e:
logger.error("Failed to parse integer from object_id: %s\%s", annotation.object_id, e)
return DEFAULT_OBJECT_COLOR
color = OBJECT_COLORMAP(object_id % len(OBJECT_COLORMAP.color_stops))
object_id = annotation.object_id.split(":")[-1]
color = OBJECT_COLORMAP(hash(object_id) % len(OBJECT_COLORMAP.color_stops))
return np.array(color.rgba)


Expand Down

0 comments on commit 0c1c380

Please sign in to comment.