use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class ResultsManager method addTableResults.
private void addTableResults(MemoryPeakResults results, PeakResultsList resultsList, boolean showDeviations, boolean showEndFrame) {
if (resultsSettings.getResultsTable() != ResultsTable.NONE) {
IJTablePeakResults r = new IJTablePeakResults(showDeviations);
r.setPeakIdColumnName("Frame");
r.setShowCalibratedValues(resultsSettings.getResultsTable() == ResultsTable.CALIBRATED);
// Get a bias if required
Calibration calibration = results.getCalibration();
if (r.isShowCalibratedValues() && calibration.getBias() == 0) {
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Calibrated results requires a camera bias");
gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
gd.showDialog();
if (!gd.wasCanceled()) {
calibration.setBias(Math.abs(gd.getNextNumber()));
}
}
r.setShowEndFrame(showEndFrame);
resultsList.addOutput(r);
}
}
use of gdsc.smlm.results.Calibration 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.results.Calibration in project GDSC-SMLM by aherbert.
the class PeakFit method configureFitSolver.
/**
* Show a dialog to configure the fit solver. The updated settings are saved to the settings file. An error
* message is shown if the dialog is cancelled or the configuration is invalid.
*
* @param settings
* @param filename
* @param extraOptions
* True if extra configuration options should be allowed
* @param ignoreCalibration
* True if the calibration should not be configured
* @return True if the configuration succeeded
*/
public static boolean configureFitSolver(GlobalSettings settings, String filename, boolean extraOptions, boolean ignoreCalibration) {
FitEngineConfiguration config = settings.getFitEngineConfiguration();
FitConfiguration fitConfig = config.getFitConfiguration();
Calibration calibration = settings.getCalibration();
boolean isBoundedLVM = fitConfig.getFitSolver() == FitSolver.LVM_MLE || fitConfig.getFitSolver() == FitSolver.BOUNDED_LVM || fitConfig.getFitSolver() == FitSolver.BOUNDED_LVM_WEIGHTED;
if (fitConfig.getFitSolver() == FitSolver.MLE) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Maximum Likelihood Estimation requires additional parameters");
if (!ignoreCalibration) {
gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
gd.addCheckbox("Model_camera_noise", fitConfig.isModelCamera());
gd.addNumericField("Read_noise (ADUs)", calibration.getReadNoise(), 2);
gd.addNumericField("Amplification (ADU/electron)", calibration.getAmplification(), 2);
gd.addCheckbox("EM-CCD", calibration.isEmCCD());
}
String[] searchNames = SettingsManager.getNames((Object[]) MaximumLikelihoodFitter.SearchMethod.values());
gd.addChoice("Search_method", searchNames, searchNames[fitConfig.getSearchMethod().ordinal()]);
gd.addStringField("Relative_threshold", "" + fitConfig.getRelativeThreshold());
gd.addStringField("Absolute_threshold", "" + fitConfig.getAbsoluteThreshold());
gd.addNumericField("Max_iterations", fitConfig.getMaxIterations(), 0);
gd.addNumericField("Max_function_evaluations", fitConfig.getMaxFunctionEvaluations(), 0);
if (extraOptions)
gd.addCheckbox("Gradient_line_minimisation", fitConfig.isGradientLineMinimisation());
gd.showDialog();
if (gd.wasCanceled())
return false;
if (!ignoreCalibration) {
calibration.setBias(Math.abs(gd.getNextNumber()));
fitConfig.setModelCamera(gd.getNextBoolean());
calibration.setReadNoise(Math.abs(gd.getNextNumber()));
calibration.setAmplification(Math.abs(gd.getNextNumber()));
calibration.setEmCCD(gd.getNextBoolean());
fitConfig.setBias(calibration.getBias());
fitConfig.setReadNoise(calibration.getReadNoise());
fitConfig.setAmplification(calibration.getAmplification());
fitConfig.setEmCCD(calibration.isEmCCD());
}
fitConfig.setSearchMethod(gd.getNextChoiceIndex());
try {
fitConfig.setRelativeThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
fitConfig.setAbsoluteThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
} catch (NumberFormatException e) {
fitConfig.setRelativeThreshold(0);
fitConfig.setAbsoluteThreshold(0);
}
fitConfig.setMaxIterations((int) gd.getNextNumber());
fitConfig.setMaxFunctionEvaluations((int) gd.getNextNumber());
if (extraOptions)
fitConfig.setGradientLineMinimisation(gd.getNextBoolean());
else
// This option is for the Conjugate Gradient optimiser and makes it less stable
fitConfig.setGradientLineMinimisation(false);
if (filename != null)
SettingsManager.saveSettings(settings, filename);
try {
Parameters.isAboveZero("Relative threshold", fitConfig.getRelativeThreshold());
Parameters.isAboveZero("Absolute threshold", fitConfig.getAbsoluteThreshold());
Parameters.isAboveZero("Max iterations", fitConfig.getMaxIterations());
Parameters.isAboveZero("Max function evaluations", fitConfig.getMaxFunctionEvaluations());
fitConfig.getFunctionSolver();
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
} else if (isBoundedLVM || fitConfig.getFitSolver() == FitSolver.LVM || fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
boolean isWeightedLVM = fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED || fitConfig.getFitSolver() == FitSolver.BOUNDED_LVM_WEIGHTED;
boolean requireGain = fitConfig.getFitSolver() == FitSolver.LVM_MLE;
boolean requireBias = isWeightedLVM || requireGain;
// Collect options for LVM fitting
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage(fitConfig.getFitSolver().getShortName() + " requires additional parameters");
String[] criteriaNames = SettingsManager.getNames((Object[]) FitCriteria.values());
gd.addChoice("Fit_criteria", criteriaNames, criteriaNames[fitConfig.getFitCriteria().ordinal()]);
gd.addNumericField("Significant_digits", fitConfig.getSignificantDigits(), 0);
gd.addNumericField("Coord_delta", fitConfig.getDelta(), 4);
gd.addNumericField("Lambda", fitConfig.getLambda(), 4);
if (extraOptions)
gd.addNumericField("Min_iterations", fitConfig.getMinIterations(), 0);
gd.addNumericField("Max_iterations", fitConfig.getMaxIterations(), 0);
// Extra parameters are needed for the weighted LVM
if (isWeightedLVM && !ignoreCalibration) {
gd.addMessage("Weighted LVM fitting requires a CCD camera noise model");
gd.addNumericField("Read_noise (ADUs)", calibration.getReadNoise(), 2);
}
if (requireBias)
gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
if (requireGain)
gd.addNumericField("Gain (ADU/photon)", calibration.getGain(), 2);
if (isBoundedLVM) {
gd.addCheckbox("Use_clamping", fitConfig.isUseClamping());
gd.addCheckbox("Dynamic_clamping", fitConfig.isUseDynamicClamping());
if (extraOptions) {
gd.addNumericField("Clamp_background", fitConfig.getClampBackground(), 2);
gd.addNumericField("Clamp_signal", fitConfig.getClampSignal(), 2);
gd.addNumericField("Clamp_angle", fitConfig.getClampAngle(), 2);
gd.addNumericField("Clamp_x", fitConfig.getClampX(), 2);
gd.addNumericField("Clamp_y", fitConfig.getClampY(), 2);
gd.addNumericField("Clamp_sd0", fitConfig.getClampXSD(), 2);
gd.addNumericField("Clamp_sd1", fitConfig.getClampYSD(), 2);
}
}
gd.showDialog();
if (gd.wasCanceled())
return false;
fitConfig.setFitCriteria(gd.getNextChoiceIndex());
fitConfig.setSignificantDigits((int) gd.getNextNumber());
fitConfig.setDelta(gd.getNextNumber());
fitConfig.setLambda(gd.getNextNumber());
if (extraOptions)
fitConfig.setMinIterations((int) gd.getNextNumber());
fitConfig.setMaxIterations((int) gd.getNextNumber());
if (isWeightedLVM && !ignoreCalibration) {
calibration.setReadNoise(Math.abs(gd.getNextNumber()));
}
if (requireBias) {
calibration.setBias(Math.abs(gd.getNextNumber()));
fitConfig.setBias(calibration.getBias());
}
if (requireGain) {
calibration.setGain(Math.abs(gd.getNextNumber()));
fitConfig.setGain(calibration.getGain());
}
if (isBoundedLVM) {
fitConfig.setUseClamping(gd.getNextBoolean());
fitConfig.setUseDynamicClamping(gd.getNextBoolean());
if (extraOptions) {
fitConfig.setClampBackground(Math.abs(gd.getNextNumber()));
fitConfig.setClampSignal(Math.abs(gd.getNextNumber()));
fitConfig.setClampAngle(Math.abs(gd.getNextNumber()));
fitConfig.setClampX(Math.abs(gd.getNextNumber()));
fitConfig.setClampY(Math.abs(gd.getNextNumber()));
fitConfig.setClampXSD(Math.abs(gd.getNextNumber()));
fitConfig.setClampYSD(Math.abs(gd.getNextNumber()));
}
}
if (isWeightedLVM && !ignoreCalibration) {
fitConfig.setNoiseModel(CameraNoiseModel.createNoiseModel(calibration.getReadNoise(), calibration.getBias(), calibration.isEmCCD()));
}
if (filename != null)
SettingsManager.saveSettings(settings, filename);
try {
Parameters.isAboveZero("Significant digits", fitConfig.getSignificantDigits());
Parameters.isAboveZero("Delta", fitConfig.getDelta());
Parameters.isAboveZero("Lambda", fitConfig.getLambda());
Parameters.isAboveZero("Max iterations", fitConfig.getMaxIterations());
fitConfig.getFunctionSolver();
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
} else if (fitConfig.getFitSolver() == FitSolver.LVM_QUASI_NEWTON) {
// No options yet for Apache LVM fitting. Save options for consistency
if (filename != null)
SettingsManager.saveSettings(settings, filename);
}
if (config.isIncludeNeighbours()) {
if (!fitConfig.getFunctionSolver().isBounded()) {
IJ.error(TITLE, "Including neighbours requires a bounded fit solver");
return false;
}
}
return true;
}
use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class PeakFit method initialiseFitting.
/**
* Set-up the fitting using all the configured properties. Prepare the output results.
*/
public boolean initialiseFitting() {
if (source == null)
return false;
// Do this to ensure the serialised configuration is correct
updateFitConfiguration(config);
results.setSource(source);
if (maximaIdentification)
results.setName(source.getName() + " (Maxima)");
else if (fitMaxima)
results.setName(source.getName() + " (" + getSolverName() + " Fit Maxima)");
else
results.setName(source.getName() + " (" + getSolverName() + ")");
results.setBounds(bounds);
Calibration cal = calibration.clone();
// Account for the frame integration
// TODO - Should we change this so that if integrate frames is used then the data
// are converted to ExtendedPeakResult with a start and end frame
//cal.exposureTime *= integrateFrames;
//if (interlacedData)
//{
// cal.exposureTime *= ((double)dataBlock / (dataBlock + dataSkip));
//}
results.setCalibration(cal);
results.setConfiguration(XmlUtils.toXML(config));
addMemoryResults(results, false);
addImageResults(results);
addFileResults(results);
addTableResults(results);
addDefaultResults(results);
results.begin();
if (simpleFit && showImage) {
for (PeakResults r : results.toArray()) {
if (r instanceof IJImagePeakResults) {
ImagePlus i = ((IJImagePeakResults) r).getImagePlus();
Utils.log("Super-resolution image title = " + i.getTitle());
WindowManager.toFront(i.getWindow());
}
}
}
return true;
}
use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class IJTablePeakResults method begin.
/*
* (non-Javadoc)
*
* @see gdsc.utils.fitting.PeakResults#begin()
*/
public void begin() {
tableActive = false;
createSourceText();
createResultsWindow();
if (clearAtStart) {
tp.clear();
}
if (showCalibratedValues) {
Calibration cal = getCalibration();
if (cal != null) {
gain = cal.getGain();
nmPerPixel = cal.getNmPerPixel();
} else {
gain = 1;
nmPerPixel = 1;
}
}
size = 0;
// Let some results appear before drawing.
// ImageJ will auto-layout columns if it has less than 10 rows
nextRepaintSize = 9;
tableActive = true;
}
Aggregations