use of gdsc.core.utils.StoredData in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFilter method histogramFailures.
/**
* Histogram the number of negatives preceeding each positive.
*
* @param filterResult
* the filter result
* @return
*/
private double[][] histogramFailures(BenchmarkFilterResult filterResult) {
final StoredData data = new StoredData();
filterResult.filterResults.forEachEntry(new TIntObjectProcedure<FilterResult>() {
public boolean execute(int peak, FilterResult filterResult) {
for (ScoredSpot spot : filterResult.spots) {
if (spot.match) {
data.add(spot.fails);
}
}
return true;
}
});
double[][] h = Maths.cumulativeHistogram(data.getValues(), true);
filterResult.cumul = h;
filterResult.stats = data;
return h;
}
use of gdsc.core.utils.StoredData in project GDSC-SMLM by aherbert.
the class PSFCreator method plotCumulativeSignal.
/**
* Show a plot of the cumulative signal vs distance from the centre
*
* @param z
* The slice to plot
* @param normalise
* normalise the sum to 1
* @param resetScale
* Reset the y-axis maximum
* @param distanceThreshold
* The distance threshold for the cumulative total shown in the plot label
*/
private void plotCumulativeSignal(int z, boolean normalise, boolean resetScale, double distanceThreshold) {
float[] data = (float[]) psf.getProcessor(z).getPixels();
final int size = psf.getWidth();
if (indexLookup == null || indexLookup.length != data.length) {
// Precompute square distances
double[] d2 = new double[size];
for (int y = 0, y2 = -size / 2; y < size; y++, y2++) d2[y] = y2 * y2;
// Precompute distances
double[] d = new double[data.length];
for (int y = 0, i = 0; y < size; y++) {
for (int x = 0; x < size; x++, i++) {
d[i] = Math.sqrt(d2[y] + d2[x]);
}
}
// Sort
int[] indices = Utils.newArray(d.length, 0, 1);
Sort.sort(indices, d, true);
// The sort is made in descending order so invert
Sort.reverse(indices);
Sort.reverse(d);
// Store a unique cumulative index for each distance
double lastD = d[0];
int lastI = 0;
int counter = 0;
StoredData distance = new StoredData();
indexLookup = new int[indices.length];
for (int i = 0; i < indices.length; i++) {
if (lastD != d[i]) {
distance.add(lastD * psfNmPerPixel);
for (int j = lastI; j < i; j++) {
indexLookup[indices[j]] = counter;
}
lastD = d[i];
lastI = i;
counter++;
}
}
// Do the final distance
distance.add(lastD * psfNmPerPixel);
for (int j = lastI; j < indices.length; j++) {
indexLookup[indices[j]] = counter;
}
counter++;
distances = distance.getValues();
}
// Get the signal at each distance
double[] signal = new double[distances.length];
for (int i = 0; i < data.length; i++) {
if (data[i] > 0)
signal[indexLookup[i]] += data[i];
}
// Get the cumulative signal
for (int i = 1; i < signal.length; i++) signal[i] += signal[i - 1];
// Get the total up to the distance threshold
double sum = 0;
for (int i = 0; i < signal.length; i++) {
if (distances[i] > distanceThreshold)
break;
sum = signal[i];
}
if (normalise && distanceThreshold > 0) {
for (int i = 0; i < signal.length; i++) signal[i] /= sum;
}
if (resetScale)
maxCumulativeSignal = 0;
maxCumulativeSignal = Maths.maxDefault(maxCumulativeSignal, signal);
String title = "Cumulative Signal";
boolean alignWindows = (WindowManager.getFrame(title) == null);
Plot2 plot = new Plot2(title, "Distance (nm)", "Signal", distances, signal);
plot.setLimits(0, distances[distances.length - 1], 0, maxCumulativeSignal);
plot.addLabel(0, 0, String.format("Total = %s (@ %s nm). z = %s nm", Utils.rounded(sum), Utils.rounded(distanceThreshold), Utils.rounded((z - zCentre) * nmPerSlice)));
plot.setColor(Color.green);
plot.drawLine(distanceThreshold, 0, distanceThreshold, maxCumulativeSignal);
plot.setColor(Color.blue);
PlotWindow plotWindow = Utils.display(title, plot);
if (alignWindows && plotWindow != null) {
PlotWindow otherWindow = getPlot(TITLE_PSF_PARAMETERS);
if (otherWindow != null) {
// Put the two plots tiled together so both are visible
Point l = plotWindow.getLocation();
l.x = otherWindow.getLocation().x + otherWindow.getWidth();
l.y = otherWindow.getLocation().y + otherWindow.getHeight();
plotWindow.setLocation(l);
}
}
// Update the PSF to the correct slice
if (psfImp != null)
psfImp.setSlice(z);
}
use of gdsc.core.utils.StoredData in project GDSC-SMLM by aherbert.
the class CircularMeanFilter method getRadii.
/**
* Get the radii where different smoothing will be applied
*
* @param max
* The maximum radii to include
* @param increment
* The increment to use between radii
* @return The radiis where a different smoothing will be applied
*/
public static double[] getRadii(double max, double increment) {
StoredData radii = new StoredData();
double lastN = 0;
if (increment < 0)
increment = 0.1;
for (double r = 0.5; r <= max; r += increment) {
int nPoints = getNPoints(r);
if (nPoints > lastN)
radii.add(r);
lastN = nPoints;
}
return radii.getValues();
}
Aggregations