use of uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings in project GDSC-SMLM by aherbert.
the class DoubletAnalysis method itemStateChanged.
@Override
public void itemStateChanged(ItemEvent event) {
if (event.getSource() instanceof Choice) {
// Update the settings from the template
final Choice choice = (Choice) event.getSource();
final String templateName = choice.getSelectedItem();
// Get the configuration template
final TemplateSettings template = ConfigurationTemplate.getTemplate(templateName);
if (textCoordinateShiftFactor != null) {
// Start with a default. This will cause a reset.
final FitConfiguration fitConfig = new FitConfiguration();
if (template != null) {
fitConfig.setFitSettings(template.getFitEngineSettings().getFitSettings());
}
cbSmartFilter.setState(fitConfig.isSmartFilter());
textCoordinateShiftFactor.setText("" + fitConfig.getCoordinateShiftFactor());
textSignalStrength.setText("" + fitConfig.getSignalStrength());
textMinPhotons.setText("" + fitConfig.getMinPhotons());
textMinWidthFactor.setText("" + fitConfig.getMinWidthFactor());
textWidthFactor.setText("" + fitConfig.getMaxWidthFactor());
textPrecisionThreshold.setText("" + fitConfig.getPrecisionThreshold());
textPrecisionMethod.select(fitConfig.getPrecisionMethod().ordinal());
} else if (template != null) {
if (template.hasFitEngineSettings()) {
final boolean custom = ConfigurationTemplate.isCustomTemplate(templateName);
final FitEngineConfiguration config2 = new FitEngineConfiguration(template.getFitEngineSettings(), template.getCalibration(), template.getPsf());
final FitConfiguration fitConfig2 = config2.getFitConfiguration();
if (custom && template.hasPsf()) {
textPsf.select(PeakFit.getPsfTypeNames()[fitConfig2.getPsfType().ordinal()]);
}
textDataFilterType.select(config2.getDataFilterType().ordinal());
textDataFilter.select(config2.getDataFilterMethod(0).ordinal());
textSmooth.setText("" + config2.getDataFilterParameterValue(0));
textSearch.setText("" + config2.getSearch());
textBorder.setText("" + config2.getBorder());
textFitting.setText("" + config2.getFitting());
textFitSolver.select(FitProtosHelper.getName(fitConfig2.getFitSolver()));
// Copy settings not in the dialog for the fit solver
final FitConfiguration fitConfig = config.getFitConfiguration();
if (custom) {
fitConfig.setPsf(fitConfig2.getPsf());
}
fitConfig.setFitSolverSettings(fitConfig2.getFitSolverSettings());
}
} else {
// Ignore
}
} else if (event.getSource() instanceof Checkbox) {
final Checkbox checkbox = (Checkbox) event.getSource();
if (!checkbox.getState()) {
return;
}
if (textCoordinateShiftFactor != null) {
if (!updateFilterConfiguration(filterFitConfig)) {
return;
}
cbSmartFilter.setState(filterFitConfig.isSmartFilter());
textCoordinateShiftFactor.setText("" + filterFitConfig.getCoordinateShiftFactor());
textSignalStrength.setText("" + filterFitConfig.getSignalStrength());
textMinPhotons.setText("" + filterFitConfig.getMinPhotons());
textMinWidthFactor.setText("" + filterFitConfig.getMinWidthFactor());
textWidthFactor.setText("" + filterFitConfig.getMaxWidthFactor());
textPrecisionThreshold.setText("" + filterFitConfig.getPrecisionThreshold());
textPrecisionMethod.select(filterFitConfig.getPrecisionMethod().ordinal());
} else {
if (!updateFitConfiguration(config)) {
return;
}
final FitConfiguration fitConfig = config.getFitConfiguration();
textPsf.select(PeakFit.getPsfTypeNames()[fitConfig.getPsfType().ordinal()]);
textDataFilterType.select(config.getDataFilterType().ordinal());
textDataFilter.select(config.getDataFilterMethod(0).ordinal());
textSmooth.setText("" + config.getDataFilterParameterValue(0));
textSearch.setText("" + config.getSearch());
textBorder.setText("" + config.getBorder());
textFitting.setText("" + config.getFitting());
textFitSolver.select(FitProtosHelper.getName(fitConfig.getFitSolver()));
textMatchDistance.setText("" + settings.matchDistance);
textLowerDistance.setText("" + settings.lowerDistance);
textSignalFactor.setText("" + settings.signalFactor);
textLowerFactor.setText("" + settings.lowerSignalFactor);
}
}
}
use of uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings in project GDSC-SMLM by aherbert.
the class SpotFinderPreview method itemStateChanged.
private void itemStateChanged(ItemEvent event) {
if (event.getSource() instanceof Choice) {
// Update the settings from the template
final Choice choice = (Choice) event.getSource();
final String templateName = choice.getSelectedItem();
// Get the configuration template
final TemplateSettings template = ConfigurationTemplate.getTemplate(templateName);
if (template != null) {
refreshing = true;
IJ.log("Applying template: " + templateName);
for (final String note : template.getNotesList()) {
IJ.log(note);
}
final boolean custom = ConfigurationTemplate.isCustomTemplate(templateName);
if (template.hasPsf()) {
refreshSettings(template.getPsf(), custom);
}
if (template.hasFitEngineSettings()) {
refreshSettings(template.getFitEngineSettings(), custom);
}
refreshing = false;
}
}
}
use of uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings in project GDSC-SMLM by aherbert.
the class Configuration method itemStateChanged.
private void itemStateChanged(ItemEvent event) {
if (event.getSource() instanceof Choice) {
// Update the settings from the template
final Choice choice = (Choice) event.getSource();
final String templateName = choice.getSelectedItem();
// Get the configuration template
final TemplateSettings template = ConfigurationTemplate.getTemplate(templateName);
if (template != null) {
IJ.log("Applying template: " + templateName);
final File file = ConfigurationTemplate.getTemplateFile(templateName);
if (file != null) {
pluginSettings.templateFilename = file.getPath();
}
final StringBuilder sb = new StringBuilder();
for (final String note : template.getNotesList()) {
sb.append(note);
if (!note.endsWith("\n")) {
sb.append("\n");
}
IJ.log(note);
}
pluginSettings.notes = sb.toString();
final boolean custom = ConfigurationTemplate.isCustomTemplate(templateName);
if (template.hasCalibration()) {
refreshSettings(template.getCalibration());
}
if (template.hasPsf()) {
refreshSettings(template.getPsf(), custom);
}
if (template.hasFitEngineSettings()) {
refreshSettings(template.getFitEngineSettings());
}
}
} else if (event.getSource() instanceof Checkbox) {
if (event.getSource() == textSmartFilter) {
textDisableSimpleFilter.setState(textSmartFilter.getState());
}
updateFilterInput();
}
}
use of uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings in project GDSC-SMLM by aherbert.
the class ConfigurationTemplate method showTemplateInfo.
/**
* Show the info from the template.
*
* @param name the name
*/
private void showTemplateInfo(String name) {
final TemplateSettings settings = getTemplate(name);
if (settings == null || settings.getNotesCount() == 0) {
return;
}
if (infoWindow == null || !infoWindow.isVisible()) {
infoWindow = new TextWindow(title + " Info", "", "", 450, 250);
// Put underneath the results window
if (resultsWindow != null) {
final Point p = resultsWindow.getLocation();
p.y += resultsWindow.getHeight();
infoWindow.setLocation(p);
}
}
infoWindow.getTextPanel().clear();
for (final String note : settings.getNotesList()) {
// Text window cannot show tabs
infoWindow.append(note.replace('\t', ','));
}
}
use of uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method saveTemplate.
/**
* Save PeakFit configuration template using the current benchmark settings.
*
* @param topFilterSummary the top filter summary
*/
private void saveTemplate(String topFilterSummary) {
final FitEngineConfiguration config = new FitEngineConfiguration();
if (!updateAllConfiguration(config, true)) {
IJ.log("Unable to create the template configuration");
return;
}
// Remove the PSF width to make the template generic
config.getFitConfiguration().setInitialPeakStdDev(0);
// Only get this once when doing iterative analysis
String filename;
final boolean localSaveTemplateIsSet = saveTemplateIsSet;
if (localSaveTemplateIsSet) {
filename = settings.templateFilename;
} else {
filename = getFilename("Template_File", settings.templateFilename);
saveTemplateIsSet = true;
}
if (filename != null) {
settings.templateFilename = filename;
Prefs.set(Settings.KEY_TEMPLATE_FILENAME, filename);
final TemplateSettings.Builder templateSettings = TemplateSettings.newBuilder();
getNotes(templateSettings, topFilterSummary);
templateSettings.setFitEngineSettings(config.getFitEngineSettings());
if (!SettingsManager.toJson(templateSettings.build(), filename, SettingsManager.FLAG_SILENT | SettingsManager.FLAG_JSON_WHITESPACE)) {
IJ.log("Unable to save the template configuration");
return;
}
// This need only be performed once as the sample image is the same for all iterations.
if (localSaveTemplateIsSet) {
return;
}
// Save some random frames from the test image data
final ImagePlus imp = CreateData.getImage();
if (imp == null) {
return;
}
// Get the number of frames
final ResultsImageSampler sampler = getSampler(results, imp);
if (!sampler.isValid()) {
return;
}
// Iteratively show the example until the user is happy.
// Yes = OK, No = Repeat, Cancel = Do not save
final String keyNo = "nNo";
final String keyLow = "nLower";
final String keyHigh = "nHigher";
if (ImageJUtils.isMacro()) {
// Collect the options if running in a macro
final String options = Macro.getOptions();
settings.countNo = Integer.parseInt(Macro.getValue(options, keyNo, Integer.toString(settings.countNo)));
settings.countLow = Integer.parseInt(Macro.getValue(options, keyLow, Integer.toString(settings.countLow)));
settings.countHigh = Integer.parseInt(Macro.getValue(options, keyHigh, Integer.toString(settings.countHigh)));
} else if (settings.countLow + settings.countHigh == 0) {
settings.countLow = settings.countHigh = 1;
}
final ImagePlus[] out = new ImagePlus[1];
out[0] = sampler.getSample(settings.countNo, settings.countLow, settings.countHigh);
if (!ImageJUtils.isMacro()) {
// Show the template results
final ConfigurationTemplate configTemplate = new ConfigurationTemplate();
// Interactively show the sample image data
final boolean[] close = new boolean[1];
final ImagePlus[] outImp = new ImagePlus[1];
if (out[0] != null) {
final WindowOrganiser windowOrganiser = new WindowOrganiser();
outImp[0] = display(out[0], windowOrganiser);
if (windowOrganiser.isNotEmpty()) {
close[0] = true;
// Zoom a bit
final ImageWindow iw = outImp[0].getWindow();
for (int i = 7; i-- > 0 && Math.max(iw.getWidth(), iw.getHeight()) < 512; ) {
iw.getCanvas().zoomIn(0, 0);
}
}
configTemplate.createResults(outImp[0]);
}
// TODO - fix this when a second sample is made as the results are not updated.
final ImageListener listener = new ImageListener() {
@Override
public void imageOpened(ImagePlus imp) {
// Do nothing
}
@Override
public void imageClosed(ImagePlus imp) {
// Do nothing
}
@Override
public void imageUpdated(ImagePlus imp) {
if (imp != null && imp == outImp[0]) {
configTemplate.updateResults(imp.getCurrentSlice());
}
}
};
ImagePlus.addImageListener(listener);
// Turn off the recorder when the dialog is showing
final boolean record = Recorder.record;
Recorder.record = false;
final NonBlockingGenericDialog gd = new NonBlockingGenericDialog(TITLE);
ImageJUtils.addMessage(gd, "Showing image data for the template example.\n \nSample Frames:\nEmpty = %d\n" + "Lower density = %d\nHigher density = %d\n", sampler.getNumberOfEmptySamples(), sampler.getNumberOfLowDensitySamples(), sampler.getNumberOfHighDensitySamples());
gd.addSlider(keyNo, 0, 10, settings.countNo);
gd.addSlider(keyLow, 0, 10, settings.countLow);
gd.addSlider(keyHigh, 0, 10, settings.countHigh);
gd.addDialogListener((genDialog, event) -> {
// image the user has not seen.
if (event == null) {
return true;
}
settings.countNo = (int) genDialog.getNextNumber();
settings.countLow = (int) genDialog.getNextNumber();
settings.countHigh = (int) genDialog.getNextNumber();
out[0] = sampler.getSample(settings.countNo, settings.countLow, settings.countHigh);
if (out[0] != null) {
final WindowOrganiser windowOrganiser = new WindowOrganiser();
outImp[0] = display(out[0], windowOrganiser);
if (windowOrganiser.isNotEmpty()) {
close[0] = true;
// Zoom a bit
final ImageWindow iw = outImp[0].getWindow();
for (int i = 7; i-- > 0 && Math.max(iw.getWidth(), iw.getHeight()) < 512; ) {
iw.getCanvas().zoomIn(0, 0);
}
}
configTemplate.createResults(outImp[0]);
}
return true;
});
gd.showDialog();
if (gd.wasCanceled()) {
out[0] = null;
// For the recorder
settings.countNo = settings.countLow = settings.countHigh = 0;
}
if (close[0]) {
// Because closing the image sets the stack pixels array to null
if (out[0] != null) {
out[0] = out[0].duplicate();
}
outImp[0].close();
}
configTemplate.closeResults();
ImagePlus.removeImageListener(listener);
if (record) {
Recorder.record = true;
Recorder.recordOption(keyNo, Integer.toString(settings.countNo));
Recorder.recordOption(keyLow, Integer.toString(settings.countLow));
Recorder.recordOption(keyHigh, Integer.toString(settings.countHigh));
}
}
if (out[0] == null) {
return;
}
final ImagePlus example = out[0];
filename = FileUtils.replaceExtension(filename, ".tif");
IJ.save(example, filename);
}
}
Aggregations