Search in sources :

Example 6 with TraceManager

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;
}
Also used : Trace(gdsc.smlm.results.Trace) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) ArrayList(java.util.ArrayList) TraceManager(gdsc.smlm.results.TraceManager)

Example 7 with TraceManager

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);
            }
        }
    }
}
Also used : Trace(gdsc.smlm.results.Trace) TraceManager(gdsc.smlm.results.TraceManager) PeakResult(gdsc.smlm.results.PeakResult)

Example 8 with TraceManager

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);
}
Also used : Trace(gdsc.smlm.results.Trace) IJTrackProgress(gdsc.core.ij.IJTrackProgress) Cluster(gdsc.core.clustering.Cluster) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) ClusteringEngine(gdsc.core.clustering.ClusteringEngine) TraceManager(gdsc.smlm.results.TraceManager) ClusterPoint(gdsc.core.clustering.ClusterPoint)

Aggregations

TraceManager (gdsc.smlm.results.TraceManager)8 Trace (gdsc.smlm.results.Trace)7 IJTrackProgress (gdsc.core.ij.IJTrackProgress)4 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)3 PeakResult (gdsc.smlm.results.PeakResult)3 Cluster (gdsc.core.clustering.Cluster)2 ClusteringEngine (gdsc.core.clustering.ClusteringEngine)2 ArrayList (java.util.ArrayList)2 ClusterPoint (gdsc.core.clustering.ClusterPoint)1 StoredData (gdsc.core.utils.StoredData)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 Plot2 (ij.gui.Plot2)1 LinkedList (java.util.LinkedList)1