use of gdsc.core.utils.Statistics in project GDSC-SMLM by aherbert.
the class TraceMolecules method summarise.
private void summarise(Trace[] traces, int filtered, double dThreshold, double tThreshold) {
IJ.showStatus("Calculating summary ...");
// Create summary table
createSummaryTable();
Statistics[] stats = new Statistics[NAMES.length];
for (int i = 0; i < stats.length; i++) {
stats[i] = (settings.showHistograms || settings.saveTraceData) ? new StoredDataStatistics() : new Statistics();
}
int singles = 0;
for (Trace trace : traces) {
int nBlinks = trace.getNBlinks() - 1;
stats[BLINKS].add(nBlinks);
int[] onTimes = trace.getOnTimes();
int[] offTimes = trace.getOffTimes();
double tOn = 0;
for (int t : onTimes) {
stats[T_ON].add(t * exposureTime);
tOn += t * exposureTime;
}
stats[TOTAL_T_ON].add(tOn);
if (offTimes != null) {
double tOff = 0;
for (int t : offTimes) {
stats[T_OFF].add(t * exposureTime);
tOff += t * exposureTime;
}
stats[TOTAL_T_OFF].add(tOff);
}
final double signal = trace.getSignal() / results.getGain();
stats[TOTAL_SIGNAL].add(signal);
stats[SIGNAL_PER_FRAME].add(signal / trace.size());
if (trace.size() == 1)
singles++;
}
// Add to the summary table
StringBuilder sb = new StringBuilder();
sb.append(results.getName()).append("\t");
sb.append(outputName.equals("Cluster") ? settings.getClusteringAlgorithm() : settings.getTraceMode()).append("\t");
sb.append(Utils.rounded(exposureTime * 1000, 3)).append("\t");
sb.append(Utils.rounded(dThreshold, 3)).append("\t");
sb.append(Utils.rounded(tThreshold, 3));
if (settings.splitPulses)
sb.append(" *");
sb.append("\t");
sb.append(timeInFrames2(tThreshold)).append("\t");
sb.append(traces.length).append("\t");
sb.append(filtered).append("\t");
sb.append(singles).append("\t");
sb.append(traces.length - singles).append("\t");
for (int i = 0; i < stats.length; i++) {
sb.append(Utils.rounded(stats[i].getMean(), 3)).append("\t");
}
if (java.awt.GraphicsEnvironment.isHeadless()) {
IJ.log(sb.toString());
return;
} else {
summaryTable.append(sb.toString());
}
if (settings.showHistograms) {
IJ.showStatus("Calculating histograms ...");
int[] idList = new int[NAMES.length];
int count = 0;
boolean requireRetile = false;
for (int i = 0; i < NAMES.length; i++) {
if (displayHistograms[i]) {
idList[count++] = Utils.showHistogram(TITLE, (StoredDataStatistics) stats[i], NAMES[i], (integerDisplay[i]) ? 1 : 0, (settings.removeOutliers || alwaysRemoveOutliers[i]) ? 2 : 0, settings.histogramBins);
requireRetile = requireRetile || Utils.isNewWindow();
}
}
if (count > 0 && requireRetile) {
idList = Arrays.copyOf(idList, count);
new WindowOrganiser().tileWindows(idList);
}
}
if (settings.saveTraceData) {
saveTraceData(stats);
}
IJ.showStatus("");
}
use of gdsc.core.utils.Statistics in project GDSC-SMLM by aherbert.
the class PCPALMAnalysis method computeRadialAverage.
/**
* Compute the radial average correlation function (gr)
*
* @param maxRadius
* the maximum radius to process (in pixels)
* @param nmPerPixel
* covert pixel distances to nm
* @param correlation
* auto-correlation
* @return { distances[], gr[], gr_se[] }
*/
private double[][] computeRadialAverage(int maxRadius, double nmPerPixel, FloatProcessor correlation) {
// Perform averaging of the correlation function using integer distance bins
log(" Computing distance vs correlation curve");
final int centre = correlation.getHeight() / 2;
// Count the number of pixels at each distance and sum the correlations
Statistics[] gr = new Statistics[maxRadius + 1];
// Cache distances
int[] d2 = new int[maxRadius + 1];
for (int dy = 0; dy <= maxRadius; dy++) {
gr[dy] = new Statistics();
d2[dy] = dy * dy;
}
int[][] distance = new int[maxRadius + 1][maxRadius + 1];
for (int dy = 0; dy <= maxRadius; dy++) {
for (int dx = dy; dx <= maxRadius; dx++) {
distance[dy][dx] = distance[dx][dy] = (int) Math.round(Math.sqrt(d2[dx] + d2[dy]));
}
}
float[] data = (float[]) correlation.getPixels();
for (int dy = -maxRadius; dy <= maxRadius; dy++) {
final int absY = Math.abs(dy);
int index = (centre + dy) * correlation.getWidth() + centre - maxRadius;
for (int dx = -maxRadius; dx <= maxRadius; dx++, index++) {
final int d = distance[absY][Math.abs(dx)];
if (d > maxRadius || d == 0)
continue;
gr[d].add(data[index]);
}
}
// Create the final data: a curve showing distance (in nm) verses the average correlation
double[] x = new double[maxRadius + 1];
double[] y = new double[maxRadius + 1];
double[] sd = new double[maxRadius + 1];
for (int i = 0; i < x.length; i++) {
x[i] = i * nmPerPixel;
y[i] = gr[i].getMean();
sd[i] = gr[i].getStandardError();
}
y[0] = correlation.getf(centre, centre);
return new double[][] { x, y, sd };
}
Aggregations