Search in sources :

Example 1 with PlotWindow

use of ij.gui.PlotWindow in project GDSC-SMLM by aherbert.

the class PSFDrift method displayPlot.

private double[][] displayPlot(String title, String yLabel, double[] x, double[] y, double[] se, LoessInterpolator loess, int start, int end) {
    // Extract non NaN numbers
    double[] newX = new double[x.length];
    double[] newY = new double[x.length];
    int c = 0;
    for (int i = 0; i < x.length; i++) if (!Double.isNaN(y[i])) {
        newX[c] = x[i];
        newY[c] = y[i];
        c++;
    }
    newX = Arrays.copyOf(newX, c);
    newY = Arrays.copyOf(newY, c);
    title = TITLE + " " + title;
    Plot2 plot = new Plot2(title, "z (nm)", yLabel);
    double[] limitsx = Maths.limits(x);
    double[] limitsy = new double[2];
    if (se != null) {
        if (c > 0) {
            limitsy = new double[] { newY[0] - se[0], newY[0] + se[0] };
            for (int i = 1; i < newY.length; i++) {
                limitsy[0] = Maths.min(limitsy[0], newY[i] - se[i]);
                limitsy[1] = Maths.max(limitsy[1], newY[i] + se[i]);
            }
        }
    } else {
        if (c > 0)
            limitsy = Maths.limits(newY);
    }
    double rangex = Math.max(0.05 * (limitsx[1] - limitsx[0]), 0.1);
    double rangey = Math.max(0.05 * (limitsy[1] - limitsy[0]), 0.1);
    plot.setLimits(limitsx[0] - rangex, limitsx[1] + rangex, limitsy[0] - rangey, limitsy[1] + rangey);
    if (loess == null) {
        addPoints(plot, Plot.LINE, newX, newY, x[start], x[end]);
    } else {
        addPoints(plot, Plot.DOT, newX, newY, x[start], x[end]);
        newY = loess.smooth(newX, newY);
        addPoints(plot, Plot.LINE, newX, newY, x[start], x[end]);
    }
    if (se != null) {
        plot.setColor(Color.magenta);
        for (int i = 0; i < x.length; i++) {
            if (!Double.isNaN(y[i]))
                plot.drawLine(x[i], y[i] - se[i], x[i], y[i] + se[i]);
        }
        // Draw the start and end lines for the valid range
        plot.setColor(Color.green);
        plot.drawLine(x[start], limitsy[0], x[start], limitsy[1]);
        plot.drawLine(x[end], limitsy[0], x[end], limitsy[1]);
    } else {
        // draw a line for the recall limit
        plot.setColor(Color.magenta);
        plot.drawLine(limitsx[0] - rangex, recallLimit, limitsx[1] + rangex, recallLimit);
    }
    PlotWindow pw = Utils.display(title, plot);
    if (Utils.isNewWindow())
        idList[idCount++] = pw.getImagePlus().getID();
    return new double[][] { newX, newY };
}
Also used : PlotWindow(ij.gui.PlotWindow) Plot2(ij.gui.Plot2)

Example 2 with PlotWindow

use of ij.gui.PlotWindow in project GDSC-SMLM by aherbert.

the class PSFCreator method showPlots.

private void showPlots(final double[] z, final double[] a, final double[] smoothAz, final double[] smoothA, final double[] xCoord, final double[] yCoord, final double[] sd, final double[] newZ, final double[] smoothX, final double[] smoothY, double[] smoothSd, final int cz) {
    PlotWindow amplitudeWindow = null;
    // Draw a plot of the amplitude
    if (a != null) {
        Plot2 plot = new Plot2(TITLE_AMPLITUDE, "z", "Amplitude", smoothAz, smoothA);
        double[] limits2 = Maths.limits(Maths.limits(a), smoothA);
        plot.setLimits(z[0], z[z.length - 1], limits2[0], limits2[1]);
        plot.addPoints(z, a, Plot2.CIRCLE);
        // Add a line for the z-centre
        plot.setColor(Color.GREEN);
        plot.addPoints(new double[] { cz, cz }, limits2, Plot2.LINE);
        plot.setColor(Color.BLACK);
        double amplitude = Double.NaN;
        for (int i = 0; i < smoothAz.length; i++) {
            if (smoothAz[i] == cz) {
                amplitude = smoothA[i];
                break;
            }
        }
        double maxAmplitude = Double.NaN;
        for (int i = 0; i < smoothAz.length; i++) {
            if (smoothAz[i] == zCentre) {
                maxAmplitude = smoothA[i];
                break;
            }
        }
        plot.addLabel(0, 0, String.format("Amplitude = %s (%sx). z = %s nm", Utils.rounded(amplitude), Utils.rounded(amplitude / maxAmplitude), Utils.rounded((slice - zCentre) * nmPerSlice)));
        amplitudeWindow = Utils.display(TITLE_AMPLITUDE, plot);
    }
    // Show plot of width, X centre, Y centre
    if (xCoord != null) {
        Plot2 plot = new Plot2(TITLE_PSF_PARAMETERS, "z", "px", newZ, smoothSd);
        // Get the limits
        double[] sd2 = invert(sd);
        double[] limits = Maths.limits(Maths.limits(Maths.limits(Maths.limits(xCoord), yCoord), sd), sd2);
        plot.setLimits(z[0], z[z.length - 1], limits[0], limits[1]);
        plot.addPoints(newZ, invert(smoothSd), Plot2.LINE);
        plot.addPoints(z, sd, Plot2.DOT);
        plot.addPoints(z, sd2, Plot2.DOT);
        plot.setColor(Color.BLUE);
        plot.addPoints(z, xCoord, Plot2.DOT);
        plot.addPoints(newZ, smoothX, Plot2.LINE);
        plot.setColor(Color.RED);
        plot.addPoints(z, yCoord, Plot2.DOT);
        plot.addPoints(newZ, smoothY, Plot2.LINE);
        // Add a line for the z-centre
        plot.setColor(Color.GREEN);
        plot.addPoints(new double[] { cz, cz }, limits, Plot2.LINE);
        plot.setColor(Color.BLACK);
        double width = Double.NaN;
        for (int i = 0; i < smoothSd.length; i++) {
            if (newZ[i] == cz) {
                width = smoothSd[i];
                break;
            }
        }
        plot.addLabel(0, 0, String.format("Width = %s nm (%sx). z = %s nm", Utils.rounded(width * nmPerPixel), Utils.rounded(width * nmPerPixel / psfWidth), Utils.rounded((slice - zCentre) * nmPerSlice)));
        // Check if the window will need to be aligned
        boolean alignWindows = (WindowManager.getFrame(TITLE_PSF_PARAMETERS) == null);
        PlotWindow psfWindow = Utils.display(TITLE_PSF_PARAMETERS, plot);
        if (alignWindows && psfWindow != null && amplitudeWindow != null) {
            // Put the two plots tiled together so both are visible
            Point l = psfWindow.getLocation();
            l.x = amplitudeWindow.getLocation().x;
            l.y = amplitudeWindow.getLocation().y + amplitudeWindow.getHeight();
            psfWindow.setLocation(l);
        }
    }
}
Also used : PlotWindow(ij.gui.PlotWindow) Plot2(ij.gui.Plot2) Point(java.awt.Point) BasePoint(gdsc.core.match.BasePoint) Point(java.awt.Point) BasePoint(gdsc.core.match.BasePoint)

Example 3 with PlotWindow

use of ij.gui.PlotWindow in project GDSC-SMLM by aherbert.

the class FilterAnalysis method showPlots.

private void showPlots() {
    if (plots.isEmpty())
        return;
    // Display the top N plots
    int[] list = new int[plots.size()];
    int i = 0;
    for (NamedPlot p : plots) {
        Plot2 plot = new Plot2(p.name, p.xAxisName, "Jaccard", p.xValues, p.yValues);
        plot.setLimits(p.xValues[0], p.xValues[p.xValues.length - 1], 0, 1);
        plot.setColor(Color.RED);
        plot.draw();
        plot.setColor(Color.BLUE);
        plot.addPoints(p.xValues, p.yValues, Plot2.CROSS);
        PlotWindow plotWindow = Utils.display(p.name, plot);
        list[i++] = plotWindow.getImagePlus().getID();
    }
    new WindowOrganiser().tileWindows(list);
}
Also used : PlotWindow(ij.gui.PlotWindow) Plot2(ij.gui.Plot2) WindowOrganiser(ij.plugin.WindowOrganiser)

Example 4 with PlotWindow

use of ij.gui.PlotWindow in project GDSC-SMLM by aherbert.

the class DiffusionRateTest method plotMSD.

/**
	 * Plot the MSD.
	 *
	 * @param totalSteps
	 *            the total steps
	 * @param xValues
	 *            the x values (the time)
	 * @param yValues
	 *            the y values (MSD)
	 * @param lower
	 *            the lower bounds (mean-SD)
	 * @param upper
	 *            the upper bounds (mean+SD)
	 * @param fitted
	 *            the fitted line
	 * @param dimensions
	 *            the number of dimensions for the jumps
	 */
private void plotMSD(int totalSteps, double[] xValues, double[] yValues, double[] lower, double[] upper, PolynomialFunction fitted, int dimensions) {
    // TODO Auto-generated method stub
    String title = TITLE + " " + dimensions + "D";
    Plot2 plot = new Plot2(title, "Time (seconds)", "Mean-squared Distance (um^2)", xValues, yValues);
    double[] limits = Maths.limits(upper);
    limits = Maths.limits(limits, lower);
    plot.setLimits(0, totalSteps / settings.stepsPerSecond, limits[0], limits[1]);
    plot.setColor(Color.blue);
    plot.addPoints(xValues, lower, Plot2.LINE);
    plot.addPoints(xValues, upper, Plot2.LINE);
    if (fitted != null) {
        plot.setColor(Color.red);
        plot.addPoints(new double[] { xValues[0], xValues[xValues.length - 1] }, new double[] { fitted.value(xValues[0]), fitted.value(xValues[xValues.length - 1]) }, Plot2.LINE);
    }
    plot.setColor(Color.black);
    PlotWindow pw1 = Utils.display(title, plot);
    if (Utils.isNewWindow())
        idList[idCount++] = pw1.getImagePlus().getID();
}
Also used : PlotWindow(ij.gui.PlotWindow) Plot2(ij.gui.Plot2)

Example 5 with PlotWindow

use of ij.gui.PlotWindow in project GDSC-SMLM by aherbert.

the class DoubletAnalysis method showHistogram.

/**
	 * Show histogram.
	 *
	 * @param i
	 *            the i
	 * @param histogram
	 *            the spot histogram
	 */
private void showHistogram(int i, double[] histogram) {
    if (!displayHistograms[i])
        return;
    // Truncate to correct size
    for (int j = histogram.length; j-- > 0; ) if (histogram[j] != 0) {
        histogram = Arrays.copyOf(histogram, j + 1);
        break;
    }
    String[] labels = NAMES[i].split(":");
    Plot2 plot = new Plot2(labels[0], labels[1], "Count");
    double max = Maths.max(histogram);
    plot.setLimits(0, histogram.length, 0, max * 1.05);
    plot.addPoints(Utils.newArray(histogram.length, 0, 1.0), histogram, Plot2.BAR);
    PlotWindow pw = Utils.display(labels[0], plot);
    if (Utils.isNewWindow())
        windowOrganiser.add(pw.getImagePlus().getID());
}
Also used : PlotWindow(ij.gui.PlotWindow) Plot2(ij.gui.Plot2) PeakResultPoint(gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint) BasePoint(gdsc.core.match.BasePoint)

Aggregations

PlotWindow (ij.gui.PlotWindow)31 Plot2 (ij.gui.Plot2)17 Plot (ij.gui.Plot)14 Point (java.awt.Point)13 BasePoint (gdsc.core.match.BasePoint)9 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)6 WindowOrganiser (uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser)4 FractionalAssignment (gdsc.core.match.FractionalAssignment)3 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)3 PeakFractionalAssignment (gdsc.smlm.results.filter.PeakFractionalAssignment)3 GenericDialog (ij.gui.GenericDialog)3 WindowOrganiser (ij.plugin.WindowOrganiser)3 LinearInterpolator (org.apache.commons.math3.analysis.interpolation.LinearInterpolator)3 PolynomialSplineFunction (org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction)3 BasePoint (uk.ac.sussex.gdsc.core.match.BasePoint)3 Statistics (gdsc.core.utils.Statistics)2 StoredData (gdsc.core.utils.StoredData)2 ImagePlus (ij.ImagePlus)2 ByteProcessor (ij.process.ByteProcessor)2 TextWindow (ij.text.TextWindow)2