Search in sources :

Example 1 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PeakFit method configureSmartFilter.

/**
	 * Show a dialog to configure the smart filter. The updated settings are saved to the settings file.
	 * <p>
	 * If the fit configuration isSmartFilter is not enabled then this method returns true. If it is enabled then a
	 * dialog is shown to input the configuration for a smart filter. If no valid filter can be created from the input
	 * then the method returns false.
	 * <p>
	 * Note: If the smart filter is successfully configured then the use may want to disable the standard fit
	 * validation.
	 *
	 * @param settings
	 *            the settings
	 * @param filename
	 *            the filename
	 * @return true, if successful
	 */
public static boolean configureSmartFilter(GlobalSettings settings, String filename) {
    FitEngineConfiguration config = settings.getFitEngineConfiguration();
    FitConfiguration fitConfig = config.getFitConfiguration();
    Calibration calibration = settings.getCalibration();
    if (!fitConfig.isSmartFilter())
        return true;
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    String xml = fitConfig.getSmartFilterXML();
    if (Utils.isNullOrEmpty(xml))
        xml = fitConfig.getDefaultSmartFilterXML();
    gd.addMessage("Smart filter (used to pick optimum results during fitting)");
    gd.addTextAreas(XmlUtils.convertQuotes(xml), null, 8, 60);
    // Currently we just collect it here even if not needed
    gd.addMessage("Smart filters using precision filtering may require a local background level.\n \nLocal background requires the camera bias:");
    gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    xml = gd.getNextText();
    Filter f = DirectFilter.fromXML(xml);
    if (f == null || !(f instanceof DirectFilter))
        return false;
    fitConfig.setDirectFilter((DirectFilter) f);
    calibration.setBias(Math.abs(gd.getNextNumber()));
    if (filename != null)
        SettingsManager.saveSettings(settings, filename);
    return true;
}
Also used : Filter(gdsc.smlm.results.filter.Filter) PlugInFilter(ij.plugin.filter.PlugInFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) SpotFilter(gdsc.smlm.filters.SpotFilter) DataFilter(gdsc.smlm.engine.DataFilter) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) DirectFilter(gdsc.smlm.results.filter.DirectFilter) Calibration(gdsc.smlm.results.Calibration) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 2 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class DoubletAnalysis method itemStateChanged.

/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
	 */
public void itemStateChanged(ItemEvent e) {
    if (e.getSource() instanceof Choice) {
        // Update the settings from the template
        Choice choice = (Choice) e.getSource();
        String templateName = choice.getSelectedItem();
        // Get the configuration template
        GlobalSettings template = ConfigurationTemplate.getTemplate(templateName);
        if (textCoordinateShiftFactor != null) {
            if (template != null) {
                if (template.isFitEngineConfiguration()) {
                    FitConfiguration fitConfig = template.getFitEngineConfiguration().getFitConfiguration();
                    cbSmartFilter.setState(fitConfig.isSmartFilter());
                    textCoordinateShiftFactor.setText("" + fitConfig.getCoordinateShiftFactor());
                    textSignalStrength.setText("" + fitConfig.getSignalStrength());
                    textMinPhotons.setText("" + fitConfig.getMinPhotons());
                    textMinWidthFactor.setText("" + fitConfig.getMinWidthFactor());
                    textWidthFactor.setText("" + fitConfig.getWidthFactor());
                    textPrecisionThreshold.setText("" + fitConfig.getPrecisionThreshold());
                    cbLocalBackground.setState(fitConfig.isPrecisionUsingBackground());
                }
            } else {
                // Reset 
                cbSmartFilter.setState(false);
                textCoordinateShiftFactor.setText("0");
                textSignalStrength.setText("0");
                textMinPhotons.setText("0");
                textMinWidthFactor.setText("0");
                textWidthFactor.setText("0");
                textPrecisionThreshold.setText("0");
                cbLocalBackground.setState(false);
            }
        } else {
            if (template != null) {
                if (template.isFitEngineConfiguration()) {
                    boolean custom = ConfigurationTemplate.isCustomTemplate(templateName);
                    FitEngineConfiguration config2 = template.getFitEngineConfiguration();
                    FitConfiguration fitConfig2 = config2.getFitConfiguration();
                    if (custom && fitConfig2.getInitialPeakStdDev0() > 0)
                        textInitialPeakStdDev0.setText("" + fitConfig2.getInitialPeakStdDev0());
                    textDataFilterType.select(config2.getDataFilterType().ordinal());
                    textDataFilter.select(config2.getDataFilter(0).ordinal());
                    textSmooth.setText("" + config2.getSmooth(0));
                    textSearch.setText("" + config2.getSearch());
                    textBorder.setText("" + config2.getBorder());
                    textFitting.setText("" + config2.getFitting());
                    textFitSolver.select(fitConfig2.getFitSolver().ordinal());
                    textFitFunction.select(fitConfig2.getFitFunction().ordinal());
                    // Copy settings not in the dialog for the fit solver
                    fitConfig.setMaxIterations(fitConfig2.getMaxIterations());
                    fitConfig.setMaxFunctionEvaluations(fitConfig2.getMaxFunctionEvaluations());
                    // MLE settings
                    fitConfig.setModelCamera(fitConfig2.isModelCamera());
                    fitConfig.setSearchMethod(fitConfig2.getSearchMethod());
                    fitConfig.setRelativeThreshold(fitConfig2.getRelativeThreshold());
                    fitConfig.setAbsoluteThreshold(fitConfig2.getAbsoluteThreshold());
                    fitConfig.setGradientLineMinimisation(fitConfig2.isGradientLineMinimisation());
                    // LSE settings
                    fitConfig.setFitCriteria(fitConfig2.getFitCriteria());
                    fitConfig.setSignificantDigits(fitConfig2.getSignificantDigits());
                    fitConfig.setDelta(fitConfig2.getDelta());
                    fitConfig.setLambda(fitConfig2.getLambda());
                }
            } else {
            // Ignore
            }
        }
    } else if (e.getSource() instanceof Checkbox) {
        Checkbox checkbox = (Checkbox) e.getSource();
        if (!checkbox.getState())
            return;
        if (textCoordinateShiftFactor != null) {
            if (!updateFilterConfiguration(filterFitConfig))
                return;
            cbSmartFilter.setState(filterFitConfig.isSmartFilter());
            textCoordinateShiftFactor.setText("" + filterFitConfig.getCoordinateShiftFactor());
            textSignalStrength.setText("" + filterFitConfig.getSignalStrength());
            textMinPhotons.setText("" + filterFitConfig.getMinPhotons());
            textMinWidthFactor.setText("" + filterFitConfig.getMinWidthFactor());
            textWidthFactor.setText("" + filterFitConfig.getWidthFactor());
            textPrecisionThreshold.setText("" + filterFitConfig.getPrecisionThreshold());
            cbLocalBackground.setState(filterFitConfig.isPrecisionUsingBackground());
        } else {
            if (!updateFitConfiguration(config))
                return;
            textInitialPeakStdDev0.setText("" + fitConfig.getInitialPeakStdDev0());
            textDataFilterType.select(config.getDataFilterType().ordinal());
            textDataFilter.select(config.getDataFilter(0).ordinal());
            textSmooth.setText("" + config.getSmooth(0));
            textSearch.setText("" + config.getSearch());
            textBorder.setText("" + config.getBorder());
            textFitting.setText("" + config.getFitting());
            textFitSolver.select(fitConfig.getFitSolver().ordinal());
            textFitFunction.select(fitConfig.getFitFunction().ordinal());
            textMatchDistance.setText("" + matchDistance);
            textLowerDistance.setText("" + lowerDistance);
            textSignalFactor.setText("" + signalFactor);
            textLowerFactor.setText("" + lowerSignalFactor);
        }
    }
}
Also used : Choice(java.awt.Choice) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) Checkbox(java.awt.Checkbox) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings)

Example 3 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class CreateData method createConfiguration.

/**
	 * Create a dummy calibration with the initial PSF width. This is used by the SpotInspector
	 * 
	 * @param psfWidth
	 * @return
	 */
private String createConfiguration(float psfWidth) {
    FitConfiguration fitConfig = new FitConfiguration();
    fitConfig.setInitialPeakStdDev0(psfWidth);
    fitConfig.setInitialPeakStdDev1(psfWidth);
    FitEngineConfiguration config = new FitEngineConfiguration(fitConfig);
    return XmlUtils.toXML(config);
}
Also used : FitConfiguration(gdsc.smlm.fitting.FitConfiguration) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration)

Example 4 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class BatchPeakFit method getDefaultSettingsXmlDocument.

private Document getDefaultSettingsXmlDocument() {
    // Create an XML document of the default settings
    Document doc = null;
    try {
        String configXml = xs.toXML(new FitEngineConfiguration(new FitConfiguration()));
        doc = loadDocument(configXml);
    } catch (XStreamException ex) {
        ex.printStackTrace();
    }
    return doc;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) Document(org.w3c.dom.Document)

Example 5 with FitEngineConfiguration

use of gdsc.smlm.engine.FitEngineConfiguration 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)

Aggregations

FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)22 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)16 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)9 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)6 Calibration (gdsc.smlm.results.Calibration)5 GenericDialog (ij.gui.GenericDialog)4 Checkbox (java.awt.Checkbox)4 XStreamException (com.thoughtworks.xstream.XStreamException)3 BasePoint (gdsc.core.match.BasePoint)3 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)3 ResultsSettings (gdsc.smlm.ij.settings.ResultsSettings)3 DirectFilter (gdsc.smlm.results.filter.DirectFilter)3 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)3 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)2 Choice (java.awt.Choice)2 TextField (java.awt.TextField)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Vector (java.util.Vector)2