Search in sources :

Example 6 with WidthResultProcedure

use of uk.ac.sussex.gdsc.smlm.results.procedures.WidthResultProcedure 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

PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)6 WidthResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.WidthResultProcedure)6 ArrayList (java.util.ArrayList)5 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)5 ImageStack (ij.ImageStack)4 Rectangle (java.awt.Rectangle)4 StoredDataStatistics (uk.ac.sussex.gdsc.core.utils.StoredDataStatistics)4 IJ (ij.IJ)3 ImagePlus (ij.ImagePlus)3 WindowManager (ij.WindowManager)3 Plot (ij.gui.Plot)3 FloatProcessor (ij.process.FloatProcessor)3 ImageProcessor (ij.process.ImageProcessor)3 List (java.util.List)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)3 DataException (uk.ac.sussex.gdsc.core.data.DataException)3 TypeConverter (uk.ac.sussex.gdsc.core.data.utils.TypeConverter)3 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)3 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)3