use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class FilterAnalysis method readResults.
private List<MemoryPeakResults> readResults() {
if (resultsList != null && inputDirectory.equals(lastInputDirectory)) {
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Re-use results from the same directory (no to refresh)?");
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.showDialog();
if (gd.wasOKed())
return resultsList;
}
List<MemoryPeakResults> resultsList = new LinkedList<MemoryPeakResults>();
File[] fileList = (new File(inputDirectory)).listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return (name.endsWith(".xls") || name.endsWith(".csv") || name.endsWith(".bin"));
}
});
if (fileList != null) {
// Exclude directories
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].isFile()) {
IJ.showStatus(String.format("Reading results ... %d/%d", i + 1, fileList.length));
IJ.showProgress(i, fileList.length);
PeakResultsReader reader = new PeakResultsReader(fileList[i].getPath());
MemoryPeakResults results = reader.getResults();
if (results != null && results.size() > 0) {
resultsList.add(results);
}
}
}
}
IJ.showStatus("");
IJ.showProgress(1);
lastInputDirectory = inputDirectory;
return resultsList;
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class DriftCalculator method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
// Require some fit results and selected regions
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
Roi[] rois = getRois();
String[] stackTitles = createStackImageList();
if (!showDialog(rois, stackTitles))
return;
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() < 2) {
IJ.error(TITLE, "There are not enough fitting results for drift correction");
return;
}
double[][] drift = null;
int[] limits = findTimeLimits(results);
if (method.equals(MARKED_ROIS)) {
drift = calculateUsingMarkers(results, limits, rois);
} else if (method.equals(STACK_ALIGNMENT)) {
ImageStack stack = showStackDialog(stackTitles);
if (stack == null)
return;
drift = calculateUsingImageStack(stack, limits);
} else if (method.equals(DRIFT_FILE)) {
drift = calculateUsingDriftFile(limits);
} else {
if (!showSubImageDialog())
return;
drift = calculateUsingFrames(results, limits, Integer.parseInt(reconstructionSize));
}
if (drift == null)
return;
Utils.log("Drift correction interpolated for frames [%d - %d] of [%d - %d] (%s%%)", interpolationStart, interpolationEnd, limits[0], limits[1], Utils.rounded((100.0 * (interpolationEnd - interpolationStart + 1)) / (limits[1] - limits[0] + 1)));
applyDriftCorrection(results, drift);
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class CropResults method cropResults.
/**
* Apply the filters to the data
*/
private void cropResults() {
MemoryPeakResults newResults = new MemoryPeakResults();
// These bounds are integer. But this is because the results are meant to come from an image.
Rectangle bounds = results.getBounds(true);
// The crop bounds can be floating point...
// Border
double xx = bounds.x + border;
double yy = bounds.y + border;
double w = Math.max(0, bounds.width - 2 * border);
double h = Math.max(0, bounds.height - 2 * border);
Rectangle2D borderBounds = new Rectangle2D.Double(xx, yy, w, h);
// Bounding box
if (selectRegion) {
Rectangle2D boxBounds = new Rectangle2D.Double(x, y, width, height);
borderBounds = borderBounds.createIntersection(boxBounds);
}
// and create another intersection
if (myUseRoi) {
ImagePlus imp = WindowManager.getImage(roiImage);
if (imp != null && imp.getRoi() != null) {
Rectangle roi = imp.getRoi().getBounds();
int roiImageWidth = imp.getWidth();
int roiImageHeight = imp.getHeight();
double xscale = (double) roiImageWidth / bounds.width;
double yscale = (double) roiImageHeight / bounds.height;
Rectangle2D roiBounds = new Rectangle2D.Double(roi.x / xscale, roi.y / yscale, roi.width / xscale, roi.height / yscale);
borderBounds = borderBounds.createIntersection(roiBounds);
}
}
if (borderBounds.getWidth() > 0 && borderBounds.getHeight() > 0) {
for (PeakResult result : results.getResults()) {
if (borderBounds.contains(result.getXPosition(), result.getYPosition()))
newResults.add(result);
}
}
newResults.copySettings(results);
newResults.setBounds(new Rectangle((int) Math.floor(borderBounds.getX()), (int) Math.floor(borderBounds.getY()), (int) Math.ceil(borderBounds.getWidth()), (int) Math.ceil(borderBounds.getHeight())));
if (!overwrite) {
newResults.setName(results.getName() + " Cropped");
}
MemoryPeakResults.addResults(newResults);
IJ.showStatus(newResults.size() + " Cropped localisations");
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class DarkTimeAnalysis method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
// Require some fit results and selected regions
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
if (!showDialog())
return;
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, true);
if (results == null || results.size() == 0) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return;
}
msPerFrame = results.getCalibration().getExposureTime();
Utils.log("%s: %d localisations", TITLE, results.size());
if (results.size() == 0) {
IJ.error(TITLE, "No results were loaded");
return;
}
analyse(results);
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method aggregateIntoFrames.
private void aggregateIntoFrames(ArrayList<Point> points, boolean addError, double precisionInPixels, RandomGenerator[] random) {
if (myAggregateSteps < 1)
return;
MemoryPeakResults results = new MemoryPeakResults(points.size() / myAggregateSteps);
Calibration cal = new Calibration(settings.pixelPitch, 1, myAggregateSteps * 1000.0 / settings.stepsPerSecond);
results.setCalibration(cal);
results.setName(TITLE + " Aggregated");
MemoryPeakResults.addResults(results);
lastSimulatedDataset[1] = results.getName();
int id = 0;
int peak = 1;
int n = 0;
double cx = 0, cy = 0;
// Get the mean square distance
double sum = 0;
int count = 0;
PeakResult last = null;
for (Point result : points) {
final boolean newId = result.id != id;
if (n >= myAggregateSteps || newId) {
if (n != 0) {
final float[] params = new float[7];
double[] xyz = new double[] { cx / n, cy / n };
if (addError)
xyz = addError(xyz, precisionInPixels, random);
params[Gaussian2DFunction.X_POSITION] = (float) xyz[0];
params[Gaussian2DFunction.Y_POSITION] = (float) xyz[1];
params[Gaussian2DFunction.SIGNAL] = n;
params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = 1;
final float noise = 0.1f;
PeakResult r = new ExtendedPeakResult(peak, (int) params[Gaussian2DFunction.X_POSITION], (int) params[Gaussian2DFunction.Y_POSITION], n, 0, noise, params, null, peak, id);
results.add(r);
if (last != null) {
sum += last.distance2(r);
count++;
}
last = r;
n = 0;
cx = cy = 0;
peak++;
}
if (newId) {
// Increment the frame so that tracing analysis can distinguish traces
peak++;
last = null;
id = result.id;
}
}
n++;
cx += result.x;
cy += result.y;
}
// Final peak
if (n != 0) {
final float[] params = new float[7];
double[] xyz = new double[] { cx / n, cy / n };
if (addError)
xyz = addError(xyz, precisionInPixels, random);
params[Gaussian2DFunction.X_POSITION] = (float) xyz[0];
params[Gaussian2DFunction.Y_POSITION] = (float) xyz[1];
params[Gaussian2DFunction.SIGNAL] = n;
params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = 1;
final float noise = 0.1f;
PeakResult r = new ExtendedPeakResult(peak, (int) params[Gaussian2DFunction.X_POSITION], (int) params[Gaussian2DFunction.Y_POSITION], n, 0, noise, params, null, peak, id);
results.add(r);
if (last != null) {
sum += last.distance2(r);
count++;
}
}
// MSD in pixels^2 / frame
double msd = sum / count;
// Convert to um^2/second
Utils.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", Utils.rounded(settings.diffusionRate), Utils.rounded(myPrecision), count, Utils.rounded(results.getCalibration().getExposureTime() / 1000), Utils.rounded(msd / conversionFactor), Utils.rounded((msd / conversionFactor) / (results.getCalibration().getExposureTime() / 1000)));
msdAnalysis(points);
}
Aggregations