use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings in project GDSC-SMLM by aherbert.
the class AstigmatismModelManager method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
String[] options = OPTIONS;
final AstigmatismModelSettings settings = AstigmatismModelSettingsHolder.getSettings();
if (settings.getAstigmatismModelResourcesCount() == 0) {
options = OPTIONS2;
}
pluginSettings = readAstigmatismModelManagerSettings();
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addChoice("Option", options, pluginSettings.getOption());
gd.addHelp(HelpUrls.getUrl("astigmatism-model-manager"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
pluginSettings.setOption(gd.getNextChoiceIndex());
switch(pluginSettings.getOption()) {
case 5:
exportModel();
break;
case 4:
invertModel();
break;
case 3:
deleteModel();
break;
case 2:
viewModel();
break;
case 1:
importModel();
break;
default:
createModel();
}
writeAstigmatismModelManagerSettings(pluginSettings);
}
use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings in project GDSC-SMLM by aherbert.
the class AstigmatismModelManager method listAstigmatismModels.
/**
* List the astigmatism models with the correct pixel scale within an error margin.
*
* @param includeNone Set to true to include an empty string
* @param nmPerPixel the nm per pixel
* @param error the error margin
* @return the list
*/
public static String[] listAstigmatismModels(boolean includeNone, double nmPerPixel, double error) {
final AstigmatismModelSettings settings = AstigmatismModelSettingsHolder.getSettings();
final List<String> list = createList(includeNone);
error = Math.abs(error);
final double low = nmPerPixel - error;
final double high = nmPerPixel + error;
for (final Map.Entry<String, AstigmatismModel> entry : settings.getAstigmatismModelResourcesMap().entrySet()) {
final AstigmatismModel resource = entry.getValue();
if (resource.getNmPerPixel() >= low && resource.getNmPerPixel() <= high) {
list.add(entry.getKey());
}
}
return list.toArray(new String[0]);
}
use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings in project GDSC-SMLM by aherbert.
the class AstigmatismModelManager method save.
private boolean save(String name, AstigmatismModel.Builder model) {
pluginSettings.setModelName(name);
// Check existing names
final AstigmatismModelSettings settings = AstigmatismModelSettingsHolder.getSettings();
final Map<String, AstigmatismModel> map = settings.getAstigmatismModelResourcesMap();
if (map.containsKey(name)) {
name = suggest(map, name);
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Model name " + pluginSettings.getModelName() + " already exists.\n \nSuggest renaming to:");
gd.addStringField("Model_name", name);
gd.enableYesNoCancel("Rename", "Overwrite");
gd.showDialog(true);
if (gd.wasCanceled()) {
return false;
}
if (gd.wasOKed()) {
// Rename
pluginSettings.setModelName(name);
}
}
// Save the model
if (!AstigmatismModelSettingsHolder.setSettings(settings.toBuilder().putAstigmatismModelResources(pluginSettings.getModelName(), model.build()).build())) {
IJ.error(TITLE, "Failed to save the model");
return false;
}
return true;
}
use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings in project GDSC-SMLM by aherbert.
the class AstigmatismModelManager method listAstigmatismModels.
/**
* List the astigmatism models with their pixel scale.
*
* @param includeNone Set to true to include an empty string
* @param withNmPerPixel Append the nm per pixel to the model names
* @return the list
*/
public static String[] listAstigmatismModels(boolean includeNone, boolean withNmPerPixel) {
final AstigmatismModelSettings settings = AstigmatismModelSettingsHolder.getSettings();
final List<String> list = createList(includeNone);
for (final Map.Entry<String, AstigmatismModel> entry : settings.getAstigmatismModelResourcesMap().entrySet()) {
final AstigmatismModel resource = entry.getValue();
if (withNmPerPixel) {
list.add(String.format("%s [%s nm]", entry.getKey(), MathUtils.rounded(resource.getNmPerPixel())));
} else {
list.add(entry.getKey());
}
}
return list.toArray(new String[0]);
}
use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings in project GDSC-SMLM by aherbert.
the class AstigmatismModelManager method deleteModel.
private void deleteModel() {
final GenericDialog gd = new GenericDialog(TITLE);
final String[] models = listAstigmatismModels(false);
gd.addChoice("Model", models, pluginSettings.getSelected());
gd.addHelp(HelpUrls.getUrl("astigmatism-model-manager-delete"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
final String name = gd.getNextChoice();
pluginSettings.setSelected(name);
final AstigmatismModelSettings settings = AstigmatismModelSettingsHolder.getSettings();
final AstigmatismModel model = settings.getAstigmatismModelResourcesMap().get(name);
if (model == null) {
IJ.error(TITLE, "Failed to find astigmatism model: " + name);
return;
}
AstigmatismModelSettingsHolder.setSettings(settings.toBuilder().removeAstigmatismModelResources(name).build());
ImageJUtils.log("Deleted astigmatism model: %s", name);
}
Aggregations