use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method showScoreDialog.
private boolean showScoreDialog() {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
addSimulationData(gd);
// Get the last scored filter or default to the best filter
createScoreFilter(false);
gd.addSlider("Fail_count", 0, 20, settings.scoreFailCount);
computeDoublets = BenchmarkSpotFit.getComputeDoublets();
if (computeDoublets) {
gd.addSlider("Residuals_threshold", 0.01, 1, settings.scoreResidualsThreshold);
}
gd.addNumericField("Duplicate_distance", settings.scoreDuplicateDistance, 2);
gd.addTextAreas(uk.ac.sussex.gdsc.core.utils.XmlUtils.convertQuotes(scoreFilter.toXml()), null, 6, 60);
gd.addCheckbox("Reset_filter", false);
gd.addCheckbox("Show_summary", settings.showSummaryTable);
gd.addCheckbox("Clear_tables", settings.clearTables);
gd.addCheckbox("Save_best_filter", settings.saveBestFilter);
gd.addCheckbox("Save_template", settings.saveTemplate);
gd.addCheckbox("Calculate_sensitivity", settings.calculateSensitivity);
gd.addSlider("Delta", 0.01, 1, settings.delta);
if (!simulationParameters.fixedDepth) {
gd.addCheckbox("Depth_recall_analysis", settings.depthRecallAnalysis);
}
gd.addCheckbox("Score_analysis", settings.scoreAnalysis);
gd.addChoice("Component_analysis", Settings.COMPONENT_ANALYSIS_OPTIONS, settings.componentAnalysis);
gd.addStringField("Title", settings.resultsTitle, 20);
final String[] labels = { "Show_TP", "Show_FP", "Show_FN" };
gd.addCheckboxGroup(1, 3, labels, new boolean[] { settings.showTP, settings.showFP, settings.showFN });
// Dialog to have a reset checkbox. This reverts back to the default.
if (ImageJUtils.isShowGenericDialog()) {
final Checkbox cb = (Checkbox) (gd.getCheckboxes().get(0));
final Vector<TextField> v = gd.getNumericFields();
final TextArea ta = gd.getTextArea1();
cb.addItemListener(event -> {
if (cb.getState()) {
createScoreFilter(true);
int index = 0;
v.get(index++).setText(Integer.toString(settings.scoreFailCount));
if (computeDoublets) {
v.get(index++).setText(Double.toString(settings.scoreResidualsThreshold));
}
v.get(index++).setText(Double.toString(settings.scoreDuplicateDistance));
ta.setText(uk.ac.sussex.gdsc.core.utils.XmlUtils.convertQuotes(scoreFilter.toXml()));
}
});
}
gd.addHelp(HelpUrls.getUrl("score-filter"));
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.scoreFailCount = (int) Math.abs(gd.getNextNumber());
if (computeDoublets) {
settings.scoreResidualsThreshold = Math.abs(gd.getNextNumber());
}
settings.scoreDuplicateDistance = Math.abs(gd.getNextNumber());
final String xml = gd.getNextText();
boolean reset = gd.getNextBoolean();
if (!reset) {
// Try and parse the filter
try {
scoreFilter = (DirectFilter) Filter.fromXml(xml);
} catch (final Exception ex) {
// Invalid so reset
reset = true;
}
}
createScoreFilter(reset);
settings.showSummaryTable = gd.getNextBoolean();
settings.clearTables = gd.getNextBoolean();
settings.saveBestFilter = gd.getNextBoolean();
settings.saveTemplate = gd.getNextBoolean();
settings.calculateSensitivity = gd.getNextBoolean();
settings.delta = gd.getNextNumber();
if (!simulationParameters.fixedDepth) {
settings.depthRecallAnalysis = gd.getNextBoolean();
}
settings.scoreAnalysis = gd.getNextBoolean();
settings.componentAnalysis = gd.getNextChoiceIndex();
settings.resultsTitle = gd.getNextString();
settings.showTP = gd.getNextBoolean();
settings.showFP = gd.getNextBoolean();
settings.showFN = gd.getNextBoolean();
settings.save();
if (gd.invalidNumber()) {
return false;
}
resultsPrefix = spotFitResults.resultPrefix + "\t" + settings.resultsTitle + "\t";
createResultsPrefix2(settings.scoreFailCount, settings.scoreResidualsThreshold, settings.scoreDuplicateDistance);
// Check there is one output
if (!settings.showSummaryTable && !settings.calculateSensitivity && !settings.saveBestFilter && !settings.saveTemplate) {
IJ.error(TITLE, "No output selected");
return false;
}
// Check arguments
try {
ParameterUtils.isAboveZero("Delta", settings.delta);
ParameterUtils.isBelow("Delta", settings.delta, 1);
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
return selectTableColumns();
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class Test_PlugIn method run.
@Override
public void run(String arg) {
// The parameters that have options must be available statically for the OptionListener
final String[] textFields = { "Some text", "More text" };
final String[] optionFields = { "", "", "" };
final double[] numberFields = { 2.567, 7, 4.567, 7.898 };
final ExtendedGenericDialog gd = new ExtendedGenericDialog("Test");
gd.addChoice("Select1", new String[] { "One", "Two" }, optionFields[0]);
final Choice c2 = gd.addAndGetChoice("Select2", new String[] { "Three", "Four" }, optionFields[1]);
gd.addAndGetButton("Options", event -> {
final ExtendedGenericDialog gd2 = new ExtendedGenericDialog("Test2", null);
gd2.addMessage(c2.getSelectedItem());
gd2.showDialog(true);
gd2.getNextChoice();
});
gd.addStringField("Another", textFields[0]);
gd.addStringField("Testing", textFields[1], 15, new OptionListener<String>() {
@Override
public boolean collectOptions(String field) {
IJ.log(field);
return true;
}
@Override
public boolean collectOptions() {
IJ.log(textFields[1]);
return true;
}
});
gd.addFilenameField("File", "", 30);
gd.addDirectoryField("Dir", "", 30);
gd.addChoice("Select3", new String[] { "Five", "Six" }, optionFields[2], new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer field) {
IJ.log(Integer.toString(field));
return true;
}
@Override
public boolean collectOptions() {
IJ.log(optionFields[2]);
return true;
}
});
gd.addSlider("Slider1", 0.5, 4.5, numberFields[0], new OptionListener<Double>() {
@Override
public boolean collectOptions(Double field) {
IJ.log(field.toString());
return true;
}
@Override
public boolean collectOptions() {
IJ.log(Double.toString(numberFields[0]));
return true;
}
});
gd.addSlider("Slider2", 0, 10, numberFields[1], new OptionListener<Double>() {
@Override
public boolean collectOptions(Double field) {
IJ.log(field.toString());
return true;
}
@Override
public boolean collectOptions() {
IJ.log(Double.toString(numberFields[1]));
return true;
}
});
gd.addNumericField("Number1", numberFields[2], 2, new OptionListener<Double>() {
@Override
public boolean collectOptions(Double field) {
IJ.log(field.toString());
return true;
}
@Override
public boolean collectOptions() {
IJ.log(Double.toString(numberFields[2]));
return true;
}
});
gd.addNumericField("Number2", numberFields[3], 2, 6, "px", new OptionListener<Double>() {
@Override
public boolean collectOptions(Double field) {
IJ.log(field.toString());
return true;
}
@Override
public boolean collectOptions() {
IJ.log(Double.toString(numberFields[3]));
return true;
}
});
gd.setMaxUnscrolledSize(0, 300);
gd.showDialog();
optionFields[0] = gd.getNextChoice();
optionFields[1] = gd.getNextChoice();
textFields[0] = gd.getNextString();
textFields[1] = gd.getNextString();
optionFields[2] = gd.getNextChoice();
numberFields[0] = gd.getNextNumber();
numberFields[1] = gd.getNextNumber();
numberFields[2] = gd.getNextNumber();
numberFields[3] = gd.getNextNumber();
gd.collectOptions();
}
use of uk.ac.sussex.gdsc.core.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 the results
* @return True if calibrated
*/
private static boolean checkCalibration(MemoryPeakResults results) {
if (results.getCalibration() == null || !results.getCalibrationReader().hasExposureTime() || !results.getCalibrationReader().hasNmPerPixel()) {
final CalibrationWriter cal = results.getCalibrationWriterSafe();
final 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;
}
results.setCalibration(cal.getCalibration());
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method calculatePrecision.
/**
* Calculate the average precision of localisation in the traces.
*
* @param traces the traces
* @param multi true if the traces were from multiple input results
*/
private void calculatePrecision(Trace[] traces, boolean multi) {
// Check the diffusion simulation for a precision
if (DiffusionRateTest.isSimulated(results.getName()) && !multi) {
precision = DiffusionRateTest.getLastSimulationPrecision();
} else {
precision = 999;
try {
final Gaussian2DPeakResultCalculator calculator = Gaussian2DPeakResultHelper.create(results.getPsf(), results.getCalibration(), Gaussian2DPeakResultHelper.LSE_PRECISION);
// Get the average precision of the localisations
precision = 0;
int count = 0;
for (final Trace trace : traces) {
for (int k = 0; k < trace.size(); k++) {
final PeakResult r = trace.get(k);
precision += calculator.getLsePrecision(r.getParameters(), r.getNoise());
}
count += trace.size();
}
precision /= count;
} catch (final ConfigurationException ex) {
// Ignore this and we will ask the user for the precision
}
}
if (precision > 100) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("The average precision of the traced results is " + MathUtils.rounded(precision, 4) + " nm.\nPlease verify the precision.");
gd.addSlider("Precision (nm)", 5, 100, precision);
gd.showDialog();
if (!(gd.wasCanceled() || gd.invalidNumber())) {
precision = Math.abs(gd.getNextNumber());
}
}
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TranslateResults method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
final TranslateResultsSettings.Builder settings = SettingsManager.readTranslateResultsSettings(0).toBuilder();
// Show a dialog allowing the results set to be filtered
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select a dataset to translate");
ResultsManager.addInput(gd, settings.getInputOption(), InputSource.MEMORY);
gd.addNumericField("x", settings.getDx(), 3);
gd.addNumericField("y", settings.getDy(), 3);
gd.addNumericField("z", settings.getDz(), 3);
gd.addChoice("Distance_unit", SettingsManager.getDistanceUnitNames(), settings.getDistanceUnitValue());
gd.addHelp(HelpUrls.getUrl("translate-results"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
settings.setInputOption(ResultsManager.getInputSource(gd));
settings.setDx(gd.getNextNumber());
settings.setDy(gd.getNextNumber());
settings.setDz(gd.getNextNumber());
settings.setDistanceUnitValue(gd.getNextChoiceIndex());
SettingsManager.writeSettings(settings);
final MemoryPeakResults results = ResultsManager.loadInputResults(settings.getInputOption(), false, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
return;
}
TypeConverter<DistanceUnit> converter;
try {
converter = results.getDistanceConverter(settings.getDistanceUnit());
} catch (final DataException ex) {
IJ.error(TITLE, "Unit conversion error: " + ex.getMessage());
return;
}
final float x = (float) converter.convertBack(settings.getDx());
final float y = (float) converter.convertBack(settings.getDy());
final float z = (float) converter.convertBack(settings.getDz());
// Reset the 2D bounds
if (x != 0 || y != 0) {
results.setBounds(null);
}
results.forEach((PeakResultProcedure) peakResult -> {
final float[] params = peakResult.getParameters();
params[PeakResult.X] += x;
params[PeakResult.Y] += y;
params[PeakResult.Z] += z;
});
}
Aggregations