Search in sources :

Example 6 with AstigmatismModel

use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel 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 7 with AstigmatismModel

use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel 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 8 with AstigmatismModel

use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel in project GDSC-SMLM by aherbert.

the class PsfProtosHelperTest method canConvertAstigmatismModel.

@Test
void canConvertAstigmatismModel() {
    // Use a reasonable z-depth function from the Smith, et al (2010) paper (page 377)
    final double sx = 1.08;
    final double sy = 1.01;
    final double gamma = 0.389;
    final double d = 0.531;
    final double Ax = -0.0708;
    final double Bx = -0.073;
    final double Ay = 0.164;
    final double By = 0.0417;
    final double nmPerPixel = 100;
    // Ax = Ay = 0;
    // Bx = By = 0;
    final DistanceUnit zDistanceUnit = DistanceUnit.UM;
    final DistanceUnit sDistanceUnit = DistanceUnit.PIXEL;
    final AstigmatismModel.Builder builder = AstigmatismModel.newBuilder();
    builder.setGamma(gamma);
    builder.setD(d);
    builder.setS0X(sx);
    builder.setAx(Ax);
    builder.setBx(Bx);
    builder.setS0Y(sy);
    builder.setAy(Ay);
    builder.setBy(By);
    builder.setZDistanceUnit(zDistanceUnit);
    builder.setSDistanceUnit(sDistanceUnit);
    builder.setNmPerPixel(nmPerPixel);
    final AstigmatismModel model1 = builder.build();
    final PSF psf = PsfProtosHelper.createPsf(model1, zDistanceUnit, sDistanceUnit);
    final AstigmatismModel model2 = PsfProtosHelper.createModel(psf, zDistanceUnit, sDistanceUnit, nmPerPixel);
    Assertions.assertEquals(model1, model2);
}
Also used : PSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Test(org.junit.jupiter.api.Test)

Example 9 with AstigmatismModel

use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel 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 10 with AstigmatismModel

use of uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel 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

AstigmatismModel (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel)14 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)5 NonBlockingExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)5 AstigmatismModelSettings (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModelSettings)5 ConversionException (uk.ac.sussex.gdsc.core.data.utils.ConversionException)3 GenericDialog (ij.gui.GenericDialog)2 Map (java.util.Map)2 PSF (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF)2 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)2 AstigmatismZModel (uk.ac.sussex.gdsc.smlm.function.gaussian.AstigmatismZModel)2 HoltzerAstigmatismZModel (uk.ac.sussex.gdsc.smlm.function.gaussian.HoltzerAstigmatismZModel)2 Plot (ij.gui.Plot)1 File (java.io.File)1 Test (org.junit.jupiter.api.Test)1 ImagePSF (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.ImagePSF)1 FitConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitConfiguration)1 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)1