Search in sources :

Example 1 with AstigmatismModelSettings

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);
}
Also used : AstigmatismModelSettings(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 2 with AstigmatismModelSettings

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]);
}
Also used : AstigmatismModelSettings(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) Map(java.util.Map)

Example 3 with AstigmatismModelSettings

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;
}
Also used : AstigmatismModelSettings(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 4 with AstigmatismModelSettings

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]);
}
Also used : AstigmatismModelSettings(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) Map(java.util.Map)

Example 5 with AstigmatismModelSettings

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);
}
Also used : AstigmatismModelSettings(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) GenericDialog(ij.gui.GenericDialog)

Aggregations

AstigmatismModelSettings (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings)6 AstigmatismModel (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel)5 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)4 NonBlockingExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)4 GenericDialog (ij.gui.GenericDialog)2 Map (java.util.Map)2