use of uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog 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;
}
use of uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class AstigmatismModelManager method getRange.
private boolean getRange() {
minz = 0;
maxz = z.length - 1;
final NonBlockingExtendedGenericDialog gd = new NonBlockingExtendedGenericDialog(TITLE);
gd.addMessage("Select z-range for curve fit.\n" + "Choose a region with a smooth width curve and low XY drift.");
gd.addSlider("Min_z", minz, maxz, minz);
gd.addSlider("Max_z", minz, maxz, maxz);
gd.addMessage("Curve parameter estimation");
gd.addSlider("Smoothing", 0.05, 0.5, pluginSettings.getSmoothing());
gd.addCheckbox("Show_estimated_curve", pluginSettings.getShowEstimatedCurve());
gd.addMessage("Fit options");
gd.addCheckbox("Weighted_fit", pluginSettings.getWeightedFit());
gd.addDialogListener(new ZDialogListener());
gd.addHelp(HelpUrls.getUrl("astigmatism-model-manager-create"));
gd.showDialog();
// Save settings
writeAstigmatismModelManagerSettings(pluginSettings);
if (gd.wasCanceled()) {
return false;
}
// Ensure there are enough points to fit
if (maxz - minz < 10) {
IJ.error(TITLE, "Not enough points for a curve fit");
return false;
}
// Extract data for fit
fitZ = Arrays.copyOfRange(z, minz, maxz + 1);
fitSx = Arrays.copyOfRange(sx, minz, maxz + 1);
fitSy = Arrays.copyOfRange(sy, minz, maxz + 1);
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class BackgroundEstimator method showDialog.
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
settings = Settings.load();
// Save now as this just updates the reference held in memory
settings.save();
// If using a stack, provide a preview graph of the noise for two methods
if (imp.getStackSize() > 1) {
this.pfr = pfr;
drawPlot();
final NonBlockingExtendedGenericDialog gd = new NonBlockingExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("background-estimator"));
gd.addSlider("Percential", 0, 100, settings.percentile);
gd.addChoice("Noise_method", SettingsManager.getNoiseEstimatorMethodNames(), settings.noiseMethod.ordinal());
// For background based on pixel below a threshold
final String[] thresholdMethods = AutoThreshold.getMethods(true);
gd.addChoice("Threshold_method", thresholdMethods, thresholdMethods[settings.thresholdMethod.ordinal() - 1]);
gd.addSlider("Fraction", 0, 0.999, settings.fraction);
gd.addNumericField("Histogram_size", settings.histogramSize, 0);
gd.addDialogListener(this);
gd.addMessage("Click OK to compute table for all slices");
gd.showDialog();
if (gd.wasCanceled() || !dialogItemChanged(gd, null)) {
return DONE;
}
}
return IJ.setupDialog(imp, FLAGS);
}
use of uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class SpotFinderPreview method showDialog.
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
settings = Settings.load();
this.overlay = imp.getOverlay();
this.imp = imp;
// Saved by reference so do it once now
settings.save();
// The image is locked by the PlugInFilterRunner so unlock it to allow scroll.
// This should be OK as the image data is not modified and only the overlay is
// adjusted. If another plugin changes the image then the preview should update
// the overlay and it will be obvious to the user to turn this plugin off.
imp.unlock();
config = SettingsManager.readFitEngineConfiguration(0);
fitConfig = config.getFitConfiguration();
gd = new NonBlockingExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("spot-finder-preview"));
gd.addMessage("Preview candidate maxima");
final String[] templates = ConfigurationTemplate.getTemplateNames(true);
gd.addChoice("Template", templates, templates[0]);
final String[] models = CameraModelManager.listCameraModels(true);
gd.addChoice("Camera_model_name", models, fitConfig.getCameraModelName());
PeakFit.addPsfOptions(gd, (FitConfigurationProvider) () -> fitConfig);
final PeakFit.SimpleFitEngineConfigurationProvider provider = new PeakFit.SimpleFitEngineConfigurationProvider(config);
PeakFit.addDataFilterOptions(gd, provider);
gd.addChoice("Spot_filter_2", SettingsManager.getDataFilterMethodNames(), config.getDataFilterMethod(1, settings.defaultDataFilterMethod).ordinal());
PeakFit.addRelativeParameterOptions(gd, new RelativeParameterProvider(2.5, 4.5, "Smoothing_2", provider) {
@Override
void setAbsolute(boolean absolute) {
final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
final DataFilterMethod m = c.getDataFilterMethod(1, settings.defaultDataFilterMethod);
final double smooth = c.getDataFilterParameterValue(1, settings.defaultSmooth);
c.setDataFilter(m, smooth, absolute, 1);
}
@Override
boolean isAbsolute() {
return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterAbsolute(1, false);
}
@Override
double getValue() {
return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterValue(1, settings.defaultSmooth);
}
});
PeakFit.addSearchOptions(gd, provider);
PeakFit.addBorderOptions(gd, provider);
// Find if this image was created with ground truth data
if (imp.getID() == CreateData.getImageId()) {
final MemoryPeakResults results = CreateData.getResults();
if (results != null) {
gd.addSlider("Match_distance", 0, 2.5, settings.distance);
gd.addSlider("Lower_match_distance (%)", 0, 100, settings.lowerDistance);
gd.addCheckbox("Multiple_matches", settings.multipleMatches);
gd.addCheckbox("Show_TP", settings.showTP);
gd.addCheckbox("Show_FP", settings.showFP);
gd.addMessage("");
label = (Label) gd.getMessage();
final boolean integerCoords = false;
actualCoordinates = ResultsMatchCalculator.getCoordinates(results, integerCoords);
}
}
if (label == null) {
// If no ground truth data add options to show the spots by their rank
// and number of neighbours
gd.addSlider("Top_N", 0, 100, settings.topN);
topNScrollBar = gd.getLastScrollbar();
gd.addSlider("Select", 0, 100, settings.select);
selectScrollBar = gd.getLastScrollbar();
gd.addSlider("Neigbour_radius", 0, 10, settings.neighbourRadius);
}
ImageListener imageListener = null;
if (ImageJUtils.isShowGenericDialog()) {
// Listen for changes in the dialog options
gd.addOptionCollectedListener(event -> {
// Just run on the current processor
if (preview) {
run(imp.getProcessor());
}
});
// Listen for changes to an image
imageListener = new ImageAdapter() {
@Override
public void imageUpdated(ImagePlus imp) {
if (SpotFinderPreview.this.imp.getID() == imp.getID() && preview && imp.getCurrentSlice() != currentSlice && filter != null) {
run(imp.getProcessor(), filter);
}
}
};
ImagePlus.addImageListener(imageListener);
// Support template settings
final Vector<TextField> numerics = gd.getNumericFields();
final Vector<Choice> choices = gd.getChoices();
final Iterator<TextField> nu = numerics.iterator();
final Iterator<Choice> ch = choices.iterator();
final Choice textTemplate = ch.next();
textTemplate.removeItemListener(gd);
textTemplate.removeKeyListener(gd);
textTemplate.addItemListener(this::itemStateChanged);
textCameraModelName = ch.next();
textPsf = ch.next();
textDataFilterType = ch.next();
textDataFilterMethod = ch.next();
textSmooth = nu.next();
textDataFilterMethod2 = ch.next();
textSmooth2 = nu.next();
textSearch = nu.next();
textBorder = nu.next();
}
gd.addPreviewCheckbox(pfr);
gd.addDialogListener(this::dialogItemChanged);
gd.setOKLabel("Save");
gd.setCancelLabel("Close");
gd.showDialog();
if (imageListener != null) {
ImagePlus.removeImageListener(imageListener);
}
if (!gd.wasCanceled() && !SettingsManager.writeSettings(config, SettingsManager.FLAG_SILENT)) {
IJ.error(TITLE, "Failed to save settings");
}
// Reset
imp.setOverlay(overlay);
return DONE;
}
use of uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceLengthAnalysis method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "No localisations in memory");
return;
}
if (!showDialog()) {
return;
}
// Load the results
MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, false, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
return;
}
try {
distanceConverter = results.getDistanceConverter(DistanceUnit.UM);
timeConverter = results.getTimeConverter(TimeUnit.SECOND);
} catch (final Exception ex) {
IJ.error(TITLE, "Cannot convert units to um or seconds: " + ex.getMessage());
return;
}
// Get the localisation error (4s^2) in raw units^2
double precision = 0;
try {
final PrecisionResultProcedure p = new PrecisionResultProcedure(results);
p.getPrecision();
// Precision in nm using the median
precision = new Percentile().evaluate(p.precisions, 50);
// Convert from nm to um to raw units
final double rawPrecision = distanceConverter.convertBack(precision / 1e3);
// Get the localisation error (4s^2) in units^2
error = 4 * rawPrecision * rawPrecision;
} catch (final Exception ex) {
ImageJUtils.log(TITLE + " - Unable to compute precision: " + ex.getMessage());
}
// Analyse the track lengths
results = results.copy();
results.sort(IdFramePeakResultComparator.INSTANCE);
// Ensure the first result triggers an id change
lastid = results.getFirst().getId() - 1;
results.forEach(this::processTrackLength);
// For the final track
store();
msds = msdList.toArray();
lengths = lengthList.toArray();
ids = idList.toArray();
final int[] limits = MathUtils.limits(lengths);
h1 = new int[limits[1] + 1];
h2 = new int[h1.length];
x1 = SimpleArrayUtils.newArray(h1.length, 0, 1f);
y1 = new float[x1.length];
y2 = new float[x1.length];
// Sort by MSD
final int[] indices = SimpleArrayUtils.natural(msds.length);
SortUtils.sortIndices(indices, msds, false);
final double[] msds2 = msds.clone();
final int[] lengths2 = lengths.clone();
final int[] ids2 = ids.clone();
for (int i = 0; i < indices.length; i++) {
msds[i] = msds2[indices[i]];
lengths[i] = lengths2[indices[i]];
ids[i] = ids2[indices[i]];
}
// Interactive analysis
final NonBlockingExtendedGenericDialog gd = new NonBlockingExtendedGenericDialog(TITLE);
ImageJUtils.addMessage(gd, "Split traces into fixed or moving using the track diffusion coefficient (D).\n" + "Localisation error has been subtracted from jumps (%s nm).", MathUtils.rounded(precision));
final Statistics s = Statistics.create(msds);
final double av = s.getMean();
final String msg = String.format("Average D per track = %s um^2/s", MathUtils.rounded(av));
gd.addMessage(msg);
// Histogram the diffusion coefficients
final WindowOrganiser wo = new WindowOrganiser();
final HistogramPlot histogramPlot = new HistogramPlotBuilder("Trace diffusion coefficient", StoredData.create(msds), "D (um^2/s)").setRemoveOutliersOption(1).setPlotLabel(msg).build();
histogramPlot.show(wo);
final double[] xvalues = histogramPlot.getPlotXValues();
final double min = xvalues[0];
final double max = xvalues[xvalues.length - 1];
// see if we can build a nice slider range from the histogram limits
if (max - min < 5) {
// Because sliders are used when the range is <5 and floating point
gd.addSlider("D_threshold", min, max, settings.msdThreshold);
} else {
gd.addNumericField("D_threshold", settings.msdThreshold, 2, 6, "um^2/s");
}
gd.addCheckbox("Normalise", settings.normalise);
gd.addDialogListener((gd1, event) -> {
settings.msdThreshold = gd1.getNextNumber();
settings.normalise = gd1.getNextBoolean();
update();
return true;
});
if (ImageJUtils.isShowGenericDialog()) {
draw(wo);
wo.tile();
}
gd.setOKLabel("Save datasets");
gd.setCancelLabel("Close");
gd.addHelp(HelpUrls.getUrl("trace-length-analysis"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
// Sort by ID
final PeakResult[] list = results.toArray();
Arrays.sort(list, IdFramePeakResultComparator.INSTANCE);
createResults(results, "Fixed", 0, lastIndex, list);
createResults(results, "Moving", lastIndex, msds.length, list);
}
Aggregations