use of uk.ac.sussex.gdsc.smlm.results.TraceManager 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));
}
use of uk.ac.sussex.gdsc.smlm.results.TraceManager in project GDSC-SMLM by aherbert.
the class BlinkEstimator method calculateCounts.
/**
* Calculate the counts of molecules using different dark times. The distance threshold for
* molecule tracing will be absolute or relative. If relative it is set using the average
* precision multiplied by the search distance.
*
* <p>Note that index 0 corresponds to a t-threshold of 1 in the tracing algorithm, i.e. adjacent
* frames in the sequence. This is equivalent to a dark time of (up to) the frame acquisition
* rate, i.e. the molecule is not allowed to blink.
*
* @param results the results
* @param maxDarkTimeSetting the max dark time
* @param searchDistanceSetting the search distance
* @param relativeDistanceSetting the relative distance
* @param verbose Output log messages
* @return the counts of molecules
*/
private double[] calculateCounts(MemoryPeakResults results, int maxDarkTimeSetting, double searchDistanceSetting, boolean relativeDistanceSetting, boolean verbose) {
double distanceThreshold;
if (relativeDistanceSetting) {
final double averagePrecision = calculateAveragePrecision(results, verbose);
distanceThreshold = averagePrecision * searchDistanceSetting / results.getNmPerPixel();
if (verbose) {
ImageJUtils.log("Average precision = %f, Distance threshold = %f px", averagePrecision, distanceThreshold);
}
} else {
distanceThreshold = searchDistanceSetting;
ImageJUtils.log("Distance threshold = %f px", distanceThreshold);
}
final double[] ntd = new double[maxDarkTimeSetting + 1];
final TraceManager tm = new TraceManager(results);
IJ.showStatus("Computing counts ...");
for (int td = 0; td <= maxDarkTimeSetting; td++) {
IJ.showProgress(td, maxDarkTimeSetting);
ntd[td] = tm.traceMolecules(distanceThreshold, td + 1);
}
ImageJUtils.finished();
return ntd;
}
use of uk.ac.sussex.gdsc.smlm.results.TraceManager in project GDSC-SMLM by aherbert.
the class TraceFilter method setup.
@Override
public void setup(MemoryPeakResults peakResults) {
ok = new HashSet<>();
// Trace molecules. Anything that is part of a trace is OK
final TraceManager tm = new TraceManager(peakResults);
tm.traceMolecules(d, t);
final Trace[] traces = tm.getTraces();
for (final Trace trace : traces) {
if (trace.size() > 1) {
for (int i = 0; i < trace.size(); i++) {
ok.add(trace.get(i));
}
}
}
}
Aggregations