Search in sources :

Example 1 with MemoryPeakResults

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

the class ResequenceResults method run.

/*
	 * (non-)
	 * 
	 * @see ij.plugin.PlugIn#run(java.lang.String)
	 */
public void run(String arg) {
    SMLMUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    if (!showDialog())
        return;
    MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, true);
    if (results == null || results.size() == 0) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    if (resequenceResults(results, start, block, skip, (logMapping) ? new IJTrackProgress() : null))
        IJ.showStatus("Resequenced " + results.getName());
}
Also used : IJTrackProgress(gdsc.core.ij.IJTrackProgress) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults)

Example 2 with MemoryPeakResults

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

the class ResultsManager method loadInputResults.

/**
	 * Load the results from the named input option
	 * 
	 * @param inputOption
	 * @param checkCalibration
	 *            Set to true to ensure the results have a valid calibration
	 * @return
	 */
public static MemoryPeakResults loadInputResults(String inputOption, boolean checkCalibration) {
    MemoryPeakResults results = null;
    PeakResultsReader reader = null;
    if (inputOption.equals(INPUT_NONE)) {
    } else if (inputOption.equals(INPUT_FILE)) {
        IJ.showStatus("Reading results file ...");
        reader = new PeakResultsReader(inputFilename);
        IJ.showStatus("Reading " + reader.getFormat() + " results file ...");
        ResultOption[] options = reader.getOptions();
        if (options != null)
            collectOptions(reader, options);
        reader.setTracker(new IJTrackProgress());
        results = reader.getResults();
        reader.getTracker().progress(1.0);
        if (results != null && results.size() > 0) {
            // If the name contains a .tif suffix then create an image source
            if (results.getName() != null && results.getName().contains(".tif") && results.getSource() == null) {
                int index = results.getName().indexOf(".tif");
                results.setSource(new IJImageSource(results.getName().substring(0, index)));
            }
        }
    } else {
        results = loadMemoryResults(inputOption);
    }
    if (results != null && results.size() > 0 && checkCalibration) {
        if (!checkCalibration(results, reader))
            results = null;
    }
    IJ.showStatus("");
    return results;
}
Also used : IJImageSource(gdsc.smlm.ij.IJImageSource) IJTrackProgress(gdsc.core.ij.IJTrackProgress) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResultsReader(gdsc.smlm.results.PeakResultsReader)

Example 3 with MemoryPeakResults

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

the class ResultsManager method cropToRoi.

private MemoryPeakResults cropToRoi(MemoryPeakResults results) {
    if (roiBounds == null)
        return results;
    // Adjust bounds relative to input results image
    double xscale = roiImageWidth / results.getBounds().width;
    double yscale = roiImageHeight / results.getBounds().height;
    roiBounds.x /= xscale;
    roiBounds.width /= xscale;
    roiBounds.y /= yscale;
    roiBounds.height /= yscale;
    float minX = (int) (roiBounds.x);
    float maxX = (int) Math.ceil(roiBounds.x + roiBounds.width);
    float minY = (int) (roiBounds.y);
    float maxY = (int) Math.ceil(roiBounds.y + roiBounds.height);
    // Create a new set of results within the bounds
    MemoryPeakResults newResults = new MemoryPeakResults();
    newResults.begin();
    for (PeakResult peakResult : results.getResults()) {
        float x = peakResult.params[Gaussian2DFunction.X_POSITION];
        float y = peakResult.params[Gaussian2DFunction.Y_POSITION];
        if (x < minX || x > maxX || y < minY || y > maxY)
            continue;
        newResults.add(peakResult);
    }
    newResults.end();
    newResults.copySettings(results);
    newResults.setBounds(new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY)));
    return newResults;
}
Also used : Rectangle(java.awt.Rectangle) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult)

Example 4 with MemoryPeakResults

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

the class PeakFit method showResults.

protected void showResults() {
    IJ.showProgress(1.0);
    if (time >= 0) {
        if (silent) {
            results.end();
            return;
        }
        // Check if we are sorting
        IJ.showStatus("Finalising results ...");
        for (PeakResults r : results.toArray()) if (r instanceof MemoryPeakResults) {
            if (((MemoryPeakResults) r).isSortAfterEnd())
                IJ.showStatus("Sorting " + r.size() + " results ...");
            break;
        }
        results.end();
        String textTime = Utils.timeToString(time / 1000000.0);
        String textRunTime = Utils.timeToString(runTime / 1000000.0);
        int size = getSize();
        String message = String.format("%s. Fitting Time = %s. Run time = %s", Utils.pleural(size, "localisation"), textTime, textRunTime);
        if (resultsSettings.logProgress)
            IJ.log("-=-=-=-");
        IJ.log(message);
        IJ.showStatus(message);
    } else {
        IJ.showStatus("");
    }
}
Also used : PeakResults(gdsc.smlm.results.PeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults)

Example 5 with MemoryPeakResults

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

the class PulseActivationAnalysis method runSimulation.

private void runSimulation() {
    TITLE += " Simulation";
    if (!showSimulationDialog())
        return;
    long start = System.currentTimeMillis();
    RandomDataGenerator rdg = getRandomDataGenerator();
    // Draw the molecule positions
    Utils.showStatus("Simulating molecules ...");
    float[][][] molecules = new float[3][][];
    MemoryPeakResults[] results = new MemoryPeakResults[3];
    Rectangle bounds = new Rectangle(0, 0, sim_size, sim_size);
    for (int c = 0; c < 3; c++) {
        molecules[c] = simulateMolecules(rdg, c);
        // Create a dataset to store the activations
        MemoryPeakResults r = new MemoryPeakResults();
        r.setCalibration(new Calibration(sim_nmPerPixel, 1, 100));
        r.setBounds(bounds);
        r.setName(TITLE + " C" + (c + 1));
        results[c] = r;
    }
    // Simulate activation
    Utils.showStatus("Simulating activations ...");
    for (int c = 0; c < 3; c++) simulateActivations(rdg, molecules, c, results);
    // Combine
    Utils.showStatus("Producing simulation output ...");
    MemoryPeakResults r = new MemoryPeakResults();
    r.setCalibration(new Calibration(sim_nmPerPixel, 1, 100));
    r.setBounds(new Rectangle(0, 0, sim_size, sim_size));
    r.setName(TITLE);
    ImageProcessor[] images = new ImageProcessor[3];
    for (int c = 0; c < 3; c++) {
        ArrayList<PeakResult> list = (ArrayList<PeakResult>) results[c].getResults();
        r.addAllf(list);
        // Draw the unmixed activations
        IJImagePeakResults image = ImagePeakResultsFactory.createPeakResultsImage(ResultsImage.LOCALISATIONS, true, true, TITLE, bounds, sim_nmPerPixel, 1, 1024.0 / sim_size, 0, ResultsMode.ADD);
        image.setLiveImage(false);
        image.setDisplayImage(false);
        image.begin();
        image.addAll(list);
        image.end();
        images[c] = image.getImagePlus().getProcessor();
    }
    displayComposite(images, TITLE);
    // Add to memory. Set the composite dataset first.
    MemoryPeakResults.addResults(r);
    for (int c = 0; c < 3; c++) MemoryPeakResults.addResults(results[c]);
    // TODO:
    // Show an image of what it looks like with no unmixing, i.e. colours allocated 
    // from the frame
    Utils.showStatus("Simulation complete: " + Utils.timeToString(System.currentTimeMillis() - start));
}
Also used : RandomDataGenerator(org.apache.commons.math3.random.RandomDataGenerator) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) Calibration(gdsc.smlm.results.Calibration) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) PeakResult(gdsc.smlm.results.PeakResult) IdPeakResult(gdsc.smlm.results.IdPeakResult) ImageProcessor(ij.process.ImageProcessor) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults)

Aggregations

MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)86 PeakResult (gdsc.smlm.results.PeakResult)40 Rectangle (java.awt.Rectangle)16 ArrayList (java.util.ArrayList)13 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)10 ImagePlus (ij.ImagePlus)10 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)8 Statistics (gdsc.core.utils.Statistics)7 IJImageSource (gdsc.smlm.ij.IJImageSource)7 Calibration (gdsc.smlm.results.Calibration)7 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)7 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)6 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)6 Trace (gdsc.smlm.results.Trace)6 LinkedList (java.util.LinkedList)6 BasePoint (gdsc.core.match.BasePoint)5 ImageStack (ij.ImageStack)5 Plot2 (ij.gui.Plot2)5 Point (java.awt.Point)5 ClusterPoint (gdsc.core.clustering.ClusterPoint)4