Search in sources :

Example 1 with ResultsSettings

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

the class BatchPeakFit method processImage.

private void processImage(BatchSettings settings, ImagePlus imp, ArrayList<String> xmlSettings) {
    String imageFilename = imp.getOriginalFileInfo().directory + imp.getOriginalFileInfo().fileName;
    String basename = getBaseName(imp.getOriginalFileInfo().fileName);
    String format = settings.resultsDirectory + File.separatorChar + basename + ".%05d";
    String statusSuffix = String.format(" / %d: %s", xmlSettings.size(), imp.getOriginalFileInfo().fileName);
    for (int i = 0; i < xmlSettings.size(); i++) {
        IJ.showStatus((i + 1) + statusSuffix);
        // Create the configuration
        FitEngineConfiguration fitConfig = null;
        try {
            fitConfig = (FitEngineConfiguration) xs.fromXML(xmlSettings.get(i));
        } catch (XStreamException e) {
        // Ignore
        }
        if (fitConfig == null)
            continue;
        // No need to skip settings that do not make sense as we will catch exceptions.
        // This relies on the fit engine throw exceptions for invalid settings.
        // Ensure the state is restored after XStream object reconstruction
        fitConfig.getFitConfiguration().initialiseState();
        String prefix = String.format(format, i);
        // Save the settings
        String settingsFilename = saveRunSettings(prefix, imageFilename, fitConfig);
        // Run the fit engine
        if (settings.runPeakFit) {
            ResultsSettings resultsSettings = createResultsSettings(fitConfig, prefix);
            try {
                PeakFit peakFit = new PeakFit(fitConfig, resultsSettings, settings.getCalibration());
                peakFit.setSilent(true);
                peakFit.run(imp, false);
                IJ.log(String.format("%s : %s : Size %d : Time = %s", imageFilename, settingsFilename, peakFit.getSize(), Utils.timeToString(peakFit.getTime())));
            } catch (Exception e) {
            // Ignore this as we assume this is from incorrect fit configuration
            }
        }
    }
    IJ.showStatus("");
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings) TransformerException(javax.xml.transform.TransformerException) XStreamException(com.thoughtworks.xstream.XStreamException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with ResultsSettings

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

the class BatchPeakFit method createResultsSettings.

private ResultsSettings createResultsSettings(FitEngineConfiguration fitConfig, String prefix) {
    ResultsSettings resultsSettings = new ResultsSettings();
    resultsSettings.setResultsImage(ResultsImage.NONE);
    resultsSettings.resultsInMemory = false;
    resultsSettings.setResultsTable(ResultsTable.NONE);
    resultsSettings.logProgress = false;
    resultsSettings.resultsDirectory = null;
    resultsSettings.showDeviations = fitConfig.getFitConfiguration().isComputeDeviations();
    resultsSettings.resultsFilename = prefix + ".xls";
    resultsSettings.setResultsFileFormat(ResultsFileFormat.GDSC_TEXT);
    return resultsSettings;
}
Also used : ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings)

Example 3 with ResultsSettings

use of gdsc.smlm.ij.settings.ResultsSettings 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 4 with ResultsSettings

use of gdsc.smlm.ij.settings.ResultsSettings 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 5 with ResultsSettings

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

the class PSFEstimator method createFitter.

private PeakFit createFitter() {
    ResultsSettings resultsSettings = new ResultsSettings();
    resultsSettings.setResultsTable(ResultsTable.NONE);
    resultsSettings.showDeviations = false;
    resultsSettings.logProgress = false;
    resultsSettings.setResultsImage(0);
    resultsSettings.resultsDirectory = null;
    PeakFit fitter = new PeakFit(config, resultsSettings, globalSettings.getCalibration());
    return fitter;
}
Also used : ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings)

Aggregations

ResultsSettings (gdsc.smlm.ij.settings.ResultsSettings)5 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)3 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)2 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)2 XStreamException (com.thoughtworks.xstream.XStreamException)1 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)1 Calibration (gdsc.smlm.results.Calibration)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1