Search in sources :

Example 6 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class CreateData method addPsfOptions.

/**
 * Check if there are any suitable PSF images open. If so add a choice to allow the selection of
 * the Gaussian or Image PSF model. If no PSF images are open then add options for the wavelength
 * and NA for the simulated microscope.
 *
 * @param gd the gd
 */
private void addPsfOptions(final ExtendedGenericDialog gd) {
    gd.addMessage("--- PSF Model ---");
    final List<String> imageNames = PsfCombiner.createImageList();
    final LocalList<String> availableModels = new LocalList<>();
    availableModels.add(PSF_MODELS[PSF_MODEL_GAUSSIAN]);
    availableModels.add(PSF_MODELS[PSF_MODEL_AIRY]);
    final String[] images;
    if (!imageNames.isEmpty()) {
        availableModels.add(PSF_MODELS[PSF_MODEL_IMAGE]);
        images = imageNames.toArray(new String[0]);
    } else {
        images = null;
    }
    final String[] astigmatismModels = AstigmatismModelManager.listAstigmatismModels(false, true);
    if (astigmatismModels.length != 0) {
        availableModels.add(PSF_MODELS[PSF_MODEL_ASTIGMATISM]);
    }
    final String[] models = availableModels.toArray(new String[0]);
    gd.addChoice("PSF_model", models, settings.getPsfModel(), new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer value) {
            settings.setPsfModel(models[value]);
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE, null);
            egd.addMessage("Configure the " + settings.getPsfModel() + " PSF model");
            int type = 0;
            // Get the image
            if (settings.getPsfModel().equals(PSF_MODELS[PSF_MODEL_IMAGE])) {
                egd.addChoice("PSF_image", images, settings.getPsfImageName());
            } else if (settings.getPsfModel().equals(PSF_MODELS[PSF_MODEL_ASTIGMATISM])) {
                type = 1;
                egd.addChoice("Astigmatism_model", astigmatismModels, settings.getAstigmatismModel());
                egd.addMessage(TextUtils.wrap("Note: The pixel size of the astigmatism model should match" + " the pixel pitch if fitting of the data is to be performed (i.e. fitting requires" + " the astigmatism model to be calibrated to the image). If not then the model will" + " be optionally converted before the simulation.", 80));
            } else {
                // Get the width of the model
                type = 2;
                egd.addNumericField("Depth-of-focus (nm)", settings.getDepthOfFocus(), 2);
                egd.addCheckbox("Enter_width", settings.getEnterWidth());
                egd.addNumericField("PSF_SD (nm)", settings.getPsfSd(), 2);
                egd.addMessage("Or compute from optics:");
                egd.addNumericField("Wavelength (nm)", settings.getWavelength(), 2);
                egd.addNumericField("Numerical_aperture", settings.getNumericalAperture(), 2);
            }
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            if (type == 0) {
                settings.setPsfImageName(egd.getNextChoice());
            } else if (type == 1) {
                settings.setAstigmatismModel(AstigmatismModelManager.removeFormatting(egd.getNextChoice()));
            } else {
                settings.setDepthOfFocus(egd.getNextNumber());
                settings.setEnterWidth(egd.getNextBoolean());
                settings.setPsfSd(Math.abs(egd.getNextNumber()));
                settings.setWavelength(Math.abs(egd.getNextNumber()));
                settings.setNumericalAperture(Math.abs(egd.getNextNumber()));
            }
            return true;
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 7 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class CreateData method showSimpleDialog.

/**
 * Show a dialog allowing the parameters for a simple/benchmark simulation to be performed.
 *
 * @return True if the parameters were collected
 */
private boolean showSimpleDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    settings = SettingsManager.readCreateDataSettings(0).toBuilder();
    if (simpleMode) {
        helpKey = "create-simple-data";
    } else if (benchmarkMode) {
        helpKey = "create-benchmark-data";
    } else {
        helpKey = "create-spot-data";
    }
    // Image size
    gd.addMessage("--- Image Size ---");
    gd.addNumericField("Pixel_pitch (nm)", settings.getPixelPitch(), 2);
    gd.addNumericField("Size (px)", settings.getSize(), 0);
    if (!benchmarkMode) {
        gd.addNumericField("Depth (nm)", settings.getDepth(), 0);
        gd.addCheckbox("Fixed_depth", settings.getFixedDepth());
    }
    // Noise model
    gd.addMessage("--- Noise Model ---");
    if (extraOptions) {
        gd.addCheckbox("No_poisson_noise", !settings.getPoissonNoise());
    }
    gd.addNumericField("Background (photons)", settings.getBackground(), 2);
    addCameraOptions(gd);
    addPsfOptions(gd);
    gd.addMessage("--- Fluorophores ---");
    // Do not allow grid or mask distribution
    if (simpleMode) {
        // Allow mask but not the grid
        gd.addChoice("Distribution", Arrays.copyOf(DISTRIBUTION, DISTRIBUTION.length - 1), settings.getDistribution());
        gd.addCheckbox("Sample_per_frame", settings.getSamplePerFrame());
    }
    gd.addNumericField("Particles", settings.getParticles(), 0);
    if (simpleMode) {
        gd.addNumericField("Density (um^-2)", settings.getDensity(), 2);
    } else if (benchmarkMode) {
        gd.addNumericField("X_position (nm)", settings.getXPosition(), 2);
        gd.addNumericField("Y_position (nm)", settings.getYPosition(), 2);
        gd.addNumericField("Z_position (nm)", settings.getZPosition(), 2);
    }
    gd.addNumericField("Min_Photons", settings.getPhotonsPerSecond(), 0);
    gd.addNumericField("Max_Photons", settings.getPhotonsPerSecondMaximum(), 0);
    gd.addMessage("--- Save options ---");
    gd.addCheckbox("Raw_image", settings.getRawImage());
    gd.addCheckbox("Save_image", settings.getSaveImage());
    gd.addCheckbox("Save_image_results", settings.getSaveImageResults());
    gd.addCheckbox("Save_localisations", settings.getSaveLocalisations());
    gd.addMessage("--- Report options ---");
    gd.addCheckbox("Show_histograms", settings.getShowHistograms());
    gd.addCheckbox("Choose_histograms", settings.getChooseHistograms());
    gd.addNumericField("Histogram_bins", settings.getHistogramBins(), 0);
    gd.addCheckbox("Remove_outliers", settings.getRemoveOutliers());
    if (simpleMode) {
        gd.addSlider("Density_radius (N x HWHM)", 0, 4.5, settings.getDensityRadius());
    }
    gd.addNumericField("Depth-of-field (nm)", settings.getDepthOfField(), 0);
    gd.addHelp(HelpUrls.getUrl(helpKey));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.setPixelPitch(Math.abs(gd.getNextNumber()));
    settings.setSize(Math.abs((int) gd.getNextNumber()));
    if (!benchmarkMode) {
        // Allow negative depth
        settings.setDepth(gd.getNextNumber());
        settings.setFixedDepth(gd.getNextBoolean());
    }
    if (extraOptions) {
        settings.setPoissonNoise(!gd.getNextBoolean());
        poissonNoise = settings.getPoissonNoise();
    }
    settings.setBackground(Math.abs(gd.getNextNumber()));
    settings.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
    settings.setPsfModel(gd.getNextChoice());
    if (simpleMode) {
        settings.setDistribution(gd.getNextChoice());
        settings.setSamplePerFrame(gd.getNextBoolean());
    }
    settings.setParticles(Math.abs((int) gd.getNextNumber()));
    if (simpleMode) {
        settings.setDensity(Math.abs(gd.getNextNumber()));
    } else if (benchmarkMode) {
        settings.setXPosition(gd.getNextNumber());
        settings.setYPosition(gd.getNextNumber());
        settings.setZPosition(gd.getNextNumber());
    }
    settings.setPhotonsPerSecond(Math.abs((int) gd.getNextNumber()));
    settings.setPhotonsPerSecondMaximum(Math.abs((int) gd.getNextNumber()));
    settings.setRawImage(gd.getNextBoolean());
    settings.setSaveImage(gd.getNextBoolean());
    settings.setSaveImageResults(gd.getNextBoolean());
    settings.setSaveLocalisations(gd.getNextBoolean());
    settings.setShowHistograms(gd.getNextBoolean());
    settings.setChooseHistograms(gd.getNextBoolean());
    settings.setHistogramBins((int) Math.abs(gd.getNextNumber()));
    settings.setRemoveOutliers(gd.getNextBoolean());
    if (simpleMode) {
        settings.setDensityRadius((float) gd.getNextNumber());
    }
    settings.setDepthOfField((float) Math.abs(gd.getNextNumber()));
    gd.collectOptions();
    // Save before validation so that the current values are preserved.
    SettingsManager.writeSettings(settings.build());
    if (gd.invalidNumber()) {
        return false;
    }
    // Check arguments
    try {
        ParameterUtils.isAboveZero("Pixel Pitch", settings.getPixelPitch());
        ParameterUtils.isAboveZero("Size", settings.getSize());
        if (!benchmarkMode && !settings.getFixedDepth()) {
            ParameterUtils.isPositive("Depth", settings.getDepth());
        }
        ParameterUtils.isPositive("Background", settings.getBackground());
        ParameterUtils.isAboveZero("Particles", settings.getParticles());
        if (simpleMode) {
            ParameterUtils.isAboveZero("Density", settings.getDensity());
        }
        ParameterUtils.isAboveZero("Min Photons", settings.getPhotonsPerSecond());
        if (settings.getPhotonsPerSecondMaximum() < settings.getPhotonsPerSecond()) {
            settings.setPhotonsPerSecondMaximum(settings.getPhotonsPerSecond());
        }
        ParameterUtils.isPositive("Histogram bins", settings.getHistogramBins());
        if (simpleMode) {
            ParameterUtils.isPositive("Density radius", settings.getDensityRadius());
        }
        validateCameraOptions();
        validatePsfOptions();
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    if (!benchmarkMode && settings.getDistribution().equals(DISTRIBUTION[MASK])) {
        final String[] maskImages = createDistributionImageList();
        if (maskImages != null) {
            gd = new ExtendedGenericDialog(TITLE);
            gd.addMessage("Select the mask image for the distribution");
            gd.addChoice("Distribution_mask", maskImages, settings.getDistributionMask());
            if (maskListContainsStacks) {
                gd.addNumericField("Distribution_slice_depth (nm)", settings.getDistributionMaskSliceDepth(), 0);
            }
            gd.addHelp(HelpUrls.getUrl(helpKey));
            gd.showDialog();
            if (gd.wasCanceled()) {
                return false;
            }
            settings.setDistributionMask(gd.getNextChoice());
            if (maskListContainsStacks) {
                settings.setDistributionMaskSliceDepth(Math.abs(gd.getNextNumber()));
            }
        }
        SettingsManager.writeSettings(settings.build());
    }
    return getHistogramOptions();
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 8 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class PcPalmClusters method showDialog.

private boolean showDialog() {
    moleculesResults = PcPalmMolecules.getMoleculesResults();
    settings = Settings.load();
    if (moleculesResults.molecules == null || moleculesResults.molecules.size() < 2) {
        ImageJUtils.log(TITLE + " defaulting to File mode");
        fileInput = true;
        // Ensure this gets recorded
        Recorder.recordOption("Method", "File");
    } else {
        final GenericDialog gd = new GenericDialog(TITLE);
        final String[] items = { "Clustering", "File" };
        gd.addMessage("Fit a Binomial distribution to a histogram of cluster sizes.\n \n" + "Select the method to generate the histogram:");
        gd.addChoice("Method", items, items[settings.runMode]);
        gd.addHelp(HelpUrls.getUrl("pc-palm-clusters"));
        gd.showDialog();
        if (gd.wasCanceled()) {
            return false;
        }
        settings.runMode = gd.getNextChoiceIndex();
        fileInput = (settings.runMode == 1);
    }
    settings.save();
    if (fileInput) {
        final String newFile = ImageJUtils.getFilename("Histogram_file", settings.histogramFile);
        if (newFile == null) {
            return false;
        }
        settings.histogramFile = newFile;
    }
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    // Check if the molecules have weights
    boolean haveWeights = false;
    if (!fileInput) {
        haveWeights = checkForWeights();
        gd.addMessage("Find clusters using centroid-linkage clustering.");
        gd.addNumericField("Distance", settings.distance, 0, 6, "nm");
        final String[] clusteringAlgorithmNames = SettingsManager.getNames((Object[]) ClusteringAlgorithm.values());
        gd.addChoice("Algorithm", clusteringAlgorithmNames, settings.clusteringAlgorithm.ordinal());
        gd.addCheckbox("Multi_thread", settings.multiThread);
        if (haveWeights) {
            gd.addCheckbox("Weighted_clustering", settings.weightedClustering);
        }
    }
    gd.addSlider("Min_N", 1, 10, settings.minN);
    gd.addSlider("Max_N", 0, 10, settings.maxN);
    gd.addCheckbox("Show_cumulative_histogram", settings.showCumulativeHistogram);
    gd.addCheckbox("Maximum_likelihood", settings.maximumLikelihood);
    if (!fileInput) {
        gd.addCheckbox("Save_histogram", settings.saveHistogram);
        gd.addMessage("Histogram calibration (optional)");
        gd.addCheckbox("Calibrate_histogram", settings.calibrateHistogram);
        gd.addNumericField("Frames", settings.frames, 0);
        gd.addNumericField("Area", settings.area, 2);
        gd.addChoice("Units", Settings.UNITS, settings.units);
    }
    gd.addHelp(HelpUrls.getUrl("pc-palm-clusters"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    if (!fileInput) {
        settings.distance = gd.getNextNumber();
        clusteringAlgorithm = settings.clusteringAlgorithm = ClusteringAlgorithm.values()[gd.getNextChoiceIndex()];
        settings.multiThread = gd.getNextBoolean();
        if (haveWeights) {
            weightedClustering = settings.weightedClustering = gd.getNextBoolean();
        }
    }
    settings.minN = (int) Math.abs(gd.getNextNumber());
    settings.maxN = (int) Math.abs(gd.getNextNumber());
    settings.showCumulativeHistogram = gd.getNextBoolean();
    settings.maximumLikelihood = gd.getNextBoolean();
    if (!fileInput) {
        settings.saveHistogram = gd.getNextBoolean();
        settings.calibrateHistogram = gd.getNextBoolean();
        settings.frames = (int) Math.abs(gd.getNextNumber());
        settings.area = Math.abs(gd.getNextNumber());
        settings.units = gd.getNextChoiceIndex();
    }
    // Check arguments
    try {
        ParameterUtils.isAboveZero("Min N", settings.minN);
        if (!fileInput) {
            ParameterUtils.isAboveZero("Distance", settings.distance);
            ParameterUtils.isAboveZero("Frames", settings.frames);
            ParameterUtils.isAboveZero("Area", settings.area);
        }
    } catch (final IllegalArgumentException ex) {
        error(ex.getMessage());
        return false;
    }
    return true;
}
Also used : GenericDialog(ij.gui.GenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 9 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class PcPalmMolecules method showSimulationDialog.

private boolean showSimulationDialog() {
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Simulate a random distribution of molecules.");
    gd.addNumericField("Molecules", settings.numberOfMolecules, 0);
    gd.addNumericField("Simulation_size", settings.simulationSize, 2, 6, "um");
    gd.addNumericField("Blinking_rate", settings.blinkingRate, 2);
    gd.addChoice("Blinking_distribution", Settings.BLINKING_DISTRIBUTION, settings.blinkingDistribution);
    gd.addNumericField("Average_precision", settings.sigmaS, 2, 6, "nm");
    gd.addCheckbox("Show_histograms", settings.showHistograms);
    gd.addCheckbox("Distance_analysis", settings.distanceAnalysis);
    gd.addChoice("Cluster_simulation", Settings.CLUSTER_SIMULATION, settings.clusterSimulation);
    gd.addNumericField("Cluster_number", settings.clusterNumber, 2);
    gd.addNumericField("Cluster_variation (SD)", settings.clusterNumberStdDev, 2);
    gd.addNumericField("Cluster_radius", settings.clusterRadius, 2, 6, "nm");
    gd.addCheckbox("Show_cluster_mask", settings.showClusterMask);
    gd.addHelp(HelpUrls.getUrl("pc-palm-molecules"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.numberOfMolecules = (int) Math.abs(gd.getNextNumber());
    settings.simulationSize = Math.abs(gd.getNextNumber());
    settings.blinkingRate = Math.abs(gd.getNextNumber());
    settings.blinkingDistribution = gd.getNextChoiceIndex();
    settings.sigmaS = Math.abs(gd.getNextNumber());
    settings.showHistograms = gd.getNextBoolean();
    settings.distanceAnalysis = gd.getNextBoolean();
    settings.clusterSimulation = gd.getNextChoiceIndex();
    settings.clusterNumber = Math.abs(gd.getNextNumber());
    settings.clusterNumberStdDev = Math.abs(gd.getNextNumber());
    settings.clusterRadius = Math.abs(gd.getNextNumber());
    settings.showClusterMask = gd.getNextBoolean();
    // Check arguments
    try {
        ParameterUtils.isAboveZero("Molecules", settings.numberOfMolecules);
        ParameterUtils.isAboveZero("Simulation size", settings.simulationSize);
        ParameterUtils.isEqualOrAbove("Blinking rate", settings.blinkingRate, 1);
        ParameterUtils.isEqualOrAbove("Cluster number", settings.clusterNumber, 1);
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    return getPValue();
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 10 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class DoubletAnalysis method showDialog.

/**
 * Show dialog.
 *
 * @return true, if successful
 */
private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    final String helpKey = "doublet-analysis";
    settings = Settings.load();
    config = configRef.get().createCopy();
    final FitConfiguration fitConfig = config.getFitConfiguration();
    final double sa = getSa();
    ImageJUtils.addMessage(gd, "Fits the benchmark image created by CreateData plugin.\nPSF width = %s, adjusted = %s", MathUtils.rounded(simulationParameters.sd / simulationParameters.pixelPitch), MathUtils.rounded(sa));
    // For each new benchmark width, reset the PSF width to the square pixel adjustment
    if (lastId.get() != simulationParameters.id) {
        final double w = sa;
        settings.matchDistance = w * Gaussian2DFunction.SD_TO_HWHM_FACTOR;
        settings.lowerDistance = 0.5 * settings.matchDistance;
        fitConfig.setInitialPeakStdDev(w);
        final CalibrationWriter cal = new CalibrationWriter(fitConfig.getCalibration());
        cal.setNmPerPixel(simulationParameters.pixelPitch);
        cal.setCountPerPhoton(simulationParameters.gain);
        cal.setQuantumEfficiency(simulationParameters.qe);
        cal.setExposureTime(100);
        cal.setReadNoise(simulationParameters.readNoise);
        cal.setBias(simulationParameters.bias);
        cal.setCameraType(simulationParameters.cameraType);
        fitConfig.setCameraModel(CreateData.getCameraModel(simulationParameters));
        fitConfig.setCalibration(cal.getCalibration());
    }
    // Support for using templates
    final 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", settings.useBenchmarkSettings);
    // Collect options for fitting
    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);
    gd.addChoice("Fit_solver", SettingsManager.getFitSolverNames(), fitConfig.getFitSolver().ordinal());
    gd.addSlider("Iteration_increase", 1, 4.5, settings.iterationIncrease);
    gd.addCheckbox("Ignore_with_neighbours", settings.ignoreWithNeighbours);
    gd.addCheckbox("Show_overlay", settings.showOverlay);
    gd.addCheckbox("Show_histograms", settings.showHistograms);
    gd.addCheckbox("Show_results", settings.showResults);
    gd.addCheckbox("Show_Jaccard_Plot", settings.showJaccardPlot);
    gd.addCheckbox("Use_max_residuals", settings.useMaxResiduals);
    gd.addNumericField("Match_distance", settings.matchDistance, 2);
    gd.addNumericField("Lower_distance", settings.lowerDistance, 2);
    gd.addNumericField("Signal_factor", settings.signalFactor, 2);
    gd.addNumericField("Lower_factor", settings.lowerSignalFactor, 2);
    gd.addChoice("Matching", Settings.MATCHING_METHODS, settings.matchingMethod);
    // Add a mouse listener to the config file field
    if (ImageJUtils.isShowGenericDialog()) {
        final Vector<TextField> numerics = gd.getNumericFields();
        final Vector<Choice> choices = gd.getChoices();
        final Iterator<TextField> nu = numerics.iterator();
        final Iterator<Choice> ch = choices.iterator();
        ch.next().addItemListener(this);
        final Checkbox b = (Checkbox) gd.getCheckboxes().get(0);
        b.addItemListener(this);
        textPsf = ch.next();
        textDataFilterType = ch.next();
        textDataFilter = ch.next();
        textSmooth = nu.next();
        textSearch = nu.next();
        textBorder = nu.next();
        textFitting = nu.next();
        textFitSolver = ch.next();
        // Iteration increase
        nu.next();
        textMatchDistance = nu.next();
        textLowerDistance = nu.next();
        textSignalFactor = nu.next();
        textLowerFactor = nu.next();
    }
    gd.addHelp(HelpUrls.getUrl(helpKey));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    // Ignore the template
    gd.getNextChoice();
    settings.useBenchmarkSettings = gd.getNextBoolean();
    fitConfig.setPsfType(PeakFit.getPsfTypeValues()[gd.getNextChoiceIndex()]);
    config.setDataFilterType(gd.getNextChoiceIndex());
    config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), false, 0);
    config.setSearch(gd.getNextNumber());
    config.setBorder(gd.getNextNumber());
    config.setFitting(gd.getNextNumber());
    // Some enum values are not supported
    fitConfig.setFitSolver(SettingsManager.getFitSolverValues()[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.setMaxWidthFactor(10);
    settings.iterationIncrease = gd.getNextNumber();
    settings.ignoreWithNeighbours = gd.getNextBoolean();
    settings.showOverlay = gd.getNextBoolean();
    settings.showHistograms = gd.getNextBoolean();
    settings.showResults = gd.getNextBoolean();
    settings.showJaccardPlot = gd.getNextBoolean();
    settings.useMaxResiduals = gd.getNextBoolean();
    settings.matchDistance = Math.abs(gd.getNextNumber());
    settings.lowerDistance = Math.abs(gd.getNextNumber());
    settings.signalFactor = Math.abs(gd.getNextNumber());
    settings.lowerSignalFactor = Math.abs(gd.getNextNumber());
    settings.matchingMethod = gd.getNextChoiceIndex();
    gd.collectOptions();
    settings.save();
    configRef.set(config);
    if (gd.invalidNumber()) {
        return false;
    }
    if (settings.lowerDistance > settings.matchDistance) {
        settings.lowerDistance = settings.matchDistance;
    }
    if (settings.lowerSignalFactor > settings.signalFactor) {
        settings.lowerSignalFactor = settings.signalFactor;
    }
    if (settings.useBenchmarkSettings && !updateFitConfiguration(config)) {
        return false;
    }
    boolean configure = true;
    if (settings.useBenchmarkSettings) {
        // Only configure the fit solver if not in a macro
        configure = Macro.getOptions() == null;
    }
    if (configure && !PeakFit.configurePsfModel(config)) {
        return false;
    }
    if (configure && !PeakFit.configureFitSolver(config, IJImageSource.getBounds(imp), null, PeakFit.FLAG_NO_SAVE)) {
        return false;
    }
    lastId.set(simulationParameters.id);
    if (settings.showHistograms) {
        gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage("Select the histograms to display");
        for (int i = 0; i < Settings.NAMES.length; i++) {
            gd.addCheckbox(Settings.NAMES[i].replace(' ', '_'), settings.displayHistograms[i]);
        }
        for (int i = 0; i < Settings.NAMES2.length; i++) {
            gd.addCheckbox(Settings.NAMES2[i].replace(' ', '_'), settings.displayHistograms[i + Settings.NAMES.length]);
        }
        gd.addHelp(HelpUrls.getUrl(helpKey));
        gd.showDialog();
        if (gd.wasCanceled()) {
            return false;
        }
        for (int i = 0; i < settings.displayHistograms.length; i++) {
            settings.displayHistograms[i] = gd.getNextBoolean();
        }
    }
    return true;
}
Also used : Choice(java.awt.Choice) PeakFit(uk.ac.sussex.gdsc.smlm.ij.plugins.PeakFit) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) Checkbox(java.awt.Checkbox) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) TextField(java.awt.TextField)

Aggregations

ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)151 NonBlockingExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)38 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)21 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)14 Checkbox (java.awt.Checkbox)13 ImagePlus (ij.ImagePlus)12 File (java.io.File)11 Rectangle (java.awt.Rectangle)10 TextField (java.awt.TextField)10 ResultsImageSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings)10 FitConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitConfiguration)10 Choice (java.awt.Choice)9 ArrayList (java.util.ArrayList)9 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)9 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)8 CalibrationReader (uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader)7 ResultsSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings)7 ResultsTableSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsTableSettings)7 IJ (ij.IJ)6 GenericDialog (ij.gui.GenericDialog)5