Search in sources :

Example 46 with ExtendedGenericDialog

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

the class BenchmarkFilterAnalysis method showScoreDialog.

private boolean showScoreDialog() {
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    addSimulationData(gd);
    // Get the last scored filter or default to the best filter
    createScoreFilter(false);
    gd.addSlider("Fail_count", 0, 20, settings.scoreFailCount);
    computeDoublets = BenchmarkSpotFit.getComputeDoublets();
    if (computeDoublets) {
        gd.addSlider("Residuals_threshold", 0.01, 1, settings.scoreResidualsThreshold);
    }
    gd.addNumericField("Duplicate_distance", settings.scoreDuplicateDistance, 2);
    gd.addTextAreas(uk.ac.sussex.gdsc.core.utils.XmlUtils.convertQuotes(scoreFilter.toXml()), null, 6, 60);
    gd.addCheckbox("Reset_filter", false);
    gd.addCheckbox("Show_summary", settings.showSummaryTable);
    gd.addCheckbox("Clear_tables", settings.clearTables);
    gd.addCheckbox("Save_best_filter", settings.saveBestFilter);
    gd.addCheckbox("Save_template", settings.saveTemplate);
    gd.addCheckbox("Calculate_sensitivity", settings.calculateSensitivity);
    gd.addSlider("Delta", 0.01, 1, settings.delta);
    if (!simulationParameters.fixedDepth) {
        gd.addCheckbox("Depth_recall_analysis", settings.depthRecallAnalysis);
    }
    gd.addCheckbox("Score_analysis", settings.scoreAnalysis);
    gd.addChoice("Component_analysis", Settings.COMPONENT_ANALYSIS_OPTIONS, settings.componentAnalysis);
    gd.addStringField("Title", settings.resultsTitle, 20);
    final String[] labels = { "Show_TP", "Show_FP", "Show_FN" };
    gd.addCheckboxGroup(1, 3, labels, new boolean[] { settings.showTP, settings.showFP, settings.showFN });
    // Dialog to have a reset checkbox. This reverts back to the default.
    if (ImageJUtils.isShowGenericDialog()) {
        final Checkbox cb = (Checkbox) (gd.getCheckboxes().get(0));
        final Vector<TextField> v = gd.getNumericFields();
        final TextArea ta = gd.getTextArea1();
        cb.addItemListener(event -> {
            if (cb.getState()) {
                createScoreFilter(true);
                int index = 0;
                v.get(index++).setText(Integer.toString(settings.scoreFailCount));
                if (computeDoublets) {
                    v.get(index++).setText(Double.toString(settings.scoreResidualsThreshold));
                }
                v.get(index++).setText(Double.toString(settings.scoreDuplicateDistance));
                ta.setText(uk.ac.sussex.gdsc.core.utils.XmlUtils.convertQuotes(scoreFilter.toXml()));
            }
        });
    }
    gd.addHelp(HelpUrls.getUrl("score-filter"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.scoreFailCount = (int) Math.abs(gd.getNextNumber());
    if (computeDoublets) {
        settings.scoreResidualsThreshold = Math.abs(gd.getNextNumber());
    }
    settings.scoreDuplicateDistance = Math.abs(gd.getNextNumber());
    final String xml = gd.getNextText();
    boolean reset = gd.getNextBoolean();
    if (!reset) {
        // Try and parse the filter
        try {
            scoreFilter = (DirectFilter) Filter.fromXml(xml);
        } catch (final Exception ex) {
            // Invalid so reset
            reset = true;
        }
    }
    createScoreFilter(reset);
    settings.showSummaryTable = gd.getNextBoolean();
    settings.clearTables = gd.getNextBoolean();
    settings.saveBestFilter = gd.getNextBoolean();
    settings.saveTemplate = gd.getNextBoolean();
    settings.calculateSensitivity = gd.getNextBoolean();
    settings.delta = gd.getNextNumber();
    if (!simulationParameters.fixedDepth) {
        settings.depthRecallAnalysis = gd.getNextBoolean();
    }
    settings.scoreAnalysis = gd.getNextBoolean();
    settings.componentAnalysis = gd.getNextChoiceIndex();
    settings.resultsTitle = gd.getNextString();
    settings.showTP = gd.getNextBoolean();
    settings.showFP = gd.getNextBoolean();
    settings.showFN = gd.getNextBoolean();
    settings.save();
    if (gd.invalidNumber()) {
        return false;
    }
    resultsPrefix = spotFitResults.resultPrefix + "\t" + settings.resultsTitle + "\t";
    createResultsPrefix2(settings.scoreFailCount, settings.scoreResidualsThreshold, settings.scoreDuplicateDistance);
    // Check there is one output
    if (!settings.showSummaryTable && !settings.calculateSensitivity && !settings.saveBestFilter && !settings.saveTemplate) {
        IJ.error(TITLE, "No output selected");
        return false;
    }
    // Check arguments
    try {
        ParameterUtils.isAboveZero("Delta", settings.delta);
        ParameterUtils.isBelow("Delta", settings.delta, 1);
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    return selectTableColumns();
}
Also used : TextArea(java.awt.TextArea) Checkbox(java.awt.Checkbox) TextField(java.awt.TextField) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ConcurrentRuntimeException(org.apache.commons.lang3.concurrent.ConcurrentRuntimeException)

Example 47 with ExtendedGenericDialog

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

the class Test_PlugIn method run.

@Override
public void run(String arg) {
    // The parameters that have options must be available statically for the OptionListener
    final String[] textFields = { "Some text", "More text" };
    final String[] optionFields = { "", "", "" };
    final double[] numberFields = { 2.567, 7, 4.567, 7.898 };
    final ExtendedGenericDialog gd = new ExtendedGenericDialog("Test");
    gd.addChoice("Select1", new String[] { "One", "Two" }, optionFields[0]);
    final Choice c2 = gd.addAndGetChoice("Select2", new String[] { "Three", "Four" }, optionFields[1]);
    gd.addAndGetButton("Options", event -> {
        final ExtendedGenericDialog gd2 = new ExtendedGenericDialog("Test2", null);
        gd2.addMessage(c2.getSelectedItem());
        gd2.showDialog(true);
        gd2.getNextChoice();
    });
    gd.addStringField("Another", textFields[0]);
    gd.addStringField("Testing", textFields[1], 15, new OptionListener<String>() {

        @Override
        public boolean collectOptions(String field) {
            IJ.log(field);
            return true;
        }

        @Override
        public boolean collectOptions() {
            IJ.log(textFields[1]);
            return true;
        }
    });
    gd.addFilenameField("File", "", 30);
    gd.addDirectoryField("Dir", "", 30);
    gd.addChoice("Select3", new String[] { "Five", "Six" }, optionFields[2], new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer field) {
            IJ.log(Integer.toString(field));
            return true;
        }

        @Override
        public boolean collectOptions() {
            IJ.log(optionFields[2]);
            return true;
        }
    });
    gd.addSlider("Slider1", 0.5, 4.5, numberFields[0], new OptionListener<Double>() {

        @Override
        public boolean collectOptions(Double field) {
            IJ.log(field.toString());
            return true;
        }

        @Override
        public boolean collectOptions() {
            IJ.log(Double.toString(numberFields[0]));
            return true;
        }
    });
    gd.addSlider("Slider2", 0, 10, numberFields[1], new OptionListener<Double>() {

        @Override
        public boolean collectOptions(Double field) {
            IJ.log(field.toString());
            return true;
        }

        @Override
        public boolean collectOptions() {
            IJ.log(Double.toString(numberFields[1]));
            return true;
        }
    });
    gd.addNumericField("Number1", numberFields[2], 2, new OptionListener<Double>() {

        @Override
        public boolean collectOptions(Double field) {
            IJ.log(field.toString());
            return true;
        }

        @Override
        public boolean collectOptions() {
            IJ.log(Double.toString(numberFields[2]));
            return true;
        }
    });
    gd.addNumericField("Number2", numberFields[3], 2, 6, "px", new OptionListener<Double>() {

        @Override
        public boolean collectOptions(Double field) {
            IJ.log(field.toString());
            return true;
        }

        @Override
        public boolean collectOptions() {
            IJ.log(Double.toString(numberFields[3]));
            return true;
        }
    });
    gd.setMaxUnscrolledSize(0, 300);
    gd.showDialog();
    optionFields[0] = gd.getNextChoice();
    optionFields[1] = gd.getNextChoice();
    textFields[0] = gd.getNextString();
    textFields[1] = gd.getNextString();
    optionFields[2] = gd.getNextChoice();
    numberFields[0] = gd.getNextNumber();
    numberFields[1] = gd.getNextNumber();
    numberFields[2] = gd.getNextNumber();
    numberFields[3] = gd.getNextNumber();
    gd.collectOptions();
}
Also used : Choice(java.awt.Choice) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 48 with ExtendedGenericDialog

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

the class TraceDiffusion method checkCalibration.

/**
 * Check the results have a calibrated exposure time and pixel pitch. If not then show a dialog to
 * collect the calibration.
 *
 * @param results the results
 * @return True if calibrated
 */
private static boolean checkCalibration(MemoryPeakResults results) {
    if (results.getCalibration() == null || !results.getCalibrationReader().hasExposureTime() || !results.getCalibrationReader().hasNmPerPixel()) {
        final CalibrationWriter cal = results.getCalibrationWriterSafe();
        final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage("Uncalibrated results! Please enter the calibration:");
        gd.addNumericField("Exposure_time (ms)", cal.getExposureTime(), 2);
        gd.addNumericField("Pixel_pitch (nm)", cal.getNmPerPixel(), 2);
        gd.showDialog();
        if (gd.wasCanceled() || gd.invalidNumber()) {
            return false;
        }
        cal.setExposureTime(gd.getNextNumber());
        cal.setNmPerPixel(gd.getNextNumber());
        if (cal.getExposureTime() <= 0 || cal.getNmPerPixel() <= 0) {
            return false;
        }
        results.setCalibration(cal.getCalibration());
    }
    return true;
}
Also used : CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 49 with ExtendedGenericDialog

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

the class TraceDiffusion method calculatePrecision.

/**
 * Calculate the average precision of localisation in the traces.
 *
 * @param traces the traces
 * @param multi true if the traces were from multiple input results
 */
private void calculatePrecision(Trace[] traces, boolean multi) {
    // Check the diffusion simulation for a precision
    if (DiffusionRateTest.isSimulated(results.getName()) && !multi) {
        precision = DiffusionRateTest.getLastSimulationPrecision();
    } else {
        precision = 999;
        try {
            final Gaussian2DPeakResultCalculator calculator = Gaussian2DPeakResultHelper.create(results.getPsf(), results.getCalibration(), Gaussian2DPeakResultHelper.LSE_PRECISION);
            // Get the average precision of the localisations
            precision = 0;
            int count = 0;
            for (final Trace trace : traces) {
                for (int k = 0; k < trace.size(); k++) {
                    final PeakResult r = trace.get(k);
                    precision += calculator.getLsePrecision(r.getParameters(), r.getNoise());
                }
                count += trace.size();
            }
            precision /= count;
        } catch (final ConfigurationException ex) {
        // Ignore this and we will ask the user for the precision
        }
    }
    if (precision > 100) {
        final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage("The average precision of the traced results is " + MathUtils.rounded(precision, 4) + " nm.\nPlease verify the precision.");
        gd.addSlider("Precision (nm)", 5, 100, precision);
        gd.showDialog();
        if (!(gd.wasCanceled() || gd.invalidNumber())) {
            precision = Math.abs(gd.getNextNumber());
        }
    }
}
Also used : Trace(uk.ac.sussex.gdsc.smlm.results.Trace) Gaussian2DPeakResultCalculator(uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultCalculator) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

Example 50 with ExtendedGenericDialog

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

the class TranslateResults method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    final TranslateResultsSettings.Builder settings = SettingsManager.readTranslateResultsSettings(0).toBuilder();
    // Show a dialog allowing the results set to be filtered
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Select a dataset to translate");
    ResultsManager.addInput(gd, settings.getInputOption(), InputSource.MEMORY);
    gd.addNumericField("x", settings.getDx(), 3);
    gd.addNumericField("y", settings.getDy(), 3);
    gd.addNumericField("z", settings.getDz(), 3);
    gd.addChoice("Distance_unit", SettingsManager.getDistanceUnitNames(), settings.getDistanceUnitValue());
    gd.addHelp(HelpUrls.getUrl("translate-results"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    settings.setInputOption(ResultsManager.getInputSource(gd));
    settings.setDx(gd.getNextNumber());
    settings.setDy(gd.getNextNumber());
    settings.setDz(gd.getNextNumber());
    settings.setDistanceUnitValue(gd.getNextChoiceIndex());
    SettingsManager.writeSettings(settings);
    final MemoryPeakResults results = ResultsManager.loadInputResults(settings.getInputOption(), false, null, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    TypeConverter<DistanceUnit> converter;
    try {
        converter = results.getDistanceConverter(settings.getDistanceUnit());
    } catch (final DataException ex) {
        IJ.error(TITLE, "Unit conversion error: " + ex.getMessage());
        return;
    }
    final float x = (float) converter.convertBack(settings.getDx());
    final float y = (float) converter.convertBack(settings.getDy());
    final float z = (float) converter.convertBack(settings.getDz());
    // Reset the 2D bounds
    if (x != 0 || y != 0) {
        results.setBounds(null);
    }
    results.forEach((PeakResultProcedure) peakResult -> {
        final float[] params = peakResult.getParameters();
        params[PeakResult.X] += x;
        params[PeakResult.Y] += y;
        params[PeakResult.Z] += z;
    });
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) IJ(ij.IJ) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) TranslateResultsSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.TranslateResultsSettings) DataException(uk.ac.sussex.gdsc.core.data.DataException) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) PlugIn(ij.plugin.PlugIn) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) DataException(uk.ac.sussex.gdsc.core.data.DataException) TranslateResultsSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.TranslateResultsSettings) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

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