Search in sources :

Example 16 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class Configuration method showDialog.

/**
	 * Show the current properties
	 */
@SuppressWarnings("unchecked")
public void showDialog() {
    configurationChanged = false;
    String filename = SettingsManager.getSettingsFilename();
    GlobalSettings settings = SettingsManager.loadSettings(filename);
    FitEngineConfiguration config = settings.getFitEngineConfiguration();
    FitConfiguration fitConfig = config.getFitConfiguration();
    Calibration calibration = settings.getCalibration();
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Configuration settings for the single-molecule localisation microscopy plugins");
    gd.addStringField("Config_file", filename, 40);
    gd.addNumericField("Calibration (nm/px)", calibration.getNmPerPixel(), 2);
    gd.addNumericField("Gain", calibration.getGain(), 2);
    gd.addCheckbox("EM-CCD", calibration.isEmCCD());
    gd.addNumericField("Exposure_time (ms)", calibration.getExposureTime(), 2);
    gd.addMessage("--- Gaussian parameters ---");
    gd.addNumericField("Initial_StdDev0", fitConfig.getInitialPeakStdDev0(), 3);
    gd.addNumericField("Initial_StdDev1", fitConfig.getInitialPeakStdDev1(), 3);
    gd.addNumericField("Initial_Angle", fitConfig.getInitialAngle(), 3);
    gd.addMessage("--- Maxima identification ---");
    String[] filterTypes = SettingsManager.getNames((Object[]) DataFilterType.values());
    gd.addChoice("Spot_filter_type", filterTypes, filterTypes[config.getDataFilterType().ordinal()]);
    String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values());
    gd.addChoice("Spot_filter", filterNames, filterNames[config.getDataFilter(0).ordinal()]);
    gd.addSlider("Smoothing", 0, 2.5, config.getSmooth(0));
    gd.addSlider("Search_width", 0.5, 2.5, config.getSearch());
    gd.addSlider("Border", 0.5, 2.5, config.getBorder());
    gd.addSlider("Fitting_width", 2, 4.5, config.getFitting());
    gd.addMessage("--- Gaussian fitting ---");
    Component splitLabel = gd.getMessage();
    String[] solverNames = SettingsManager.getNames((Object[]) FitSolver.values());
    gd.addChoice("Fit_solver", solverNames, solverNames[fitConfig.getFitSolver().ordinal()]);
    String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values());
    gd.addChoice("Fit_function", functionNames, functionNames[fitConfig.getFitFunction().ordinal()]);
    // Parameters specific to each Fit solver are collected in a second dialog 
    gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
    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.addSlider("Duplicate_distance", 0, 1.5, fitConfig.getDuplicateDistance());
    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.01, 5, fitConfig.getWidthFactor());
    gd.addNumericField("Precision_threshold", fitConfig.getPrecisionThreshold(), 2);
    // Add a mouse listener to the config file field
    if (Utils.isShowGenericDialog()) {
        Vector<TextField> texts = (Vector<TextField>) gd.getStringFields();
        Vector<TextField> numerics = (Vector<TextField>) gd.getNumericFields();
        Vector<Checkbox> checkboxes = (Vector<Checkbox>) gd.getCheckboxes();
        Vector<Choice> choices = (Vector<Choice>) gd.getChoices();
        int n = 0;
        int t = 0;
        int b = 0;
        int ch = 0;
        textConfigFile = texts.get(t++);
        textConfigFile.addMouseListener(this);
        textConfigFile.addTextListener(this);
        // TODO: add a value changed listener to detect when typing a new file
        textNmPerPixel = numerics.get(n++);
        textGain = numerics.get(n++);
        textEMCCD = checkboxes.get(b++);
        textExposure = numerics.get(n++);
        textInitialPeakStdDev0 = numerics.get(n++);
        textInitialPeakStdDev1 = numerics.get(n++);
        textInitialAngleD = numerics.get(n++);
        textDataFilterType = choices.get(ch++);
        textDataFilter = choices.get(ch++);
        textSmooth = numerics.get(n++);
        textSearch = numerics.get(n++);
        textBorder = numerics.get(n++);
        textFitting = numerics.get(n++);
        textFitSolver = choices.get(ch++);
        textFitFunction = choices.get(ch++);
        textFailuresLimit = numerics.get(n++);
        textIncludeNeighbours = checkboxes.get(b++);
        textNeighbourHeightThreshold = numerics.get(n++);
        textResidualsThreshold = numerics.get(n++);
        textDuplicateDistance = numerics.get(n++);
        textSmartFilter = checkboxes.get(b++);
        textDisableSimpleFilter = checkboxes.get(b++);
        textCoordinateShiftFactor = numerics.get(n++);
        textSignalStrength = numerics.get(n++);
        textMinPhotons = numerics.get(n++);
        textMinWidthFactor = numerics.get(n++);
        textWidthFactor = numerics.get(n++);
        textPrecisionThreshold = numerics.get(n++);
        updateFilterInput();
        textSmartFilter.addItemListener(this);
        textDisableSimpleFilter.addItemListener(this);
    }
    if (gd.getLayout() != null) {
        GridBagLayout grid = (GridBagLayout) gd.getLayout();
        int xOffset = 0, yOffset = 0;
        int lastY = -1, rowCount = 0;
        for (Component comp : gd.getComponents()) {
            // Check if this should be the second major column
            if (comp == splitLabel) {
                xOffset += 2;
                yOffset -= rowCount;
            }
            // Reposition the field
            GridBagConstraints c = grid.getConstraints(comp);
            if (lastY != c.gridy)
                rowCount++;
            lastY = c.gridy;
            c.gridx = c.gridx + xOffset;
            c.gridy = c.gridy + yOffset;
            c.insets.left = c.insets.left + 10 * xOffset;
            c.insets.top = 0;
            c.insets.bottom = 0;
            grid.setConstraints(comp, c);
        }
        if (IJ.isLinux())
            gd.setBackground(new Color(238, 238, 238));
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return;
    filename = gd.getNextString();
    calibration.setNmPerPixel(gd.getNextNumber());
    calibration.setGain(gd.getNextNumber());
    calibration.setEmCCD(gd.getNextBoolean());
    calibration.setExposureTime(gd.getNextNumber());
    fitConfig.setInitialPeakStdDev0(gd.getNextNumber());
    fitConfig.setInitialPeakStdDev1(gd.getNextNumber());
    fitConfig.setInitialAngleD(gd.getNextNumber());
    config.setDataFilterType(gd.getNextChoiceIndex());
    config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), 0);
    config.setSearch(gd.getNextNumber());
    config.setBorder(gd.getNextNumber());
    config.setFitting(gd.getNextNumber());
    fitConfig.setFitSolver(gd.getNextChoiceIndex());
    fitConfig.setFitFunction(gd.getNextChoiceIndex());
    config.setFailuresLimit((int) gd.getNextNumber());
    config.setIncludeNeighbours(gd.getNextBoolean());
    config.setNeighbourHeightThreshold(gd.getNextNumber());
    config.setResidualsThreshold(gd.getNextNumber());
    fitConfig.setDuplicateDistance(gd.getNextNumber());
    fitConfig.setSmartFilter(gd.getNextBoolean());
    fitConfig.setDisableSimpleFilter(gd.getNextBoolean());
    fitConfig.setCoordinateShiftFactor(gd.getNextNumber());
    fitConfig.setSignalStrength(gd.getNextNumber());
    fitConfig.setMinPhotons(gd.getNextNumber());
    fitConfig.setMinWidthFactor(gd.getNextNumber());
    fitConfig.setWidthFactor(gd.getNextNumber());
    fitConfig.setPrecisionThreshold(gd.getNextNumber());
    // Check arguments
    try {
        Parameters.isAboveZero("nm per pixel", calibration.getNmPerPixel());
        Parameters.isAboveZero("Gain", calibration.getGain());
        Parameters.isAboveZero("Exposure time", calibration.getExposureTime());
        Parameters.isAboveZero("Initial SD0", fitConfig.getInitialPeakStdDev0());
        Parameters.isAboveZero("Initial SD1", fitConfig.getInitialPeakStdDev1());
        Parameters.isPositive("Initial angle", fitConfig.getInitialAngleD());
        Parameters.isAboveZero("Search_width", config.getSearch());
        Parameters.isAboveZero("Fitting_width", config.getFitting());
        Parameters.isPositive("Failures limit", config.getFailuresLimit());
        Parameters.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
        Parameters.isPositive("Residuals threshold", config.getResidualsThreshold());
        Parameters.isPositive("Duplicate distance", fitConfig.getDuplicateDistance());
        Parameters.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
        Parameters.isPositive("Signal strength", fitConfig.getSignalStrength());
        Parameters.isPositive("Min photons", fitConfig.getMinPhotons());
        Parameters.isPositive("Min width factor", fitConfig.getMinWidthFactor());
        Parameters.isPositive("Width factor", fitConfig.getWidthFactor());
        Parameters.isPositive("Precision threshold", fitConfig.getPrecisionThreshold());
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return;
    }
    if (gd.invalidNumber())
        return;
    configurationChanged = SettingsManager.saveSettings(settings, filename);
    if (configurationChanged)
        SettingsManager.saveSettingsFilename(filename);
    if (!PeakFit.configureSmartFilter(settings, filename))
        return;
    if (!PeakFit.configureDataFilter(settings, filename, false))
        return;
    PeakFit.configureFitSolver(settings, filename, false);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Choice(java.awt.Choice) GridBagLayout(java.awt.GridBagLayout) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) Color(java.awt.Color) SystemColor(java.awt.SystemColor) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) Calibration(gdsc.smlm.results.Calibration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog) TextField(java.awt.TextField) Component(java.awt.Component) Vector(java.util.Vector)

Example 17 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PeakFit method showSimpleDialog.

private int showSimpleDialog(final String filename) {
    GlobalSettings settings = SettingsManager.loadSettings(filename);
    // Initialise the fit config so that it can be used in the calibration wizard 
    fitConfig = settings.getFitEngineConfiguration().getFitConfiguration();
    boolean requireCalibration = requireCalibration(settings, filename);
    if (requireCalibration) {
        if (!showCalibrationWizard(settings, true))
            return DONE;
    }
    // Present dialog with simple output options: Image, Table
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Fit single-molecule localisations");
    if (!requireCalibration)
        gd.addCheckbox("Use_current_calibration", true);
    gd.addCheckbox("Show_table", showTable);
    gd.addCheckbox("Show_image", showImage);
    gd.showDialog();
    if (gd.wasCanceled())
        return DONE;
    boolean useCurrentCalibration = true;
    if (!requireCalibration)
        useCurrentCalibration = gd.getNextBoolean();
    showTable = gd.getNextBoolean();
    showImage = gd.getNextBoolean();
    if (!useCurrentCalibration) {
        if (!showCalibrationWizard(settings, false))
            return DONE;
    }
    // Restore fitting to default settings but maintain the calibrated width
    final double sd = fitConfig.getInitialPeakStdDev0();
    config = new FitEngineConfiguration(new FitConfiguration());
    fitConfig = config.getFitConfiguration();
    fitConfig.setInitialPeakStdDev(sd);
    // Allow to move 1 SD
    fitConfig.setCoordinateShiftFactor(1);
    resultsSettings = new ResultsSettings();
    // Do simple results output
    resultsSettings.resultsInMemory = true;
    resultsSettings.setResultsTable((showTable) ? ResultsTable.UNCALIBRATED : ResultsTable.NONE);
    if (showImage) {
        resultsSettings.setResultsImage(ResultsImage.SIGNAL_INTENSITY);
        resultsSettings.imageScale = Math.ceil(1024 / (FastMath.max(bounds.width, bounds.height)));
        resultsSettings.weightedImage = true;
        resultsSettings.equalisedImage = true;
    } else {
        resultsSettings.setResultsImage(ResultsImage.NONE);
    }
    // Log the settings we care about:
    calibration = settings.getCalibration();
    IJ.log("-=-=-=-");
    IJ.log("Peak Fit");
    IJ.log("-=-=-=-");
    Utils.log("Pixel pitch = %s", Utils.rounded(calibration.getNmPerPixel(), 4));
    Utils.log("Exposure Time = %s", Utils.rounded(calibration.getExposureTime(), 4));
    Utils.log("Gain = %s", Utils.rounded(calibration.getGain(), 4));
    Utils.log("PSF width = %s", Utils.rounded(fitConfig.getInitialPeakStdDev0(), 4));
    // Save
    settings.setFitEngineConfiguration(config);
    settings.setResultsSettings(resultsSettings);
    SettingsManager.saveSettings(settings, filename);
    return FLAGS;
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings)

Example 18 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PeakFit method configureDataFilter.

/**
	 * Show a dialog to configure the data filter. The updated settings are saved to the settings file. An error
	 * message is shown if the dialog is cancelled or the configuration is invalid.
	 * 
	 * @param settings
	 * @param filename
	 * @param extraOptions
	 *            True if extra configuration options should be allowed
	 * @return True if the configuration succeeded
	 */
public static boolean configureDataFilter(GlobalSettings settings, String filename, boolean extraOptions) {
    FitEngineConfiguration config = settings.getFitEngineConfiguration();
    int numberOfFilters = 1;
    final int n;
    switch(config.getDataFilterType()) {
        case JURY:
            n = Integer.MAX_VALUE;
            break;
        case DIFFERENCE:
            n = 2;
            break;
        case SINGLE:
        default:
            n = 1;
    }
    String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values());
    for (int i = 1; i < n; i++) {
        int filter = i + 1;
        ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.enableYesNoCancel("Add", "Continue");
        gd.addMessage(String.format("Configure the %s filter.\nClick continue to proceed with the current set of %d.", config.getDataFilterType().toString(), i));
        String fieldName = "Spot_filter" + filter;
        if (IJ.isMacro())
            // Use blank default value so bad macro parameters return nothing
            gd.addStringField(fieldName, "");
        else
            gd.addChoice(fieldName, filterNames, filterNames[config.getDataFilter(i).ordinal()]);
        gd.addSlider("Smoothing" + filter, 0, 4.5, config.getSmooth(i));
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        if (gd.wasOKed()) {
            int filterIndex = -1;
            if (IJ.isMacro()) {
                String filterName = gd.getNextString();
                for (int j = 0; j < filterNames.length; j++) if (filterNames[j].equals(filterName)) {
                    filterIndex = j;
                    break;
                }
                if (filterIndex < 0)
                    break;
            } else
                filterIndex = gd.getNextChoiceIndex();
            config.setDataFilter(filterIndex, Math.abs(gd.getNextNumber()), i);
            numberOfFilters++;
        } else {
            break;
        }
    }
    config.setNumberOfFilters(numberOfFilters);
    if (filename != null)
        SettingsManager.saveSettings(settings, filename);
    return true;
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 19 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PeakFit method refreshSettings.

private void refreshSettings(String newFilename) {
    if (newFilename != null && new File(newFilename).exists()) {
        ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage("Reload settings from file");
        gd.showDialog();
        if (gd.wasOKed()) {
            // Reload the settings and update the GUI
            GlobalSettings settings = SettingsManager.unsafeLoadSettings(newFilename, false);
            if (settings == null)
                return;
            Calibration calibration = settings.getCalibration();
            refreshSettings(calibration);
            FitEngineConfiguration config = settings.getFitEngineConfiguration();
            refreshSettings(config, true);
            ResultsSettings resultsSettings = settings.getResultsSettings();
            refreshSettings(resultsSettings);
        }
    }
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) Calibration(gdsc.smlm.results.Calibration) ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings) File(java.io.File)

Example 20 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PeakFit method configureFitSolver.

/**
	 * Show a dialog to configure the fit solver. The updated settings are saved to the settings file. An error
	 * message is shown if the dialog is cancelled or the configuration is invalid.
	 * 
	 * @param settings
	 * @param filename
	 * @param extraOptions
	 *            True if extra configuration options should be allowed
	 * @param ignoreCalibration
	 *            True if the calibration should not be configured
	 * @return True if the configuration succeeded
	 */
public static boolean configureFitSolver(GlobalSettings settings, String filename, boolean extraOptions, boolean ignoreCalibration) {
    FitEngineConfiguration config = settings.getFitEngineConfiguration();
    FitConfiguration fitConfig = config.getFitConfiguration();
    Calibration calibration = settings.getCalibration();
    boolean isBoundedLVM = fitConfig.getFitSolver() == FitSolver.LVM_MLE || fitConfig.getFitSolver() == FitSolver.BOUNDED_LVM || fitConfig.getFitSolver() == FitSolver.BOUNDED_LVM_WEIGHTED;
    if (fitConfig.getFitSolver() == FitSolver.MLE) {
        ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage("Maximum Likelihood Estimation requires additional parameters");
        if (!ignoreCalibration) {
            gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
            gd.addCheckbox("Model_camera_noise", fitConfig.isModelCamera());
            gd.addNumericField("Read_noise (ADUs)", calibration.getReadNoise(), 2);
            gd.addNumericField("Amplification (ADU/electron)", calibration.getAmplification(), 2);
            gd.addCheckbox("EM-CCD", calibration.isEmCCD());
        }
        String[] searchNames = SettingsManager.getNames((Object[]) MaximumLikelihoodFitter.SearchMethod.values());
        gd.addChoice("Search_method", searchNames, searchNames[fitConfig.getSearchMethod().ordinal()]);
        gd.addStringField("Relative_threshold", "" + fitConfig.getRelativeThreshold());
        gd.addStringField("Absolute_threshold", "" + fitConfig.getAbsoluteThreshold());
        gd.addNumericField("Max_iterations", fitConfig.getMaxIterations(), 0);
        gd.addNumericField("Max_function_evaluations", fitConfig.getMaxFunctionEvaluations(), 0);
        if (extraOptions)
            gd.addCheckbox("Gradient_line_minimisation", fitConfig.isGradientLineMinimisation());
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        if (!ignoreCalibration) {
            calibration.setBias(Math.abs(gd.getNextNumber()));
            fitConfig.setModelCamera(gd.getNextBoolean());
            calibration.setReadNoise(Math.abs(gd.getNextNumber()));
            calibration.setAmplification(Math.abs(gd.getNextNumber()));
            calibration.setEmCCD(gd.getNextBoolean());
            fitConfig.setBias(calibration.getBias());
            fitConfig.setReadNoise(calibration.getReadNoise());
            fitConfig.setAmplification(calibration.getAmplification());
            fitConfig.setEmCCD(calibration.isEmCCD());
        }
        fitConfig.setSearchMethod(gd.getNextChoiceIndex());
        try {
            fitConfig.setRelativeThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
            fitConfig.setAbsoluteThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
        } catch (NumberFormatException e) {
            fitConfig.setRelativeThreshold(0);
            fitConfig.setAbsoluteThreshold(0);
        }
        fitConfig.setMaxIterations((int) gd.getNextNumber());
        fitConfig.setMaxFunctionEvaluations((int) gd.getNextNumber());
        if (extraOptions)
            fitConfig.setGradientLineMinimisation(gd.getNextBoolean());
        else
            // This option is for the Conjugate Gradient optimiser and makes it less stable
            fitConfig.setGradientLineMinimisation(false);
        if (filename != null)
            SettingsManager.saveSettings(settings, filename);
        try {
            Parameters.isAboveZero("Relative threshold", fitConfig.getRelativeThreshold());
            Parameters.isAboveZero("Absolute threshold", fitConfig.getAbsoluteThreshold());
            Parameters.isAboveZero("Max iterations", fitConfig.getMaxIterations());
            Parameters.isAboveZero("Max function evaluations", fitConfig.getMaxFunctionEvaluations());
            fitConfig.getFunctionSolver();
        } catch (IllegalArgumentException e) {
            IJ.error(TITLE, e.getMessage());
            return false;
        }
    } else if (isBoundedLVM || fitConfig.getFitSolver() == FitSolver.LVM || fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
        boolean isWeightedLVM = fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED || fitConfig.getFitSolver() == FitSolver.BOUNDED_LVM_WEIGHTED;
        boolean requireGain = fitConfig.getFitSolver() == FitSolver.LVM_MLE;
        boolean requireBias = isWeightedLVM || requireGain;
        // Collect options for LVM fitting
        ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage(fitConfig.getFitSolver().getShortName() + " requires additional parameters");
        String[] criteriaNames = SettingsManager.getNames((Object[]) FitCriteria.values());
        gd.addChoice("Fit_criteria", criteriaNames, criteriaNames[fitConfig.getFitCriteria().ordinal()]);
        gd.addNumericField("Significant_digits", fitConfig.getSignificantDigits(), 0);
        gd.addNumericField("Coord_delta", fitConfig.getDelta(), 4);
        gd.addNumericField("Lambda", fitConfig.getLambda(), 4);
        if (extraOptions)
            gd.addNumericField("Min_iterations", fitConfig.getMinIterations(), 0);
        gd.addNumericField("Max_iterations", fitConfig.getMaxIterations(), 0);
        // Extra parameters are needed for the weighted LVM
        if (isWeightedLVM && !ignoreCalibration) {
            gd.addMessage("Weighted LVM fitting requires a CCD camera noise model");
            gd.addNumericField("Read_noise (ADUs)", calibration.getReadNoise(), 2);
        }
        if (requireBias)
            gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
        if (requireGain)
            gd.addNumericField("Gain (ADU/photon)", calibration.getGain(), 2);
        if (isBoundedLVM) {
            gd.addCheckbox("Use_clamping", fitConfig.isUseClamping());
            gd.addCheckbox("Dynamic_clamping", fitConfig.isUseDynamicClamping());
            if (extraOptions) {
                gd.addNumericField("Clamp_background", fitConfig.getClampBackground(), 2);
                gd.addNumericField("Clamp_signal", fitConfig.getClampSignal(), 2);
                gd.addNumericField("Clamp_angle", fitConfig.getClampAngle(), 2);
                gd.addNumericField("Clamp_x", fitConfig.getClampX(), 2);
                gd.addNumericField("Clamp_y", fitConfig.getClampY(), 2);
                gd.addNumericField("Clamp_sd0", fitConfig.getClampXSD(), 2);
                gd.addNumericField("Clamp_sd1", fitConfig.getClampYSD(), 2);
            }
        }
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        fitConfig.setFitCriteria(gd.getNextChoiceIndex());
        fitConfig.setSignificantDigits((int) gd.getNextNumber());
        fitConfig.setDelta(gd.getNextNumber());
        fitConfig.setLambda(gd.getNextNumber());
        if (extraOptions)
            fitConfig.setMinIterations((int) gd.getNextNumber());
        fitConfig.setMaxIterations((int) gd.getNextNumber());
        if (isWeightedLVM && !ignoreCalibration) {
            calibration.setReadNoise(Math.abs(gd.getNextNumber()));
        }
        if (requireBias) {
            calibration.setBias(Math.abs(gd.getNextNumber()));
            fitConfig.setBias(calibration.getBias());
        }
        if (requireGain) {
            calibration.setGain(Math.abs(gd.getNextNumber()));
            fitConfig.setGain(calibration.getGain());
        }
        if (isBoundedLVM) {
            fitConfig.setUseClamping(gd.getNextBoolean());
            fitConfig.setUseDynamicClamping(gd.getNextBoolean());
            if (extraOptions) {
                fitConfig.setClampBackground(Math.abs(gd.getNextNumber()));
                fitConfig.setClampSignal(Math.abs(gd.getNextNumber()));
                fitConfig.setClampAngle(Math.abs(gd.getNextNumber()));
                fitConfig.setClampX(Math.abs(gd.getNextNumber()));
                fitConfig.setClampY(Math.abs(gd.getNextNumber()));
                fitConfig.setClampXSD(Math.abs(gd.getNextNumber()));
                fitConfig.setClampYSD(Math.abs(gd.getNextNumber()));
            }
        }
        if (isWeightedLVM && !ignoreCalibration) {
            fitConfig.setNoiseModel(CameraNoiseModel.createNoiseModel(calibration.getReadNoise(), calibration.getBias(), calibration.isEmCCD()));
        }
        if (filename != null)
            SettingsManager.saveSettings(settings, filename);
        try {
            Parameters.isAboveZero("Significant digits", fitConfig.getSignificantDigits());
            Parameters.isAboveZero("Delta", fitConfig.getDelta());
            Parameters.isAboveZero("Lambda", fitConfig.getLambda());
            Parameters.isAboveZero("Max iterations", fitConfig.getMaxIterations());
            fitConfig.getFunctionSolver();
        } catch (IllegalArgumentException e) {
            IJ.error(TITLE, e.getMessage());
            return false;
        }
    } else if (fitConfig.getFitSolver() == FitSolver.LVM_QUASI_NEWTON) {
        // No options yet for Apache LVM fitting. Save options for consistency
        if (filename != null)
            SettingsManager.saveSettings(settings, filename);
    }
    if (config.isIncludeNeighbours()) {
        if (!fitConfig.getFunctionSolver().isBounded()) {
            IJ.error(TITLE, "Including neighbours requires a bounded fit solver");
            return false;
        }
    }
    return true;
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) Calibration(gdsc.smlm.results.Calibration) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Aggregations

FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)22 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)16 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)9 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)6 Calibration (gdsc.smlm.results.Calibration)5 GenericDialog (ij.gui.GenericDialog)4 Checkbox (java.awt.Checkbox)4 XStreamException (com.thoughtworks.xstream.XStreamException)3 BasePoint (gdsc.core.match.BasePoint)3 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)3 ResultsSettings (gdsc.smlm.ij.settings.ResultsSettings)3 DirectFilter (gdsc.smlm.results.filter.DirectFilter)3 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)3 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)2 Choice (java.awt.Choice)2 TextField (java.awt.TextField)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Vector (java.util.Vector)2