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