use of uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult in project GDSC-SMLM by aherbert.
the class CreateData method savePulses.
/**
* Create a set of results that represent the molecule continuous on-times (pulses).
*
* @param localisations the localisations
* @param results the results
*/
@SuppressWarnings("null")
private void savePulses(List<LocalisationModel> localisations, MemoryPeakResults results) {
sortLocalisationsByIdThenTime(localisations);
final MemoryPeakResults traceResults = copyMemoryPeakResults("Pulses");
LocalisationModel start = null;
int currentId = -1;
int count = 0;
float[] params = Gaussian2DPeakResultHelper.createTwoAxisParams(0, 0, 0, 0, 0, 0, 0);
final int isx = Gaussian2DPeakResultHelper.INDEX_SX;
final int isy = Gaussian2DPeakResultHelper.INDEX_SY;
double noise = 0;
int lastT = -1;
for (final LocalisationModel localisation : localisations) {
if (currentId != localisation.getId() || lastT + 1 != localisation.getTime()) {
if (count > 0) {
params[PeakResult.BACKGROUND] /= count;
params[PeakResult.X] /= count;
params[PeakResult.Y] /= count;
params[isx] /= count;
params[isy] /= count;
final ExtendedPeakResult p = new ExtendedPeakResult(start.getTime(), (int) Math.round(start.getX()), (int) Math.round(start.getY()), 0, 0, (float) (Math.sqrt(noise)), 0, params, null, lastT, currentId);
// if (p.getPrecision(107, 1) > 2000)
// {
// System.out.printf("Weird precision = %g (%d)\n", p.getPrecision(107, 1), n);
// }
traceResults.add(p);
}
start = localisation;
currentId = localisation.getId();
count = 0;
params = new float[7];
noise = 0;
}
final double[] data = localisation.getData();
params[PeakResult.BACKGROUND] += data[0];
params[PeakResult.X] += localisation.getX();
params[PeakResult.Y] += localisation.getY();
params[PeakResult.INTENSITY] += localisation.getIntensity();
noise += data[1] * data[1];
params[isx] += data[2];
params[isy] += data[3];
count++;
lastT = localisation.getTime();
}
// Final pulse
if (count > 0) {
params[PeakResult.BACKGROUND] /= count;
params[PeakResult.X] /= count;
params[PeakResult.Y] /= count;
params[isx] /= count;
params[isy] /= count;
traceResults.add(new ExtendedPeakResult(start.getTime(), (int) Math.round(start.getX()), (int) Math.round(start.getY()), 0, 0, (float) (Math.sqrt(noise)), 0, params, null, lastT, currentId));
}
traceResults.end();
}
use of uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult in project GDSC-SMLM by aherbert.
the class PcPalmClusters method doClustering.
/**
* Extract the results from the PCPALM molecules using the area ROI and then do clustering to
* obtain the histogram of molecules per cluster.
*
* @return the histogram data
*/
private HistogramData doClustering() {
// Perform clustering analysis to generate the histogram of cluster sizes
final PcPalmAnalysis analysis = new PcPalmAnalysis();
final List<Molecule> molecules = analysis.cropToRoi(WindowManager.getCurrentImage(), moleculesResults);
if (molecules.size() < 2) {
error("No results within the crop region");
return null;
}
ImageJUtils.log("Using %d molecules (Density = %s um^-2) @ %s nm", molecules.size(), MathUtils.rounded(molecules.size() / analysis.croppedArea), MathUtils.rounded(settings.distance));
final long s1 = System.nanoTime();
final ClusteringEngine engine = new ClusteringEngine(1, clusteringAlgorithm, SimpleImageJTrackProgress.getInstance());
if (settings.multiThread) {
engine.setThreadCount(Prefs.getThreads());
}
engine.setTracker(SimpleImageJTrackProgress.getInstance());
IJ.showStatus("Clustering ...");
final List<Cluster> clusters = engine.findClusters(convertToPoint(molecules), settings.distance);
IJ.showStatus("");
if (clusters == null) {
ImageJUtils.log("Aborted");
return null;
}
numberOfMolecules = molecules.size();
ImageJUtils.log("Finished : %d total clusters (%s ms)", clusters.size(), MathUtils.rounded((System.nanoTime() - s1) / 1e6));
// Save cluster centroids to a results set in memory. Then they can be plotted.
final MemoryPeakResults results = new MemoryPeakResults(clusters.size());
results.setName(TITLE);
// Set an arbitrary calibration so that the lifetime of the results is stored in the exposure
// time
// The results will be handled as a single mega-frame containing all localisation.
results.setCalibration(CalibrationHelper.create(100, 1, moleculesResults.seconds * 1000));
int id = 0;
for (final Cluster c : clusters) {
results.add(new ExtendedPeakResult((float) c.getX(), (float) c.getY(), c.getSize(), ++id));
}
MemoryPeakResults.addResults(results);
// Get the data for fitting
final float[] values = new float[clusters.size()];
for (int i = 0; i < values.length; i++) {
values[i] = clusters.get(i).getSize();
}
final float yMax = (int) Math.ceil(MathUtils.max(values));
final int nBins = (int) (yMax + 1);
final float[][] hist = HistogramPlot.calcHistogram(values, 0, yMax, nBins);
final HistogramData histogramData = (settings.calibrateHistogram) ? new HistogramData(hist, settings.frames, settings.area, Settings.UNITS[settings.units]) : new HistogramData(hist);
saveHistogram(histogramData);
return histogramData;
}
use of uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method aggregateIntoFrames.
private void aggregateIntoFrames(ArrayList<Point> points, boolean addError, double precisionInPixels, NormalizedGaussianSampler gauss) {
if (myAggregateSteps < 1) {
return;
}
final MemoryPeakResults results = new MemoryPeakResults(points.size() / myAggregateSteps);
results.setCalibration(CalibrationHelper.create(settings.getPixelPitch(), 1, myAggregateSteps * 1000.0 / settings.getStepsPerSecond()));
results.setName(TITLE + " Aggregated");
results.setPsf(PsfHelper.create(PSFType.CUSTOM));
MemoryPeakResults.addResults(results);
simulation.dataset[1] = results.getName();
int id = 0;
int peak = 1;
int number = 0;
double cx = 0;
double cy = 0;
// Get the mean square distance
double sum = 0;
int count = 0;
PeakResult last = null;
for (final Point result : points) {
final boolean newId = result.id != id;
if (number >= myAggregateSteps || newId) {
if (number != 0) {
double[] xyz = new double[] { cx / number, cy / number };
if (addError) {
xyz = addError(xyz, precisionInPixels, gauss);
}
final float[] params = PeakResult.createParams(0, number, (float) xyz[0], (float) xyz[1], 0);
final float noise = 0.1f;
final PeakResult r = new ExtendedPeakResult(peak, (int) params[PeakResult.X], (int) params[PeakResult.Y], number, 0, noise, 0, params, null, peak, id);
results.add(r);
if (last != null) {
sum += last.distance2(r);
count++;
}
last = r;
number = 0;
cx = cy = 0;
peak++;
}
if (newId) {
// Increment the frame so that tracing analysis can distinguish traces
peak++;
last = null;
id = result.id;
}
}
number++;
cx += result.x;
cy += result.y;
}
// Final peak
if (number != 0) {
double[] xyz = new double[] { cx / number, cy / number };
if (addError) {
xyz = addError(xyz, precisionInPixels, gauss);
}
final float[] params = PeakResult.createParams(0, number, (float) xyz[0], (float) xyz[1], 0);
final float noise = 0.1f;
final PeakResult r = new ExtendedPeakResult(peak, (int) params[PeakResult.X], (int) params[PeakResult.Y], number, 0, noise, 0, params, null, peak, id);
results.add(r);
if (last != null) {
sum += last.distance2(r);
count++;
}
}
// MSD in pixels^2 / frame
final double msd = sum / count;
// Convert to um^2/second
ImageJUtils.log("Aggregated data D=%s um^2/s, Precision=%s nm, N=%d, step=%s s, mean=%s um^2, " + "MSD = %s um^2/s", MathUtils.rounded(settings.getDiffusionRate()), MathUtils.rounded(myPrecision), count, MathUtils.rounded(results.getCalibrationReader().getExposureTime() / 1000), MathUtils.rounded(msd / conversionFactor), MathUtils.rounded((msd / conversionFactor) / (results.getCalibrationReader().getExposureTime() / 1000)));
msdAnalysis(points);
}
use of uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method record.
private static int record(double[] xyz, int id, int peak, Statistics stats2D, Statistics stats3D, StoredDataStatistics jumpDistances2D, StoredDataStatistics jumpDistances3D, double[] origin, MemoryPeakResults results) {
final double dx = xyz[0] - origin[0];
final double dy = xyz[1] - origin[1];
final double dz = xyz[2] - origin[2];
final double jump2D = dx * dx + dy * dy;
jumpDistances2D.add(jump2D);
jumpDistances3D.add(jump2D + dz * dz);
for (int i = 0; i < 3; i++) {
origin[i] = xyz[i];
}
final double d2 = squared2D(xyz);
stats2D.add(d2);
stats3D.add(d2 + xyz[2] * xyz[2]);
final float[] params = PeakResult.createParams(0, 10f, (float) xyz[0], (float) xyz[1], (float) xyz[2]);
final float noise = 0.1f;
results.add(new ExtendedPeakResult(peak, (int) params[PeakResult.X], (int) params[PeakResult.Y], 10, 0, noise, 0, params, null, peak, id));
return ++peak;
}
use of uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult 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);
}
Aggregations