use of uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing in project GDSC-SMLM by aherbert.
the class TraceDiffusion method createTraceFunction.
/**
* Creates the trace function for the configured trace diffusion mode.
*
* @return the function
*/
private Function<MemoryPeakResults, Trace[]> createTraceFunction() {
if (clusteringSettings.getTraceDiffusionMode() == 1) {
final DmttConfiguration config = createDmttConfiguration();
return r -> new DynamicMultipleTargetTracing(r).traceMolecules(config).toArray(new Trace[0]);
}
// Nearest neighbour
// Convert from NM to the native units of the results
final Converter c = CalibrationHelper.getDistanceConverter(results.getCalibration(), DistanceUnit.NM);
final double distanceThreshold = c.convertBack(clusteringSettings.getDistanceThreshold());
final double distanceExclusion = c.convertBack(clusteringSettings.getDistanceExclusion());
return r -> {
final TraceManager manager = new TraceManager(r);
// Run the tracing
manager.setTracker(SimpleImageJTrackProgress.getInstance());
manager.setDistanceExclusion(distanceExclusion);
manager.traceMolecules(distanceThreshold, 1);
return manager.getTraces();
};
}
use of uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing in project GDSC-SMLM by aherbert.
the class TraceMolecules method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(pluginTitle, "No localisations in memory");
return;
}
altKeyDown = ImageJUtils.isExtraOptions();
Trace[] traces = null;
int totalFiltered = 0;
if ("dynamic".equals(arg)) {
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Dynamic Mutliple Target Tracing
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
outputName = "Dynamic Trace";
if (!showDynamicTraceDialog()) {
return;
}
final DmttConfiguration config = createDmttConfiguration();
traces = new DynamicMultipleTargetTracing(results).traceMolecules(config).toArray(new Trace[0]);
} else if ("cluster".equals(arg)) {
// -=-=-=-=-=
// Clustering
// -=-=-=-=-=
outputName = "Cluster";
if (!showClusterDialog()) {
return;
}
final ClusteringEngine engine = new ClusteringEngine(Prefs.getThreads(), getClusteringAlgorithm(settings.getClusteringAlgorithm()), SimpleImageJTrackProgress.getInstance());
if (settings.getSplitPulses()) {
engine.setPulseInterval(settings.getPulseInterval());
limitTimeThreshold(settings.getPulseInterval());
}
final List<Cluster> clusters = engine.findClusters(convertToClusterPoints(), getDistance(settings.getDistanceThreshold(), results.getCalibration()), timeThresholdInFrames());
if (clusters == null) {
ImageJUtils.log("Aborted");
return;
}
traces = convertToTraces(clusters);
} else {
// -=-=-=-
// Tracing
// -=-=-=-
outputName = "Trace";
if (!showDialog()) {
return;
}
final TraceManager manager = new TraceManager(results);
manager.setTraceMode(getTraceMode(settings.getTraceMode()));
manager.setActivationFrameInterval(settings.getPulseInterval());
manager.setActivationFrameWindow(settings.getPulseWindow());
manager.setDistanceExclusion(getDistance(settings.getDistanceExclusion(), results.getCalibration()));
if (settings.getOptimise()) {
// Optimise before configuring for a pulse interval
runOptimiser(manager);
}
if (settings.getSplitPulses()) {
manager.setPulseInterval(settings.getPulseInterval());
limitTimeThreshold(settings.getPulseInterval());
}
manager.setTracker(SimpleImageJTrackProgress.getInstance());
manager.traceMolecules(getDistance(settings.getDistanceThreshold(), results.getCalibration()), timeThresholdInFrames());
traces = manager.getTraces();
totalFiltered = manager.getTotalFiltered();
}
// --=-=-=-=-=-
// Results processing
// --=-=-=-=-=-
outputName += (outputName.endsWith("e") ? "" : "e") + "d";
saveResults(results, traces, outputName);
// Save singles + single localisations in a trace
saveCentroidResults(results, getSingles(traces), outputName + " Singles");
final Trace[] multiTraces = getTraces(traces);
saveResults(results, multiTraces, outputName + " Multi");
// Save centroids
outputName += " Centroids";
final MemoryPeakResults tracedResults = saveCentroidResults(results, traces, outputName);
// Save traces separately
saveCentroidResults(results, multiTraces, outputName + " Multi");
// Sort traces by time to assist the results source in extracting frames sequentially.
// Do this before saving to assist in debugging using the saved traces file.
sortByTime(traces);
if (settings.getSaveTraces()) {
saveTraces(traces);
}
summarise(createSummaryTable(), traces, totalFiltered, settings.getDistanceThreshold(), timeThresholdInSeconds());
IJ.showStatus(String.format("%d localisations => %d traces (%d filtered)", results.size(), tracedResults.size(), totalFiltered));
}
Aggregations