Search in sources :

Example 21 with GlobalSettings

use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.

the class LoadLocalisations method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.PlugIn#run(java.lang.String)
	 */
public void run(String arg) {
    SMLMUsageTracker.recordPlugin(this.getClass(), arg);
    GlobalSettings globalSettings = SettingsManager.loadSettings();
    CreateDataSettings settings = globalSettings.getCreateDataSettings();
    String[] path = Utils.decodePath(settings.localisationsFilename);
    OpenDialog chooser = new OpenDialog("Localisations_File", path[0], path[1]);
    if (chooser.getFileName() == null)
        return;
    settings.localisationsFilename = chooser.getDirectory() + chooser.getFileName();
    SettingsManager.saveSettings(globalSettings);
    LocalisationList localisations = loadLocalisations(settings.localisationsFilename);
    if (localisations == null)
        // Cancelled
        return;
    if (localisations.isEmpty()) {
        IJ.error(TITLE, "No localisations could be loaded");
        return;
    }
    MemoryPeakResults results = localisations.toPeakResults();
    // Ask the user what depth to use to create the in-memory results
    if (!getZDepth(results))
        return;
    if (myLimitZ) {
        MemoryPeakResults results2 = new MemoryPeakResults(results.size());
        results.setName(name);
        results.copySettings(results);
        for (PeakResult peak : results.getResults()) {
            if (peak.error < minz || peak.error > maxz)
                continue;
            results2.add(peak);
        }
        results = results2;
    }
    // Create the in-memory results
    if (results.size() > 0) {
        MemoryPeakResults.addResults(results);
    }
    IJ.showStatus(String.format("Loaded %d localisations", results.size()));
    if (myLimitZ)
        Utils.log("Loaded %d localisations, z between %.2f - %.2f", results.size(), minz, maxz);
    else
        Utils.log("Loaded %d localisations", results.size());
}
Also used : CreateDataSettings(gdsc.smlm.ij.settings.CreateDataSettings) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult) AttributePeakResult(gdsc.smlm.results.AttributePeakResult) OpenDialog(ij.io.OpenDialog)

Example 22 with GlobalSettings

use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.

the class FreeFilterResults method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Select a dataset to filter");
    ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
    GlobalSettings gs = SettingsManager.loadSettings();
    filterSettings = gs.getFilterSettings();
    String text;
    try {
        text = XmlUtils.prettyPrintXml(filterSettings.freeFilter);
    } catch (Exception e) {
        text = filterSettings.freeFilter;
    }
    gd.addTextAreas(text, null, 20, 80);
    gd.addCheckbox("Show_demo_filters", false);
    if (Utils.isShowGenericDialog()) {
        Checkbox cb = (Checkbox) gd.getCheckboxes().get(0);
        cb.addItemListener(this);
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    inputOption = ResultsManager.getInputSource(gd);
    filterSettings.freeFilter = gd.getNextText();
    boolean demoFilters = gd.getNextBoolean();
    if (demoFilters) {
        logDemoFilters(TITLE);
        return false;
    }
    return SettingsManager.saveSettings(gs);
}
Also used : Checkbox(java.awt.Checkbox) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 23 with GlobalSettings

use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.

the class FilterAnalysis method getInputDirectory.

private String getInputDirectory() {
    GlobalSettings gs = SettingsManager.loadSettings();
    FilterSettings filterSettings = gs.getFilterSettings();
    if (filterSettings.filterAnalysisDirectory != null)
        OpenDialog.setDefaultDirectory(filterSettings.filterAnalysisDirectory);
    filterSettings.filterAnalysisDirectory = IJ.getDirectory("Select results directory ...");
    if (filterSettings.filterAnalysisDirectory == null)
        return null;
    SettingsManager.saveSettings(gs);
    return inputDirectory = filterSettings.filterAnalysisDirectory;
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) FilterSettings(gdsc.smlm.ij.settings.FilterSettings)

Example 24 with GlobalSettings

use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.

the class FilterAnalysis method saveFilterSets.

private void saveFilterSets(List<FilterSet> filterSets) {
    GlobalSettings gs = SettingsManager.loadSettings();
    FilterSettings filterSettings = gs.getFilterSettings();
    String[] path = Utils.decodePath(filterSettings.filterSetFilename);
    OpenDialog chooser = new OpenDialog("Filter_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        filterSettings.filterSetFilename = chooser.getDirectory() + chooser.getFileName();
        OutputStreamWriter out = null;
        try {
            FileOutputStream fos = new FileOutputStream(filterSettings.filterSetFilename);
            out = new OutputStreamWriter(fos, "UTF-8");
            XStreamWrapper.getInstance().toXML(filterSets, out);
            SettingsManager.saveSettings(gs);
        } catch (Exception e) {
            IJ.log("Unable to save the filter sets to file: " + e.getMessage());
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                // Ignore
                }
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) FilterSettings(gdsc.smlm.ij.settings.FilterSettings) IOException(java.io.IOException) OpenDialog(ij.io.OpenDialog)

Example 25 with GlobalSettings

use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.

the class DoubletAnalysis method showDialog.

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

Aggregations

GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)34 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)9 GenericDialog (ij.gui.GenericDialog)9 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)8 Checkbox (java.awt.Checkbox)7 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)6 Choice (java.awt.Choice)6 BasePoint (gdsc.core.match.BasePoint)5 FilterSettings (gdsc.smlm.ij.settings.FilterSettings)5 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)4 Calibration (gdsc.smlm.results.Calibration)4 Point (java.awt.Point)4 TextField (java.awt.TextField)4 Vector (java.util.Vector)4 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)3 DirectFilter (gdsc.smlm.results.filter.DirectFilter)3 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)3 ImagePlus (ij.ImagePlus)3 OpenDialog (ij.io.OpenDialog)3 File (java.io.File)3