Search in sources :

Example 11 with ConfigurationException

use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.

the class PeakResultConversionHelper method getConverters.

/**
 * Gets the converters for the peak results parameters. This includes the standard parameters and
 * any additional parameters defined in the PSF. If a parameter unit type is undefined then an
 * identity converter is created.
 *
 * @return the converters
 */
public Converter[] getConverters() {
    final LocalList<Converter> list = new LocalList<>(5);
    getIntensityConverter();
    getDistanceConverter();
    list.add(intensityConverter);
    list.add(intensityConverter);
    list.add(distanceConverter);
    list.add(distanceConverter);
    list.add(distanceConverter);
    if (psf != null) {
        try {
            for (final PSFParameter p : PsfHelper.getParameters(psf)) {
                switch(p.getUnit()) {
                    case DISTANCE:
                        list.add(distanceConverter);
                        break;
                    case INTENSITY:
                        list.add(intensityConverter);
                        break;
                    case ANGLE:
                        list.add(getAngleConverter());
                        break;
                    default:
                        list.add(new IdentityTypeConverter<>(p.getUnit()));
                }
            }
        } catch (final ConfigurationException ex) {
        // Ignore
        }
    }
    return list.toArray(new Converter[0]);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) IdentityTypeConverter(uk.ac.sussex.gdsc.core.data.utils.IdentityTypeConverter) Converter(uk.ac.sussex.gdsc.core.data.utils.Converter) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter)

Example 12 with ConfigurationException

use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.

the class PeakResultConversionHelper method getUnitNames.

/**
 * Gets the unit names for the peak results parameters. This includes the standard parameters and
 * any additional parameters defined in the PSF. If a parameter unit is undefined then an empty
 * string is returned.
 *
 * @return the converters
 */
public String[] getUnitNames() {
    final LocalList<String> list = new LocalList<>(5);
    getIntensityConverter();
    getDistanceConverter();
    final String safeIntensityUnit = (intensityConverter.to() != null) ? UnitHelper.getShortName(intensityConverter.to()) : "";
    final String safeDistanceUnit = (distanceConverter.to() != null) ? UnitHelper.getShortName(distanceConverter.to()) : "";
    String safeAngleUnit = null;
    list.add(safeIntensityUnit);
    list.add(safeIntensityUnit);
    list.add(safeDistanceUnit);
    list.add(safeDistanceUnit);
    list.add(safeDistanceUnit);
    if (psf != null) {
        try {
            for (final PSFParameter p : PsfHelper.getParameters(psf)) {
                switch(p.getUnit()) {
                    case DISTANCE:
                        list.add(safeDistanceUnit);
                        break;
                    case INTENSITY:
                        list.add(safeIntensityUnit);
                        break;
                    case ANGLE:
                        safeAngleUnit = getOrCreateAngleUnit(safeAngleUnit);
                        list.add(safeAngleUnit);
                        break;
                    default:
                        list.add("");
                }
            }
        } catch (final ConfigurationException ex) {
        // Ignore
        }
    }
    return list.toArray(new String[0]);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter)

Example 13 with ConfigurationException

use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.

the class PsfEstimator method estimatePsf.

private int estimatePsf() {
    log("Estimating PSF ... Press escape to abort");
    final PeakFit fitter = createFitter();
    // Use the fit configuration to generate a Gaussian function to test what is being evaluated
    final Gaussian2DFunction gf = config.getFitConfiguration().createGaussianFunction(1, 1, 1);
    ignore[ANGLE] = !gf.evaluatesAngle();
    ignore[X] = !gf.evaluatesSD0();
    ignore[Y] = !gf.evaluatesSD1();
    final double[] params = new double[] { gf.evaluatesAngle() ? initialPeakAngle : 0, gf.evaluatesSD0() ? initialPeakStdDev0 : 0, gf.evaluatesSD1() ? initialPeakStdDev1 : 0, 0, 0 };
    final double[] paramsDev = new double[3];
    final boolean[] identical = new boolean[4];
    final double[] p = new double[] { Double.NaN, Double.NaN, Double.NaN, Double.NaN };
    final TextWindow resultsWindow = createResultsWindow();
    addToResultTable(resultsWindow, 0, 0, params, paramsDev, p);
    if (!calculateStatistics(fitter, params, paramsDev)) {
        return (ImageJUtils.isInterrupted()) ? ABORTED : INSUFFICIENT_PEAKS;
    }
    if (!addToResultTable(resultsWindow, 1, size(), params, paramsDev, p)) {
        return BAD_ESTIMATE;
    }
    boolean tryAgain = false;
    int iteration = 2;
    for (; ; ) {
        if (!calculateStatistics(fitter, params, paramsDev)) {
            return (ImageJUtils.isInterrupted()) ? ABORTED : INSUFFICIENT_PEAKS;
        }
        try {
            for (int i = 0; i < 3; i++) {
                getP(i, p, identical);
            }
            if (!ignore[Y]) {
                getPairedP(sampleNew[X], sampleNew[Y], XY, p, identical);
            }
            if (!addToResultTable(resultsWindow, iteration++, size(), params, paramsDev, p)) {
                return BAD_ESTIMATE;
            }
            if ((ignore[ANGLE] || identical[ANGLE] || identical[XY]) && (ignore[X] || identical[X]) && (ignore[Y] || identical[Y])) {
                tryAgain = checkAngleSignificance() || checkXySignificance(identical);
                // Update recommended values. Only use if significant
                params[X] = sampleNew[X].getMean();
                params[Y] = (!ignore[Y] && !identical[XY]) ? sampleNew[Y].getMean() : params[X];
                params[ANGLE] = (!ignore[ANGLE]) ? sampleNew[ANGLE].getMean() : 0;
                // update starting configuration
                initialPeakAngle = (float) params[ANGLE];
                initialPeakStdDev0 = (float) params[X];
                initialPeakStdDev1 = (float) params[Y];
                if (settings.getUpdatePreferences()) {
                    config.getFitConfiguration().setInitialPeakStdDev0((float) params[X]);
                    try {
                        config.getFitConfiguration().setInitialPeakStdDev1((float) params[Y]);
                        config.getFitConfiguration().setInitialAngle((float) params[ANGLE]);
                    } catch (final IllegalStateException | ConfigurationException ex) {
                    // Ignore this as the current PSF is not a 2 axis and theta Gaussian PSF
                    }
                }
                break;
            }
            if (IJ.escapePressed()) {
                IJ.beep();
                IJ.showStatus("Aborted");
                return ABORTED;
            }
        } catch (final Exception ex) {
            Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error while estimating the PSF", ex);
            return EXCEPTION;
        }
    }
    return (tryAgain) ? TRY_AGAIN : COMPLETE;
}
Also used : Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) TextWindow(ij.text.TextWindow) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) ConcurrentRuntimeException(org.apache.commons.lang3.concurrent.ConcurrentRuntimeException)

Example 14 with ConfigurationException

use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.

the class PsfEstimator method showDialog.

/**
 * Show dialog.
 *
 * @param imp the imp
 * @return the int
 */
private int showDialog(ImagePlus imp) {
    // Keep class variables for the parameters we are fitting
    final FitConfiguration fitConfig = config.getFitConfiguration();
    initialPeakStdDev0 = 1;
    initialPeakStdDev1 = 1;
    initialPeakAngle = 0;
    try {
        initialPeakStdDev0 = fitConfig.getInitialXSd();
        initialPeakStdDev1 = fitConfig.getInitialYSd();
        initialPeakAngle = fitConfig.getInitialAngle();
    } catch (final IllegalStateException | ConfigurationException ex) {
    // Ignore this as the current PSF is not a 2 axis and theta Gaussian PSF
    }
    if (!extraOptions) {
        interlacedData = false;
        integrateFrames = 1;
    }
    this.imp = imp;
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("psf-estimator"));
    gd.addMessage("Estimate 2D Gaussian to fit maxima");
    gd.addNumericField("Initial_StdDev0", initialPeakStdDev0, 3);
    gd.addNumericField("Initial_StdDev1", initialPeakStdDev1, 3);
    gd.addNumericField("Initial_Angle", initialPeakAngle, 3);
    gd.addNumericField("Number_of_peaks", settings.getNumberOfPeaks(), 0);
    // pValue sets the smallest significance level probability level at which they are said to be
    // different.
    // i.e. p <= pValue they are different
    // lower pValue means harder to be found different.
    // lower pValue means easier to be found the same.
    gd.addNumericField("p-Value", settings.getPValue(), 4);
    gd.addCheckbox("Update_preferences", settings.getUpdatePreferences());
    gd.addCheckbox("Log_progress", settings.getDebugPsfEstimator());
    gd.addCheckbox("Iterate", settings.getIterate());
    gd.addCheckbox("Show_histograms", settings.getShowHistograms());
    gd.addNumericField("Histogram_bins", settings.getHistogramBins(), 0);
    PeakFit.addCameraOptions(gd, fitConfig);
    PeakFit.addPsfOptions(gd, fitConfig);
    final PeakFit.SimpleFitEngineConfigurationProvider provider = new PeakFit.SimpleFitEngineConfigurationProvider(config);
    PeakFit.addDataFilterOptions(gd, provider);
    PeakFit.addSearchOptions(gd, provider);
    PeakFit.addBorderOptions(gd, provider);
    PeakFit.addFittingOptions(gd, provider);
    if (extraOptions) {
        pluginSettings = Settings.load();
        gd.addCheckbox("Interlaced_data", pluginSettings.interlacedData);
        gd.addSlider("Integrate_frames", 1, 5, pluginSettings.integrateFrames);
    }
    gd.addMessage("--- Gaussian fitting ---");
    gd.addChoice("Fit_solver", SettingsManager.getFitSolverNames(), FitProtosHelper.getName(fitConfig.getFitSolver()));
    // Parameters specific to each Fit solver are collected in a second dialog
    gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
    gd.addNumericField("Pass_rate", config.getPassRate(), 2);
    gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours());
    gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold());
    gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold());
    gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract");
    gd.addCheckbox("Smart_filter", fitConfig.isSmartFilter());
    gd.addCheckbox("Disable_simple_filter", fitConfig.isDisableSimpleFilter());
    gd.addSlider("Shift_factor", 0.01, 2, fitConfig.getCoordinateShiftFactor());
    gd.addNumericField("Signal_strength", fitConfig.getSignalStrength(), 2);
    gd.addNumericField("Min_photons", fitConfig.getMinPhotons(), 0);
    gd.addSlider("Min_width_factor", 0, 0.99, fitConfig.getMinWidthFactor());
    gd.addSlider("Width_factor", 1, 4.5, fitConfig.getMaxWidthFactor());
    PeakFit.addPrecisionOptions(gd, new PeakFit.SimpleFitConfigurationProvider(fitConfig));
    gd.showDialog();
    if (gd.wasCanceled() || !readDialog(gd)) {
        return DONE;
    }
    return FLAGS;
}
Also used : ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Aggregations

ConfigurationException (uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException)14 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)5 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)4 ConversionException (uk.ac.sussex.gdsc.core.data.utils.ConversionException)3 PSFParameter (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 GenericDialog (ij.gui.GenericDialog)2 IOException (java.io.IOException)2 Converter (uk.ac.sussex.gdsc.core.data.utils.Converter)2 Gaussian2DPeakResultCalculator (uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultCalculator)2 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)2 PeakResultConversionHelper (uk.ac.sussex.gdsc.smlm.results.PeakResultConversionHelper)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 TextWindow (ij.text.TextWindow)1 BufferedOutputStream (java.io.BufferedOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1