Search in sources :

Example 11 with PrecisionResultProcedure

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

the class FilterResults method analyseResults.

/**
 * Analyse the results and determine the range for each filter.
 */
private boolean analyseResults() {
    IJ.showStatus("Analysing results ...");
    final ArrayList<String> error = new ArrayList<>();
    try {
        wp = new WidthResultProcedure(results, DistanceUnit.PIXEL);
        wp.getW();
        final float[] limits = MathUtils.limits(wp.wx);
        maxWidth = limits[1];
        minWidth = limits[0];
        averageWidth = MathUtils.sum(wp.wx) / wp.size();
    } catch (final DataException ex) {
        error.add(ex.getMessage());
        wp = null;
        maxWidth = minWidth = 0;
    }
    try {
        pp = new PrecisionResultProcedure(results);
        pp.getPrecision();
        final double[] limits = MathUtils.limits(pp.precisions);
        maxPrecision = limits[1];
        minPrecision = limits[0];
    } catch (final DataException ex) {
        error.add(ex.getMessage());
        pp = null;
        maxPrecision = minPrecision = 0;
    }
    try {
        sp = new StandardResultProcedure(results, DistanceUnit.PIXEL);
        sp.getXyr();
        // Re-use for convenience
        sp.intensity = new float[sp.x.length];
        sp.background = new float[sp.x.length];
        sp.z = new float[sp.x.length];
        for (int i = 0; i < sp.size(); i++) {
            if (i % 64 == 0) {
                IJ.showProgress(i, sp.size());
            }
            final PeakResult result = sp.peakResults[i];
            final float drift = getDrift(result, sp.x[i], sp.y[i]);
            if (maxDrift < drift) {
                maxDrift = drift;
            }
            if (minDrift > drift) {
                minDrift = drift;
            }
            final float signal = result.getIntensity();
            if (maxSignal < signal) {
                maxSignal = signal;
            }
            if (minSignal > signal) {
                minSignal = signal;
            }
            final float snr = getSnr(result);
            if (maxSnr < snr) {
                maxSnr = snr;
            }
            if (minSnr > snr) {
                minSnr = snr;
            }
            // for convenience
            sp.z[i] = drift;
            sp.intensity[i] = signal;
            sp.background[i] = snr;
        }
    } catch (final DataException ex) {
        error.add(ex.getMessage());
        sp = null;
    }
    if (error.size() == 3 || sp == null) {
        final StringBuilder sb = new StringBuilder("Unable to analyse the results:\n");
        for (final String s : error) {
            sb.append(s).append(".\n");
        }
        IJ.error(TITLE, sb.toString());
        return false;
    }
    ImageJUtils.finished();
    return true;
}
Also used : ArrayList(java.util.ArrayList) WidthResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.WidthResultProcedure) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) DataException(uk.ac.sussex.gdsc.core.data.DataException) StandardResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.StandardResultProcedure)

Aggregations

PrecisionResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure)11 DataException (uk.ac.sussex.gdsc.core.data.DataException)6 ArrayList (java.util.ArrayList)5 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)5 Statistics (uk.ac.sussex.gdsc.core.utils.Statistics)4 StandardResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.StandardResultProcedure)4 Rectangle (java.awt.Rectangle)3 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)3 ClusterPoint (uk.ac.sussex.gdsc.core.clustering.ClusterPoint)3 StoredDataStatistics (uk.ac.sussex.gdsc.core.utils.StoredDataStatistics)3 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)2 IJ (ij.IJ)2 ImagePlus (ij.ImagePlus)2 ImageStack (ij.ImageStack)2 WindowManager (ij.WindowManager)2 GenericDialog (ij.gui.GenericDialog)2 PlugIn (ij.plugin.PlugIn)2 FloatProcessor (ij.process.FloatProcessor)2 ImageProcessor (ij.process.ImageProcessor)2 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)2