Search in sources :

Example 1 with PSFParameter

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

the class PsfCreator method fitPsf.

/**
 * Fit the new PSF image and show a graph of the amplitude/width.
 *
 * @param psfStack the psf stack
 * @param loess the loess
 * @param cz the cz
 * @param averageRange the average range
 * @param fitCom the fit com
 * @return The width of the PSF in the z-centre
 */
private double fitPsf(ImageStack psfStack, LoessInterpolator loess, int cz, double averageRange, final double[][] fitCom) {
    IJ.showStatus("Fitting final PSF");
    // is not appropriate for a normalised PSF.
    if (fitConfig.getFitSolver() != FitSolver.LVM_LSE) {
        ImageJUtils.log("  " + FitProtosHelper.getName(fitConfig.getFitSolver()) + " is not appropriate for final PSF fitting.");
        ImageJUtils.log("  Switching to Least Square Estimation");
        fitConfig.setFitSolver(FitSolver.LVM_LSE);
        if (settings.getInteractiveMode()) {
            // This assumes the LVM does not need the calibration
            PeakFit.configureFitSolver(config, null, null, 0);
        }
    }
    // Update the box radius since this is used in the fitSpot method.
    boxRadius = psfStack.getWidth() / 2;
    final int x = boxRadius;
    final int y = boxRadius;
    final double shift = fitConfig.getCoordinateShiftFactor();
    // Scale the PSF
    final PSF.Builder localPsf = fitConfig.getPsf().toBuilder();
    for (int i = 0; i < localPsf.getParametersCount(); i++) {
        final PSFParameter param = localPsf.getParameters(i);
        if (param.getUnit() == PSFParameterUnit.DISTANCE) {
            final PSFParameter.Builder b = param.toBuilder();
            b.setValue(b.getValue() * settings.getMagnification());
            localPsf.setParameters(i, b);
        }
    }
    fitConfig.setPsf(localPsf.build());
    // Need to be updated after the widths have been set
    fitConfig.setCoordinateShiftFactor(shift);
    fitConfig.setBackgroundFitting(false);
    // Since the PSF will be normalised remove the camera calibration
    fitConfig.setCameraType(CameraType.CAMERA_TYPE_NA);
    fitConfig.setMinPhotons(0);
    fitConfig.setBias(0);
    fitConfig.setGain(1);
    // No complex filtering so we get a fit. It should be easy to fit anyway.
    fitConfig.setPrecisionThreshold(0);
    fitConfig.setDirectFilter(null);
    // fitConfig.setDisableSimpleFilter(true);
    // Use this for debugging the fit
    // fitConfig.setLog(uk.ac.sussex.gdsc.core.ij.ImageJPluginLoggerHelper.getDefaultLogger());
    final MemoryPeakResults results = fitSpot(psfStack, psfStack.getWidth(), psfStack.getHeight(), x, y);
    if (results.size() < 5) {
        ImageJUtils.log("  Final PSF: Not enough fit results %d", results.size());
        return 0;
    }
    // Get the results for the spot centre and width
    final double[] z = new double[results.size()];
    final double[] xCoord = new double[z.length];
    final double[] yCoord = new double[z.length];
    final double[] sd = new double[z.length];
    final double[] a = new double[z.length];
    // Set limits for the fit
    final float maxWidth = (float) (Math.max(fitConfig.getInitialXSd(), fitConfig.getInitialYSd()) * settings.getMagnification() * 4);
    // PSF is normalised to 1
    final float maxSignal = 2;
    final WidthResultProcedure wp = new WidthResultProcedure(results, DistanceUnit.PIXEL);
    wp.getWxWy();
    final HeightResultProcedure hp = new HeightResultProcedure(results, IntensityUnit.COUNT);
    hp.getH();
    final Counter counter = new Counter();
    final Counter counterOk = new Counter();
    // We have fit the results so they will be in the preferred units
    results.forEach((PeakResultProcedure) peak -> {
        int index = counter.getAndIncrement();
        final float w = Math.max(wp.wx[index], wp.wy[index]);
        if (peak.getIntensity() > maxSignal || w > maxWidth) {
            return;
        }
        index = counterOk.getAndIncrement();
        z[index] = peak.getFrame();
        fitCom[0][peak.getFrame() - 1] = xCoord[index] = peak.getXPosition() - x;
        fitCom[1][peak.getFrame() - 1] = yCoord[index] = peak.getYPosition() - y;
        sd[index] = w;
        a[index] = hp.heights[index];
    });
    // Truncate
    final double[] z2 = Arrays.copyOf(z, counter.getCount());
    final double[] xCoord2 = Arrays.copyOf(xCoord, z2.length);
    final double[] yCoord2 = Arrays.copyOf(yCoord, z2.length);
    final double[] sd2 = Arrays.copyOf(sd, z2.length);
    final double[] a2 = Arrays.copyOf(a, z2.length);
    // Extract the average smoothed range from the individual fits
    final int r = (int) Math.ceil(averageRange / 2);
    int start = 0;
    int stop = z2.length - 1;
    for (int j = 0; j < z2.length; j++) {
        if (z2[j] > cz - r) {
            start = j;
            break;
        }
    }
    for (int j = z2.length; j-- > 0; ) {
        if (z2[j] < cz + r) {
            stop = j;
            break;
        }
    }
    // Extract xy centre coords and smooth
    double[] smoothX = new double[stop - start + 1];
    double[] smoothY = new double[smoothX.length];
    double[] smoothSd = new double[smoothX.length];
    double[] smoothA = new double[smoothX.length];
    final double[] newZ = new double[smoothX.length];
    int smoothCzIndex = 0;
    for (int j = start, k = 0; j <= stop; j++, k++) {
        smoothX[k] = xCoord2[j];
        smoothY[k] = yCoord2[j];
        smoothSd[k] = sd2[j];
        smoothA[k] = a2[j];
        newZ[k] = z2[j];
        if (newZ[k] == cz) {
            smoothCzIndex = k;
        }
    }
    smoothX = loess.smooth(newZ, smoothX);
    smoothY = loess.smooth(newZ, smoothY);
    smoothSd = loess.smooth(newZ, smoothSd);
    smoothA = loess.smooth(newZ, smoothA);
    // Update the widths and positions using the magnification
    final double scale = 1.0 / settings.getMagnification();
    for (int j = 0; j < xCoord2.length; j++) {
        xCoord2[j] *= scale;
        yCoord2[j] *= scale;
        sd2[j] *= scale;
    }
    for (int j = 0; j < smoothX.length; j++) {
        smoothX[j] *= scale;
        smoothY[j] *= scale;
        smoothSd[j] *= scale;
    }
    showPlots(z2, a2, newZ, smoothA, xCoord2, yCoord2, sd2, newZ, smoothX, smoothY, smoothSd, cz);
    // Store the data for replotting
    this.z = z2;
    this.amplitude = a2;
    this.smoothAz = newZ;
    this.smoothA = smoothA;
    this.xCoord = xCoord2;
    this.yCoord = yCoord2;
    this.sd = sd2;
    this.newZ = newZ;
    this.smoothX = smoothX;
    this.smoothY = smoothY;
    this.smoothSd = smoothSd;
    // maximumIndex = findMinimumIndex(smoothSd, maximumIndex - start);
    return smoothSd[smoothCzIndex];
}
Also used : HeightResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.HeightResultProcedure) Color(java.awt.Color) Tensor2D(uk.ac.sussex.gdsc.smlm.utils.Tensor2D) Arrays(java.util.Arrays) ByteProcessor(ij.process.ByteProcessor) UnitConverterUtils(uk.ac.sussex.gdsc.smlm.data.config.UnitConverterUtils) ImageProcessor(ij.process.ImageProcessor) WindowMethod(uk.ac.sussex.gdsc.core.utils.ImageWindow.WindowMethod) MemoryUtils(uk.ac.sussex.gdsc.core.utils.MemoryUtils) PSFType(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFType) CustomTricubicFunction(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicFunction) Future(java.util.concurrent.Future) PSFCreatorSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.PSFCreatorSettings) ImageWindow(uk.ac.sussex.gdsc.core.utils.ImageWindow) ImageCanvas(ij.gui.ImageCanvas) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Blitter(ij.process.Blitter) FitProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.FitProtosHelper) ImageJImageConverter(uk.ac.sussex.gdsc.smlm.ij.utils.ImageJImageConverter) SoftLock(uk.ac.sussex.gdsc.core.utils.SoftLock) Frame(java.awt.Frame) LoessInterpolator(org.apache.commons.math3.analysis.interpolation.LoessInterpolator) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) GuiProtosHelper(uk.ac.sussex.gdsc.smlm.ij.settings.GuiProtosHelper) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) Plot(ij.gui.Plot) Executors(java.util.concurrent.Executors) ImagePlus(ij.ImagePlus) Line(ij.gui.Line) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Prefs(ij.Prefs) StoredData(uk.ac.sussex.gdsc.core.utils.StoredData) SimpleDateFormat(java.text.SimpleDateFormat) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) ArrayList(java.util.ArrayList) GenericDialog(ij.gui.GenericDialog) SortUtils(uk.ac.sussex.gdsc.core.utils.SortUtils) RounderUtils(uk.ac.sussex.gdsc.core.data.utils.RounderUtils) SubPixelMethod(uk.ac.sussex.gdsc.core.ij.AlignImagesFft.SubPixelMethod) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) ImagePsfHelper(uk.ac.sussex.gdsc.smlm.ij.settings.ImagePsfHelper) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) Overlay(ij.gui.Overlay) ImageExtractor(uk.ac.sussex.gdsc.core.utils.ImageExtractor) SimpleImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.SimpleImageJTrackProgress) Size(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicInterpolatingFunction.Size) FitEngine(uk.ac.sussex.gdsc.smlm.engine.FitEngine) FloatProcessor(ij.process.FloatProcessor) FloatStackTrivalueProvider(uk.ac.sussex.gdsc.core.data.FloatStackTrivalueProvider) CubicSplinePsf(uk.ac.sussex.gdsc.smlm.ij.plugins.CubicSplineManager.CubicSplinePsf) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) ImageStack(ij.ImageStack) CameraModel(uk.ac.sussex.gdsc.smlm.model.camera.CameraModel) PsfHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfHelper) Erf(uk.ac.sussex.gdsc.smlm.function.Erf) FloatStackTrivalueProcedure(uk.ac.sussex.gdsc.core.data.procedures.FloatStackTrivalueProcedure) AngleUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit) Date(java.util.Date) Point(java.awt.Point) ImagePSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.ImagePSF) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter) FitSolver(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.FitSolver) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) OptionCollectedListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionCollectedListener) Locale(java.util.Locale) DataException(uk.ac.sussex.gdsc.core.data.DataException) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) PlotWindow(ij.gui.PlotWindow) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) CustomTricubicInterpolatingFunction(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicInterpolatingFunction) PlugInFilter(ij.plugin.filter.PlugInFilter) PsfProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfProtosHelper) FitParameters(uk.ac.sussex.gdsc.smlm.engine.FitParameters) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint) CameraType(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType) BlockMeanFilter(uk.ac.sussex.gdsc.smlm.filters.BlockMeanFilter) CustomTricubicInterpolator(uk.ac.sussex.gdsc.core.math.interpolation.CustomTricubicInterpolator) HeightResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.HeightResultProcedure) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) AlignImagesFft(uk.ac.sussex.gdsc.core.ij.AlignImagesFft) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) FloatPolygon(ij.process.FloatPolygon) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) WidthResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.WidthResultProcedure) PSFParameterUnit(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameterUnit) List(java.util.List) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) OptionCollectedEvent(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionCollectedEvent) FitQueue(uk.ac.sussex.gdsc.smlm.engine.FitQueue) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) ParameterisedFitJob(uk.ac.sussex.gdsc.smlm.engine.ParameterisedFitJob) Image3DAligner(uk.ac.sussex.gdsc.smlm.ij.utils.Image3DAligner) Rectangle(java.awt.Rectangle) PSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF) HashMap(java.util.HashMap) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) OptionListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener) AWTEvent(java.awt.AWTEvent) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) LinkedList(java.util.LinkedList) CcdCameraModel(uk.ac.sussex.gdsc.smlm.model.camera.CcdCameraModel) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) ExecutorService(java.util.concurrent.ExecutorService) DialogListener(ij.gui.DialogListener) Calibration(ij.measure.Calibration) Checkbox(java.awt.Checkbox) CubicSplinePosition(uk.ac.sussex.gdsc.core.math.interpolation.CubicSplinePosition) Label(java.awt.Label) CreateData(uk.ac.sussex.gdsc.smlm.ij.plugins.benchmark.CreateData) Rounder(uk.ac.sussex.gdsc.core.data.utils.Rounder) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) SynchronizedPeakResults(uk.ac.sussex.gdsc.smlm.results.SynchronizedPeakResults) IJ(ij.IJ) FileInfo(ij.io.FileInfo) Image2DAligner(uk.ac.sussex.gdsc.smlm.ij.utils.Image2DAligner) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ImagePSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.ImagePSF) PSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter) WidthResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.WidthResultProcedure) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 2 with PSFParameter

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

the class PeakResultConversionHelper method getNames.

/**
 * Gets the names for the peak results parameters. This includes the standard parameters and any
 * additional parameters defined in the PSF. If a parameter name is undefined then unknown is
 * returned.
 *
 * @return the converters
 */
public String[] getNames() {
    final LocalList<String> list = new LocalList<>(5);
    list.add("Background");
    list.add("Intensity");
    list.add("X");
    list.add("Y");
    list.add("Z");
    if (psf != null) {
        try {
            for (final PSFParameter p : PsfHelper.getParameters(psf)) {
                final String name = p.getName();
                list.add(TextUtils.isNullOrEmpty(name) ? "unknown" : name);
            }
        } catch (final ConfigurationException ex) {
        // Ignore
        }
    }
    return list.toArray(new String[0]);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter)

Example 3 with PSFParameter

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

the class PeakResultConversionHelper method getConverters.

/**
 * Gets the converters for the peak results parameters. This includes the standard parameters and
 * any additional parameters defined in the PSF. If a parameter unit type is undefined then an
 * identity converter is created.
 *
 * @return the converters
 */
public Converter[] getConverters() {
    final LocalList<Converter> list = new LocalList<>(5);
    getIntensityConverter();
    getDistanceConverter();
    list.add(intensityConverter);
    list.add(intensityConverter);
    list.add(distanceConverter);
    list.add(distanceConverter);
    list.add(distanceConverter);
    if (psf != null) {
        try {
            for (final PSFParameter p : PsfHelper.getParameters(psf)) {
                switch(p.getUnit()) {
                    case DISTANCE:
                        list.add(distanceConverter);
                        break;
                    case INTENSITY:
                        list.add(intensityConverter);
                        break;
                    case ANGLE:
                        list.add(getAngleConverter());
                        break;
                    default:
                        list.add(new IdentityTypeConverter<>(p.getUnit()));
                }
            }
        } catch (final ConfigurationException ex) {
        // Ignore
        }
    }
    return list.toArray(new Converter[0]);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) IdentityTypeConverter(uk.ac.sussex.gdsc.core.data.utils.IdentityTypeConverter) Converter(uk.ac.sussex.gdsc.core.data.utils.Converter) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter)

Example 4 with PSFParameter

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

the class PeakResultConversionHelper method getUnitNames.

/**
 * Gets the unit names for the peak results parameters. This includes the standard parameters and
 * any additional parameters defined in the PSF. If a parameter unit is undefined then an empty
 * string is returned.
 *
 * @return the converters
 */
public String[] getUnitNames() {
    final LocalList<String> list = new LocalList<>(5);
    getIntensityConverter();
    getDistanceConverter();
    final String safeIntensityUnit = (intensityConverter.to() != null) ? UnitHelper.getShortName(intensityConverter.to()) : "";
    final String safeDistanceUnit = (distanceConverter.to() != null) ? UnitHelper.getShortName(distanceConverter.to()) : "";
    String safeAngleUnit = null;
    list.add(safeIntensityUnit);
    list.add(safeIntensityUnit);
    list.add(safeDistanceUnit);
    list.add(safeDistanceUnit);
    list.add(safeDistanceUnit);
    if (psf != null) {
        try {
            for (final PSFParameter p : PsfHelper.getParameters(psf)) {
                switch(p.getUnit()) {
                    case DISTANCE:
                        list.add(safeDistanceUnit);
                        break;
                    case INTENSITY:
                        list.add(safeIntensityUnit);
                        break;
                    case ANGLE:
                        safeAngleUnit = getOrCreateAngleUnit(safeAngleUnit);
                        list.add(safeAngleUnit);
                        break;
                    default:
                        list.add("");
                }
            }
        } catch (final ConfigurationException ex) {
        // Ignore
        }
    }
    return list.toArray(new String[0]);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter)

Example 5 with PSFParameter

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

the class PeakFit method addPsfOptions.

/**
 * Adds the PSF options.
 *
 * <p>Note that if an astigmatic PSF is selected then the model must be created with
 * {@link #configurePsfModel(FitEngineConfiguration, int)}.
 *
 * @param gd the dialog
 * @param fitConfigurationProvider the fit configuration provider
 */
public static void addPsfOptions(final ExtendedGenericDialog gd, final FitConfigurationProvider fitConfigurationProvider) {
    final FitConfiguration fitConfig = fitConfigurationProvider.getFitConfiguration();
    gd.addChoice("PSF", getPsfTypeNames(), PsfProtosHelper.getName(fitConfig.getPsfType()), new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer field) {
            final FitConfiguration fitConfig = fitConfigurationProvider.getFitConfiguration();
            fitConfig.setPsfType(PeakFit.getPsfTypeValues()[field]);
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            final FitConfiguration localFitConfig = fitConfigurationProvider.getFitConfiguration();
            final PSFType psfType = localFitConfig.getPsfType();
            final ExtendedGenericDialog egd = new ExtendedGenericDialog("PSF Options", null);
            PSF oldPsf = null;
            if (psfType == PSFType.ASTIGMATIC_GAUSSIAN_2D) {
                // The PSF is entirely defined in the model
                String[] list = AstigmatismModelManager.listAstigmatismModels(false, localFitConfig.getCalibrationReader().getNmPerPixel(), 0.1);
                // In case the calibration has not been updated
                if (list.length == 0) {
                    list = AstigmatismModelManager.listAstigmatismModels(false, true);
                }
                egd.addChoice("Z-model", list, localFitConfig.getPsfModelName());
            } else {
                // Collect the PSF parameters
                oldPsf = localFitConfig.getPsf();
                for (int i = 0; i < oldPsf.getParametersCount(); i++) {
                    final PSFParameter p = oldPsf.getParameters(i);
                    egd.addNumericField(String.format("PSF_parameter_%d (%s)", i + 1, p.getName()), p.getValue(), 3);
                }
                if (psfType == PSFType.ONE_AXIS_GAUSSIAN_2D) {
                    egd.addCheckbox("Fixed", localFitConfig.isFixedPsf());
                }
            }
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            if (psfType == PSFType.ASTIGMATIC_GAUSSIAN_2D) {
                // The PSF is entirely defined in the model
                localFitConfig.setPsfModelName(egd.getNextChoice());
                return true;
            }
            @SuppressWarnings("null") final PSF.Builder b = oldPsf.toBuilder();
            final int n = b.getParametersCount();
            for (int i = 0; i < n; i++) {
                b.getParametersBuilder(i).setValue(egd.getNextNumber());
            }
            final PSF newPsf = b.build();
            localFitConfig.setPsf(newPsf);
            boolean changed = !oldPsf.equals(newPsf);
            if (psfType == PSFType.ONE_AXIS_GAUSSIAN_2D) {
                final boolean newFixed = egd.getNextBoolean();
                changed = changed || (newFixed != localFitConfig.isFixedPsf());
                localFitConfig.setFixedPsf(newFixed);
            }
            return changed;
        }
    });
}
Also used : PSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter) PSFType(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFType) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Aggregations

PSFParameter (uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter)4 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)3 ConfigurationException (uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException)3 IJ (ij.IJ)1 ImagePlus (ij.ImagePlus)1 ImageStack (ij.ImageStack)1 Prefs (ij.Prefs)1 WindowManager (ij.WindowManager)1 DialogListener (ij.gui.DialogListener)1 GenericDialog (ij.gui.GenericDialog)1 ImageCanvas (ij.gui.ImageCanvas)1 Line (ij.gui.Line)1 Overlay (ij.gui.Overlay)1 Plot (ij.gui.Plot)1 PlotWindow (ij.gui.PlotWindow)1 Roi (ij.gui.Roi)1 FileInfo (ij.io.FileInfo)1 Calibration (ij.measure.Calibration)1 PlugInFilter (ij.plugin.filter.PlugInFilter)1 Blitter (ij.process.Blitter)1