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);
}
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;
}
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"));
}
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;
}
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);
}
Aggregations