use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class SummariseResults method addSummary.
private void addSummary(StringBuilder sb, MemoryPeakResults result) {
DescriptiveStatistics[] stats = new DescriptiveStatistics[2];
char[] suffix = new char[2];
for (int i = 0; i < stats.length; i++) {
stats[i] = new DescriptiveStatistics();
suffix[i] = 0;
}
if (result.hasNullResults()) {
IJ.log("Null results in dataset: " + result.getName());
if (removeNullResults == UNKNOWN) {
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("There are invalid results in memory.\n \nClean these results?");
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.showDialog();
removeNullResults = (gd.wasOKed()) ? YES : NO;
}
if (removeNullResults == NO)
result = result.copy();
result.removeNullResults();
}
final int size = result.size();
if (size > 0) {
// Check if we can use the stored precision
if (result.hasStoredPrecision()) {
suffix[0] = '*';
for (PeakResult peakResult : result.getResults()) {
stats[0].addValue(peakResult.getPrecision());
}
} else if (result.isCalibratedForPrecision()) {
final double nmPerPixel = result.getNmPerPixel();
final double gain = result.getGain();
final boolean emCCD = result.isEMCCD();
for (PeakResult peakResult : result.getResults()) {
stats[0].addValue(peakResult.getPrecision(nmPerPixel, gain, emCCD));
}
}
// SNR requires noise
if (result.getHead().noise > 0) {
for (PeakResult peakResult : result.getResults()) {
stats[1].addValue(peakResult.getSignal() / peakResult.noise);
}
}
}
sb.append(result.getName());
sb.append("\t").append(result.size());
int maxT = getMaxT(result);
sb.append("\t").append(maxT);
final double exposureTime = (result.getCalibration() != null) ? result.getCalibration().getExposureTime() : 0;
sb.append("\t").append(Utils.timeToString(maxT * exposureTime));
if (size > 0) {
boolean includeDeviations = result.getHead().paramsStdDev != null;
long memorySize = MemoryPeakResults.estimateMemorySize(size, includeDeviations);
String memory = MemoryPeakResults.memorySizeString(memorySize);
sb.append("\t").append(memory);
} else {
sb.append("\t-");
}
Rectangle bounds = result.getBounds(true);
sb.append(String.format("\t%d,%d,%d,%d\t%s\t%s\t%s", bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, Utils.rounded(result.getNmPerPixel(), 4), Utils.rounded(result.getGain(), 4), Utils.rounded(exposureTime, 4)));
for (int i = 0; i < stats.length; i++) {
if (Double.isNaN(stats[i].getMean())) {
sb.append("\t-\t-\t-\t-");
} else {
sb.append("\t").append(IJ.d2s(stats[i].getMean(), 3));
if (suffix[i] != 0)
sb.append(suffix[i]);
sb.append("\t").append(IJ.d2s(stats[i].getPercentile(50), 3));
sb.append("\t").append(IJ.d2s(stats[i].getMin(), 3));
sb.append("\t").append(IJ.d2s(stats[i].getMax(), 3));
}
}
sb.append("\n");
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class SpotAnalysis method saveSpot.
private void saveSpot() {
if (onFrames.isEmpty() || !updated)
return;
createResultsWindow();
id++;
double signal = 0;
Trace trace = null;
float psfWidth = Float.parseFloat(widthTextField.getText());
float cx = areaBounds.x + areaBounds.width / 2.0f;
float cy = areaBounds.y + areaBounds.height / 2.0f;
for (Spot s : onFrames) {
// Get the signal again since the background may have changed.
final double spotSignal = getSignal(s.frame);
signal += spotSignal;
//signal += s.signal;
float[] params = new float[7];
params[Gaussian2DFunction.X_POSITION] = cx;
params[Gaussian2DFunction.Y_POSITION] = cy;
params[Gaussian2DFunction.SIGNAL] = (float) (spotSignal);
params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = psfWidth;
PeakResult result = new PeakResult(s.frame, (int) cx, (int) cy, 0, 0, 0, params, null);
if (trace == null)
trace = new Trace(result);
else
trace.add(result);
}
Statistics tOn = new Statistics(trace.getOnTimes());
Statistics tOff = new Statistics(trace.getOffTimes());
resultsWindow.append(String.format("%d\t%.1f\t%.1f\t%s\t%s\t%s\t%d\t%s\t%s\t%s", id, cx, cy, Utils.rounded(signal, 4), Utils.rounded(tOn.getSum() * msPerFrame, 3), Utils.rounded(tOff.getSum() * msPerFrame, 3), trace.getNBlinks() - 1, Utils.rounded(tOn.getMean() * msPerFrame, 3), Utils.rounded(tOff.getMean() * msPerFrame, 3), imp.getTitle()));
// Save the individual on/off times for use in creating a histogram
traces.put(id, trace);
updated = false;
//clearSelectedFrames();
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class PeakFit method runMaximaFitting.
/**
* Load the selected results from memory. All multiple frame results are added directly to the results. All single
* frame
* results are added to a list of candidate maxima per frame and fitted using the configured parameters.
*/
private void runMaximaFitting() {
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() == 0) {
log("No results for maxima fitting");
return;
}
// No check for imageSource since this has been check in the calling method
int totalFrames = source.getFrames();
// Store the indices of each new time-frame
results.sort();
List<PeakResult> candidateMaxima = results.getResults();
// Use the FitEngine to allow multi-threading.
FitEngine engine = createFitEngine(getNumberOfThreads(totalFrames));
final int step = Utils.getProgressInterval(totalFrames);
runTime = System.nanoTime();
boolean shutdown = false;
int slice = candidateMaxima.get(0).getFrame();
ArrayList<PeakResult> sliceCandidates = new ArrayList<PeakResult>();
Iterator<PeakResult> iter = candidateMaxima.iterator();
while (iter.hasNext()) {
PeakResult r = iter.next();
if (slice != r.getFrame()) {
if (escapePressed()) {
shutdown = true;
break;
}
if (slice % step == 0) {
if (Utils.showStatus("Slice: " + slice + " / " + totalFrames))
IJ.showProgress(slice, totalFrames);
}
// Process results
if (!processResults(engine, sliceCandidates, slice))
break;
sliceCandidates.clear();
}
slice = r.getFrame();
sliceCandidates.add(r);
}
// Process final results
if (!shutdown)
processResults(engine, sliceCandidates, slice);
engine.end(shutdown);
time = engine.getTime();
runTime = System.nanoTime() - runTime;
showResults();
source.close();
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class Filter method fractionScoreSubset.
/**
* Filter the results and return the performance score. Allows benchmarking the filter by marking the results as
* true or false.
* <p>
* Input PeakResults must be allocated a score for true positive, false positive, true negative and false negative
* (accessed via the object property get methods). The filter is run and results that pass accumulate scores for
* true positive and false positive, otherwise the scores are accumulated for true negative and false negative. The
* simplest scoring scheme is to mark valid results as tp=fn=1 and fp=tn=0 and invalid results the opposite.
* <p>
* The number of consecutive rejections are counted per frame. When the configured number of failures is reached all
* remaining results for the frame are rejected. This assumes the results are ordered by the frame.
* <p>
* Note that this method is to be used to score a subset that was generated using
* {@link #filterSubset(MemoryPeakResults, int)} since the number of consecutive failures before each peak are
* expected to be stored in the origX property.
*
* @param resultsList
* a list of results to analyse
* @param failures
* the number of failures to allow per frame before all peaks are rejected
* @param tn
* The initial true negatives (used when the results have been pre-filtered)
* @param fn
* The initial false negatives (used when the results have been pre-filtered)
* @param n
* The initial negatives (used when the results have been pre-filtered)
* @return the score
*/
public FractionClassificationResult fractionScoreSubset(List<MemoryPeakResults> resultsList, int failures, double tn, double fn, int n) {
int p = 0;
double fp = 0;
double tp = 0;
for (MemoryPeakResults peakResults : resultsList) {
setup(peakResults);
int frame = -1;
int failCount = 0;
for (PeakResult peak : peakResults.getResults()) {
// Reset fail count for new frames
if (frame != peak.getFrame()) {
frame = peak.getFrame();
failCount = 0;
}
failCount += peak.origX;
// Reject all peaks if we have exceeded the fail count
final boolean isPositive;
if (failCount > failures) {
isPositive = false;
} else {
// Otherwise assess the peak
isPositive = accept(peak);
}
if (isPositive) {
failCount = 0;
} else {
failCount++;
}
if (isPositive) {
p++;
tp += peak.getTruePositiveScore();
fp += peak.getFalsePositiveScore();
} else {
fn += peak.getFalseNegativeScore();
tn += peak.getTrueNegativeScore();
}
}
n += peakResults.size();
end();
}
n -= p;
return new FractionClassificationResult(tp, fp, tn, fn, p, n);
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class Filter method filter.
/**
* Filter the results
*
* @param results
* @return the filtered results
*/
public MemoryPeakResults filter(MemoryPeakResults results) {
MemoryPeakResults newResults = new MemoryPeakResults();
newResults.copySettings(results);
setup(results);
for (PeakResult peak : results.getResults()) {
if (accept(peak))
newResults.add(peak);
}
end();
return newResults;
}
Aggregations