Search in sources :

Example 6 with TraceManager

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));
}
Also used : Trace(uk.ac.sussex.gdsc.smlm.results.Trace) DmttConfiguration(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing.DmttConfiguration) DynamicMultipleTargetTracing(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing) List(java.util.List) ArrayList(java.util.ArrayList) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ClusteringEngine(uk.ac.sussex.gdsc.core.clustering.ClusteringEngine) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint)

Example 7 with TraceManager

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

Example 8 with TraceManager

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

Aggregations

TraceManager (uk.ac.sussex.gdsc.smlm.results.TraceManager)8 Trace (uk.ac.sussex.gdsc.smlm.results.Trace)7 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)4 ArrayList (java.util.ArrayList)3 Plot (ij.gui.Plot)2 List (java.util.List)2 SimpleImageJTrackProgress (uk.ac.sussex.gdsc.core.ij.SimpleImageJTrackProgress)2 CalibrationReader (uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader)2 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)2 Gaussian2DPeakResultCalculator (uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultCalculator)2 Gaussian2DPeakResultHelper (uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultHelper)2 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)2 XStreamAsAttribute (com.thoughtworks.xstream.annotations.XStreamAsAttribute)1 XStreamOmitField (com.thoughtworks.xstream.annotations.XStreamOmitField)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 IJ (ij.IJ)1 PlugIn (ij.plugin.PlugIn)1 TextWindow (ij.text.TextWindow)1 Checkbox (java.awt.Checkbox)1 Color (java.awt.Color)1