Search in sources :

Example 31 with GlobalSettings

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;
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings)

Example 32 with GlobalSettings

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);
        }
    }
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) Calibration(gdsc.smlm.results.Calibration) ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings) File(java.io.File)

Example 33 with GlobalSettings

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());
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) Test(org.junit.Test)

Example 34 with GlobalSettings

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);
}
Also used : FloatProcessor(ij.process.FloatProcessor) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) Well19937c(org.apache.commons.math3.random.Well19937c) ImagePlus(ij.ImagePlus) File(java.io.File) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) Test(org.junit.Test)

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