Search in sources :

Example 1 with PeakResults

use of gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.

the class PeakFit method createFitEngine.

/**
	 * Creates a fitting engine using the current configuration.
	 * 
	 * @param numberOfThreads
	 * @param queue
	 * @param queueSize
	 * @return The fiting engine
	 */
public FitEngine createFitEngine(int numberOfThreads, FitQueue queue, int queueSize) {
    PeakResults r = results;
    if (results.numberOfOutputs() == 1)
        // Reduce to single object for speed
        r = results.toArray()[0];
    // Update the configuration
    updateFitConfiguration(config);
    FitEngine engine = new FitEngine(config, r, numberOfThreads, queue, queueSize);
    // Write settings out to the IJ log
    if (resultsSettings.logProgress) {
        IJ.log("-=-=-=-");
        IJ.log("Peak Fit");
        IJ.log("-=-=-=-");
        Utils.log("Initial Peak SD = %s,%s", Utils.rounded(fitConfig.getInitialPeakStdDev0()), Utils.rounded(fitConfig.getInitialPeakStdDev1()));
        SpotFilter spotFilter = engine.getSpotFilter();
        IJ.log("Spot Filter = " + spotFilter.getDescription());
        int w = 2 * engine.getFitting() + 1;
        Utils.log("Fit window = %d x %d", w, w);
        if (!fitConfig.isDisableSimpleFilter()) {
            IJ.log("Coordinate shift = " + Utils.rounded(config.getFitConfiguration().getCoordinateShift()));
            IJ.log("Signal strength = " + Utils.rounded(fitConfig.getSignalStrength()));
        }
        if (fitConfig.isDirectFilter())
            IJ.log("Smart filter = " + fitConfig.getSmartFilter().getDescription());
        if (extraOptions)
            IJ.log("Noise = " + Utils.rounded(fitConfig.getNoise()));
        IJ.log("Width factor = " + Utils.rounded(fitConfig.getWidthFactor()));
        IJ.log("-=-=-=-");
    }
    return engine;
}
Also used : FitEngine(gdsc.smlm.engine.FitEngine) PeakResults(gdsc.smlm.results.PeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) SpotFilter(gdsc.smlm.filters.SpotFilter)

Example 2 with PeakResults

use of gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.

the class PeakFit method showResults.

protected void showResults() {
    IJ.showProgress(1.0);
    if (time >= 0) {
        if (silent) {
            results.end();
            return;
        }
        // Check if we are sorting
        IJ.showStatus("Finalising results ...");
        for (PeakResults r : results.toArray()) if (r instanceof MemoryPeakResults) {
            if (((MemoryPeakResults) r).isSortAfterEnd())
                IJ.showStatus("Sorting " + r.size() + " results ...");
            break;
        }
        results.end();
        String textTime = Utils.timeToString(time / 1000000.0);
        String textRunTime = Utils.timeToString(runTime / 1000000.0);
        int size = getSize();
        String message = String.format("%s. Fitting Time = %s. Run time = %s", Utils.pleural(size, "localisation"), textTime, textRunTime);
        if (resultsSettings.logProgress)
            IJ.log("-=-=-=-");
        IJ.log(message);
        IJ.showStatus(message);
    } else {
        IJ.showStatus("");
    }
}
Also used : PeakResults(gdsc.smlm.results.PeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults)

Example 3 with PeakResults

use of gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.

the class PeakFit method addFileResults.

private void addFileResults(PeakResultsList resultsList) {
    String filename = null;
    if (resultsSettings.resultsDirectory != null && new File(resultsSettings.resultsDirectory).exists()) {
        filename = resultsSettings.resultsDirectory + File.separatorChar + source.getName() + ".results." + resultsSettings.getResultsFileFormat().getExtension();
    } else if (resultsSettings.resultsFilename != null && resultsSettings.resultsFilename.length() > 0) {
        filename = resultsSettings.resultsFilename;
    }
    if (filename != null) {
        PeakResults r;
        switch(resultsSettings.getResultsFileFormat()) {
            case GDSC_BINARY:
                r = new BinaryFilePeakResults(filename, resultsSettings.showDeviations);
                break;
            case GDSC_TEXT:
                r = new FilePeakResults(filename, resultsSettings.showDeviations);
                break;
            case MALK:
                r = new MALKFilePeakResults(resultsSettings.resultsFilename);
                break;
            case TSF:
                r = new TSFPeakResultsWriter(resultsSettings.resultsFilename);
                break;
            default:
                throw new RuntimeException("Unsupported file format: " + resultsSettings.getResultsFileFormat());
        }
        if (r instanceof FilePeakResults) {
            FilePeakResults fr = (FilePeakResults) r;
            fr.setSortAfterEnd(Prefs.getThreads() > 1);
            fr.setPeakIdColumnName("Frame");
        }
        resultsList.addOutput(r);
    }
}
Also used : MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) TSFPeakResultsWriter(gdsc.smlm.results.TSFPeakResultsWriter) PeakResults(gdsc.smlm.results.PeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) File(java.io.File) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults)

Example 4 with PeakResults

use of gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.

the class ResultsManager method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.PlugIn#run(java.lang.String)
	 */
public void run(String arg) {
    SMLMUsageTracker.recordPlugin(this.getClass(), arg);
    if (arg != null && arg.startsWith("clear")) {
        Collection<MemoryPeakResults> allResults;
        boolean removeAll = false;
        if (arg.contains("multi")) {
            MultiDialog md = new MultiDialog(TITLE, new MultiDialog.MemoryResultsItems());
            md.addSelected(selected);
            md.showDialog();
            if (md.wasCanceled())
                return;
            selected = md.getSelectedResults();
            if (selected.isEmpty())
                return;
            allResults = new ArrayList<MemoryPeakResults>(selected.size());
            for (String name : selected) {
                MemoryPeakResults r = MemoryPeakResults.getResults(name);
                if (r != null)
                    allResults.add(r);
            }
        } else {
            removeAll = true;
            allResults = MemoryPeakResults.getAllResults();
        }
        if (allResults.isEmpty())
            return;
        long memorySize = 0;
        int size = 0;
        for (MemoryPeakResults results : allResults) {
            memorySize += MemoryPeakResults.estimateMemorySize(results.getResults());
            size += results.size();
        }
        String memory = MemoryPeakResults.memorySizeString(memorySize);
        String count = Utils.pleural(size, "result");
        String sets = Utils.pleural(allResults.size(), "set");
        GenericDialog gd = new GenericDialog(TITLE);
        gd.addMessage(String.format("Do you want to remove %s from memory (%s, %s)?", count, sets, memory));
        gd.enableYesNoCancel();
        gd.showDialog();
        if (!gd.wasOKed())
            return;
        if (removeAll)
            MemoryPeakResults.clearMemory();
        else {
            for (MemoryPeakResults results : allResults) MemoryPeakResults.removeResults(results.getName());
        }
        SummariseResults.clearSummaryTable();
        IJ.log(String.format("Cleared %s (%s, %s)", count, sets, memory));
        return;
    }
    if (!showDialog())
        return;
    MemoryPeakResults results = loadResults(inputOption);
    if (results == null || results.size() == 0) {
        IJ.error(TITLE, "No results could be loaded");
        IJ.showStatus("");
        return;
    }
    results = cropToRoi(results);
    if (results.size() == 0) {
        IJ.error(TITLE, "No results within the crop region");
        return;
    }
    if (resultsSettings.resultsInMemory && fileInput)
        MemoryPeakResults.addResults(results);
    IJ.showStatus("Processing outputs ...");
    Rectangle bounds = results.getBounds(true);
    boolean showDeviations = resultsSettings.showDeviations && canShowDeviations(results);
    boolean showEndFrame = canShowEndFrame(results);
    boolean showId = canShowId(results);
    // Display the configured output
    PeakResultsList outputList = new PeakResultsList();
    outputList.copySettings(results);
    //String title = results.getSource();
    //if (title == null || title.length() == 0)
    //	output.setSource(TITLE);
    addTableResults(results, outputList, showDeviations, showEndFrame);
    addImageResults(outputList, results.getName(), bounds, results.getNmPerPixel(), results.getGain());
    addFileResults(outputList, showDeviations, showEndFrame, showId);
    // Reduce to single object for speed
    PeakResults output = (outputList.numberOfOutputs() == 1) ? outputList.toArray()[0] : outputList;
    output.begin();
    // Process in batches to provide progress
    List<PeakResult> list = results.getResults();
    int progress = 0;
    int totalProgress = list.size();
    int stepProgress = Utils.getProgressInterval(totalProgress);
    TurboList<PeakResult> batch = new TurboList<PeakResult>(stepProgress);
    for (PeakResult result : list) {
        if (progress % stepProgress == 0) {
            IJ.showProgress(progress, totalProgress);
        }
        progress++;
        batch.addf(result);
        if (batch.size() == stepProgress) {
            output.addAll(batch);
            batch.clearf();
            if (isInterrupted())
                break;
        }
    }
    IJ.showProgress(1);
    output.end();
    IJ.showStatus(String.format("Processed %d result%s", results.size(), (results.size() > 1) ? "s" : ""));
}
Also used : TurboList(gdsc.core.utils.TurboList) Rectangle(java.awt.Rectangle) PeakResult(gdsc.smlm.results.PeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult) PeakResultsList(gdsc.smlm.results.PeakResultsList) PeakResults(gdsc.smlm.results.PeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) GenericDialog(ij.gui.GenericDialog) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults)

Example 5 with PeakResults

use of gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.

the class ResultsManager method addFileResults.

private void addFileResults(PeakResultsList resultsList, boolean showDeviations, boolean showEndFrame, boolean showId) {
    if (resultsSettings.resultsFilename != null && resultsSettings.resultsFilename.length() > 0) {
        // Remove extension
        resultsSettings.resultsFilename = Utils.replaceExtension(resultsSettings.resultsFilename, resultsSettings.getResultsFileFormat().getExtension());
        if (fileInput && inputFilename.equals(resultsSettings.resultsFilename)) {
            IJ.log(TITLE + ": Input and output files are the same, skipping output ...");
            return;
        }
        // Check if file exists
        File file = new File(resultsSettings.resultsFilename);
        if (file.exists()) {
            YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), TITLE, "Overwrite existing file?\n" + resultsSettings.resultsFilename);
            if (!d.yesPressed())
                return;
        }
        File parent = file.getParentFile();
        if (parent != null && parent.exists()) {
            PeakResults r;
            switch(resultsSettings.getResultsFileFormat()) {
                case GDSC_BINARY:
                    r = new BinaryFilePeakResults(resultsSettings.resultsFilename, showDeviations, showEndFrame, showId);
                    break;
                case GDSC_TEXT:
                    r = new FilePeakResults(resultsSettings.resultsFilename, showDeviations, showEndFrame, showId);
                    break;
                case MALK:
                    r = new MALKFilePeakResults(resultsSettings.resultsFilename);
                    break;
                case TSF:
                    r = new TSFPeakResultsWriter(resultsSettings.resultsFilename);
                    break;
                default:
                    throw new RuntimeException("Unsupported file format: " + resultsSettings.getResultsFileFormat());
            }
            if (r instanceof FilePeakResults) {
                FilePeakResults fr = (FilePeakResults) r;
                fr.setPeakIdColumnName("Frame");
            }
            resultsList.addOutput(r);
        }
    }
}
Also used : MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) TSFPeakResultsWriter(gdsc.smlm.results.TSFPeakResultsWriter) PeakResults(gdsc.smlm.results.PeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) YesNoCancelDialog(ij.gui.YesNoCancelDialog) File(java.io.File) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults)

Aggregations

IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)8 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)8 PeakResults (gdsc.smlm.results.PeakResults)8 IJTablePeakResults (gdsc.smlm.ij.results.IJTablePeakResults)7 BinaryFilePeakResults (gdsc.smlm.results.BinaryFilePeakResults)7 FilePeakResults (gdsc.smlm.results.FilePeakResults)7 MALKFilePeakResults (gdsc.smlm.results.MALKFilePeakResults)7 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)2 PeakResult (gdsc.smlm.results.PeakResult)2 TSFPeakResultsWriter (gdsc.smlm.results.TSFPeakResultsWriter)2 ImagePlus (ij.ImagePlus)2 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)2 File (java.io.File)2 TurboList (gdsc.core.utils.TurboList)1 FitEngine (gdsc.smlm.engine.FitEngine)1 SpotFilter (gdsc.smlm.filters.SpotFilter)1 IJImageSource (gdsc.smlm.ij.IJImageSource)1 Calibration (gdsc.smlm.results.Calibration)1 PeakResultsList (gdsc.smlm.results.PeakResultsList)1 GenericDialog (ij.gui.GenericDialog)1