Skip to content

Commit

Permalink
Modernize scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tferr committed Oct 28, 2024
1 parent 7cc98cf commit 043acd6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
9 changes: 6 additions & 3 deletions src/main/java/sc/fiji/snt/analysis/TreeStatistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,18 @@ public static List<String> getAllMetrics() {
* Gets a subset of supported metrics.
*
* @param type the type. Either 'legacy' (metrics supported up to SNTv4.0.5),
* "safe" (metrics that can be computed from invalid graphs) or
* 'common' (commonly used metrics) or 'quick' (used by the 'quick
* measure' GUI commands).
* "safe" (metrics that can be computed from invalid graphs),
* 'common' (commonly used metrics), 'quick' (used by the 'quick
* measure' GUI commands), or 'all' (shortcut to {@link #getAllMetrics()})
* @return the list metrics
*/
public static List<String> getMetrics(final String type) {
// We could use Arrays.asList() here but that would make list immutable
String[] metrics;
switch (type) {
case "all":
measure(getAllMetrics(), true);
return getAllMetrics();
case "legacy":
// Historical metrics up to SNTv4.0.10
metrics = new String[] { BRANCH_LENGTH, CONTRACTION, REMOTE_BIF_ANGLES, PARTITION_ASYMMETRY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.scijava.command.ContextCommand;
import org.scijava.plugin.Parameter;

import ij.IJ;
import ij.ImagePlus;
import ij.gui.Line;
import ij.gui.Roi;
Expand All @@ -42,6 +41,7 @@
import sc.fiji.snt.SNTUtils;
import sc.fiji.snt.analysis.sholl.Profile;
import sc.fiji.snt.analysis.sholl.ShollUtils;
import sc.fiji.snt.util.ColorMaps;
import sc.fiji.snt.util.ShollPoint;

/**
Expand Down Expand Up @@ -378,7 +378,7 @@ public ImagePlus getMask() {
getMaskProcessor(false, profile.countsAsArray()));
img.setCalibration(cal);
try {
IJ.run(img, "mpl-inferno", "");
ColorMaps.applyPlasma(img, 100, false);
} catch (final Exception ignored) {
// do nothing ...
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* disks in 3D along an axon.
*/

import net.imglib2.Point;
import net.imglib2.util.LinAlgHelpers;
import net.imglib2.algorithm.region.hypersphere.HyperSphere;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.Point
import net.imglib2.util.LinAlgHelpers
import net.imglib2.algorithm.region.hypersphere.HyperSphere
import net.imglib2.img.display.imagej.ImageJFunctions
import sc.fiji.snt.*
import sc.fiji.snt.analysis.*
import sc.fiji.snt.analysis.graph.*
Expand All @@ -21,8 +21,8 @@ import sc.fiji.snt.io.*
import sc.fiji.snt.plugin.*
import sc.fiji.snt.util.*
import sc.fiji.snt.viewer.*
import ij3d.Image3DUniverse;
import org.scijava.vecmath.Color3f;
import ij3d.Image3DUniverse
import org.jogamp.vecmath.Color3f

// Documentation Resources: https://imagej.net/plugins/snt/scripting
// Latest SNT API: https://javadoc.scijava.org/SNT/
Expand Down Expand Up @@ -76,4 +76,5 @@ def main()
univ.addVoltex(imp, new Color3f(0,255,0), "OP_1", 25, new boolean[] {true, true, true}, 1);
}

main();
main()
return null // suppress unsupported output `ij3d.Content` warning
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def error():


shell_width = 10
imp = IJ.getImage()
overlay = imp.getOverlay()
raster_shells = []
imp = IJ.getImage()

if imp and overlay:
if imp and imp.getOverlay():
overlay = imp.getOverlay()
for i in range(overlay.size()):
roi = overlay.get(i)
if roi.getName() and "Shell" in roi.getName():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
#@File(label="Input file:", description="Reconstruction file (.traces, .swc, json) to be analyzed") input_file
#@String(label="Restrict to :", choices={"Axon", "Dendrites", "All processes"}) subtree_choice
#@File(label="Input file (leave empty for demo):", required="false", description="Reconstruction file (.traces, .swc, json) to be analyzed. A folder of files is also supported.") input_file
#@String(label="Restrict to :", choices={"All processes", "Axon", "Dendrites"}) subtree_choice
#@ImageJ ij
#@SNTService snt


"""
file: Strahler_Analysis.py
author: Tiago Ferreira
version: 20220110
info: Performs Strahler Analysis on a single reconstruction file.
info: Performs Strahler Analysis on a single reconstruction file(s).
See Batch>Strahler_Bulk_Analysis for a batch processing alternative.
"""

from sc.fiji.snt import Tree
from sc.fiji.snt.plugin import StrahlerCmd
import os.path


def main():
def getTrees():
global subtree_choice, input_file

# A single file may contain more than one cell, so by default,
# we'll assume it contains a collection of Trees
# return a demo reconstruction if input_file is empty:
if not str(input_file) or not os.path.isfile(str(input_file)):
subtree_choice = "All"
return [snt.demoTree("pyramidal")]
# A single file may contain more than one cell, so we'll
# assume input_file may contain a collection of Trees
trees = Tree.listFromFile(input_file.getAbsolutePath())
if not trees or trees.isEmpty():
ij.ui().showDialog("File did not contain a valid reconstruction.", "Error")
return trees


def main():

trees = getTrees()
if not trees:
ij.ui().showDialog("File did not contain valid reconstruction(s).", "Error")
return
else:
msg = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# @Context context

"""
file: Filter_Multiple_Images.py
author: Tiago Ferreira, Cameron Arshadi
file: Filter_Multiple_Images.py
author: Tiago Ferreira, Cameron Arshadi
version: 20190525
info: Bulk filtering of image files using Frangi Vesselness
info: Bulk filtering of image files using Frangi Vesselness
"""

import os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
file: Monitor_Memory.groovy
info: Runs IJ's built in Memory Monitor. Double click for gc
"""
new ij.plugin.frame.MemoryMonitor()
new ij.plugin.frame.MemoryMonitor()
return null // suppress 'ignoring unsupported output' warning

0 comments on commit 043acd6

Please sign in to comment.