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]);
}
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;
}
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);
}
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]);
}
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);
}
Aggregations