Search in sources :

Example 11 with PeakResultPoint

use of uk.ac.sussex.gdsc.smlm.results.PeakResultPoint in project GDSC-SMLM by aherbert.

the class BenchmarkSmartSpotRanking method runAnalysis.

private void runAnalysis() {
    // Extract all the results in memory into a list per frame. This can be cached
    boolean refresh = false;
    final Pair<Integer, TIntObjectHashMap<List<Coordinate>>> coords = coordinateCache.get();
    TIntObjectHashMap<List<Coordinate>> actualCoordinates;
    if (coords.getKey() != simulationParameters.id) {
        // Do not get integer coordinates
        // The Coordinate objects will be PeakResultPoint objects that store the original PeakResult
        // from the MemoryPeakResults
        actualCoordinates = ResultsMatchCalculator.getCoordinates(results, false);
        coordinateCache.set(Pair.of(simulationParameters.id, actualCoordinates));
        refresh = true;
    } else {
        actualCoordinates = coords.getValue();
    }
    // Extract all the candidates into a list per frame. This can be cached if the settings have not
    // changed.
    CandidateData candidateData = candidateDataCache.get();
    if (refresh || candidateData == null || candidateData.differentSettings(filterResult.id, settings)) {
        candidateData = subsetFilterResults(filterResult.filterResults);
        candidateDataCache.set(candidateData);
    }
    final TIntObjectHashMap<FilterCandidates> filterCandidates = candidateData.filterCandidates;
    final ImageStack stack = imp.getImageStack();
    // Create a pool of workers
    final int nThreads = Prefs.getThreads();
    final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<>(nThreads * 2);
    final List<Worker> workers = new LinkedList<>();
    final List<Thread> threads = new LinkedList<>();
    final Ticker ticker = ImageJUtils.createTicker(filterCandidates.size(), nThreads);
    for (int i = 0; i < nThreads; i++) {
        final Worker worker = new Worker(jobs, stack, actualCoordinates, filterCandidates, ticker);
        final Thread t = new Thread(worker);
        workers.add(worker);
        threads.add(t);
        t.start();
    }
    // Process the frames
    filterCandidates.forEachKey(value -> {
        put(jobs, value);
        return true;
    });
    // Finish all the worker threads by passing in a null job
    for (int i = 0; i < threads.size(); i++) {
        put(jobs, -1);
    }
    // Wait for all to finish
    for (int i = 0; i < threads.size(); i++) {
        try {
            threads.get(i).join();
        } catch (final InterruptedException ex) {
            Thread.currentThread().interrupt();
            throw new ConcurrentRuntimeException("Unexpected interrupt", ex);
        }
    }
    threads.clear();
    IJ.showProgress(1);
    if (ImageJUtils.isInterrupted()) {
        IJ.showStatus("Aborted");
        return;
    }
    IJ.showStatus("Collecting results ...");
    final TIntObjectHashMap<RankResults> rankResults = new TIntObjectHashMap<>();
    for (final Worker w : workers) {
        rankResults.putAll(w.results);
    }
    summariseResults(rankResults, candidateData);
    IJ.showStatus("");
}
Also used : ImageStack(ij.ImageStack) Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) LinkedList(java.util.LinkedList) ConcurrentRuntimeException(org.apache.commons.lang3.concurrent.ConcurrentRuntimeException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) FitWorker(uk.ac.sussex.gdsc.smlm.engine.FitWorker) List(java.util.List) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)11 PointPair (uk.ac.sussex.gdsc.core.match.PointPair)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)7 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)6 TIntHashSet (gnu.trove.set.hash.TIntHashSet)6 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)6 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)6 IJ (ij.IJ)5 TextWindow (ij.text.TextWindow)5 Point (java.awt.Point)5 BufferedTextWindow (uk.ac.sussex.gdsc.core.ij.BufferedTextWindow)5 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)4 TIntProcedure (gnu.trove.procedure.TIntProcedure)4 Prefs (ij.Prefs)4 PlugIn (ij.plugin.PlugIn)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4