use of ij.gui.ExtendedGenericDialog 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 ij.gui.ExtendedGenericDialog 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 ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method checkCalibration.
/**
* Check the results have a calibrated exposure time and pixel pitch. If not then show a dialog to collect the
* calibration.
*
* @param results
* @return True if calibrated
*/
private boolean checkCalibration(MemoryPeakResults results) {
if (results.getCalibration() == null || results.getCalibration().getExposureTime() <= 0 || results.getCalibration().getNmPerPixel() <= 0) {
Calibration cal = results.getCalibration();
if (cal == null)
cal = new Calibration();
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Uncalibrated results! Please enter the calibration:");
gd.addNumericField("Exposure_time (ms)", cal.getExposureTime(), 2);
gd.addNumericField("Pixel_pitch (nm)", cal.getNmPerPixel(), 2);
gd.showDialog();
if (gd.wasCanceled() || gd.invalidNumber())
return false;
cal.setExposureTime(gd.getNextNumber());
cal.setNmPerPixel(gd.getNextNumber());
if (cal.getExposureTime() <= 0 || cal.getNmPerPixel() <= 0)
return false;
}
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method showDialog.
private boolean showDialog() {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Compare the points in two results sets\nand compute the match statistics");
ResultsManager.addInput(gd, "Results1", inputOption1, InputSource.MEMORY_MULTI_FRAME);
ResultsManager.addInput(gd, "Results2", inputOption2, InputSource.MEMORY_MULTI_FRAME);
ResultsManager.addInput(gd, "Results3", inputOption3, InputSource.NONE, InputSource.MEMORY_MULTI_FRAME);
gd.addNumericField("Distance", dThreshold, 2);
gd.addNumericField("Beta", beta, 2);
gd.addCheckbox("Show_pairs", showPairs);
gd.addChoice("Sort_pairs", SORT_OPTIONS, SORT_OPTIONS[sortIndex]);
gd.showDialog();
if (gd.wasCanceled())
return false;
inputOption1 = gd.getNextChoice();
inputOption2 = gd.getNextChoice();
inputOption3 = gd.getNextChoice();
dThreshold = gd.getNextNumber();
beta = gd.getNextNumber();
showPairs = gd.getNextBoolean();
sortIndex = gd.getNextChoiceIndex();
// Check arguments
try {
Parameters.isAboveZero("Distance threshold", dThreshold);
Parameters.isPositive("Beta", beta);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method readDialog.
private boolean readDialog(ExtendedGenericDialog gd) {
settings.truncate = gd.getNextBoolean();
settings.internalDistances = gd.getNextBoolean();
//settings.subSampledDistances = gd.getNextBoolean();
settings.fitLength = (int) Math.abs(gd.getNextNumber());
settings.msdCorrection = gd.getNextBoolean();
settings.precisionCorrection = gd.getNextBoolean();
settings.mle = gd.getNextBoolean();
settings.fitRestarts = (int) Math.abs(gd.getNextNumber());
settings.jumpDistance = (int) Math.abs(gd.getNextNumber());
minDifference = Math.abs(gd.getNextNumber());
minFraction = Math.abs(gd.getNextNumber());
if (extraOptions)
myMinN = minN = (int) Math.abs(gd.getNextNumber());
maxN = (int) Math.abs(gd.getNextNumber());
debugFitting = gd.getNextBoolean();
saveTraceDistances = gd.getNextBoolean();
saveRawData = gd.getNextBoolean();
settings.showHistograms = gd.getNextBoolean();
title = gd.getNextString();
if (gd.invalidNumber())
return false;
if (settings.showHistograms) {
gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select the histograms to display");
gd.addCheckbox("Remove_outliers", settings.removeOutliers);
gd.addNumericField("Histogram_bins", settings.histogramBins, 0);
for (int i = 0; i < displayHistograms.length; i++) gd.addCheckbox(NAMES[i].replace(' ', '_'), displayHistograms[i]);
gd.addCheckbox("MSD/Molecule", displayMSDHistogram);
gd.addCheckbox("D/Molecule", displayDHistogram);
gd.addCheckbox("Trace_length", displayTraceLength);
gd.addCheckbox("Trace_size", displayTraceSize);
gd.showDialog();
if (gd.wasCanceled())
return false;
settings.removeOutliers = gd.getNextBoolean();
settings.histogramBins = (int) Math.abs(gd.getNextNumber());
for (int i = 0; i < displayHistograms.length; i++) displayHistograms[i] = gd.getNextBoolean();
displayMSDHistogram = gd.getNextBoolean();
displayDHistogram = gd.getNextBoolean();
displayTraceLength = gd.getNextBoolean();
displayTraceSize = gd.getNextBoolean();
}
// Check arguments
try {
Parameters.isAboveZero("Histogram bins", settings.histogramBins);
Parameters.isAbove("Fit length", settings.fitLength, 1);
Parameters.isAboveZero("Jump distance", settings.jumpDistance);
Parameters.isEqualOrAbove("Maximum N", maxN, myMinN);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
return true;
}
Aggregations