Search in sources :

Example 1 with ArrayPeakResultStore

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

the class PeakResultTableModel method toMemoryPeakResults.

// *************************************************************************/
// Data management
// *************************************************************************/
/**
 * To memory peak results.
 *
 * @return the memory peak results
 */
public MemoryPeakResults toMemoryPeakResults() {
    final ArrayPeakResultStore store = new ArrayPeakResultStore(data.size());
    store.addArray(data.toArray());
    final MemoryPeakResults results = new MemoryPeakResults(store);
    results.setPsf(psf);
    results.setCalibration(calibration);
    results.setSource(source);
    results.setConfiguration(configuration);
    return results;
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ArrayPeakResultStore(uk.ac.sussex.gdsc.smlm.results.ArrayPeakResultStore)

Example 2 with ArrayPeakResultStore

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

the class TraceDiffusion method filterTraces.

/**
 * Split traces to contiguous traces and filter traces that are not the minimum length. Re-assigns
 * the ID for the output traces.
 *
 * @param name the name
 * @param traces the traces
 * @param minimumTraceLength the minimum trace length
 * @param ignoreEnds the ignore ends
 * @return The new traces
 */
private static Trace[] filterTraces(String name, Trace[] traces, int minimumTraceLength, boolean ignoreEnds) {
    final LocalList<Trace> list = new LocalList<>(traces.length);
    final int minLength = (ignoreEnds) ? minimumTraceLength + 2 : minimumTraceLength;
    final Consumer<Trace> action = (ignoreEnds) ? t -> {
        if (t.size() >= minLength) {
            t.removeEnds();
            list.add(t);
            t.setId(list.size());
        }
    } : t -> {
        if (t.size() >= minLength) {
            list.add(t);
            t.setId(list.size());
        }
    };
    final Consumer<ArrayPeakResultStore> action2 = (ignoreEnds) ? r -> {
        if (r.size() >= minLength) {
            r.remove(0);
            r.remove(r.size() - 1);
            final Trace t = new Trace(r);
            list.add(t);
            t.setId(list.size());
        }
    } : r -> {
        if (r.size() >= minLength) {
            final Trace t = new Trace(r);
            list.add(t);
            t.setId(list.size());
        }
    };
    final ArrayPeakResultStore results = new ArrayPeakResultStore(11);
    for (final Trace trace : traces) {
        if (trace.size() < minLength) {
            // Too short
            continue;
        }
        if (trace.size() == trace.getTail().getFrame() - trace.getHead().getFrame() + 1) {
            // Contiguous
            action.accept(trace);
        } else {
            // Split the trace
            int t1 = trace.getHead().getFrame();
            for (int i = 0; i < trace.size(); i++) {
                final PeakResult peak = trace.get(i);
                final int t2 = peak.getFrame();
                if (t2 - t1 > 1) {
                    // Non-contiguous
                    action2.accept(results);
                    results.clear();
                }
                t1 = t2;
                results.add(peak);
            }
            // Final trace
            action2.accept(results);
            results.clear();
        }
    }
    ImageJUtils.log("Filtered results '%s' : %s split and filtered to %d using " + "minimum length %d (Ignore ends = %b)", name, TextUtils.pleural(traces.length, "trace"), list.size(), minimumTraceLength, ignoreEnds);
    return list.toArray(new Trace[0]);
}
Also used : Trace(uk.ac.sussex.gdsc.smlm.results.Trace) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ArrayPeakResultStore(uk.ac.sussex.gdsc.smlm.results.ArrayPeakResultStore) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

Example 3 with ArrayPeakResultStore

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

the class PeakResultTableModelFrameDemo method main.

/**
 * Launch the application.
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    final SplitMix r = SplitMix.new64(System.currentTimeMillis());
    final int n = 20;
    final ListSelectionModel selectionModel = new DefaultListSelectionModel();
    EventQueue.invokeLater((Runnable) () -> {
        try {
            final PeakResultStoreList store = new ArrayPeakResultStore(10);
            for (int i = n; i-- > 0; ) {
                store.add(new PeakResult(r.nextInt(), r.nextInt(), r.nextInt(), r.nextFloat(), r.nextDouble(), r.nextFloat(), r.nextFloat(), PeakResult.createParams(r.nextFloat(), r.nextFloat(), r.nextFloat(), r.nextFloat(), r.nextFloat()), null));
            }
            final CalibrationWriter cw = new CalibrationWriter();
            cw.setNmPerPixel(100);
            cw.setCountPerPhoton(10);
            cw.setDistanceUnit(DistanceUnit.PIXEL);
            cw.setIntensityUnit(IntensityUnit.COUNT);
            final ResultsTableSettings.Builder tableSettings = ResultsTableSettings.newBuilder();
            tableSettings.setDistanceUnit(DistanceUnit.NM);
            tableSettings.setIntensityUnit(IntensityUnit.PHOTON);
            tableSettings.setShowFittingData(true);
            tableSettings.setShowNoiseData(true);
            tableSettings.setShowPrecision(true);
            tableSettings.setRoundingPrecision(4);
            final PeakResultTableModel model = new PeakResultTableModel(store, cw.getCalibration(), null, tableSettings.build());
            final PeakResultTableModelFrame d = new PeakResultTableModelFrame(model, null, selectionModel);
            d.setTitle("D");
            d.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
            d.setVisible(true);
            // Selecting in one list activates the other list
            final PeakResultTableModelFrame d2 = new PeakResultTableModelFrame(model, null, selectionModel);
            d2.setTitle("D2");
            // Since we have the same selection model we need the same row sorter,
            // otherwise the selection is scrambled by sorting.
            // The alternative would be to get the source for the selection event (the table)
            // and get the row sorter to do the mapping.
            // However this breaks deletion of data as the row sorter double processes the deletion.
            // Basically only one table can use the same selection model when sorting is desired.
            // d2.table.setRowSorter(d.table.getRowSorter())
            d2.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
            d2.setVisible(true);
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    });
}
Also used : PeakResultStoreList(uk.ac.sussex.gdsc.smlm.results.PeakResultStoreList) SplitMix(uk.ac.sussex.gdsc.core.utils.rng.SplitMix) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ArrayPeakResultStore(uk.ac.sussex.gdsc.smlm.results.ArrayPeakResultStore) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

Aggregations

ArrayPeakResultStore (uk.ac.sussex.gdsc.smlm.results.ArrayPeakResultStore)3 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)2 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)1 ListSelectionModel (javax.swing.ListSelectionModel)1 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)1 SplitMix (uk.ac.sussex.gdsc.core.utils.rng.SplitMix)1 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)1 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)1 PeakResultStoreList (uk.ac.sussex.gdsc.smlm.results.PeakResultStoreList)1 Trace (uk.ac.sussex.gdsc.smlm.results.Trace)1