use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.
the class PeakFit method showSimpleDialog.
private int showSimpleDialog(final String filename) {
GlobalSettings settings = SettingsManager.loadSettings(filename);
// Initialise the fit config so that it can be used in the calibration wizard
fitConfig = settings.getFitEngineConfiguration().getFitConfiguration();
boolean requireCalibration = requireCalibration(settings, filename);
if (requireCalibration) {
if (!showCalibrationWizard(settings, true))
return DONE;
}
// Present dialog with simple output options: Image, Table
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Fit single-molecule localisations");
if (!requireCalibration)
gd.addCheckbox("Use_current_calibration", true);
gd.addCheckbox("Show_table", showTable);
gd.addCheckbox("Show_image", showImage);
gd.showDialog();
if (gd.wasCanceled())
return DONE;
boolean useCurrentCalibration = true;
if (!requireCalibration)
useCurrentCalibration = gd.getNextBoolean();
showTable = gd.getNextBoolean();
showImage = gd.getNextBoolean();
if (!useCurrentCalibration) {
if (!showCalibrationWizard(settings, false))
return DONE;
}
// Restore fitting to default settings but maintain the calibrated width
final double sd = fitConfig.getInitialPeakStdDev0();
config = new FitEngineConfiguration(new FitConfiguration());
fitConfig = config.getFitConfiguration();
fitConfig.setInitialPeakStdDev(sd);
// Allow to move 1 SD
fitConfig.setCoordinateShiftFactor(1);
resultsSettings = new ResultsSettings();
// Do simple results output
resultsSettings.resultsInMemory = true;
resultsSettings.setResultsTable((showTable) ? ResultsTable.UNCALIBRATED : ResultsTable.NONE);
if (showImage) {
resultsSettings.setResultsImage(ResultsImage.SIGNAL_INTENSITY);
resultsSettings.imageScale = Math.ceil(1024 / (FastMath.max(bounds.width, bounds.height)));
resultsSettings.weightedImage = true;
resultsSettings.equalisedImage = true;
} else {
resultsSettings.setResultsImage(ResultsImage.NONE);
}
// Log the settings we care about:
calibration = settings.getCalibration();
IJ.log("-=-=-=-");
IJ.log("Peak Fit");
IJ.log("-=-=-=-");
Utils.log("Pixel pitch = %s", Utils.rounded(calibration.getNmPerPixel(), 4));
Utils.log("Exposure Time = %s", Utils.rounded(calibration.getExposureTime(), 4));
Utils.log("Gain = %s", Utils.rounded(calibration.getGain(), 4));
Utils.log("PSF width = %s", Utils.rounded(fitConfig.getInitialPeakStdDev0(), 4));
// Save
settings.setFitEngineConfiguration(config);
settings.setResultsSettings(resultsSettings);
SettingsManager.saveSettings(settings, filename);
return FLAGS;
}
use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.
the class PeakFit method refreshSettings.
private void refreshSettings(String newFilename) {
if (newFilename != null && new File(newFilename).exists()) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage("Reload settings from file");
gd.showDialog();
if (gd.wasOKed()) {
// Reload the settings and update the GUI
GlobalSettings settings = SettingsManager.unsafeLoadSettings(newFilename, false);
if (settings == null)
return;
Calibration calibration = settings.getCalibration();
refreshSettings(calibration);
FitEngineConfiguration config = settings.getFitEngineConfiguration();
refreshSettings(config, true);
ResultsSettings resultsSettings = settings.getResultsSettings();
refreshSettings(resultsSettings);
}
}
}
use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.
the class ConfigurationTemplateTest method canListTemplateNameInOrder.
@Test
public void canListTemplateNameInOrder() {
ConfigurationTemplate.clearTemplates();
String[] names = new String[10];
for (int i = 0; i < names.length; i++) {
String name = "Test" + i;
names[i] = name;
ConfigurationTemplate.saveTemplate(name, new GlobalSettings(), null);
}
Assert.assertArrayEquals(names, ConfigurationTemplate.getTemplateNames());
}
use of gdsc.smlm.ij.settings.GlobalSettings in project GDSC-SMLM by aherbert.
the class ConfigurationTemplateTest method canLoadTemplateImageFromFile.
@Test
public void canLoadTemplateImageFromFile() throws IOException {
ConfigurationTemplate.clearTemplates();
Assert.assertEquals(0, ConfigurationTemplate.getTemplateNamesWithImage().length);
// Create a dummy image
int size = 20;
float[] pixels = new float[size * size];
RandomGenerator r = new Well19937c();
for (int i = pixels.length; i-- > 0; ) pixels[i] = r.nextFloat();
ImagePlus imp = new ImagePlus("test", new FloatProcessor(size, size, pixels));
File tmpFile = File.createTempFile("tmp", ".tif");
tmpFile.deleteOnExit();
IJ.save(imp, tmpFile.getPath());
String name = "canLoadTemplateImageFromFile";
File file = new File(Utils.replaceExtension(tmpFile.getPath(), ".xml"));
ConfigurationTemplate.saveTemplate(name, new GlobalSettings(), file);
Assert.assertEquals(1, ConfigurationTemplate.getTemplateNamesWithImage().length);
ImagePlus imp2 = ConfigurationTemplate.getTemplateImage(name);
Assert.assertNotNull(imp2);
float[] data = (float[]) imp2.getProcessor().toFloat(0, null).getPixels();
Assert.assertArrayEquals(pixels, data, 0);
}
Aggregations