Search in sources :

Example 61 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class EMGainAnalysis method showDialog.

private int showDialog() {
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Analyse the white-light histogram of an image stack to determine EM-gain parameters.\n \n" + "See Ulbrich & Isacoff (2007). Nature Methods 4, 319-321 (Supplementary Information).");
    if (extraOptions) {
        gd.addCheckbox("Simulate", _simulate);
        gd.addNumericField("Bias", _bias, 0);
        gd.addNumericField("Gain", _gain, 2);
        gd.addNumericField("Noise", _noise, 2);
        gd.addNumericField("Photons", _photons, 2);
        gd.addNumericField("Samples", simulationSize, 0);
        gd.addCheckbox("Sample_PDF", usePDF);
    }
    gd.addNumericField("Bias_estimate", bias, 0);
    gd.addNumericField("Gain_estimate", gain, 2);
    gd.addNumericField("Noise_estimate", noise, 2);
    gd.addCheckbox("Show_approximation", showApproximation);
    gd.showDialog();
    if (gd.wasCanceled())
        return DONE;
    if (extraOptions) {
        simulate = _simulate = gd.getNextBoolean();
        _bias = gd.getNextNumber();
        _gain = gd.getNextNumber();
        _noise = FastMath.abs(gd.getNextNumber());
        _photons = FastMath.abs(gd.getNextNumber());
        simulationSize = (int) FastMath.abs(gd.getNextNumber());
        usePDF = gd.getNextBoolean();
        if (gd.invalidNumber() || _bias < 0 || _gain < 1 || _photons == 0 || simulationSize == 0)
            return DONE;
    }
    bias = gd.getNextNumber();
    gain = gd.getNextNumber();
    noise = FastMath.abs(gd.getNextNumber());
    showApproximation = gd.getNextBoolean();
    if (gd.invalidNumber() || bias < 0 || gain < 1)
        return DONE;
    return (simulate) ? NO_IMAGE_REQUIRED : FLAGS;
}
Also used : GenericDialog(ij.gui.GenericDialog)

Example 62 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class EMGainAnalysis method showPMFDialog.

private boolean showPMFDialog() {
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Plot the probability mass function for EM-gain");
    gd.addNumericField("Gain", _gain, 2);
    gd.addNumericField("Noise", _noise, 2);
    gd.addNumericField("Photons", _photons, 2);
    gd.addChoice("Approx", APPROXIMATION, APPROXIMATION[approximation]);
    gd.addCheckbox("Show_approximation", showApproximation);
    if (extraOptions)
        gd.addNumericField("Approximation_offset (%)", _offset, 2);
    gd.addNumericField("Remove_head", head, 3);
    gd.addNumericField("Remove_tail", tail, 3);
    gd.addCheckbox("Relative_delta", relativeDelta);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    _gain = gd.getNextNumber();
    _noise = FastMath.abs(gd.getNextNumber());
    _photons = FastMath.abs(gd.getNextNumber());
    approximation = gd.getNextChoiceIndex();
    showApproximation = gd.getNextBoolean();
    if (extraOptions)
        offset = _offset = gd.getNextNumber();
    head = FastMath.abs(gd.getNextNumber());
    tail = FastMath.abs(gd.getNextNumber());
    relativeDelta = gd.getNextBoolean();
    if (gd.invalidNumber() || _bias < 0 || _gain < 1 || _photons == 0 || tail > 0.5 || head > 0.5)
        return false;
    return true;
}
Also used : GenericDialog(ij.gui.GenericDialog)

Example 63 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class DoubletAnalysis method showAnalysisDialog.

/**
	 * Show dialog.
	 *
	 * @return true, if successful
	 */
@SuppressWarnings("unchecked")
private boolean showAnalysisDialog() {
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    StringBuilder sb = new StringBuilder("Filters the doublet fits and reports the performance increase\n");
    // Show the fitting settings that will effect filters, i.e. fit standard deviation, fit width
    sb.append("SD0 = ").append(Utils.rounded(fitConfig.getInitialPeakStdDev0())).append("\n");
    sb.append("SD1 = ").append(Utils.rounded(fitConfig.getInitialPeakStdDev1())).append("\n");
    sb.append("Fit Width = ").append(config.getRelativeFitting()).append("\n");
    gd.addMessage(sb.toString());
    // Collect options for filtering
    gd.addChoice("Selection_Criteria", SELECTION_CRITERIA, SELECTION_CRITERIA[selectionCriteria]);
    // Copy the settings used when fitting
    filterFitConfig.setInitialPeakStdDev0(fitConfig.getInitialPeakStdDev0());
    filterFitConfig.setInitialPeakStdDev1(fitConfig.getInitialPeakStdDev1());
    filterFitConfig.setModelCamera(fitConfig.isModelCamera());
    filterFitConfig.setNmPerPixel(cal.getNmPerPixel());
    filterFitConfig.setGain(cal.getGain());
    filterFitConfig.setBias(cal.getBias());
    filterFitConfig.setReadNoise(cal.getReadNoise());
    filterFitConfig.setAmplification(cal.getAmplification());
    filterFitConfig.setEmCCD(cal.isEmCCD());
    filterFitConfig.setFitSolver(fitConfig.getFitSolver());
    String[] templates = ConfigurationTemplate.getTemplateNames(true);
    gd.addChoice("Template", templates, templates[0]);
    // Allow the settings from the benchmark analysis to be used
    gd.addCheckbox("Benchmark_settings", analysisUseBenchmarkSettings);
    gd.addCheckbox("Smart_filter", fitConfig.isSmartFilter());
    gd.addSlider("Shift_factor", 0.01, 2, filterFitConfig.getCoordinateShiftFactor());
    gd.addNumericField("Signal_strength", filterFitConfig.getSignalStrength(), 2);
    gd.addNumericField("Min_photons", filterFitConfig.getMinPhotons(), 0);
    gd.addSlider("Min_width_factor", 0, 0.99, filterFitConfig.getMinWidthFactor());
    gd.addSlider("Max_width_factor", 1.01, 5, filterFitConfig.getWidthFactor());
    gd.addNumericField("Precision", filterFitConfig.getPrecisionThreshold(), 2);
    gd.addCheckbox("Local_background", filterFitConfig.isPrecisionUsingBackground());
    gd.addNumericField("Drift_angle", analysisDriftAngle, 2);
    gd.addNumericField("Min_gap", minGap, 2);
    // Collect display options
    gd.addCheckbox("Show_results", analysisShowResults);
    gd.addCheckbox("Show_Jaccard_Plot", showJaccardPlot);
    gd.addCheckbox("Use_max_residuals", useMaxResiduals);
    gd.addCheckbox("Logging", analysisLogging);
    gd.addStringField("Title", analysisTitle);
    gd.addCheckbox("Save_template", saveTemplate);
    // Add a mouse listener to the config file field
    if (Utils.isShowGenericDialog()) {
        Vector<TextField> numerics = (Vector<TextField>) gd.getNumericFields();
        Vector<Checkbox> checkboxes = (Vector<Checkbox>) gd.getCheckboxes();
        Vector<Choice> choices = (Vector<Choice>) gd.getChoices();
        int n = 0;
        choices.get(1).addItemListener(this);
        checkboxes.get(0).addItemListener(this);
        cbSmartFilter = checkboxes.get(1);
        textCoordinateShiftFactor = numerics.get(n++);
        textSignalStrength = numerics.get(n++);
        textMinPhotons = numerics.get(n++);
        textMinWidthFactor = numerics.get(n++);
        textWidthFactor = numerics.get(n++);
        textPrecisionThreshold = numerics.get(n++);
        cbLocalBackground = checkboxes.get(2);
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    if (gd.invalidNumber())
        return false;
    selectionCriteria = gd.getNextChoiceIndex();
    // Ignore the template
    gd.getNextChoice();
    analysisUseBenchmarkSettings = gd.getNextBoolean();
    fitConfig.setSmartFilter(gd.getNextBoolean());
    filterFitConfig.setCoordinateShiftFactor(gd.getNextNumber());
    filterFitConfig.setSignalStrength(gd.getNextNumber());
    filterFitConfig.setMinPhotons(gd.getNextNumber());
    filterFitConfig.setMinWidthFactor(gd.getNextNumber());
    filterFitConfig.setWidthFactor(gd.getNextNumber());
    filterFitConfig.setPrecisionThreshold(gd.getNextNumber());
    filterFitConfig.setPrecisionUsingBackground(gd.getNextBoolean());
    analysisDriftAngle = gd.getNextNumber();
    minGap = gd.getNextNumber();
    analysisShowResults = gd.getNextBoolean();
    showJaccardPlot = gd.getNextBoolean();
    useMaxResiduals = gd.getNextBoolean();
    analysisLogging = gd.getNextBoolean();
    analysisTitle = gd.getNextString();
    saveTemplate = gd.getNextBoolean();
    if (gd.invalidNumber())
        return false;
    if (analysisUseBenchmarkSettings) {
        if (!updateFilterConfiguration(filterFitConfig))
            return false;
    }
    return true;
}
Also used : Choice(java.awt.Choice) Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog) TextField(java.awt.TextField) Vector(java.util.Vector) PeakResultPoint(gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint) BasePoint(gdsc.core.match.BasePoint)

Example 64 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class DoubletAnalysis method showDialog.

/**
	 * Show dialog.
	 *
	 * @return true, if successful
	 */
@SuppressWarnings("unchecked")
private boolean showDialog() {
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    final double sa = getSa();
    gd.addMessage(String.format("Fits the benchmark image created by CreateData plugin.\nPSF width = %s, adjusted = %s", Utils.rounded(simulationParameters.s / simulationParameters.a), Utils.rounded(sa)));
    // For each new benchmark width, reset the PSF width to the square pixel adjustment
    if (lastId != simulationParameters.id) {
        double w = sa;
        matchDistance = w * Gaussian2DFunction.SD_TO_HWHM_FACTOR;
        lowerDistance = 0.5 * matchDistance;
        fitConfig.setInitialPeakStdDev(w);
        cal.setNmPerPixel(simulationParameters.a);
        cal.setGain(simulationParameters.gain);
        cal.setAmplification(simulationParameters.amplification);
        cal.setExposureTime(100);
        cal.setReadNoise(simulationParameters.readNoise);
        cal.setBias(simulationParameters.bias);
        cal.setEmCCD(simulationParameters.emCCD);
        fitConfig.setGain(cal.getGain());
        fitConfig.setBias(cal.getBias());
        fitConfig.setReadNoise(cal.getReadNoise());
        fitConfig.setAmplification(cal.getAmplification());
    }
    // Support for using templates
    String[] templates = ConfigurationTemplate.getTemplateNames(true);
    gd.addChoice("Template", templates, templates[0]);
    // Allow the settings from the benchmark analysis to be used
    gd.addCheckbox("Benchmark_settings", useBenchmarkSettings);
    // Collect options for fitting
    gd.addNumericField("Initial_StdDev", fitConfig.getInitialPeakStdDev0(), 3);
    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());
    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()]);
    gd.addSlider("Iteration_increase", 1, 4.5, iterationIncrease);
    gd.addCheckbox("Ignore_with_neighbours", ignoreWithNeighbours);
    gd.addCheckbox("Show_overlay", showOverlay);
    gd.addCheckbox("Show_histograms", showHistograms);
    gd.addCheckbox("Show_results", showResults);
    gd.addCheckbox("Show_Jaccard_Plot", showJaccardPlot);
    gd.addCheckbox("Use_max_residuals", useMaxResiduals);
    gd.addNumericField("Match_distance", matchDistance, 2);
    gd.addNumericField("Lower_distance", lowerDistance, 2);
    gd.addNumericField("Signal_factor", signalFactor, 2);
    gd.addNumericField("Lower_factor", lowerSignalFactor, 2);
    gd.addChoice("Matching", MATCHING, MATCHING[matching]);
    // Add a mouse listener to the config file field
    if (Utils.isShowGenericDialog()) {
        Vector<TextField> numerics = (Vector<TextField>) gd.getNumericFields();
        Vector<Choice> choices = (Vector<Choice>) gd.getChoices();
        int n = 0;
        int ch = 0;
        choices.get(ch++).addItemListener(this);
        Checkbox b = (Checkbox) gd.getCheckboxes().get(0);
        b.addItemListener(this);
        textInitialPeakStdDev0 = 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++);
        // Iteration increase
        n++;
        textMatchDistance = numerics.get(n++);
        textLowerDistance = numerics.get(n++);
        textSignalFactor = numerics.get(n++);
        textLowerFactor = numerics.get(n++);
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    // Ignore the template
    gd.getNextChoice();
    useBenchmarkSettings = gd.getNextBoolean();
    fitConfig.setInitialPeakStdDev(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());
    // Avoid stupidness. Note: We are mostly ignoring the validation result and 
    // checking the results for the doublets manually.
    // Realistically we cannot fit lower than this
    fitConfig.setMinPhotons(15);
    // Set the width factors to help establish bounds for bounded fitters
    fitConfig.setMinWidthFactor(1.0 / 10);
    fitConfig.setWidthFactor(10);
    iterationIncrease = gd.getNextNumber();
    ignoreWithNeighbours = gd.getNextBoolean();
    showOverlay = gd.getNextBoolean();
    showHistograms = gd.getNextBoolean();
    showResults = gd.getNextBoolean();
    showJaccardPlot = gd.getNextBoolean();
    useMaxResiduals = gd.getNextBoolean();
    matchDistance = Math.abs(gd.getNextNumber());
    lowerDistance = Math.abs(gd.getNextNumber());
    signalFactor = Math.abs(gd.getNextNumber());
    lowerSignalFactor = Math.abs(gd.getNextNumber());
    matching = gd.getNextChoiceIndex();
    if (gd.invalidNumber())
        return false;
    if (lowerDistance > matchDistance)
        lowerDistance = matchDistance;
    if (lowerSignalFactor > signalFactor)
        lowerSignalFactor = signalFactor;
    if (useBenchmarkSettings) {
        if (!updateFitConfiguration(config))
            return false;
    }
    GlobalSettings settings = new GlobalSettings();
    settings.setFitEngineConfiguration(config);
    settings.setCalibration(cal);
    boolean configure = true;
    if (useBenchmarkSettings) {
        // Only configure the fit solver if not in a macro
        configure = Macro.getOptions() == null;
    }
    if (configure && !PeakFit.configureFitSolver(settings, null, false))
        return false;
    lastId = simulationParameters.id;
    if (showHistograms) {
        gd = new GenericDialog(TITLE);
        gd.addMessage("Select the histograms to display");
        for (int i = 0; i < NAMES.length; i++) gd.addCheckbox(NAMES[i].replace(' ', '_'), displayHistograms[i]);
        for (int i = 0; i < NAMES2.length; i++) gd.addCheckbox(NAMES2[i].replace(' ', '_'), displayHistograms[i + NAMES.length]);
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        for (int i = 0; i < displayHistograms.length; i++) displayHistograms[i] = gd.getNextBoolean();
    }
    return true;
}
Also used : Choice(java.awt.Choice) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) PeakResultPoint(gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint) BasePoint(gdsc.core.match.BasePoint) Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog) TextField(java.awt.TextField) Vector(java.util.Vector)

Example 65 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class DiffusionRateTest method showDialog.

private boolean showDialog() {
    GenericDialog gd = new GenericDialog(TITLE);
    GlobalSettings globalSettings = SettingsManager.loadSettings();
    settings = globalSettings.getCreateDataSettings();
    if (settings.stepsPerSecond < 1)
        settings.stepsPerSecond = 1;
    gd.addNumericField("Pixel_pitch (nm)", settings.pixelPitch, 2);
    gd.addNumericField("Seconds", settings.seconds, 1);
    gd.addSlider("Steps_per_second", 1, 15, settings.stepsPerSecond);
    if (extraOptions) {
        gd.addSlider("Aggregate_steps", 2, 20, aggregateSteps);
        gd.addNumericField("MSD_analysis_steps", msdAnalysisSteps, 0);
    }
    gd.addNumericField("Particles", settings.particles, 0);
    gd.addNumericField("Diffusion_rate (um^2/sec)", settings.diffusionRate, 2);
    if (extraOptions)
        gd.addNumericField("Precision (nm)", precision, 2);
    String[] diffusionTypes = SettingsManager.getNames((Object[]) DiffusionType.values());
    gd.addChoice("Diffusion_type", diffusionTypes, diffusionTypes[settings.getDiffusionType().ordinal()]);
    gd.addCheckbox("Use_confinement", useConfinement);
    gd.addSlider("Confinement_attempts", 1, 20, confinementAttempts);
    gd.addSlider("Confinement_radius (nm)", 0, 3000, settings.confinementRadius);
    gd.addSlider("Fit_N", 5, 20, fitN);
    gd.addCheckbox("Show_example", showDiffusionExample);
    gd.addSlider("Magnification", 1, 10, magnification);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    settings.pixelPitch = Math.abs(gd.getNextNumber());
    settings.seconds = Math.abs(gd.getNextNumber());
    settings.stepsPerSecond = Math.abs(gd.getNextNumber());
    if (extraOptions) {
        myAggregateSteps = aggregateSteps = Math.abs((int) gd.getNextNumber());
        myMsdAnalysisSteps = msdAnalysisSteps = Math.abs((int) gd.getNextNumber());
    }
    settings.particles = Math.abs((int) gd.getNextNumber());
    settings.diffusionRate = Math.abs(gd.getNextNumber());
    if (extraOptions)
        myPrecision = precision = Math.abs(gd.getNextNumber());
    settings.setDiffusionType(gd.getNextChoiceIndex());
    useConfinement = gd.getNextBoolean();
    confinementAttempts = Math.abs((int) gd.getNextNumber());
    settings.confinementRadius = Math.abs(gd.getNextNumber());
    fitN = Math.abs((int) gd.getNextNumber());
    showDiffusionExample = gd.getNextBoolean();
    magnification = gd.getNextNumber();
    // Save before validation so that the current values are preserved.
    SettingsManager.saveSettings(globalSettings);
    // Check arguments
    try {
        Parameters.isAboveZero("Pixel Pitch", settings.pixelPitch);
        Parameters.isAboveZero("Seconds", settings.seconds);
        Parameters.isAboveZero("Steps per second", settings.stepsPerSecond);
        Parameters.isAboveZero("Particles", settings.particles);
        Parameters.isPositive("Diffusion rate", settings.diffusionRate);
        Parameters.isAboveZero("Magnification", magnification);
        Parameters.isAboveZero("Confinement attempts", confinementAttempts);
        Parameters.isAboveZero("Fit N", fitN);
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    if (settings.diffusionRate == 0)
        IJ.error(TITLE, "Warning : Diffusion rate is zero");
    if (gd.invalidNumber())
        return false;
    SettingsManager.saveSettings(globalSettings);
    return true;
}
Also used : GenericDialog(ij.gui.GenericDialog) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings)

Aggregations

GenericDialog (ij.gui.GenericDialog)87 NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)12 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)10 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)9 Checkbox (java.awt.Checkbox)9 Color (java.awt.Color)8 Component (java.awt.Component)8 GridBagConstraints (java.awt.GridBagConstraints)8 GridBagLayout (java.awt.GridBagLayout)8 Rectangle (java.awt.Rectangle)7 BasePoint (gdsc.core.match.BasePoint)6 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)6 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)6 Calibration (gdsc.smlm.results.Calibration)6 ArrayList (java.util.ArrayList)6 PeakResult (gdsc.smlm.results.PeakResult)5 TextField (java.awt.TextField)5 File (java.io.File)5 Vector (java.util.Vector)5 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)4