Search in sources :

Example 41 with MemoryPeakResults

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

the class TrackPopulationAnalysis method showInputDialog.

private boolean showInputDialog(List<MemoryPeakResults> combinedResults) {
    // Show a list box containing all the clustered results.
    // This should remember the last set of chosen items.
    final MultiDialog md = ResultsManager.createMultiDialog(TITLE, MemoryPeakResults::hasId);
    md.setSelected(settings.input);
    md.setHelpUrl(HelpUrls.getUrl("track-population-analysis"));
    md.showDialog();
    if (md.wasCancelled()) {
        return false;
    }
    final List<String> selected = md.getSelectedResults();
    if (selected.isEmpty()) {
        IJ.error(TITLE, "No results were selected");
        return false;
    }
    settings.input = selected;
    for (final String name : selected) {
        final MemoryPeakResults r = MemoryPeakResults.getResults(name);
        if (r != null) {
            combinedResults.add(r);
        }
    }
    // Check calibration exists for the first set of results
    if (combinedResults.isEmpty() || !checkCalibration(combinedResults.get(0))) {
        return false;
    }
    // Check the calibration is the same for the rest
    final CalibrationReader cal = combinedResults.get(0).getCalibrationReader();
    final double nmPerPixel = cal.getNmPerPixel();
    final double exposureTime = cal.getExposureTime();
    final DistanceUnit distanceUnit = cal.getDistanceUnit();
    for (int i = 1; i < combinedResults.size(); i++) {
        final MemoryPeakResults results = combinedResults.get(i);
        if (!results.hasCalibration() || results.getCalibrationReader().getExposureTime() != exposureTime || results.getNmPerPixel() != nmPerPixel || results.getDistanceUnit() != distanceUnit) {
            IJ.error(TITLE, "The exposure time, pixel pitch and distance unit must match across all the results");
            return false;
        }
    }
    return true;
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Example 42 with MemoryPeakResults

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

the class TranslateResults method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    final TranslateResultsSettings.Builder settings = SettingsManager.readTranslateResultsSettings(0).toBuilder();
    // Show a dialog allowing the results set to be filtered
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Select a dataset to translate");
    ResultsManager.addInput(gd, settings.getInputOption(), InputSource.MEMORY);
    gd.addNumericField("x", settings.getDx(), 3);
    gd.addNumericField("y", settings.getDy(), 3);
    gd.addNumericField("z", settings.getDz(), 3);
    gd.addChoice("Distance_unit", SettingsManager.getDistanceUnitNames(), settings.getDistanceUnitValue());
    gd.addHelp(HelpUrls.getUrl("translate-results"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    settings.setInputOption(ResultsManager.getInputSource(gd));
    settings.setDx(gd.getNextNumber());
    settings.setDy(gd.getNextNumber());
    settings.setDz(gd.getNextNumber());
    settings.setDistanceUnitValue(gd.getNextChoiceIndex());
    SettingsManager.writeSettings(settings);
    final MemoryPeakResults results = ResultsManager.loadInputResults(settings.getInputOption(), false, null, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    TypeConverter<DistanceUnit> converter;
    try {
        converter = results.getDistanceConverter(settings.getDistanceUnit());
    } catch (final DataException ex) {
        IJ.error(TITLE, "Unit conversion error: " + ex.getMessage());
        return;
    }
    final float x = (float) converter.convertBack(settings.getDx());
    final float y = (float) converter.convertBack(settings.getDy());
    final float z = (float) converter.convertBack(settings.getDz());
    // Reset the 2D bounds
    if (x != 0 || y != 0) {
        results.setBounds(null);
    }
    results.forEach((PeakResultProcedure) peakResult -> {
        final float[] params = peakResult.getParameters();
        params[PeakResult.X] += x;
        params[PeakResult.Y] += y;
        params[PeakResult.Z] += z;
    });
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) IJ(ij.IJ) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) TranslateResultsSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.TranslateResultsSettings) DataException(uk.ac.sussex.gdsc.core.data.DataException) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) PlugIn(ij.plugin.PlugIn) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) DataException(uk.ac.sussex.gdsc.core.data.DataException) TranslateResultsSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.TranslateResultsSettings) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

Example 43 with MemoryPeakResults

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

the class TraceMolecules method convertToClusterPoints.

/**
 * Convert a list of peak results into points for the clustering engine.
 *
 * @param results the results
 * @return the list of clusters
 */
public static List<ClusterPoint> convertToClusterPoints(MemoryPeakResults results) {
    final ArrayList<ClusterPoint> points = new ArrayList<>(results.size());
    final Counter counter = new Counter();
    results.forEach((PeakResultProcedure) result -> points.add(ClusterPoint.newTimeClusterPoint(counter.getAndIncrement(), result.getXPosition(), result.getYPosition(), result.getIntensity(), result.getFrame(), result.getEndFrame())));
    return points;
}
Also used : Arrays(java.util.Arrays) ClusteringEngine(uk.ac.sussex.gdsc.core.clustering.ClusteringEngine) UnitConverterUtils(uk.ac.sussex.gdsc.smlm.data.config.UnitConverterUtils) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) TextWindow(ij.text.TextWindow) CalibrationOrBuilder(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CalibrationOrBuilder) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ClusteringAlgorithm(uk.ac.sussex.gdsc.core.clustering.ClusteringAlgorithm) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) ClusteringSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ClusteringSettings) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) TraceMode(uk.ac.sussex.gdsc.smlm.results.TraceManager.TraceMode) Logger(java.util.logging.Logger) TIntHashSet(gnu.trove.set.hash.TIntHashSet) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) ImagePlus(ij.ImagePlus) LutLoader(ij.plugin.LutLoader) List(java.util.List) Converter(uk.ac.sussex.gdsc.core.data.utils.Converter) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) FileUtils(uk.ac.sussex.gdsc.core.utils.FileUtils) PlugIn(ij.plugin.PlugIn) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) SplineInterpolator(org.apache.commons.math3.analysis.interpolation.SplineInterpolator) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) PolygonRoi(ij.gui.PolygonRoi) PolynomialSplineFunction(org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction) Prefs(ij.Prefs) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WindowManager(ij.WindowManager) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint) DmttConfiguration(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing.DmttConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) SimpleImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.SimpleImageJTrackProgress) Files(java.nio.file.Files) Calibration(ij.measure.Calibration) Checkbox(java.awt.Checkbox) BufferedWriter(java.io.BufferedWriter) DynamicMultipleTargetTracing(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing) TimeUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.TimeUnit) Consumer(java.util.function.Consumer) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) FloatProcessor(ij.process.FloatProcessor) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) Paths(java.nio.file.Paths) Cluster(uk.ac.sussex.gdsc.core.clustering.Cluster) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) IJ(ij.IJ) Collections(java.util.Collections) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ArrayList(java.util.ArrayList) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint)

Example 44 with MemoryPeakResults

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

the class SpotAnalysis method saveTraces.

private void saveTraces() {
    if (!onFrames.isEmpty() && updated) {
        final GenericDialog gd = new GenericDialog(PLUGIN_TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage("The list contains unsaved selected frames.\n \nDo you want to continue?");
        gd.showDialog();
        if (!gd.wasOKed()) {
            return;
        }
    }
    // For all spots in the results window, get the ID and then save the traces to memory
    if (!ImageJUtils.isShowing(resultsWindow)) {
        return;
    }
    // Create a results set in memory
    final MemoryPeakResults results = new MemoryPeakResults();
    results.setName(PLUGIN_TITLE);
    results.begin();
    MemoryPeakResults.addResults(results);
    final ArrayList<TraceResult> traceResults = new ArrayList<>(resultsWindow.getTextPanel().getLineCount());
    for (int i = 0; i < resultsWindow.getTextPanel().getLineCount(); i++) {
        final String line = resultsWindow.getTextPanel().getLine(i);
        try (Scanner s = new Scanner(line)) {
            s.useDelimiter("\t");
            int id = -1;
            double signal = -1;
            // Be careful as the text panel may not contain what we expect, i.e. empty lines, etc
            if (s.hasNextInt()) {
                id = s.nextInt();
                try {
                    // cx
                    s.nextDouble();
                    // cy
                    s.nextDouble();
                    signal = s.nextDouble();
                } catch (final NoSuchElementException ex) {
                // Ignore
                }
            }
            if (id != -1 && signal != -1) {
                final Trace trace = traces.get(id);
                if (trace != null) {
                    results.addAll(trace.getPoints());
                    traceResults.add(new TraceResult(new Spot(id, signal), trace));
                }
            }
        }
    }
    results.end();
    saveTracesToFile(traceResults);
    IJ.showStatus("Saved traces");
}
Also used : Trace(uk.ac.sussex.gdsc.smlm.results.Trace) Scanner(java.util.Scanner) GenericDialog(ij.gui.GenericDialog) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Point(java.awt.Point) NoSuchElementException(java.util.NoSuchElementException)

Example 45 with MemoryPeakResults

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

the class SpotAnalysis method addCandidateFrames.

private void addCandidateFrames(String title) {
    for (final MemoryPeakResults r : MemoryPeakResults.getAllResults()) {
        if (r.getSource() instanceof IJImageSource && r.getSource().getName().equals(title)) {
            final float minx = areaBounds.x;
            final float maxx = minx + areaBounds.width;
            final float miny = areaBounds.y;
            final float maxy = miny + areaBounds.height;
            r.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
                if (result.getXPosition() >= minx && result.getXPosition() <= maxx && result.getYPosition() >= miny && result.getYPosition() <= maxy) {
                    candidateFrames.add(result.getFrame());
                }
            });
        }
    }
}
Also used : Color(java.awt.Color) Choice(java.awt.Choice) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) Arrays(java.util.Arrays) GaussianBlur(ij.plugin.filter.GaussianBlur) TIntArrayList(gnu.trove.list.array.TIntArrayList) ImageProcessor(ij.process.ImageProcessor) TextWindow(ij.text.TextWindow) Scanner(java.util.Scanner) GUI(ij.gui.GUI) Point(java.awt.Point) ZProjector(ij.plugin.ZProjector) ItemListener(java.awt.event.ItemListener) ImageRoiPainter(uk.ac.sussex.gdsc.smlm.ij.utils.ImageRoiPainter) Button(java.awt.Button) Panel(java.awt.Panel) Future(java.util.concurrent.Future) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Gaussian2DFitter(uk.ac.sussex.gdsc.smlm.fitting.Gaussian2DFitter) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) BorderLayout(java.awt.BorderLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PsfProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfProtosHelper) ItemEvent(java.awt.event.ItemEvent) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) Frame(java.awt.Frame) LoessInterpolator(org.apache.commons.math3.analysis.interpolation.LoessInterpolator) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Gaussian2DPeakResultHelper(uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultHelper) GridBagConstraints(java.awt.GridBagConstraints) KeyEvent(java.awt.event.KeyEvent) Logger(java.util.logging.Logger) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) Component(java.awt.Component) Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) Plot(ij.gui.Plot) WindowEvent(java.awt.event.WindowEvent) Executors(java.util.concurrent.Executors) ImagePlus(ij.ImagePlus) FitStatus(uk.ac.sussex.gdsc.smlm.fitting.FitStatus) List(java.util.List) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) GridBagLayout(java.awt.GridBagLayout) Roi(ij.gui.Roi) JPanel(javax.swing.JPanel) Rectangle(java.awt.Rectangle) Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) PolynomialSplineFunction(org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction) Prefs(ij.Prefs) WindowManager(ij.WindowManager) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) KeyAdapter(java.awt.event.KeyAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) ImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.ImageJTrackProgress) GenericDialog(ij.gui.GenericDialog) Menus(ij.Menus) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) ExecutorService(java.util.concurrent.ExecutorService) FlowLayout(java.awt.FlowLayout) FitResult(uk.ac.sussex.gdsc.smlm.fitting.FitResult) Files(java.nio.file.Files) PlugInFrame(ij.plugin.frame.PlugInFrame) BufferedWriter(java.io.BufferedWriter) Label(java.awt.Label) JList(javax.swing.JList) ImageAdapter(uk.ac.sussex.gdsc.core.ij.ImageAdapter) IOException(java.io.IOException) Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) ActionEvent(java.awt.event.ActionEvent) JScrollPane(javax.swing.JScrollPane) DefaultListModel(javax.swing.DefaultListModel) Paths(java.nio.file.Paths) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) ImageStack(ij.ImageStack) ListSelectionListener(javax.swing.event.ListSelectionListener) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Aggregations

MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)138 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)61 List (java.util.List)47 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)46 IJ (ij.IJ)39 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)39 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)38 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)38 ArrayList (java.util.ArrayList)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)36 PlugIn (ij.plugin.PlugIn)34 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)33 Counter (uk.ac.sussex.gdsc.smlm.results.count.Counter)33 ImagePlus (ij.ImagePlus)31 Rectangle (java.awt.Rectangle)31 SimpleArrayUtils (uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils)31 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)28 TextUtils (uk.ac.sussex.gdsc.core.utils.TextUtils)28 SettingsManager (uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager)28 FrameCounter (uk.ac.sussex.gdsc.smlm.results.count.FrameCounter)28