Search in sources :

Example 1 with NonBlockingExtendedGenericDialog

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

the class OPTICS method showDialog.

private boolean showDialog(boolean isDBSCAN) {
    logReferences(isDBSCAN);
    NonBlockingExtendedGenericDialog gd = new NonBlockingExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    ResultsManager.addInput(gd, inputSettings.inputOption, InputSource.MEMORY);
    //globalSettings = SettingsManager.loadSettings();
    //settings = globalSettings.getClusteringSettings();
    gd.addMessage("--- " + TITLE + " ---");
    gd.addNumericField("Min_points", inputSettings.minPoints, 0);
    if (isDBSCAN) {
        // Add fields to auto-compute the clustering distance from the K-nearest neighbour distance profile
        gd.addSlider("Noise (%)", 0, 50, inputSettings.fractionNoise * 100);
        gd.addNumericField("Samples", inputSettings.samples, 0);
        gd.addSlider("Sample_fraction (%)", 0, 15, inputSettings.sampleFraction * 100);
        gd.addNumericField("Clustering_distance", inputSettings.clusteringDistance, 2, 6, "nm");
    } else {
        String[] opticsModes = SettingsManager.getNames((Object[]) OPTICSMode.values());
        gd.addChoice("OPTICS_mode", opticsModes, inputSettings.getOPTICSMode().toString());
        gd.addNumericField("Number_of_splits", inputSettings.numberOfSplitSets, 0);
        if (extraOptions) {
            gd.addCheckbox("Random_vectors", inputSettings.useRandomVectors);
            gd.addCheckbox("Approx_sets", inputSettings.saveApproximateSets);
            String[] sampleModes = SettingsManager.getNames((Object[]) SampleMode.values());
            gd.addChoice("Sample_mode", sampleModes, inputSettings.getSampleMode().toString());
        }
        gd.addNumericField("Generating_distance", inputSettings.generatingDistance, 2, 6, "nm");
    }
    gd.addMessage("--- Clustering ---");
    if (isDBSCAN) {
        gd.addCheckbox("Core_points", inputSettings.core);
    } else {
        String[] clusteringModes = SettingsManager.getNames((Object[]) ClusteringMode.values());
        gd.addChoice("Clustering_mode", clusteringModes, inputSettings.getClusteringMode().toString());
        gd.addMessage(ClusteringMode.XI.toString() + " options:\n" + ClusteringMode.XI.toString() + " controls the change in reachability (profile steepness) to define a cluster");
        gd.addNumericField("Xi", inputSettings.xi, 4);
        gd.addCheckbox("Top_clusters", inputSettings.topLevel);
        gd.addNumericField("Upper_limit", inputSettings.upperLimit, 4);
        gd.addNumericField("Lower_limit", inputSettings.lowerLimit, 4);
        gd.addMessage(ClusteringMode.DBSCAN.toString() + " options:");
        gd.addNumericField("Clustering_distance", inputSettings.clusteringDistance, 4);
        gd.addCheckbox("Core_points", inputSettings.core);
    }
    gd.addMessage("--- Image ---");
    gd.addSlider("Image_scale", 0, 15, inputSettings.imageScale);
    TreeSet<ImageMode> imageModeSet = new TreeSet<ImageMode>();
    imageModeSet.addAll(Arrays.asList(ImageMode.values()));
    if (isDBSCAN) {
        imageModeSet.remove(ImageMode.CLUSTER_DEPTH);
        imageModeSet.remove(ImageMode.CLUSTER_ORDER);
    }
    imageModeArray = imageModeSet.toArray();
    String[] imageModes = SettingsManager.getNames(imageModeArray);
    gd.addChoice("Image_mode", imageModes, inputSettings.getImageMode().toString());
    gd.addCheckboxGroup(1, 2, new String[] { "Weighted", "Equalised" }, new boolean[] { inputSettings.weighted, inputSettings.equalised }, new String[] { "Image" });
    if (extraOptions) {
        gd.addNumericField("LoOP_lambda", inputSettings.lambda, 4);
    }
    TreeSet<OutlineMode> outlineModeSet = new TreeSet<OutlineMode>();
    outlineModeSet.addAll(Arrays.asList(OutlineMode.values()));
    if (isDBSCAN) {
        outlineModeSet.remove(OutlineMode.COLOURED_BY_DEPTH);
    }
    outlineModeArray = outlineModeSet.toArray();
    String[] outlineModes = SettingsManager.getNames(outlineModeArray);
    gd.addChoice("Outline", outlineModes, inputSettings.getOutlineMode().toString());
    if (!isDBSCAN) {
        String[] spanningTreeModes = SettingsManager.getNames((Object[]) SpanningTreeMode.values());
        gd.addChoice("Spanning_tree", spanningTreeModes, spanningTreeModes[inputSettings.getSpanningTreeModeOridinal()]);
        gd.addMessage("--- Reachability Plot ---");
        String[] plotModes = SettingsManager.getNames((Object[]) PlotMode.values());
        gd.addChoice("Plot_mode", plotModes, plotModes[inputSettings.getPlotModeOridinal()]);
    }
    // Start disabled so the user can choose settings to update
    gd.addCheckbox("Preview", false);
    if (extraOptions)
        gd.addCheckbox("Debug", false);
    // Everything is done within the dialog listener
    if (isDBSCAN)
        gd.addDialogListener(new DBSCANDialogListener());
    else
        gd.addDialogListener(new OPTICSDialogListener());
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    // The dialog was OK'd so run if work was staged in the workflow.
    if (workflow.isStaged())
        workflow.runStaged();
    // Record the options for macros since the NonBlocking dialog does not
    if (Recorder.record) {
        Recorder.recordOption("Min_points", Integer.toString(inputSettings.minPoints));
        if (isDBSCAN) {
            // Add fields to auto-compute the clustering distance from the K-nearest neighbour distance profile
            Recorder.recordOption("Noise", Double.toString(inputSettings.fractionNoise * 100));
            Recorder.recordOption("Samples", Double.toString(inputSettings.samples));
            Recorder.recordOption("Sample_fraction", Double.toString(inputSettings.sampleFraction * 100));
            Recorder.recordOption("Clustering_distance", Double.toString(inputSettings.clusteringDistance));
        } else {
            Recorder.recordOption("OPTICS_mode", inputSettings.getOPTICSMode().toString());
            Recorder.recordOption("Number_of_splits", Integer.toString(inputSettings.numberOfSplitSets));
            if (extraOptions) {
                if (inputSettings.useRandomVectors)
                    Recorder.recordOption("Random_vectors");
                if (inputSettings.saveApproximateSets)
                    Recorder.recordOption("Approx_sets");
                Recorder.recordOption("Sample_mode", inputSettings.getSampleMode().toString());
            }
            Recorder.recordOption("Generating_distance", Double.toString(inputSettings.generatingDistance));
        }
        if (isDBSCAN) {
            if (inputSettings.core)
                Recorder.recordOption("Core_points");
        } else {
            Recorder.recordOption("Clustering_mode", inputSettings.getClusteringMode().toString());
            Recorder.recordOption("Xi", Double.toString(inputSettings.xi));
            if (inputSettings.topLevel)
                Recorder.recordOption("Top_clusters");
            Recorder.recordOption("Upper_limit", Double.toString(inputSettings.upperLimit));
            Recorder.recordOption("Lower_limit", Double.toString(inputSettings.lowerLimit));
            Recorder.recordOption("Clustering_distance", Double.toString(inputSettings.clusteringDistance));
            if (inputSettings.core)
                Recorder.recordOption("Core_points");
        }
        gd.addMessage("--- Image ---");
        Recorder.recordOption("Image_scale", Double.toString(inputSettings.imageScale));
        Recorder.recordOption("Image_mode", inputSettings.getImageMode().toString());
        if (inputSettings.weighted)
            Recorder.recordOption("Weighted");
        if (inputSettings.equalised)
            Recorder.recordOption("Equalised");
        if (extraOptions) {
            Recorder.recordOption("LoOP_lambda", Double.toString(inputSettings.lambda));
        }
        Recorder.recordOption("Outline", inputSettings.getOutlineMode().toString());
        if (!isDBSCAN) {
            Recorder.recordOption("Spanning_tree", inputSettings.getSpanningTreeMode().toString());
            Recorder.recordOption("Plot_mode", inputSettings.getPlotMode().toString());
        }
        if (debug)
            Recorder.recordOption("Debug");
    }
    return true;
}
Also used : TreeSet(java.util.TreeSet) NonBlockingExtendedGenericDialog(ij.gui.NonBlockingExtendedGenericDialog) ImageMode(gdsc.smlm.ij.settings.OPTICSSettings.ImageMode) OutlineMode(gdsc.smlm.ij.settings.OPTICSSettings.OutlineMode)

Example 2 with NonBlockingExtendedGenericDialog

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

the class PulseActivationAnalysis method showPulseAnalysisDialog.

private boolean showPulseAnalysisDialog() {
    NonBlockingExtendedGenericDialog gd = new NonBlockingExtendedGenericDialog(TITLE);
    gd.addMessage("Plot molecules activated after a pulse");
    String[] correctionNames = null;
    String[] assigmentNames = null;
    if (channels > 1) {
        if (channels == 2) {
            gd.addNumericField("Crosstalk_21", ct[C21], 3);
            gd.addNumericField("Crosstalk_12", ct[C12], 3);
        } else {
            for (int i = 0; i < ctNames.length; i++) gd.addNumericField("Crosstalk_" + ctNames[i], ct[i], 3);
        }
        gd.addNumericField("Local_density_radius", densityRadius, 0, 6, "nm");
        correctionNames = SettingsManager.getNames((Object[]) specificCorrection);
        gd.addChoice("Crosstalk_correction", correctionNames, correctionNames[specificCorrectionIndex]);
        for (int c = 1; c <= channels; c++) gd.addSlider("Crosstalk_correction_cutoff_C" + c + "(%)", 0, 100, specificCorrectionCutoff[c - 1]);
        assigmentNames = SettingsManager.getNames((Object[]) nonSpecificCorrection);
        gd.addChoice("Nonspecific_assigment", assigmentNames, assigmentNames[nonSpecificCorrectionIndex]);
        gd.addSlider("Nonspecific_assignment_cutoff (%)", 0, 100, nonSpecificCorrectionCutoff);
    }
    settings = SettingsManager.loadSettings();
    resultsSettings = settings.getResultsSettings();
    gd.addMessage("--- Image output ---");
    String[] imageNames = SettingsManager.getNames((Object[]) ResultsImage.values());
    gd.addChoice("Image", imageNames, imageNames[resultsSettings.getResultsImage().ordinal()]);
    gd.addCheckbox("Weighted", resultsSettings.weightedImage);
    gd.addCheckbox("Equalised", resultsSettings.equalisedImage);
    gd.addSlider("Image_Precision (nm)", 5, 30, resultsSettings.precision);
    gd.addSlider("Image_Scale", 1, 15, resultsSettings.imageScale);
    gd.addCheckbox("Preview", false);
    gd.addDialogListener(this);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    // The dialog was OK'd so run if work was staged in the workflow.
    if (workflow.isStaged())
        workflow.runStaged();
    // Record options for a macro since the NonBlockingDialog does not
    if (Recorder.record) {
        if (channels > 1) {
            if (channels == 2) {
                Recorder.recordOption("Crosstalk_21", Double.toString(ct[C21]));
                Recorder.recordOption("Crosstalk_12", Double.toString(ct[C12]));
            } else {
                for (int i = 0; i < ctNames.length; i++) Recorder.recordOption("Crosstalk_" + ctNames[i], Double.toString(ct[i]));
            }
            Recorder.recordOption("Local_density_radius", Double.toString(densityRadius));
            Recorder.recordOption("Crosstalk_correction", correctionNames[specificCorrectionIndex]);
            for (int c = 1; c <= channels; c++) Recorder.recordOption("Crosstalk_correction_cutoff_C" + c, Double.toString(specificCorrectionCutoff[c - 1]));
            Recorder.recordOption("Nonspecific_assigment", assigmentNames[nonSpecificCorrectionIndex]);
            Recorder.recordOption("Nonspecific_assignment_cutoff (%)", Double.toString(nonSpecificCorrectionCutoff));
        }
        Recorder.recordOption("Image", imageNames[resultsSettings.getResultsImage().ordinal()]);
        if (resultsSettings.weightedImage)
            Recorder.recordOption("Weighted");
        if (resultsSettings.equalisedImage)
            Recorder.recordOption("Equalised");
        Recorder.recordOption("Image_Precision", Double.toString(resultsSettings.precision));
        Recorder.recordOption("Image_Scale", Double.toString(resultsSettings.imageScale));
    }
    SettingsManager.saveSettings(settings);
    return true;
}
Also used : NonBlockingExtendedGenericDialog(ij.gui.NonBlockingExtendedGenericDialog)

Example 3 with NonBlockingExtendedGenericDialog

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

the class FIRE method showQEstimationDialog.

private boolean showQEstimationDialog(final PrecisionHistogram histogram, final QPlot qplot, final FRCCurve frcCurve, final double nmPerPixel) {
    // This is used for the initial layout of windows
    final MyWindowOrganiser wo = new MyWindowOrganiser();
    // Use a simple workflow
    Workflow<WorkSettings, Object> workflow = new Workflow<WorkSettings, Object>();
    // Split the work to two children with a dummy initial worker
    int previous = workflow.add(new BaseWorker(wo));
    workflow.add(new HistogramWorker(wo, histogram), previous);
    workflow.add(new QPlotWorker(wo, qplot), previous);
    workflow.start();
    // The number of plots
    wo.expected = 4;
    String KEY_MEAN = "mean_estimate";
    String KEY_SIGMA = "sigma_estimate";
    String KEY_Q = "q_estimate";
    String macroOptions = Macro.getOptions();
    if (macroOptions != null) {
        // If inside a macro then just get the options and run the work
        double mean = Double.parseDouble(Macro.getValue(macroOptions, KEY_MEAN, Double.toString(histogram.mean)));
        double sigma = Double.parseDouble(Macro.getValue(macroOptions, KEY_SIGMA, Double.toString(histogram.sigma)));
        double qValue = Double.parseDouble(Macro.getValue(macroOptions, KEY_Q, Double.toString(qplot.qValue)));
        workflow.run(new WorkSettings(mean, sigma, qValue));
        workflow.shutdown(false);
    } else {
        // Draw the plots with the first set of work
        workflow.run(new WorkSettings(histogram.mean, histogram.sigma, qplot.qValue));
        // Build the dialog
        NonBlockingExtendedGenericDialog gd = new NonBlockingExtendedGenericDialog(TITLE);
        gd.addHelp(About.HELP_URL);
        double mu = histogram.mean / nmPerPixel;
        double sd = histogram.sigma / nmPerPixel;
        double plateauness = qplot.computePlateauness(qplot.qValue, mu, sd);
        gd.addMessage("Estimate the blinking correction parameter Q for Fourier Ring Correlation\n \n" + String.format("Initial estimate:\nPrecision = %.3f +/- %.3f\n", histogram.mean, histogram.sigma) + String.format("Q = %s\nCost = %.3f", Utils.rounded(qplot.qValue), plateauness));
        double mean10 = histogram.mean * 10;
        double sd10 = histogram.sigma * 10;
        double q10 = qplot.qValue * 10;
        gd.addSlider("Mean (x10)", Math.max(0, mean10 - sd10 * 2), mean10 + sd10 * 2, mean10);
        gd.addSlider("Sigma (x10)", Math.max(0, sd10 / 2), sd10 * 2, sd10);
        gd.addSlider("Q (x10)", 0, Math.max(50, q10 * 2), q10);
        gd.addCheckbox("Reset_all", false);
        gd.addMessage("Double-click a slider to reset");
        gd.addDialogListener(new FIREDialogListener(gd, histogram, qplot, workflow));
        // Show this when the workers have finished drawing the plots so it is on top
        try {
            long timeout = System.currentTimeMillis() + 5000;
            while (wo.size < wo.expected) {
                Thread.sleep(50);
                if (System.currentTimeMillis() > timeout)
                    break;
            }
        } catch (InterruptedException e) {
        // Ignore
        }
        gd.showDialog();
        // Finish the worker threads
        boolean cancelled = gd.wasCanceled();
        workflow.shutdown(cancelled);
        if (cancelled)
            return false;
    }
    // Store the Q value and the mean and sigma
    qValue = qplot.qValue;
    mean = qplot.mean;
    sigma = qplot.sigma;
    // Record the values for Macros since the NonBlockingDialog doesn't
    if (Recorder.record) {
        Recorder.recordOption(KEY_MEAN, Double.toString(mean));
        Recorder.recordOption(KEY_SIGMA, Double.toString(sigma));
        Recorder.recordOption(KEY_Q, Double.toString(qValue));
    }
    return true;
}
Also used : NonBlockingExtendedGenericDialog(ij.gui.NonBlockingExtendedGenericDialog) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint)

Aggregations

NonBlockingExtendedGenericDialog (ij.gui.NonBlockingExtendedGenericDialog)3 ImageMode (gdsc.smlm.ij.settings.OPTICSSettings.ImageMode)1 OutlineMode (gdsc.smlm.ij.settings.OPTICSSettings.OutlineMode)1 TreeSet (java.util.TreeSet)1 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)1