Search in sources :

Example 6 with GlobalSettings

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

the class ConfigurationTemplate method addTemplate.

/**
	 * Adds the template using the configuration. This should be used to add templates that have not been produced using
	 * benchmarking on a specific image. Those can be added to the /gdsc/smlm/templates/ resources directory.
	 *
	 * @param name
	 *            the name
	 * @param config
	 *            the config
	 */
private static void addTemplate(String name, FitEngineConfiguration config) {
    GlobalSettings settings = new GlobalSettings();
    settings.setFitEngineConfiguration(config.clone());
    addTemplate(name, settings, false, null, null);
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings)

Example 7 with GlobalSettings

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

the class ConfigurationTemplate method loadTemplates.

/**
	 * Load templates from package resources.
	 *
	 * @param templates
	 *            the templates
	 */
static int loadTemplates(TemplateResource[] templates) {
    if (templates == null || templates.length == 0)
        return 0;
    int count = 0;
    Class<ConfigurationTemplate> resourceClass = ConfigurationTemplate.class;
    for (TemplateResource template : templates) {
        // Skip those already done
        if (map.containsKey(template.name))
            continue;
        InputStream templateStream = resourceClass.getResourceAsStream(template.path);
        if (templateStream == null)
            continue;
        GlobalSettings settings = SettingsManager.unsafeLoadSettings(templateStream, true);
        if (settings != null) {
            count++;
            addTemplate(template.name, settings, false, null, template.tifPath);
        }
    }
    return count;
}
Also used : InputStream(java.io.InputStream) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) Point(java.awt.Point)

Example 8 with GlobalSettings

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

the class ConfigurationTemplate method loadTemplatesFromDirectory.

private void loadTemplatesFromDirectory() {
    // Allow the user to specify a configuration directory
    String newDirectory = Utils.getDirectory("Template_directory", configurationDirectory);
    if (newDirectory == null)
        return;
    configurationDirectory = newDirectory;
    // Search the configuration directory and add any custom templates that can be deserialised from XML files
    File[] fileList = (new File(configurationDirectory)).listFiles(new FilenameFilter() {

        public boolean accept(File arg0, String arg1) {
            return arg1.toLowerCase().endsWith("xml");
        }
    });
    if (fileList == null)
        return;
    // Sort partially numerically
    String[] list = new String[fileList.length];
    int n = 0;
    for (File file : fileList) {
        if (file.isFile()) {
            list[n++] = file.getPath();
        }
    }
    list = StringSorter.sortNumerically(list);
    int count = 0;
    for (String path : list) {
        GlobalSettings settings = SettingsManager.unsafeLoadSettings(path, false);
        if (settings != null) {
            count++;
            File file = new File(path);
            String name = Utils.removeExtension(file.getName());
            addTemplate(name, settings, true, file, null);
        }
    }
    IJ.showMessage("Loaded " + Utils.pleural(count, "custom template"));
}
Also used : FilenameFilter(java.io.FilenameFilter) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) File(java.io.File) Point(java.awt.Point)

Example 9 with GlobalSettings

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

the class BenchmarkFilterAnalysis method readFilterSets.

@SuppressWarnings("unchecked")
private List<FilterSet> readFilterSets() {
    if (extraOptions && BenchmarkSpotFit.multiFilter != null) {
        IDirectFilter f = BenchmarkSpotFit.multiFilter.getFilter();
        if (f instanceof DirectFilter) {
            GenericDialog gd = new GenericDialog(TITLE);
            gd.addMessage("Use an identical filter to " + BenchmarkSpotFit.TITLE);
            gd.enableYesNoCancel();
            gd.hideCancelButton();
            gd.showDialog();
            if (gd.wasOKed()) {
                setLastFile(null);
                List<FilterSet> filterSets = new ArrayList<FilterSet>(1);
                List<Filter> filters = new ArrayList<Filter>(1);
                filters.add((DirectFilter) f);
                FilterSet filterSet = new FilterSet(filters);
                filterSets.add(filterSet);
                resetParametersFromFitting();
                createResultsPrefix2();
                return filterSets;
            }
        }
    }
    GlobalSettings gs = SettingsManager.loadSettings();
    FilterSettings filterSettings = gs.getFilterSettings();
    String filename = Utils.getFilename("Filter_File", filterSettings.filterSetFilename);
    if (filename != null) {
        IJ.showStatus("Reading filters ...");
        filterSettings.filterSetFilename = filename;
        // Allow the filters to be cached
        if (isSameFile(filename)) {
            GenericDialog gd = new GenericDialog(TITLE);
            gd.hideCancelButton();
            gd.addMessage("The same filter file was selected.");
            gd.addCheckbox("Re-use_filters", reUseFilters);
            gd.showDialog();
            if (!gd.wasCanceled()) {
                if ((reUseFilters = gd.getNextBoolean())) {
                    SettingsManager.saveSettings(gs);
                    return filterList;
                }
            }
        }
        BufferedReader input = null;
        setLastFile(null);
        try {
            FileInputStream fis = new FileInputStream(filename);
            input = new BufferedReader(new UnicodeReader(fis, null));
            Object o = XStreamWrapper.getInstance().fromXML(input);
            if (o != null && o instanceof List<?>) {
                SettingsManager.saveSettings(gs);
                List<FilterSet> filterSets = (List<FilterSet>) o;
                if (containsStandardFilters(filterSets)) {
                    IJ.log("Filter sets must contain 'Direct' filters");
                    return null;
                }
                // Check they are not empty lists
                List<FilterSet> filterSets2 = new LinkedList<FilterSet>();
                for (FilterSet filterSet : filterSets) {
                    if (filterSet.size() != 0) {
                        filterSets2.add(filterSet);
                    } else {
                        IJ.log("Filter set empty: " + filterSet.getName());
                    }
                }
                if (filterSets2.isEmpty()) {
                    IJ.log("All Filter sets are empty");
                    return null;
                }
                // Maintain the same list type
                filterSets.clear();
                filterSets.addAll(filterSets2);
                filterList = filterSets;
                // Option to enumerate filters
                expandFilters();
                setLastFile(filename);
                return filterList;
            }
            IJ.log("No filter sets defined in the specified file: " + filename);
        } catch (Exception e) {
            IJ.log("Unable to load the filter sets from file: " + e.getMessage());
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                // Ignore
                }
            }
            IJ.showStatus("");
        }
    }
    return null;
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) ArrayList(java.util.ArrayList) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) UnicodeReader(gdsc.core.utils.UnicodeReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) IOException(java.io.IOException) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) Filter(gdsc.smlm.results.filter.Filter) MultiPathFilter(gdsc.smlm.results.filter.MultiPathFilter) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) GenericDialog(ij.gui.GenericDialog) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) FilterSettings(gdsc.smlm.ij.settings.FilterSettings)

Example 10 with GlobalSettings

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

the class PSFCreator method loadConfiguration.

private void loadConfiguration() {
    final String filename = SettingsManager.getSettingsFilename();
    GlobalSettings settings = SettingsManager.loadSettings(filename);
    nmPerPixel = settings.getCalibration().getNmPerPixel();
    config = settings.getFitEngineConfiguration();
    fitConfig = config.getFitConfiguration();
    if (radius < 5 * FastMath.max(fitConfig.getInitialPeakStdDev0(), fitConfig.getInitialPeakStdDev1())) {
        radius = 5 * FastMath.max(fitConfig.getInitialPeakStdDev0(), fitConfig.getInitialPeakStdDev1());
        Utils.log("Radius is less than 5 * PSF standard deviation, increasing to %s", Utils.rounded(radius));
    }
    boxRadius = (int) Math.ceil(radius);
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings)

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