Skip to content

Commit e0470f8

Browse files
committed
Make template scripts aware of stream mode
1 parent 0a63c99 commit e0470f8

15 files changed

Lines changed: 209 additions & 79 deletions

‎src/main/java/sc/fiji/snt/SNTService.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ public boolean isActive() {
129129
return SNTUtils.getInstance() != null;
130130
}
131131

132+
/**
133+
* Gets whether SNT is currently running in Stream mode ("SNT Stream"), i.e., tethered to a
134+
* streamed dataset (N5/OME-Zarr/IMS/BDV-XML) via the Big Data Loader, with no in-core
135+
* {@code ImagePlus}/classic canvas available. Several script-facing APIs (ImagePlus-based
136+
* snapshots, ROI-based inputs, {@code SNT#rebuildDisplayCanvases()}, etc.) are not available
137+
* in this mode. Scripts can use this method to detect that and abort/adapt early.
138+
*
139+
* @return true if SNT is active and running in Stream mode; false otherwise (including when
140+
* SNT is not running, or is running without a GUI)
141+
*/
142+
public boolean isStreamMode() {
143+
final SNT instance = SNTUtils.getInstance();
144+
return instance != null && instance.getUI() != null && instance.getUI().isStreamMode();
145+
}
146+
132147
/**
133148
* Assigns pixel intensities at each Path node, storing them as Path values.
134149
* Assigned intensities are those of the channel and time point currently being

‎src/main/resources/script_templates/Neuroanatomy/Spines_and_Varicosities/Peripath_Detection_Demo.groovy‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* file: Peripath_Detection_Demo.groovy
33
* author: Tiago Ferreira
4-
* version: 2026.04.09
4+
* version: 2026.07.31
55
* info: Demonstrates the PeripathDetector workflow: automated detection of
66
* intensity maxima (spines, varicosities, puncta) around traced paths.
77
*
@@ -21,12 +21,21 @@
2121
#@ SNTService snt
2222

2323
// Ensure SNT is up-to-date and is not busy with another operation
24-
snt.requireVersion("5.0.7")
25-
if (snt.isActive() && snt.getUI() && !snt.getUI().isReady()) {
24+
snt.requireVersion("5.0.14")
25+
if (snt.isActive() && snt.getUI() && !snt.isStreamMode() && !snt.getUI().isReady()) {
2626
print("Please complete current operation before running this script!")
2727
return
2828
}
2929

30+
// This demo re-initializes SNT with its own classic (in-core) demo image, which would
31+
// replace/reconfigure an existing Stream ("SNT Stream") session
32+
if (snt.isStreamMode()) {
33+
snt.getUI().error("This demo requires re-initializing SNT with a classic (non-streamed) "
34+
+ "image, which would replace the current Stream-mode session. Please switch to "
35+
+ "Standard mode to run it.")
36+
return
37+
}
38+
3039
// 1) Load a demo image. We'll use CIL:810: it is a cultured hippocampal
3140
// neuron with 3 channels: Ch1: N-caherin; Ch2: V-glut; Ch3: NMDAR. We'll
3241
// detect V-glut puncta (Ch2) around a traced dendrite traced from Ch1

‎src/main/resources/script_templates/Neuroanatomy/Spines_and_Varicosities/Spacing_Analysis.groovy‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* file: Spacing_Analysis.groovy
33
* author: Tiago Ferreira
4-
* version: 2026.04.21
4+
* version: 2026.07.31
55
* info: Demonstrates how to compute geodesic (along-the-path) distances
66
* between consecutive detections from PeripathDetector. The script
77
* detects intensity maxima (varicosities, synaptic puncta, etc.)
@@ -24,8 +24,8 @@
2424
#@ SNTService snt
2525

2626
// Ensure SNT is up-to-date and is not busy with another operation
27-
snt.requireVersion("5.0.7")
28-
if (snt.isActive() && snt.getUI() && !snt.getUI().isReady()) {
27+
snt.requireVersion("5.0.14")
28+
if (snt.isActive() && snt.getUI() && !snt.isStreamMode() && !snt.getUI().isReady()) {
2929
print("Please complete current operation before running this script!")
3030
return
3131
}
@@ -39,6 +39,15 @@ def getImageAndPaths(fileImg, fileTree) {
3939
for (tree in Tree.listFromFile(fileTree.getAbsolutePath()))
4040
paths.addAll(tree.list())
4141
} else {
42+
// The demo re-initializes SNT with its own classic (in-core) image, which would
43+
// replace/reconfigure an existing Stream ("SNT Stream") session, which is unexpected
44+
if (snt.isStreamMode()) {
45+
snt.getUI().error("The demo image requires re-initializing SNT with a classic "
46+
+ "(non-streamed) image, which would replace the current Stream-mode "
47+
+ "session. Please supply your own image/reconstruction files above, or "
48+
+ "switch to Standard mode to run the demo.")
49+
return Tuple.tuple(null, null)
50+
}
4251
// demo mode: CIL:810 hippocampal neuron (Ch1: N-cadherin; Ch2: V-glut; Ch3: NMDAR)
4352
// see Peripath_Detection_Demo.groovy template script
4453
imp = snt.demoImage("cil810")
@@ -54,6 +63,9 @@ def getImageAndPaths(fileImg, fileTree) {
5463
}
5564

5665
(imp, paths) = getImageAndPaths(imageFile, tracesFile)
66+
if (imp == null || paths == null) {
67+
return
68+
}
5769

5870
// 2) Fit radii. PeripathDetector uses per-node radii to define the search
5971
// annulus. Without fitted radii, a fallback (2x voxel size) is used

0 commit comments

Comments
 (0)