use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class FailCountManager method showAnalysisDialog.
private boolean showAnalysisDialog() {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage(TextUtils.wrap("Analysis a set of fail counters on the current pass/fail data.", 80));
gd.addSlider("Target_pass_fraction", 0.1, 1, settings.getTargetPassFraction());
gd.addSliderIncludeDefault("Table_top_n", 0, 100, settings.getTableTopN());
gd.addNumericField("Rolling_counter_min_allowed_failures", settings.getRollingCounterMinAllowedFailures(), 0);
gd.addNumericField("Rolling_counter_max_allowed_failures", settings.getRollingCounterMaxAllowedFailures(), 0);
gd.addNumericField("Rolling_counter_min_window", settings.getRollingCounterMinWindow(), 0);
gd.addNumericField("Rolling_counter_max_window", settings.getRollingCounterMaxWindow(), 0);
gd.addNumericField("Weighted_counter_min_allowed_failures", settings.getWeightedCounterMinAllowedFailures(), 0);
gd.addNumericField("Weighted_counter_max_allowed_failures", settings.getWeightedCounterMaxAllowedFailures(), 0);
gd.addNumericField("Weighted_counter_min_pass_decrement", settings.getWeightedCounterMinPassDecrement(), 0);
gd.addNumericField("Weighted_counter_max_pass_decrement", settings.getWeightedCounterMaxPassDecrement(), 0);
gd.addNumericField("Resetting_counter_min_allowed_failures", settings.getResettingCounterMinAllowedFailures(), 0);
gd.addNumericField("Resetting_counter_max_allowed_failures", settings.getResettingCounterMaxAllowedFailures(), 0);
gd.addNumericField("Resetting_counter_min_pass_decrement", settings.getResettingCounterMinResetFraction(), 2);
gd.addNumericField("Resetting_counter_max_pass_decrement", settings.getResettingCounterMaxResetFraction(), 2);
gd.addNumericField("Resetting_counter_inc_pass_decrement", settings.getResettingCounterIncResetFraction(), 2);
gd.addNumericField("Pass_rate_counter_min_allowed_failures", settings.getPassRateCounterMinAllowedCounts(), 0);
gd.addNumericField("Pass_rate_counter_max_allowed_failures", settings.getPassRateCounterMaxAllowedCounts(), 0);
gd.addNumericField("Pass_rate_counter_min_pass_rate", settings.getPassRateCounterMinPassRate(), 3);
gd.addNumericField("Pass_rate_counter_max_pass_rate", settings.getPassRateCounterMaxPassRate(), 3);
gd.addNumericField("Pass_rate_counter_inc_pass_rate", settings.getPassRateCounterIncPassRate(), 3);
gd.addHelp(HelpUrls.getUrl("fail-count-manager-analysis"));
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.setTargetPassFraction(gd.getNextNumber());
settings.setTableTopN((int) gd.getNextNumber());
settings.setRollingCounterMinAllowedFailures((int) gd.getNextNumber());
settings.setRollingCounterMaxAllowedFailures((int) gd.getNextNumber());
settings.setRollingCounterMinWindow((int) gd.getNextNumber());
settings.setRollingCounterMaxWindow((int) gd.getNextNumber());
settings.setWeightedCounterMinAllowedFailures((int) gd.getNextNumber());
settings.setWeightedCounterMaxAllowedFailures((int) gd.getNextNumber());
settings.setWeightedCounterMinPassDecrement((int) gd.getNextNumber());
settings.setWeightedCounterMaxPassDecrement((int) gd.getNextNumber());
settings.setResettingCounterMinAllowedFailures((int) gd.getNextNumber());
settings.setResettingCounterMaxAllowedFailures((int) gd.getNextNumber());
settings.setResettingCounterMinResetFraction(gd.getNextNumber());
settings.setResettingCounterMaxResetFraction(gd.getNextNumber());
settings.setResettingCounterIncResetFraction(gd.getNextNumber());
settings.setPassRateCounterMinAllowedCounts((int) gd.getNextNumber());
settings.setPassRateCounterMaxAllowedCounts((int) gd.getNextNumber());
settings.setPassRateCounterMinPassRate(gd.getNextNumber());
settings.setPassRateCounterMaxPassRate(gd.getNextNumber());
settings.setPassRateCounterIncPassRate(gd.getNextNumber());
try {
ParameterUtils.isAboveZero("Target pass fraction", settings.getTargetPassFraction());
ParameterUtils.isAboveZero("Resetting counter inc pass decrement", settings.getResettingCounterIncResetFraction());
ParameterUtils.isAboveZero("Pass rate counter inc pass rate", settings.getPassRateCounterIncPassRate());
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DensityImage method computeRipleysPlot.
/**
* Compute the Ripley's L-function for user selected radii and show it on a plot.
*
* @param results the results
*/
private void computeRipleysPlot(MemoryPeakResults results) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Compute Ripley's L(r) - r plot");
gd.addNumericField("Min_radius", settings.minR, 2);
gd.addNumericField("Max_radius", settings.maxR, 2);
gd.addNumericField("Increment", settings.incrementR, 2);
gd.addCheckbox("Confidence_intervals", settings.confidenceIntervals);
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
settings.minR = gd.getNextNumber();
settings.maxR = gd.getNextNumber();
settings.incrementR = gd.getNextNumber();
settings.confidenceIntervals = gd.getNextBoolean();
if (settings.minR > settings.maxR || settings.incrementR < 0 || gd.invalidNumber()) {
IJ.error(TITLE, "Invalid radius parameters");
return;
}
final DensityManager dm = createDensityManager(results);
final double[][] values = calculateLScores(dm);
// 99% confidence intervals
final int iterations = (settings.confidenceIntervals) ? 99 : 0;
double[] upper = null;
double[] lower = null;
final Rectangle bounds = results.getBounds();
final double area = (double) bounds.width * bounds.height;
// Use a uniform distribution for the coordinates
final HaltonSequenceGenerator dist = new HaltonSequenceGenerator(2);
dist.skipTo(SeedFactory.createInt());
for (int i = 0; i < iterations; i++) {
IJ.showProgress(i, iterations);
IJ.showStatus(String.format("L-score confidence interval %d / %d", i + 1, iterations));
// Randomise coordinates
final float[] x = new float[results.size()];
final float[] y = new float[x.length];
for (int j = x.length; j-- > 0; ) {
final double[] d = dist.nextVector();
x[j] = (float) (d[0] * bounds.width);
y[j] = (float) (d[1] * bounds.height);
}
final double[][] values2 = calculateLScores(new DensityManager(x, y, area));
if (upper == null || lower == null) {
upper = values2[1];
lower = upper.clone();
} else {
for (int m = upper.length; m-- > 0; ) {
if (upper[m] < values2[1][m]) {
upper[m] = values2[1][m];
}
if (lower[m] > values2[1][m]) {
lower[m] = values2[1][m];
}
}
}
}
final String title = results.getName() + " Ripley's (L(r) - r) / r";
final Plot plot = new Plot(title, "Radius", "(L(r) - r) / r");
plot.addPoints(values[0], values[1], Plot.LINE);
// Get the limits
double yMin = min(0, values[1]);
double yMax = max(0, values[1]);
if (iterations > 0) {
yMin = min(yMin, lower);
yMax = max(yMax, upper);
}
plot.setLimits(0, values[0][values[0].length - 1], yMin, yMax);
if (iterations > 0) {
plot.setColor(Color.BLUE);
plot.addPoints(values[0], upper, 1);
plot.setColor(Color.RED);
plot.addPoints(values[0], lower, 1);
plot.setColor(Color.BLACK);
}
ImageJUtils.display(title, plot);
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DensityImage method showDialog.
private boolean showDialog() {
settings = Settings.load();
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("density-image"));
// Build a list of all images with a region ROI
final List<String> titles = new LinkedList<>();
for (final int imageId : ImageJUtils.getIdList()) {
final ImagePlus imp = WindowManager.getImage(imageId);
if (imp != null && imp.getRoi() != null && imp.getRoi().isArea()) {
titles.add(imp.getTitle());
}
}
gd.addMessage("Show an image using the localisation density");
ResultsManager.addInput(gd, settings.inputOption, InputSource.MEMORY);
gd.addNumericField("Radius", settings.radius, 3);
if (!titles.isEmpty()) {
gd.addCheckbox((titles.size() == 1) ? "Use_ROI" : "Choose_ROI", settings.chooseRoi);
}
gd.addCheckbox("Adjust_for_border", settings.adjustForBorder);
gd.addSlider("Image_Scale", 1, 15, settings.imageScale);
gd.addCheckbox("Cumulative_image", settings.cumulativeImage);
gd.addCheckbox("Use_square_approx", settings.useSquareApproximation);
gd.addNumericField("Square_resolution", settings.resolution, 0);
gd.addChoice("Score", Settings.scoreMethods, settings.scoreMethodIndex);
gd.addMessage("Filter localisations using the L-score / Relative density.\n" + "Filtered results will be added to memory:");
gd.addCheckbox("Filter_localisations", settings.filterLocalisations);
gd.addNumericField("Filter_threshold", settings.filterThreshold, 2);
gd.addCheckbox("Compute_Ripleys_L_plot", settings.computeRipleysPlot);
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.inputOption = ResultsManager.getInputSource(gd);
settings.radius = (float) gd.getNextNumber();
if (!titles.isEmpty()) {
settings.chooseRoi = gd.getNextBoolean();
}
settings.adjustForBorder = gd.getNextBoolean();
settings.imageScale = (int) gd.getNextNumber();
settings.cumulativeImage = gd.getNextBoolean();
settings.useSquareApproximation = gd.getNextBoolean();
settings.resolution = (int) gd.getNextNumber();
settings.scoreMethodIndex = gd.getNextChoiceIndex();
settings.filterLocalisations = gd.getNextBoolean();
settings.filterThreshold = gd.getNextNumber();
settings.computeRipleysPlot = gd.getNextBoolean();
settings.save();
// Check arguments
try {
ParameterUtils.isAboveZero("Radius", settings.radius);
ParameterUtils.isAboveZero("Image scale", settings.imageScale);
ParameterUtils.isAboveZero("Resolution", settings.resolution);
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
if (!titles.isEmpty() && settings.chooseRoi) {
if (titles.size() == 1) {
settings.roiImage = titles.get(0);
Recorder.recordOption("Image", settings.roiImage);
} else {
final String[] items = titles.toArray(new String[0]);
gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select the source image for the ROI");
gd.addChoice("Image", items, settings.roiImage);
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.roiImage = gd.getNextChoice();
}
final ImagePlus imp = WindowManager.getImage(settings.roiImage);
roiBounds = imp.getRoi().getBounds();
roiImageWidth = imp.getWidth();
roiImageHeight = imp.getHeight();
} else {
roiBounds = null;
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DriftCalculator method applyDriftCorrection.
private void applyDriftCorrection(MemoryPeakResults results, double[][] drift) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Apply drift correction to in-memory results?");
gd.addChoice("Update_method", Settings.UPDATE_METHODS, settings.updateMethod);
// Option to save the drift unless it was loaded from file
if (!Settings.DRIFT_FILE.equals(settings.method)) {
gd.addCheckbox("Save_drift", settings.saveDrift);
}
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
settings.updateMethod = gd.getNextChoiceIndex();
if (!Settings.DRIFT_FILE.equals(settings.method)) {
settings.saveDrift = gd.getNextBoolean();
saveDrift(calculatedTimepoints, lastdx, lastdy);
}
if (settings.updateMethod == 0) {
return;
}
final double[] dx = drift[0];
final double[] dy = drift[1];
if (settings.updateMethod == 1) {
// Update the results in memory
ImageJUtils.log("Applying drift correction to the results set: " + results.getName());
results.forEach((PeakResultProcedure) result -> {
result.setXPosition((float) (result.getXPosition() + dx[result.getFrame()]));
result.setYPosition((float) (result.getYPosition() + dy[result.getFrame()]));
});
} else {
// Create a new set of results
final MemoryPeakResults newResults = new MemoryPeakResults(results.size());
newResults.copySettings(results);
newResults.setName(results.getName() + " (Corrected)");
MemoryPeakResults.addResults(newResults);
final boolean truncate = settings.updateMethod == 3;
ImageJUtils.log("Creating %sdrift corrected results set: " + newResults.getName(), (truncate) ? "truncated " : "");
results.forEach((PeakResultProcedure) result -> {
if (truncate && (result.getFrame() < interpolationStart || result.getFrame() > interpolationEnd)) {
return;
}
result.setXPosition((float) (result.getXPosition() + dx[result.getFrame()]));
result.setYPosition((float) (result.getYPosition() + dy[result.getFrame()]));
newResults.add(result);
});
}
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class CameraModelAnalysis method showDialog.
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
settings = SettingsManager.readCameraModelAnalysisSettings(0).toBuilder();
gd = new NonBlockingExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("camera-model-analysis"));
gd.addMessage("Simulate on-chip camera applification.");
gd.addNumericField("Photons", settings.getPhotons(), 2);
gd.addChoice("Mode", MODE, settings.getMode(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.setMode(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final int mode = settings.getMode();
final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
if (mode == MODE_CCD) {
egd.addNumericField("Gain", settings.getGain(), 2, 6, "Count/electrons");
egd.addNumericField("Noise", settings.getNoise(), 2, 6, "Count");
} else if (mode == MODE_EM_CCD) {
egd.addNumericField("Gain", settings.getEmGain(), 2, 6, "Count/electrons");
egd.addNumericField("Noise", settings.getEmNoise(), 2, 6, "Count");
egd.addNumericField("EM_samples", settings.getEmSamples(), 0);
} else if (mode == MODE_SCMOS) {
egd.addNumericField("Gain", settings.getCmosGain(), 2, 6, "Count/electrons");
egd.addNumericField("Noise", settings.getCmosNoise(), 2, 6, "Count");
} else {
throw new IllegalStateException();
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
if (mode == MODE_CCD) {
settings.setGain(egd.getNextNumber());
settings.setNoise(egd.getNextNumber());
} else if (mode == MODE_EM_CCD) {
settings.setEmGain(egd.getNextNumber());
settings.setEmNoise(egd.getNextNumber());
settings.setEmSamples(Math.max(1, (int) egd.getNextNumber()));
} else {
// MODE_SCMOS
settings.setCmosGain(egd.getNextNumber());
settings.setCmosNoise(egd.getNextNumber());
}
return true;
}
});
if (extraOptions) {
gd.addNumericField("Seed", settings.getSeed(), 0);
}
gd.addNumericField("Samples", settings.getSamples(), 0);
gd.addNumericField("Noise_samples", settings.getNoiseSamples(), 0);
gd.addCheckbox("Round_down", settings.getRoundDown());
gd.addChoice("Model", MODEL, settings.getModel());
gd.addCheckbox("Full_integration", settings.getSimpsonIntegration());
gd.addOptionCollectedListener(this::optionCollected);
gd.addDialogListener(this::dialogItemChanged);
gd.addPreviewCheckbox(pfr);
gd.showDialog();
SettingsManager.writeSettings(settings);
if (!gd.wasCanceled() && dirty) {
execute();
}
return DONE;
}
Aggregations