Search in sources :

Example 1 with AttributePeakResult

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

the class PcPalmMolecules method traceMolecules.

/**
 * Trace localisations.
 *
 * @param results The results
 * @param precisions the precisions
 * @param distance The distance threshold (nm)
 * @param time The time threshold (frames)
 * @param singles a list of the singles (not grouped into molecules)
 * @return a list of molecules
 */
private static ArrayList<Molecule> traceMolecules(MemoryPeakResults results, double[] precisions, double distance, int time, ArrayList<Molecule> singles) {
    // These plugins are not really supported so just leave them to throw an exception if
    // the data cannot be handled
    final TypeConverter<IntensityUnit> ic = results.getCalibrationReader().getIntensityConverter(IntensityUnit.PHOTON);
    final TypeConverter<DistanceUnit> dc = results.getCalibrationReader().getDistanceConverter(DistanceUnit.NM);
    // Create a new dataset with the precision
    final MemoryPeakResults results2 = new MemoryPeakResults(results.size());
    for (int i = 0, size = results.size(); i < size; i++) {
        final AttributePeakResult peak2 = new AttributePeakResult(results.get(i));
        peak2.setPrecision(precisions[i]);
        results2.add(peak2);
    }
    final TraceManager tm = new TraceManager(results2);
    final double distanceThreshold = dc.convertBack(distance);
    tm.traceMolecules(distanceThreshold, time);
    final Trace[] traces = tm.getTraces();
    final ArrayList<Molecule> molecules = new ArrayList<>(traces.length);
    for (final Trace t : traces) {
        final double p = t.getLocalisationPrecision(dc);
        final float[] centroid = t.getCentroid();
        final List<Molecule> list = t.size() == 1 ? singles : molecules;
        list.add(new Molecule(dc.convert(centroid[0]), dc.convert(centroid[1]), p, ic.convert(t.getSignal())));
    }
    log("  %d localisations traced to %d molecules (%d singles, %d traces) using d=%.2f nm," + " t=%d frames (%s s)", results.size(), molecules.size() + singles.size(), singles.size(), molecules.size(), distance, time, MathUtils.rounded(time * results.getCalibrationReader().getExposureTime() / 1000.0));
    return molecules;
}
Also used : AttributePeakResult(uk.ac.sussex.gdsc.smlm.results.AttributePeakResult) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) ArrayList(java.util.ArrayList) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

Example 2 with AttributePeakResult

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

the class TraceExporter method splitLongTraces.

private MemoryPeakResults splitLongTraces(MemoryPeakResults results) {
    if (settings.maxLength < 1) {
        // Disabled
        return results;
    }
    final MemoryPeakResults results2 = new MemoryPeakResults(results.size());
    results2.copySettings(results);
    int nextId = results.getLast().getId();
    int id = 0;
    int idOut = 0;
    // The length that has been output under the current ID
    int length = 0;
    for (int i = 0, size = results.size(); i < size; i++) {
        final PeakResult r = results.get(i);
        if (r.getId() != id) {
            id = r.getId();
            idOut = id;
            length = 0;
        } else if (length >= settings.maxLength) {
            idOut = ++nextId;
            length = 0;
        }
        final AttributePeakResult r2 = new AttributePeakResult(r);
        r2.setId(idOut);
        results2.add(r2);
        length += getLength(r);
    }
    return results2;
}
Also used : AttributePeakResult(uk.ac.sussex.gdsc.smlm.results.AttributePeakResult) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) AttributePeakResult(uk.ac.sussex.gdsc.smlm.results.AttributePeakResult)

Example 3 with AttributePeakResult

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

the class TraceExporter method doSplit.

private MemoryPeakResults doSplit(MemoryPeakResults results) {
    final MemoryPeakResults results2 = new MemoryPeakResults(results.size());
    results2.copySettings(results);
    int nextId = results.getLast().getId();
    int id = 0;
    int idOut = 0;
    int lastT = 0;
    for (int i = 0, size = results.size(); i < size; i++) {
        final PeakResult r = results.get(i);
        if (r.getId() != id) {
            id = r.getId();
            idOut = id;
        } else if (r.getFrame() - lastT > settings.maxJump) {
            idOut = ++nextId;
        }
        final AttributePeakResult r2 = new AttributePeakResult(r);
        r2.setId(idOut);
        results2.add(r2);
        lastT = r.getEndFrame();
    }
    return results2;
}
Also used : AttributePeakResult(uk.ac.sussex.gdsc.smlm.results.AttributePeakResult) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) AttributePeakResult(uk.ac.sussex.gdsc.smlm.results.AttributePeakResult)

Example 4 with AttributePeakResult

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

the class FitWorker method createResult.

private PeakResult createResult(int origX, int origY, float origValue, double error, float noise, float meanIntensity, float[] params, float[] paramDevs, int id, double precision) {
    // Convert to a variable PSF parameter PeakResult
    params = Gaussian2DPeakResultHelper.createParams(psfType, params);
    if (paramDevs != null) {
        paramDevs = Gaussian2DPeakResultHelper.createParams(psfType, paramDevs);
        // Convert variances to standard deviations
        for (int i = 0; i < paramDevs.length; i++) {
            paramDevs[i] = (float) Math.sqrt(paramDevs[i]);
        }
    }
    if (precision > 0) {
        final AttributePeakResult r = new AttributePeakResult(slice, origX, origY, origValue, error, noise, meanIntensity, params, paramDevs);
        r.setId(id);
        r.setPrecision(precision);
        if (endT >= 0 && slice != endT) {
            r.setEndFrame(endT);
        }
        return r;
    }
    if (endT >= 0 && slice != endT) {
        return new ExtendedPeakResult(slice, origX, origY, origValue, error, noise, meanIntensity, params, paramDevs, endT, id);
    }
    return new IdPeakResult(slice, origX, origY, origValue, error, noise, meanIntensity, params, paramDevs, id);
}
Also used : ExtendedPeakResult(uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult) AttributePeakResult(uk.ac.sussex.gdsc.smlm.results.AttributePeakResult) IdPeakResult(uk.ac.sussex.gdsc.smlm.results.IdPeakResult)

Aggregations

AttributePeakResult (uk.ac.sussex.gdsc.smlm.results.AttributePeakResult)4 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)3 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)2 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 ArrayList (java.util.ArrayList)1 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)1 ClusterPoint (uk.ac.sussex.gdsc.core.clustering.ClusterPoint)1 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)1 IntensityUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit)1 ExtendedPeakResult (uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult)1 IdPeakResult (uk.ac.sussex.gdsc.smlm.results.IdPeakResult)1 Trace (uk.ac.sussex.gdsc.smlm.results.Trace)1 TraceManager (uk.ac.sussex.gdsc.smlm.results.TraceManager)1