Search in sources :

Example 1 with IJTrackProgress

use of gdsc.core.ij.IJTrackProgress in project GDSC-SMLM by aherbert.

the class ResequenceResults method run.

/*
	 * (non-)
	 * 
	 * @see ij.plugin.PlugIn#run(java.lang.String)
	 */
public void run(String arg) {
    SMLMUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    if (!showDialog())
        return;
    MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, true);
    if (results == null || results.size() == 0) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    if (resequenceResults(results, start, block, skip, (logMapping) ? new IJTrackProgress() : null))
        IJ.showStatus("Resequenced " + results.getName());
}
Also used : IJTrackProgress(gdsc.core.ij.IJTrackProgress) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults)

Example 2 with IJTrackProgress

use of gdsc.core.ij.IJTrackProgress in project GDSC-SMLM by aherbert.

the class ResultsManager method loadInputResults.

/**
	 * Load the results from the named input option
	 * 
	 * @param inputOption
	 * @param checkCalibration
	 *            Set to true to ensure the results have a valid calibration
	 * @return
	 */
public static MemoryPeakResults loadInputResults(String inputOption, boolean checkCalibration) {
    MemoryPeakResults results = null;
    PeakResultsReader reader = null;
    if (inputOption.equals(INPUT_NONE)) {
    } else if (inputOption.equals(INPUT_FILE)) {
        IJ.showStatus("Reading results file ...");
        reader = new PeakResultsReader(inputFilename);
        IJ.showStatus("Reading " + reader.getFormat() + " results file ...");
        ResultOption[] options = reader.getOptions();
        if (options != null)
            collectOptions(reader, options);
        reader.setTracker(new IJTrackProgress());
        results = reader.getResults();
        reader.getTracker().progress(1.0);
        if (results != null && results.size() > 0) {
            // If the name contains a .tif suffix then create an image source
            if (results.getName() != null && results.getName().contains(".tif") && results.getSource() == null) {
                int index = results.getName().indexOf(".tif");
                results.setSource(new IJImageSource(results.getName().substring(0, index)));
            }
        }
    } else {
        results = loadMemoryResults(inputOption);
    }
    if (results != null && results.size() > 0 && checkCalibration) {
        if (!checkCalibration(results, reader))
            results = null;
    }
    IJ.showStatus("");
    return results;
}
Also used : IJImageSource(gdsc.smlm.ij.IJImageSource) IJTrackProgress(gdsc.core.ij.IJTrackProgress) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResultsReader(gdsc.smlm.results.PeakResultsReader)

Example 3 with IJTrackProgress

use of gdsc.core.ij.IJTrackProgress in project GDSC-SMLM by aherbert.

the class DarkTimeAnalysis method analyse.

private void analyse(MemoryPeakResults results) {
    // Find min and max time frames
    results.sort();
    int min = results.getHead().getFrame();
    int max = results.getTail().getEndFrame();
    // Trace results
    double d = searchDistance / results.getCalibration().getNmPerPixel();
    int range = max - min + 1;
    if (maxDarkTime > 0)
        range = FastMath.max(1, (int) Math.round(maxDarkTime * 1000 / msPerFrame));
    IJTrackProgress tracker = new IJTrackProgress();
    tracker.status("Analysing ...");
    tracker.log("Analysing (d=%s nm (%s px) t=%s s (%d frames)) ...", Utils.rounded(searchDistance), Utils.rounded(d), Utils.rounded(range * msPerFrame / 1000.0), range);
    Trace[] traces;
    if (method == 0) {
        TraceManager tm = new TraceManager(results);
        tm.setTracker(tracker);
        tm.traceMolecules(d, range);
        traces = tm.getTraces();
    } else {
        ClusteringEngine engine = new ClusteringEngine(Prefs.getThreads(), algorithms[method - 1], tracker);
        List<PeakResult> peakResults = results.getResults();
        ArrayList<Cluster> clusters = engine.findClusters(TraceMolecules.convertToClusterPoints(peakResults), d, range);
        traces = TraceMolecules.convertToTraces(peakResults, clusters);
    }
    tracker.status("Computing histogram ...");
    // Build dark-time histogram
    int[] times = new int[range];
    StoredData stats = new StoredData();
    for (Trace trace : traces) {
        if (trace.getNBlinks() > 1) {
            for (int t : trace.getOffTimes()) {
                times[t]++;
            }
            stats.add(trace.getOffTimes());
        }
    }
    plotDarkTimeHistogram(stats);
    // Cumulative histogram
    for (int i = 1; i < times.length; i++) times[i] += times[i - 1];
    int total = times[times.length - 1];
    // Plot dark-time up to 100%
    double[] x = new double[range];
    double[] y = new double[range];
    int truncate = 0;
    for (int i = 0; i < x.length; i++) {
        x[i] = i * msPerFrame;
        y[i] = (100.0 * times[i]) / total;
        if (// 100%
        times[i] == total) {
            truncate = i + 1;
            break;
        }
    }
    if (truncate > 0) {
        x = Arrays.copyOf(x, truncate);
        y = Arrays.copyOf(y, truncate);
    }
    String title = "Cumulative Dark-time";
    Plot2 plot = new Plot2(title, "Time (ms)", "Percentile", x, y);
    Utils.display(title, plot);
    // Report percentile
    for (int i = 0; i < y.length; i++) {
        if (y[i] >= percentile) {
            Utils.log("Dark-time Percentile %.1f @ %s ms = %s s", percentile, Utils.rounded(x[i]), Utils.rounded(x[i] / 1000));
            break;
        }
    }
    tracker.status("");
}
Also used : IJTrackProgress(gdsc.core.ij.IJTrackProgress) Cluster(gdsc.core.clustering.Cluster) Plot2(ij.gui.Plot2) TraceManager(gdsc.smlm.results.TraceManager) PeakResult(gdsc.smlm.results.PeakResult) Trace(gdsc.smlm.results.Trace) StoredData(gdsc.core.utils.StoredData) ClusteringEngine(gdsc.core.clustering.ClusteringEngine)

Example 4 with IJTrackProgress

use of gdsc.core.ij.IJTrackProgress in project GDSC-SMLM by aherbert.

the class TraceDiffusion method getTraces.

private Trace[] getTraces(ArrayList<MemoryPeakResults> allResults) {
    this.results = allResults.get(0);
    // Results should be checked for calibration by this point
    exposureTime = results.getCalibration().getExposureTime() / 1000;
    final double nmPerPixel = results.getCalibration().getNmPerPixel();
    ArrayList<Trace> allTraces = new ArrayList<Trace>();
    additionalDatasets = -1;
    for (MemoryPeakResults r : allResults) {
        additionalDatasets++;
        TraceManager manager = new TraceManager(r);
        // Run the tracing
        manager.setTracker(new IJTrackProgress());
        manager.setDistanceExclusion(settings.distanceExclusion / nmPerPixel);
        manager.traceMolecules(settings.distanceThreshold / nmPerPixel, 1);
        Trace[] traces = manager.getTraces();
        traces = filterTraces(r.getName(), traces, settings.minimumTraceLength, settings.ignoreEnds);
        allTraces.addAll(Arrays.asList(traces));
        //--- Save results ---
        if (traces.length > 0) {
            // Save the traces to memory
            TraceMolecules.saveResults(r, traces, "Tracks");
            if (settings.saveTraces) {
                // 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.
                TraceMolecules.sortByTime(traces);
                String newFilename = TraceMolecules.saveTraces(r, traces, createSettingsComment(), tracesFilename, additionalDatasets);
                // Only keep the main filename in memory
                if (additionalDatasets == 0)
                    tracesFilename = newFilename;
            }
        }
    }
    Trace[] all = allTraces.toArray(new Trace[allTraces.size()]);
    if (additionalDatasets > 0) {
        Utils.log("Multiple inputs provide %d traces", allTraces.size());
        MemoryPeakResults tracedResults = TraceManager.toPeakResults(all, results.getCalibration(), true);
        tracedResults.copySettings(results);
        tracedResults.setName(createCombinedName() + " Tracks");
        MemoryPeakResults.addResults(tracedResults);
    }
    return all;
}
Also used : Trace(gdsc.smlm.results.Trace) ArrayList(java.util.ArrayList) IJTrackProgress(gdsc.core.ij.IJTrackProgress) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) TraceManager(gdsc.smlm.results.TraceManager)

Example 5 with IJTrackProgress

use of gdsc.core.ij.IJTrackProgress in project GDSC-SMLM by aherbert.

the class NeighbourAnalysis 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;
    }
    if (!showDialog())
        return;
    TraceManager manager = new TraceManager(results);
    // Run the tracing
    manager.setTracker(new IJTrackProgress());
    Trace[] traces = manager.findNeighbours(distanceThreshold, timeThreshold);
    saveTraces(traces);
}
Also used : Trace(gdsc.smlm.results.Trace) IJTrackProgress(gdsc.core.ij.IJTrackProgress) TraceManager(gdsc.smlm.results.TraceManager)

Aggregations

IJTrackProgress (gdsc.core.ij.IJTrackProgress)8 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)5 Cluster (gdsc.core.clustering.Cluster)4 ClusteringEngine (gdsc.core.clustering.ClusteringEngine)4 Trace (gdsc.smlm.results.Trace)4 TraceManager (gdsc.smlm.results.TraceManager)4 ClusterPoint (gdsc.core.clustering.ClusterPoint)3 Plot2 (ij.gui.Plot2)2 ArrayList (java.util.ArrayList)2 StoredData (gdsc.core.utils.StoredData)1 IJImageSource (gdsc.smlm.ij.IJImageSource)1 Calibration (gdsc.smlm.results.Calibration)1 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)1 PeakResult (gdsc.smlm.results.PeakResult)1 PeakResultsReader (gdsc.smlm.results.PeakResultsReader)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)1