use of gdsc.smlm.results.TraceManager in project GDSC-SMLM by aherbert.
the class PCPALMMolecules method traceMolecules.
/**
* Trace localisations
*
* @param results
* The results
* @param distance
* The distance threshold (nm)
* @param time
* The time threshold (frames)
* @param singles
* a list of the singles (not grouped into molecules)
* @return a list of molecules
*/
private ArrayList<Molecule> traceMolecules(MemoryPeakResults results, double distance, int time, ArrayList<Molecule> singles) {
TraceManager tm = new TraceManager(results);
double distanceThreshold = distance / results.getNmPerPixel();
tm.traceMolecules(distanceThreshold, time);
Trace[] traces = tm.getTraces();
ArrayList<Molecule> molecules = new ArrayList<Molecule>(traces.length);
final double nmPerPixel = results.getNmPerPixel();
final double gain = results.getGain();
final boolean emCCD = results.isEMCCD();
for (Trace t : traces) {
double p = t.getLocalisationPrecision(nmPerPixel, gain, emCCD);
if (t.size() == 1) {
float[] centroid = t.getCentroid();
singles.add(new Molecule(centroid[0] * nmPerPixel, centroid[1] * nmPerPixel, p, t.getSignal() / gain));
} else {
float[] centroid = t.getCentroid();
molecules.add(new Molecule(centroid[0] * nmPerPixel, centroid[1] * nmPerPixel, p, t.getSignal() / gain));
}
}
log(" %d localisations traced to %d molecules (%d singles, %d traces) using d=%.2f nm, t=%d frames (%s s)", results.size(), molecules.size() + singles.size(), singles.size(), molecules.size(), distance, time, Utils.rounded(time * results.getCalibration().getExposureTime() / 1000.0));
return molecules;
}
use of gdsc.smlm.results.TraceManager in project GDSC-SMLM by aherbert.
the class TraceFilter method setup.
@Override
public void setup(MemoryPeakResults peakResults) {
ok = new HashSet<PeakResult>();
// Trace molecules. Anything that is part of a trace is OK
TraceManager tm = new TraceManager(peakResults);
tm.traceMolecules(d, t);
Trace[] traces = tm.getTraces();
for (Trace trace : traces) {
if (trace.size() > 1) {
for (PeakResult result : trace.getPoints()) {
ok.add(result);
}
}
}
}
use of gdsc.smlm.results.TraceManager in project GDSC-SMLM by aherbert.
the class TraceMolecules method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "No localisations in memory");
return;
}
altKeyDown = Utils.isExtraOptions();
Trace[] traces = null;
int totalFiltered = 0;
if ("cluster".equals(arg)) {
// --=-=-=-=-=-
// Clustering
// --=-=-=-=-=-
outputName = "Cluster";
if (!showClusterDialog())
return;
ClusteringEngine engine = new ClusteringEngine(Prefs.getThreads(), settings.getClusteringAlgorithm(), new IJTrackProgress());
if (settings.splitPulses) {
engine.setPulseInterval(settings.pulseInterval);
if (settings.getTimeUnit() == TimeUnit.FRAME) {
if (settings.getTimeThreshold() > settings.pulseInterval) {
settings.setTimeThreshold(settings.pulseInterval);
}
} else {
if (timeInFrames(settings) > settings.pulseInterval) {
settings.setTimeThreshold(settings.pulseInterval * exposureTime);
}
}
}
ArrayList<Cluster> clusters = engine.findClusters(convertToClusterPoints(), settings.distanceThreshold / results.getCalibration().getNmPerPixel(), timeInFrames(settings));
if (clusters == null) {
Utils.log("Aborted");
return;
}
traces = convertToTraces(clusters);
} else {
// --=-=-=-=-=-
// Tracing
// --=-=-=-=-=-
outputName = "Trace";
if (!showDialog())
return;
TraceManager manager = new TraceManager(results);
manager.setTraceMode(settings.getTraceMode());
manager.setActivationFrameInterval(settings.pulseInterval);
manager.setActivationFrameWindow(settings.pulseWindow);
manager.setDistanceExclusion(settings.distanceExclusion / results.getCalibration().getNmPerPixel());
if (settings.optimise) {
// Optimise before configuring for a pulse interval
runOptimiser(manager);
}
if (settings.splitPulses) {
manager.setPulseInterval(settings.pulseInterval);
if (settings.getTimeUnit() == TimeUnit.FRAME) {
if (settings.getTimeThreshold() > settings.pulseInterval) {
settings.setTimeThreshold(settings.pulseInterval);
}
} else {
if (timeInFrames(settings) > settings.pulseInterval) {
settings.setTimeThreshold(settings.pulseInterval * exposureTime);
}
}
}
manager.setTracker(new IJTrackProgress());
manager.traceMolecules(settings.distanceThreshold / results.getCalibration().getNmPerPixel(), timeInFrames(settings));
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");
Trace[] multiTraces = getTraces(traces);
saveResults(results, multiTraces, outputName + " Multi");
// Save centroids
outputName += " Centroids";
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.saveTraces)
saveTraces(traces);
summarise(traces, totalFiltered, settings.distanceThreshold, timeInSeconds(settings));
IJ.showStatus(String.format("%d localisations => %d traces (%d filtered)", results.size(), tracedResults.size(), totalFiltered));
// Provide option to refit the traces as single peaks and save to memory
if (settings.refitOption)
fitTraces(results, traces);
}
Aggregations