Skip to content

Commit

Permalink
Merge pull request #317 from imagej/trackmate-import
Browse files Browse the repository at this point in the history
Better TrackMate presence checks
  • Loading branch information
gselzer authored Dec 4, 2024
2 parents de75079 + e2eb31f commit b1d2b99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/napari_imagej/readers/trackMate_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def napari_get_reader(path):
if not path.endswith(".xml"):
return None

# Determine whether TrackMate available
if not trackmate_present():
return None

# Ensure that the xml file is a TrackMate file
if not ET.parse(path).getroot().tag == "TrackMate":
return None

# Ensure TrackMate available
if not trackmate_present():
return None

# otherwise we return the *function* that can read ``path``.
return reader_function

Expand Down
28 changes: 11 additions & 17 deletions src/napari_imagej/types/converters/trackmate.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
from os import listdir
from os.path import isdir, join
from re import match

from functools import lru_cache
import numpy as np
from napari.layers import Labels, Tracks
from scyjava import JavaClasses, Priority

from napari_imagej import nij, settings
from napari_imagej import nij
from napari_imagej.java import NijJavaClasses
from napari_imagej.types.converters import java_to_py_converter


@lru_cache
def trackmate_present():
"""
Returns True iff TrackMate is on the classpath
Returns True iff TrackMate is on the classpath. Starts the JVM
"""
# Check the endpoint - this way, we can check before the JVM is running
endpoint = settings.endpoint().lower()
# Step 1 - check the endpoint string
if "sc.fiji:trackmate" in endpoint or "sc.fiji:fiji" in endpoint:
return True
# Step 2 - check the jar directory
elif isdir(join(endpoint, "jars")):
for fname in listdir(join(endpoint, "jars")):
if match("TrackMate-\d.*\.jar", fname): # noqa
return True
return False
try:
# Start the JVM
nij.ij
# Try to import the class
return jc.TrackMate is not None
except Exception:
return False


def track_overlay_predicate(obj):
Expand Down

0 comments on commit b1d2b99

Please sign in to comment.