Search in sources :

Example 1 with SnrResultProcedure

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

the class SummariseResults method createSummary.

private static String createSummary(StringBuilder sb, MemoryPeakResults result, int[] removeNullResults) {
    sb.setLength(0);
    final DescriptiveStatistics[] stats = new DescriptiveStatistics[2];
    for (int i = 0; i < stats.length; i++) {
        stats[i] = new DescriptiveStatistics();
    }
    if (result.hasNullResults()) {
        IJ.log("Null results in dataset: " + result.getName());
        if (removeNullResults[0] == UNKNOWN) {
            final GenericDialog gd = new GenericDialog(TITLE);
            gd.addMessage("There are invalid results in memory.\n \nClean these results?");
            gd.enableYesNoCancel();
            gd.hideCancelButton();
            gd.showDialog();
            removeNullResults[0] = (gd.wasOKed()) ? YES : NO;
        }
        if (removeNullResults[0] == NO) {
            result = result.copy();
        }
        result.removeNullResults();
    }
    final CalibrationReader calibration = result.getCalibrationReader();
    PrecisionMethod precisionMethod = PrecisionMethod.PRECISION_METHOD_NA;
    boolean stored = false;
    final int size = result.size();
    if (size > 0) {
        // Precision
        try {
            final PrecisionResultProcedure p = new PrecisionResultProcedure(result);
            // Use stored precision if possible
            stored = result.hasPrecision();
            precisionMethod = p.getPrecision(stored);
            for (final double v : p.precisions) {
                stats[0].addValue(v);
            }
        } catch (final DataException ex) {
        // Ignore
        }
        // SNR
        try {
            final SnrResultProcedure p = new SnrResultProcedure(result);
            p.getSnr();
            for (final double v : p.snr) {
                stats[1].addValue(v);
            }
        } catch (final DataException ex) {
        // Ignore
        }
    }
    sb.append(result.getName());
    int maxT = 0;
    if (result.size() == 0) {
        sb.append("\t0\t0");
    } else {
        sb.append('\t').append(result.size());
        maxT = result.getMaxFrame();
        sb.append('\t').append(maxT);
    }
    if (calibration != null && calibration.hasExposureTime()) {
        sb.append('\t').append(TextUtils.millisToString((long) Math.ceil(maxT * calibration.getExposureTime())));
    } else {
        sb.append("\t-");
    }
    if (size > 0) {
        final boolean includeDeviations = result.hasDeviations();
        final long memorySize = MemoryPeakResults.estimateMemorySize(size, includeDeviations);
        final String memory = TextUtils.bytesToString(memorySize);
        sb.append('\t').append(memory);
    } else {
        sb.append("\t-");
    }
    final Rectangle bounds = result.getBounds(true);
    TextUtils.formatTo(sb, "\t%d,%d,%d,%d", bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height);
    if (calibration != null) {
        sb.append('\t').append(calibration.hasNmPerPixel() ? MathUtils.rounded(calibration.getNmPerPixel()) : '-');
        sb.append('\t').append(calibration.hasExposureTime() ? MathUtils.rounded(calibration.getExposureTime()) : '-');
        if (calibration.hasCameraType()) {
            sb.append('\t').append(CalibrationProtosHelper.getName(calibration.getCameraType()));
            if (calibration.isCcdCamera()) {
                sb.append(" bias=").append(calibration.getBias());
                sb.append(" gain=").append(calibration.getCountPerPhoton());
            }
        } else {
            sb.append("\t-");
        }
        sb.append('\t').append(calibration.hasDistanceUnit() ? UnitHelper.getShortName(calibration.getDistanceUnit()) : '-');
        sb.append('\t').append(calibration.hasIntensityUnit() ? UnitHelper.getShortName(calibration.getIntensityUnit()) : '-');
    } else {
        sb.append("\t\t\t\t\t");
    }
    if (result.is3D()) {
        sb.append("\tY");
    } else {
        sb.append("\tN");
    }
    sb.append("\t").append(FitProtosHelper.getName(precisionMethod));
    if (stored) {
        sb.append(" (Stored)");
    }
    for (int i = 0; i < stats.length; i++) {
        if (Double.isNaN(stats[i].getMean())) {
            sb.append("\t-\t-\t-\t-");
        } else {
            sb.append('\t').append(IJ.d2s(stats[i].getMean(), 3));
            sb.append('\t').append(IJ.d2s(stats[i].getPercentile(50), 3));
            sb.append('\t').append(IJ.d2s(stats[i].getMin(), 3));
            sb.append('\t').append(IJ.d2s(stats[i].getMax(), 3));
        }
    }
    return sb.toString();
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) Rectangle(java.awt.Rectangle) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) PrecisionMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.PrecisionMethod) DataException(uk.ac.sussex.gdsc.core.data.DataException) GenericDialog(ij.gui.GenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) SnrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.SnrResultProcedure)

Aggregations

GenericDialog (ij.gui.GenericDialog)1 Rectangle (java.awt.Rectangle)1 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)1 DataException (uk.ac.sussex.gdsc.core.data.DataException)1 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)1 CalibrationReader (uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader)1 PrecisionMethod (uk.ac.sussex.gdsc.smlm.data.config.FitProtos.PrecisionMethod)1 PrecisionResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure)1 SnrResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.SnrResultProcedure)1