Search in sources :

Example 36 with GenericDialog

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

the class CreateData method showSimulationParametersDialog.

private SimulationParameters showSimulationParametersDialog(ImagePlus imp, MemoryPeakResults results) {
    int molecules = results.size();
    // Get the missing parameters from the user
    boolean fullSimulation = false;
    double s = -1;
    // Get these from the data
    double[] signal = getSignal(results);
    double[] limits = Maths.limits(signal);
    double minSignal = limits[0];
    double maxSignal = limits[1];
    double signalPerFrame = Maths.sum(signal) / molecules;
    double[] depths = getDepth(results);
    limits = Maths.limits(depths);
    double depth = Math.max(Math.abs(limits[0]), Math.abs(limits[1]));
    boolean fixedDepth = Double.compare(limits[0], limits[1]) == 0;
    Calibration cal = new Calibration();
    // Get any calibration we have
    if (results.getCalibration() != null)
        cal = results.getCalibration();
    // Get this from the user
    double b = -1;
    // This is good if we are re-running the plugin to load data.
    if (simulationParameters != null && simulationParameters.isLoaded()) {
        fullSimulation = simulationParameters.fullSimulation;
        s = simulationParameters.s;
        b = simulationParameters.b;
        if (!cal.hasBias())
            cal.setBias(simulationParameters.bias);
        if (!cal.hasGain())
            cal.setGain(simulationParameters.gain);
        if (!cal.hasAmplification())
            cal.setAmplification(simulationParameters.amplification);
        if (!cal.hasReadNoise())
            cal.setReadNoise(simulationParameters.readNoise);
        if (!cal.hasEMCCD())
            cal.setEmCCD(simulationParameters.emCCD);
        if (!cal.hasNmPerPixel())
            cal.setNmPerPixel(simulationParameters.a);
    }
    // Show a dialog to confirm settings
    GenericDialog gd = new GenericDialog(TITLE);
    StringBuilder sb = new StringBuilder();
    sb.append("Results contain ").append(Utils.pleural(molecules, "molecule")).append('\n');
    sb.append("Min signal = ").append(Utils.rounded(minSignal)).append(" ADU\n");
    sb.append("Max signal = ").append(Utils.rounded(maxSignal)).append(" ADU\n");
    sb.append("Av signal = ").append(Utils.rounded(signalPerFrame)).append(" ADU\n");
    if (fixedDepth)
        sb.append("Fixed depth = ").append(Utils.rounded(depth)).append('\n');
    gd.addMessage(sb.toString());
    gd.addCheckbox("Flourophore_simulation", fullSimulation);
    gd.addNumericField("Gaussian_SD", s, 3, 8, "nm");
    gd.addNumericField("Pixel_pitch", cal.getNmPerPixel(), 3, 8, "nm");
    gd.addNumericField("Background", b, 3, 8, "photon");
    gd.addNumericField("Total_gain", cal.getGain(), 3, 8, "ADU/photon");
    gd.addNumericField("Amplification", cal.getAmplification(), 3, 8, "ADU/e-");
    gd.addCheckbox("EM-CCD", cal.isEmCCD());
    gd.addNumericField("Read_noise", cal.getReadNoise(), 3, 8, "ADU");
    gd.addNumericField("Bias", cal.getBias(), 3, 8, "pixel");
    if (!fixedDepth) {
        gd.addNumericField("Depth", depth, 3, 8, "pixel");
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return null;
    fullSimulation = gd.getNextBoolean();
    s = gd.getNextNumber();
    cal.setNmPerPixel(gd.getNextNumber());
    b = gd.getNextNumber();
    cal.setGain(gd.getNextNumber());
    cal.setAmplification(gd.getNextNumber());
    cal.setEmCCD(gd.getNextBoolean());
    cal.setReadNoise(gd.getNextNumber());
    cal.setBias(gd.getNextNumber());
    double myDepth = depth;
    if (!fixedDepth) {
        myDepth = gd.getNextNumber();
        if (myDepth < depth) {
            IJ.error(TITLE, String.format("Input depth is smaller than the depth guessed from the data: %f < %f", myDepth, depth));
            return null;
        }
        depth = myDepth;
    }
    // Validate settings
    try {
        Parameters.isAboveZero("Gaussian_SD", s);
        Parameters.isAboveZero("Pixel_pitch", cal.getNmPerPixel());
        Parameters.isPositive("Background", b);
        Parameters.isAboveZero("Total_gain", cal.getGain());
        Parameters.isAboveZero("Amplification", cal.getAmplification());
        Parameters.isPositive("Read_noise", cal.getReadNoise());
        Parameters.isPositive("Bias", cal.getBias());
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return null;
    }
    // Store calibration
    results.setCalibration(cal);
    double gain = cal.getGain();
    double a = cal.getNmPerPixel();
    double bias = cal.getBias();
    double readNoise = cal.getReadNoise();
    double amplification = cal.getAmplification();
    boolean emCCD = cal.isEmCCD();
    // Convert ADU values to photons
    minSignal /= gain;
    maxSignal /= gain;
    signalPerFrame /= gain;
    // Convert +/- depth to total depth in nm
    depth *= 2 * a;
    // Compute total background variance in photons
    double backgroundVariance = b;
    // Do not add EM-CCD noise factor. The Mortensen formula also includes this factor 
    // so this is "double-counting" the EM-CCD.  
    //if (emCCD)
    //	backgroundVariance *= 2;
    // Read noise is in ADUs. Convert to Photons to get contribution to background variance
    double readNoiseInPhotons = readNoise / gain;
    // Get the expected value at each pixel in photons. Assuming a Poisson distribution this 
    // is equal to the total variance at the pixel.
    double b2 = backgroundVariance + readNoiseInPhotons * readNoiseInPhotons;
    SimulationParameters p = new SimulationParameters(molecules, fullSimulation, s, a, minSignal, maxSignal, signalPerFrame, depth, fixedDepth, bias, emCCD, gain, amplification, readNoise, b, b2);
    p.loaded = true;
    return p;
}
Also used : GenericDialog(ij.gui.GenericDialog) Calibration(gdsc.smlm.results.Calibration)

Example 37 with GenericDialog

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

the class CreateData method getHistogramOptions.

private boolean getHistogramOptions() {
    GenericDialog gd;
    if (settings.showHistograms && settings.chooseHistograms) {
        gd = new GenericDialog(TITLE);
        gd.addMessage("Select the histograms to display");
        for (int i = 0; i < displayHistograms.length; i++) gd.addCheckbox(NAMES[i].replace(' ', '_'), displayHistograms[i]);
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        for (int i = 0; i < displayHistograms.length; i++) displayHistograms[i] = gd.getNextBoolean();
    }
    return true;
}
Also used : GenericDialog(ij.gui.GenericDialog)

Example 38 with GenericDialog

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

the class CreateData method showDialog.

/**
	 * Show a dialog allowing the parameters for a simulation to be performed
	 * 
	 * @return True if the parameters were collected
	 */
private boolean showDialog() {
    // In track mode we do not need a time, illumination model or blinking model.
    // Fixed length tracks will be drawn, non-overlapping in time. This is the simplest
    // simulation for moving molecules
    GenericDialog gd = new GenericDialog(TITLE);
    globalSettings = SettingsManager.loadSettings();
    settings = globalSettings.getCreateDataSettings();
    if (settings.stepsPerSecond < 1)
        settings.stepsPerSecond = 1;
    String[] backgroundImages = createBackgroundImageList();
    gd.addNumericField("Pixel_pitch (nm)", settings.pixelPitch, 2);
    gd.addNumericField("Size (px)", settings.size, 0);
    gd.addNumericField("Depth (nm)", settings.depth, 0);
    gd.addCheckbox("Fixed_depth", settings.fixedDepth);
    if (!trackMode)
        gd.addNumericField("Seconds", settings.seconds, 1);
    gd.addNumericField("Exposure_time (ms)", settings.exposureTime, 1);
    gd.addSlider("Steps_per_second", 1, 15, settings.stepsPerSecond);
    if (!trackMode) {
        gd.addChoice("Illumination", ILLUMINATION, settings.illumination);
        gd.addNumericField("Pulse_interval", settings.pulseInterval, 0);
        gd.addNumericField("Pulse_ratio", settings.pulseRatio, 2);
    }
    if (backgroundImages != null)
        gd.addChoice("Background_image", backgroundImages, settings.backgroundImage);
    if (extraOptions)
        gd.addCheckbox("No_poisson_noise", !settings.poissonNoise);
    gd.addNumericField("Background (photons)", settings.background, 2);
    gd.addNumericField("EM_gain", settings.getEmGain(), 2);
    gd.addNumericField("Camera_gain (ADU/e-)", settings.getCameraGain(), 4);
    gd.addNumericField("Quantum_efficiency", settings.getQuantumEfficiency(), 2);
    gd.addNumericField("Read_noise (e-)", settings.readNoise, 2);
    gd.addNumericField("Bias", settings.bias, 0);
    List<String> imageNames = addPSFOptions(gd);
    gd.addMessage("--- Fluorophores ---");
    Component splitLabel = gd.getMessage();
    gd.addChoice("Distribution", DISTRIBUTION, settings.distribution);
    gd.addNumericField("Particles", settings.particles, 0);
    gd.addCheckbox("Compound_molecules", settings.compoundMolecules);
    gd.addNumericField("Diffusion_rate (um^2/sec)", settings.diffusionRate, 2);
    String[] diffusionTypes = SettingsManager.getNames((Object[]) DiffusionType.values());
    gd.addChoice("Diffusion_type", diffusionTypes, diffusionTypes[settings.getDiffusionType().ordinal()]);
    gd.addSlider("Fixed_fraction (%)", 0, 100, settings.fixedFraction * 100);
    gd.addChoice("Confinement", CONFINEMENT, settings.confinement);
    gd.addNumericField("Photons (sec^-1)", settings.photonsPerSecond, 0);
    // We cannot use the correlation moe with fixed life time tracks 
    String[] dist = (trackMode) ? Arrays.copyOf(PHOTON_DISTRIBUTION, PHOTON_DISTRIBUTION.length - 1) : PHOTON_DISTRIBUTION;
    gd.addChoice("Photon_distribution", dist, settings.photonDistribution);
    gd.addNumericField("On_time (ms)", settings.tOn, 2);
    if (!trackMode) {
        gd.addNumericField("Off_time_short (ms)", settings.tOffShort, 2);
        gd.addNumericField("Off_time_long (ms)", settings.tOffLong, 2);
        gd.addNumericField("n_Blinks_Short", settings.nBlinksShort, 2);
        gd.addNumericField("n_Blinks_Long", settings.nBlinksLong, 2);
        gd.addCheckbox("Use_geometric_distribution", settings.nBlinksGeometricDistribution);
    }
    gd.addMessage("--- Peak filtering ---");
    gd.addSlider("Min_Photons", 0, 50, settings.minPhotons);
    gd.addSlider("Min_SNR_t1", 0, 20, settings.minSNRt1);
    gd.addSlider("Min_SNR_tN", 0, 10, settings.minSNRtN);
    gd.addMessage("--- Save options ---");
    Component splitLabel2 = gd.getMessage();
    gd.addCheckbox("Raw_image", settings.rawImage);
    gd.addCheckbox("Save_image", settings.saveImage);
    gd.addCheckbox("Save_image_results", settings.saveImageResults);
    gd.addCheckbox("Save_fluorophores", settings.saveFluorophores);
    gd.addCheckbox("Save_localisations", settings.saveLocalisations);
    gd.addMessage("--- Report options ---");
    gd.addCheckbox("Show_histograms", settings.showHistograms);
    gd.addCheckbox("Choose_histograms", settings.chooseHistograms);
    gd.addNumericField("Histogram_bins", settings.histogramBins, 0);
    gd.addCheckbox("Remove_outliers", settings.removeOutliers);
    gd.addSlider("Density_radius (N x HWHM)", 0, 4.5, settings.densityRadius);
    gd.addNumericField("Depth-of-field (nm)", settings.depthOfField, 0);
    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 || comp == splitLabel2) {
                xOffset += 2;
                yOffset -= rowCount;
                rowCount = 0;
            }
            // 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 false;
    settings.pixelPitch = Math.abs(gd.getNextNumber());
    settings.size = Math.abs((int) gd.getNextNumber());
    settings.depth = Math.abs(gd.getNextNumber());
    settings.fixedDepth = gd.getNextBoolean();
    if (!trackMode)
        settings.seconds = Math.abs(gd.getNextNumber());
    settings.exposureTime = Math.abs(gd.getNextNumber());
    settings.stepsPerSecond = Math.abs(gd.getNextNumber());
    if (!trackMode) {
        settings.illumination = gd.getNextChoice();
        settings.pulseInterval = Math.abs((int) gd.getNextNumber());
        settings.pulseRatio = Math.abs(gd.getNextNumber());
    }
    if (backgroundImages != null)
        settings.backgroundImage = gd.getNextChoice();
    if (extraOptions)
        poissonNoise = settings.poissonNoise = !gd.getNextBoolean();
    settings.background = Math.abs(gd.getNextNumber());
    settings.setEmGain(Math.abs(gd.getNextNumber()));
    settings.setCameraGain(Math.abs(gd.getNextNumber()));
    settings.setQuantumEfficiency(Math.abs(gd.getNextNumber()));
    settings.readNoise = Math.abs(gd.getNextNumber());
    settings.bias = Math.abs((int) gd.getNextNumber());
    if (!collectPSFOptions(gd, imageNames))
        return false;
    settings.distribution = gd.getNextChoice();
    settings.particles = Math.abs((int) gd.getNextNumber());
    settings.compoundMolecules = gd.getNextBoolean();
    settings.diffusionRate = Math.abs(gd.getNextNumber());
    settings.setDiffusionType(gd.getNextChoiceIndex());
    settings.fixedFraction = Math.abs(gd.getNextNumber() / 100.0);
    settings.confinement = gd.getNextChoice();
    settings.photonsPerSecond = Math.abs((int) gd.getNextNumber());
    settings.photonDistribution = gd.getNextChoice();
    settings.tOn = Math.abs(gd.getNextNumber());
    if (!trackMode) {
        settings.tOffShort = Math.abs(gd.getNextNumber());
        settings.tOffLong = Math.abs(gd.getNextNumber());
        settings.nBlinksShort = Math.abs(gd.getNextNumber());
        settings.nBlinksLong = Math.abs(gd.getNextNumber());
        settings.nBlinksGeometricDistribution = gd.getNextBoolean();
    }
    minPhotons = settings.minPhotons = gd.getNextNumber();
    minSNRt1 = settings.minSNRt1 = gd.getNextNumber();
    minSNRtN = settings.minSNRtN = gd.getNextNumber();
    settings.rawImage = gd.getNextBoolean();
    settings.saveImage = gd.getNextBoolean();
    settings.saveImageResults = gd.getNextBoolean();
    settings.saveFluorophores = gd.getNextBoolean();
    settings.saveLocalisations = gd.getNextBoolean();
    settings.showHistograms = gd.getNextBoolean();
    settings.chooseHistograms = gd.getNextBoolean();
    settings.histogramBins = (int) gd.getNextNumber();
    settings.removeOutliers = gd.getNextBoolean();
    settings.densityRadius = (float) gd.getNextNumber();
    settings.depthOfField = (float) Math.abs(gd.getNextNumber());
    // Ensure tN threshold is more lenient
    if (settings.minSNRt1 < settings.minSNRtN) {
        double tmp = settings.minSNRt1;
        settings.minSNRt1 = settings.minSNRtN;
        settings.minSNRtN = tmp;
    }
    // Save before validation so that the current values are preserved.
    SettingsManager.saveSettings(globalSettings);
    // Check arguments
    try {
        Parameters.isAboveZero("Pixel Pitch", settings.pixelPitch);
        Parameters.isAboveZero("Size", settings.size);
        if (!settings.fixedDepth)
            Parameters.isPositive("Depth", settings.depth);
        if (!trackMode)
            Parameters.isAboveZero("Seconds", settings.seconds);
        Parameters.isAboveZero("Exposure time", settings.exposureTime);
        Parameters.isAboveZero("Steps per second", settings.stepsPerSecond);
        Parameters.isPositive("Background", settings.background);
        Parameters.isPositive("EM gain", settings.getEmGain());
        Parameters.isPositive("Camera gain", settings.getCameraGain());
        Parameters.isPositive("Read noise", settings.readNoise);
        double noiseRange = settings.readNoise * settings.getCameraGain() * 4;
        Parameters.isEqualOrAbove("Bias must prevent clipping the read noise (@ +/- 4 StdDev) so ", settings.bias, noiseRange);
        Parameters.isAboveZero("Particles", settings.particles);
        Parameters.isAboveZero("Photons", settings.photonsPerSecond);
        if (!imagePSF) {
            Parameters.isAboveZero("Wavelength", settings.wavelength);
            Parameters.isAboveZero("NA", settings.numericalAperture);
            Parameters.isBelow("NA", settings.numericalAperture, 2);
        }
        Parameters.isPositive("Diffusion rate", settings.diffusionRate);
        Parameters.isPositive("Fixed fraction", settings.fixedFraction);
        Parameters.isPositive("Pulse interval", settings.pulseInterval);
        Parameters.isAboveZero("Pulse ratio", settings.pulseRatio);
        Parameters.isAboveZero("tOn", settings.tOn);
        if (!trackMode) {
            Parameters.isAboveZero("tOff Short", settings.tOffShort);
            Parameters.isAboveZero("tOff Long", settings.tOffLong);
            Parameters.isPositive("n-Blinks Short", settings.nBlinksShort);
            Parameters.isPositive("n-Blinks Long", settings.nBlinksLong);
        }
        Parameters.isPositive("Min photons", settings.minPhotons);
        Parameters.isPositive("Min SNR t1", settings.minSNRt1);
        Parameters.isPositive("Min SNR tN", settings.minSNRtN);
        Parameters.isAbove("Histogram bins", settings.histogramBins, 1);
        Parameters.isPositive("Density radius", settings.densityRadius);
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    if (gd.invalidNumber())
        return false;
    if (!getHistogramOptions())
        return false;
    String[] maskImages = null;
    if (settings.distribution.equals(DISTRIBUTION[MASK])) {
        maskImages = createDistributionImageList();
        if (maskImages != null) {
            gd = new GenericDialog(TITLE);
            gd.addMessage("Select the mask image for the distribution");
            gd.addChoice("Distribution_mask", maskImages, settings.distributionMask);
            if (maskListContainsStacks)
                gd.addNumericField("Distribution_slice_depth (nm)", settings.distributionMaskSliceDepth, 0);
            gd.showDialog();
            if (gd.wasCanceled())
                return false;
            settings.distributionMask = gd.getNextChoice();
            if (maskListContainsStacks)
                settings.distributionMaskSliceDepth = Math.abs(gd.getNextNumber());
        }
    } else if (settings.distribution.equals(DISTRIBUTION[GRID])) {
        gd = new GenericDialog(TITLE);
        gd.addMessage("Select grid for the distribution");
        gd.addNumericField("Cell_size", settings.cellSize, 0);
        gd.addSlider("p-binary", 0, 1, settings.probabilityBinary);
        gd.addNumericField("Min_binary_distance (nm)", settings.minBinaryDistance, 0);
        gd.addNumericField("Max_binary_distance (nm)", settings.maxBinaryDistance, 0);
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        settings.cellSize = (int) gd.getNextNumber();
        settings.probabilityBinary = gd.getNextNumber();
        settings.minBinaryDistance = gd.getNextNumber();
        settings.maxBinaryDistance = gd.getNextNumber();
        // Check arguments
        try {
            Parameters.isAboveZero("Cell size", settings.cellSize);
            Parameters.isPositive("p-binary", settings.probabilityBinary);
            Parameters.isEqualOrBelow("p-binary", settings.probabilityBinary, 1);
            Parameters.isPositive("Min binary distance", settings.minBinaryDistance);
            Parameters.isPositive("Max binary distance", settings.maxBinaryDistance);
            Parameters.isEqualOrBelow("Min binary distance", settings.minBinaryDistance, settings.maxBinaryDistance);
        } catch (IllegalArgumentException e) {
            IJ.error(TITLE, e.getMessage());
            return false;
        }
    }
    SettingsManager.saveSettings(globalSettings);
    if (settings.diffusionRate > 0 && settings.fixedFraction < 1) {
        if (settings.confinement.equals(CONFINEMENT[CONFINEMENT_SPHERE])) {
            gd = new GenericDialog(TITLE);
            gd.addMessage("Select the sphere radius for the diffusion confinement");
            gd.addSlider("Confinement_radius (nm)", 0, 2000, settings.confinementRadius);
            gd.showDialog();
            if (gd.wasCanceled())
                return false;
            settings.confinementRadius = gd.getNextNumber();
        } else if (settings.confinement.equals(CONFINEMENT[CONFINEMENT_MASK])) {
            if (maskImages == null)
                maskImages = createDistributionImageList();
            if (maskImages != null) {
                gd = new GenericDialog(TITLE);
                gd.addMessage("Select the mask image for the diffusion confinement");
                gd.addChoice("Confinement_mask", maskImages, settings.confinementMask);
                if (maskListContainsStacks)
                    gd.addNumericField("Confinement_slice_depth (nm)", settings.confinementMaskSliceDepth, 0);
                gd.showDialog();
                if (gd.wasCanceled())
                    return false;
                settings.confinementMask = gd.getNextChoice();
                if (maskListContainsStacks)
                    settings.confinementMaskSliceDepth = Math.abs(gd.getNextNumber());
            }
        }
    }
    SettingsManager.saveSettings(globalSettings);
    if (settings.compoundMolecules) {
        // Show a second dialog where the molecule configuration is specified
        gd = new GenericDialog(TITLE);
        gd.addMessage("Specify the compound molecules");
        gd.addTextAreas(settings.compoundText, null, 20, 80);
        gd.addCheckbox("Enable_2D_diffusion", settings.diffuse2D);
        gd.addCheckbox("Rotate_initial_orientation", settings.rotateInitialOrientation);
        gd.addCheckbox("Rotate_during_simulation", settings.rotateDuringSimulation);
        gd.addCheckbox("Enable_2D_rotation", settings.rotate2D);
        gd.addCheckbox("Show_example_compounds", false);
        if (Utils.isShowGenericDialog()) {
            @SuppressWarnings("rawtypes") Vector v = gd.getCheckboxes();
            Checkbox cb = (Checkbox) v.get(v.size() - 1);
            cb.addItemListener(this);
        }
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        settings.compoundText = gd.getNextText();
        settings.diffuse2D = gd.getNextBoolean();
        settings.rotateInitialOrientation = gd.getNextBoolean();
        settings.rotateDuringSimulation = gd.getNextBoolean();
        settings.rotate2D = gd.getNextBoolean();
        if (gd.getNextBoolean()) {
            logExampleCompounds();
            return false;
        }
    }
    SettingsManager.saveSettings(globalSettings);
    gd = new GenericDialog(TITLE);
    gd.addMessage("Configure the photon distribution: " + settings.photonDistribution);
    if (PHOTON_DISTRIBUTION[PHOTON_CUSTOM].equals(settings.photonDistribution)) {
        // Nothing more to be done
        return true;
    } else if (PHOTON_DISTRIBUTION[PHOTON_UNIFORM].equals(settings.photonDistribution)) {
        gd.addNumericField("Max_Photons (sec^-1)", settings.photonsPerSecondMaximum, 0);
    } else if (PHOTON_DISTRIBUTION[PHOTON_GAMMA].equals(settings.photonDistribution)) {
        gd.addNumericField("Photon_shape", settings.photonShape, 2);
    } else if (PHOTON_DISTRIBUTION[PHOTON_CORRELATED].equals(settings.photonDistribution)) {
        gd.addNumericField("Correlation (to total tOn)", settings.correlation, 2);
    } else {
        // Nothing more to be done
        return true;
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    try {
        if (PHOTON_DISTRIBUTION[PHOTON_UNIFORM].equals(settings.photonDistribution)) {
            settings.photonsPerSecondMaximum = Math.abs((int) gd.getNextNumber());
            if (settings.photonsPerSecondMaximum < settings.photonsPerSecond)
                settings.photonsPerSecondMaximum = settings.photonsPerSecond;
        } else if (PHOTON_DISTRIBUTION[PHOTON_GAMMA].equals(settings.photonDistribution)) {
            settings.photonShape = Math.abs(gd.getNextNumber());
            Parameters.isAbove("Photon shape", settings.photonShape, 0);
        } else if (PHOTON_DISTRIBUTION[PHOTON_CORRELATED].equals(settings.photonDistribution)) {
            settings.correlation = gd.getNextNumber();
            Parameters.isEqualOrBelow("Correlation", settings.correlation, 1);
            Parameters.isEqualOrAbove("Correlation", settings.correlation, -1);
        }
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    SettingsManager.saveSettings(globalSettings);
    return true;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) Color(java.awt.Color) Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog) Component(java.awt.Component) Vector(java.util.Vector)

Example 39 with GenericDialog

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

the class CreateData method checkTotalSteps.

/**
	 * Check if the total steps can fit all the fluorophores end times. If not then ask the user if they want to draw
	 * extra
	 * frames. Return the total steps to simulate (either the original steps or a larger number to fit all the data).
	 * 
	 * @param totalSteps
	 * @param fluorophores
	 * @return The new total steps to simulate
	 */
private int checkTotalSteps(int totalSteps, List<? extends FluorophoreSequenceModel> fluorophores) {
    int max = totalSteps;
    for (FluorophoreSequenceModel f : fluorophores) {
        if (max < f.getEndTime())
            max = (int) (f.getEndTime() + 1);
    }
    if (max > totalSteps) {
        GenericDialog gd = new GenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        final double simulationStepsPerFrame = (settings.stepsPerSecond * settings.exposureTime) / 1000.0;
        int newFrames = 1 + (int) (max / simulationStepsPerFrame);
        if (totalSteps != 0) {
            int totalFrames = (int) Math.ceil(settings.seconds * 1000 / settings.exposureTime);
            gd.addMessage(String.format("Require %d (%s%%) additional frames to draw all fluorophores.\nDo you want to add extra frames?", newFrames - totalFrames, Utils.rounded((100.0 * (newFrames - totalFrames)) / totalFrames, 3)));
        } else {
            gd.addMessage(String.format("Require %d frames to draw all fluorophores.\nDo you want to proceed?", newFrames));
        }
        gd.showDialog();
        if (gd.wasOKed())
            totalSteps = max;
    }
    return totalSteps;
}
Also used : FluorophoreSequenceModel(gdsc.smlm.model.FluorophoreSequenceModel) GenericDialog(ij.gui.GenericDialog)

Example 40 with GenericDialog

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

the class CMOSAnalysis method showSimulateDialog.

private boolean showSimulateDialog() {
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Simulate per-pixel offset, variance and gain of sCMOS images.");
    gd.addNumericField("nThreads", getLastNThreads(), 0);
    gd.addNumericField("Offset (Poisson)", offset, 3);
    gd.addNumericField("Variance (Exponential)", variance, 3);
    gd.addNumericField("Gain (Gaussian)", gain, 3);
    gd.addNumericField("Gain_SD", gainSD, 3);
    gd.addNumericField("Size", size, 0);
    gd.addNumericField("Frames", frames, 0);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    setThreads((int) gd.getNextNumber());
    offset = Math.abs(gd.getNextNumber());
    variance = Math.abs(gd.getNextNumber());
    gain = Math.abs(gd.getNextNumber());
    gainSD = Math.abs(gd.getNextNumber());
    size = Math.abs((int) gd.getNextNumber());
    frames = Math.abs((int) gd.getNextNumber());
    // Check arguments
    try {
        Parameters.isAboveZero("Offset", offset);
        Parameters.isAboveZero("Variance", variance);
        Parameters.isAboveZero("Gain", gain);
        Parameters.isAboveZero("Gain SD", gainSD);
        Parameters.isAboveZero("Size", size);
        Parameters.isAboveZero("Frames", frames);
    } catch (IllegalArgumentException ex) {
        Utils.log(TITLE + ": " + ex.getMessage());
        return false;
    }
    return true;
}
Also used : GenericDialog(ij.gui.GenericDialog)

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