Search in sources :

Example 31 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class TraceMatchCalculator method extractPulses.

private Pulse[] extractPulses(MemoryPeakResults results) {
    if (results == null)
        return null;
    Pulse[] pulses = new Pulse[results.size()];
    int i = 0;
    for (PeakResult p : results.getResults()) {
        pulses[i++] = new Pulse(p.getXPosition(), p.getYPosition(), p.getFrame(), p.getEndFrame());
    }
    return pulses;
}
Also used : Pulse(gdsc.core.match.Pulse) Point(java.awt.Point) PeakResult(gdsc.smlm.results.PeakResult)

Example 32 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class CreateData method getSignal.

private static double[] getSignal(MemoryPeakResults results) {
    double[] data = new double[results.size()];
    int i = 0;
    for (PeakResult p : results.getResults()) data[i++] = p.getSignal();
    return data;
}
Also used : PeakResult(gdsc.smlm.results.PeakResult) IdPeakResult(gdsc.smlm.results.IdPeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult)

Example 33 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class CreateData method getDepth.

private static double[] getDepth(MemoryPeakResults results) {
    double[] data = new double[results.size()];
    int i = 0;
    for (PeakResult p : results.getResults()) // Results store the z-depth in the error field
    data[i++] = p.error;
    return data;
}
Also used : PeakResult(gdsc.smlm.results.PeakResult) IdPeakResult(gdsc.smlm.results.IdPeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult)

Example 34 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class ResequenceResults method resequenceResults.

/**
	 * Resequence the results for the original imaging sequence provided. Results are assumed to be continuous from 1.
	 * 
	 * @param results
	 * @param start
	 *            The first frame that contained the data
	 * @param block
	 *            The number of continuous frames containing data
	 * @param skip
	 *            The number of continuous frames to ignore before the next data
	 * @param tracker
	 *            Used to report the mapping
	 * @return
	 */
private static boolean resequenceResults(MemoryPeakResults results, int start, int block, int skip, TrackProgress tracker) {
    if (results == null || results.size() == 0)
        return false;
    results.sort();
    // Assume the results start from frame 1 (or above)
    if (results.getHead().getFrame() < 1) {
        return false;
    }
    // The current frame in the results
    int t = 1;
    // The mapped frame in the results
    int mapped = start;
    // The current block size
    int b = 1;
    boolean print = true;
    for (PeakResult r : results.getResults()) {
        if (t != r.getFrame()) {
            // Update the mapped position
            while (t < r.getFrame()) {
                // Move to the next position
                mapped++;
                // Check if this move will make the current block too large 
                if (++b > block) {
                    // Skip 
                    mapped += skip;
                    b = 1;
                }
                t++;
            }
            t = r.getFrame();
            print = true;
        }
        r.setFrame(mapped);
        if (print) {
            print = false;
            if (tracker != null)
                tracker.log("Map %d -> %d", t, mapped);
        }
    }
    return true;
}
Also used : PeakResult(gdsc.smlm.results.PeakResult)

Example 35 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class ResultsManager method checkCalibration.

/**
	 * Check the calibration of the results exists, if not then prompt for it with a dialog
	 * 
	 * @param results
	 *            The results
	 * @param reader
	 *            Used to determine the file type
	 * @return True if OK; false if calibration dialog cancelled
	 */
private static boolean checkCalibration(MemoryPeakResults results, PeakResultsReader reader) {
    // Check for Calibration
    Calibration calibration = results.getCalibration();
    String msg = "partially calibrated";
    if (calibration == null) {
        // Make sure the user knows all the values have not been set
        calibration = new Calibration();
        msg = "uncalibrated";
    } else {
        // Validate to set the valid flags
        calibration.validate();
    }
    final float noise = getNoise(results);
    // Only check for essential calibration settings (i.e. not readNoise, bias, emCCD, amplification)
    if (!calibration.hasNmPerPixel() || !calibration.hasGain() || !calibration.hasExposureTime() || noise <= 0) {
        boolean convert = false;
        // We may have results that are within configured bounds. If so we do not need the conversion
        boolean showConvert = true;
        if (results.getBounds(false) != null) {
            final Rectangle bounds = results.getBounds(false);
            showConvert = false;
            for (PeakResult r : results.getResults()) {
                if (!bounds.contains(r.getXPosition(), r.getYPosition())) {
                    showConvert = true;
                    break;
                }
            }
        }
        if (!calibration.hasNmPerPixel())
            calibration.setNmPerPixel(input_nmPerPixel);
        if (!calibration.hasGain())
            calibration.setGain(input_gain);
        if (!calibration.hasExposureTime())
            calibration.setExposureTime(input_exposureTime);
        Rectangle2D.Float dataBounds = results.getDataBounds();
        GenericDialog gd = new GenericDialog(TITLE);
        gd.addMessage(String.format("Results are %s.\nData bounds = (%s,%s) to (%s,%s)", msg, Utils.rounded(dataBounds.x), Utils.rounded(dataBounds.y), Utils.rounded(dataBounds.y + dataBounds.getWidth()), Utils.rounded(dataBounds.x + dataBounds.getHeight())));
        gd.addNumericField("Calibration (nm/px)", calibration.getNmPerPixel(), 2);
        gd.addNumericField("Gain (ADU/photon)", calibration.getGain(), 2);
        gd.addNumericField("Exposure_time (ms)", calibration.getExposureTime(), 2);
        if (noise <= 0)
            gd.addNumericField("Noise (ADU)", input_noise, 2);
        if (showConvert)
            gd.addCheckbox("Convert_nm_to_pixels", convert);
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        input_nmPerPixel = Math.abs(gd.getNextNumber());
        input_gain = Math.abs(gd.getNextNumber());
        input_exposureTime = Math.abs(gd.getNextNumber());
        if (noise == 0)
            input_noise = Math.abs((float) gd.getNextNumber());
        if (showConvert)
            convert = gd.getNextBoolean();
        Prefs.set(Constants.inputNmPerPixel, input_nmPerPixel);
        Prefs.set(Constants.inputGain, input_gain);
        Prefs.set(Constants.inputExposureTime, input_exposureTime);
        Prefs.set(Constants.inputNoise, input_noise);
        results.setCalibration(new Calibration(input_nmPerPixel, input_gain, input_exposureTime));
        if (convert && input_nmPerPixel > 0) {
            // Note: NSTORM stores 2xSD
            final double widthConversion = (reader != null && reader.getFormat() == FileFormat.NSTORM) ? 1.0 / (2 * input_nmPerPixel) : 1.0 / input_nmPerPixel;
            for (PeakResult p : results.getResults()) {
                p.params[Gaussian2DFunction.X_POSITION] /= input_nmPerPixel;
                p.params[Gaussian2DFunction.Y_POSITION] /= input_nmPerPixel;
                p.params[Gaussian2DFunction.X_SD] *= widthConversion;
                p.params[Gaussian2DFunction.Y_SD] *= widthConversion;
            }
        }
        if (noise == 0) {
            for (PeakResult p : results.getResults()) {
                p.noise = input_noise;
            }
        }
    }
    return true;
}
Also used : ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) GenericDialog(ij.gui.GenericDialog) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) Calibration(gdsc.smlm.results.Calibration) PeakResult(gdsc.smlm.results.PeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult)

Aggregations

PeakResult (gdsc.smlm.results.PeakResult)89 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)40 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)18 Rectangle (java.awt.Rectangle)18 ArrayList (java.util.ArrayList)17 IdPeakResult (gdsc.smlm.results.IdPeakResult)13 ImagePlus (ij.ImagePlus)9 Point (java.awt.Point)9 Trace (gdsc.smlm.results.Trace)8 ImageStack (ij.ImageStack)7 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)6 Calibration (gdsc.smlm.results.Calibration)6 PreprocessedPeakResult (gdsc.smlm.results.filter.PreprocessedPeakResult)6 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)6 BasePoint (gdsc.core.match.BasePoint)5 Statistics (gdsc.core.utils.Statistics)5 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)5 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)5 GenericDialog (ij.gui.GenericDialog)5 ImageProcessor (ij.process.ImageProcessor)5