Search in sources :

Example 11 with AstigmatismModel

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

the class AstigmatismModelManager method invertModel.

private void invertModel() {
    final GenericDialog gd = new GenericDialog(TITLE);
    final String[] models = listAstigmatismModels(false);
    gd.addMessage("Invert the z-orientation of a model.\n \n" + TextUtils.wrap("Note that a positive gamma puts the focal plane for the X-dimension " + "above the z-centre (positive Z) and the focal " + "plane for the Y-dimension below the z-centre (negative Z). If gamma " + "is negative then the orientation of the focal planes of X and Y are reversed.", 80));
    gd.addChoice("Model", models, pluginSettings.getSelected());
    gd.addHelp(HelpUrls.getUrl("astigmatism-model-manager-invert"));
    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;
    }
    final AstigmatismModel.Builder builder = model.toBuilder();
    // Invert the gamma
    builder.setGamma(-model.getGamma());
    // Invert the constants of z^3 as these have an asymmetric effect on the curve
    builder.setAx(-model.getAx());
    builder.setAy(-model.getAy());
    // The constants of z^4 have a symmetric effect on the curve
    // builder.setBx(-model.getBx());
    // builder.setBy(-model.getBy());
    AstigmatismModelSettingsHolder.setSettings(settings.toBuilder().putAstigmatismModelResources(name, builder.build()).build());
    ImageJUtils.log("Inverted 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)

Example 12 with AstigmatismModel

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

the class CreateData method getAstigmatismHwhm.

private double getAstigmatismHwhm() {
    AstigmatismModel model = AstigmatismModelManager.getModel(settings.getAstigmatismModel());
    if (model == null) {
        IJ.error(TITLE, "Unknown PSF model: " + settings.getAstigmatismModel());
        return -1;
    }
    try {
        // Get the width at z=0 in pixels
        model = AstigmatismModelManager.convert(model, model.getZDistanceUnit(), DistanceUnit.PIXEL);
        final AstigmatismZModel zModel = AstigmatismModelManager.create(model);
        final double sx = zModel.getSx(0);
        final double sy = zModel.getSy(0);
        return Gaussian2DPeakResultHelper.getStandardDeviation(sx, sy) * Gaussian2DFunction.SD_TO_HWHM_FACTOR * // Scale appropriately
        model.getNmPerPixel() / settings.getPixelPitch();
    } catch (final ConversionException ex) {
        IJ.error(TITLE, "Unknown PSF FWHM setting for model: " + settings.getAstigmatismModel());
        return -1;
    }
}
Also used : ConversionException(uk.ac.sussex.gdsc.core.data.utils.ConversionException) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) AstigmatismZModel(uk.ac.sussex.gdsc.smlm.function.gaussian.AstigmatismZModel) HoltzerAstigmatismZModel(uk.ac.sussex.gdsc.smlm.function.gaussian.HoltzerAstigmatismZModel)

Example 13 with AstigmatismModel

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

the class CreateData method validatePsfOptions.

private void validatePsfOptions() {
    if (settings.getPsfModel().equals(PSF_MODELS[PSF_MODEL_ASTIGMATISM])) {
        psfModelType = PSF_MODEL_ASTIGMATISM;
        final AstigmatismModel model = AstigmatismModelManager.getModel(settings.getAstigmatismModel());
        if (model == null) {
            throw new IllegalArgumentException("Failed to load model: " + settings.getAstigmatismModel());
        }
    } else if (settings.getPsfModel().equals(PSF_MODELS[PSF_MODEL_IMAGE])) {
        psfModelType = PSF_MODEL_IMAGE;
    } else {
        psfModelType = (settings.getPsfModel().equals(PSF_MODELS[PSF_MODEL_GAUSSIAN])) ? PSF_MODEL_GAUSSIAN : PSF_MODEL_AIRY;
        ParameterUtils.isAboveZero("Depth-of-focus", settings.getDepthOfFocus());
        if (settings.getEnterWidth()) {
            ParameterUtils.isAboveZero("PSF SD", settings.getPsfSd());
        } else {
            ParameterUtils.isAboveZero("Wavelength", settings.getWavelength());
            ParameterUtils.isAboveZero("NA", settings.getNumericalAperture());
            ParameterUtils.isBelow("NA", settings.getNumericalAperture(), 2);
        }
    }
}
Also used : AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel)

Example 14 with AstigmatismModel

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

the class AstigmatismModelManagerTest method canConvertModel.

private static void canConvertModel(DistanceUnit zDistanceUnit, DistanceUnit sdDistanceUnit) {
    // 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 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(DistanceUnit.UM);
    builder.setSDistanceUnit(DistanceUnit.PIXEL);
    builder.setNmPerPixel(nmPerPixel);
    final AstigmatismModel model1 = builder.build();
    final AstigmatismModel model2 = AstigmatismModelManager.convert(model1, zDistanceUnit, sdDistanceUnit);
    final AstigmatismZModel m1 = AstigmatismModelManager.create(model1);
    final AstigmatismZModel m2 = AstigmatismModelManager.create(model2);
    final TypeConverter<DistanceUnit> zc = UnitConverterUtils.createConverter(DistanceUnit.UM, zDistanceUnit, nmPerPixel);
    final TypeConverter<DistanceUnit> sc = UnitConverterUtils.createConverter(DistanceUnit.PIXEL, sdDistanceUnit, nmPerPixel);
    final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-8, 0);
    for (double z = -0.5; z <= 0.5; z += 0.1) {
        final double e = sc.convert(m1.getSx(z));
        final double o = m2.getSx(zc.convert(z));
        // logger.fine(FunctionUtils.getSupplier("%f vs %f", e, o);
        TestAssertions.assertTest(e, o, predicate);
    }
}
Also used : DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) AstigmatismZModel(uk.ac.sussex.gdsc.smlm.function.gaussian.AstigmatismZModel) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

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