use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class ResequenceResults method run.
/*
* (non-)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
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");
return;
}
if (resequenceResults(results, start, block, skip, (logMapping) ? new IJTrackProgress() : null))
IJ.showStatus("Resequenced " + results.getName());
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class ResultsManager method loadInputResults.
/**
* Load the results from the named input option
*
* @param inputOption
* @param checkCalibration
* Set to true to ensure the results have a valid calibration
* @return
*/
public static MemoryPeakResults loadInputResults(String inputOption, boolean checkCalibration) {
MemoryPeakResults results = null;
PeakResultsReader reader = null;
if (inputOption.equals(INPUT_NONE)) {
} else if (inputOption.equals(INPUT_FILE)) {
IJ.showStatus("Reading results file ...");
reader = new PeakResultsReader(inputFilename);
IJ.showStatus("Reading " + reader.getFormat() + " results file ...");
ResultOption[] options = reader.getOptions();
if (options != null)
collectOptions(reader, options);
reader.setTracker(new IJTrackProgress());
results = reader.getResults();
reader.getTracker().progress(1.0);
if (results != null && results.size() > 0) {
// If the name contains a .tif suffix then create an image source
if (results.getName() != null && results.getName().contains(".tif") && results.getSource() == null) {
int index = results.getName().indexOf(".tif");
results.setSource(new IJImageSource(results.getName().substring(0, index)));
}
}
} else {
results = loadMemoryResults(inputOption);
}
if (results != null && results.size() > 0 && checkCalibration) {
if (!checkCalibration(results, reader))
results = null;
}
IJ.showStatus("");
return results;
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class ResultsManager method cropToRoi.
private MemoryPeakResults cropToRoi(MemoryPeakResults results) {
if (roiBounds == null)
return results;
// Adjust bounds relative to input results image
double xscale = roiImageWidth / results.getBounds().width;
double yscale = roiImageHeight / results.getBounds().height;
roiBounds.x /= xscale;
roiBounds.width /= xscale;
roiBounds.y /= yscale;
roiBounds.height /= yscale;
float minX = (int) (roiBounds.x);
float maxX = (int) Math.ceil(roiBounds.x + roiBounds.width);
float minY = (int) (roiBounds.y);
float maxY = (int) Math.ceil(roiBounds.y + roiBounds.height);
// Create a new set of results within the bounds
MemoryPeakResults newResults = new MemoryPeakResults();
newResults.begin();
for (PeakResult peakResult : results.getResults()) {
float x = peakResult.params[Gaussian2DFunction.X_POSITION];
float y = peakResult.params[Gaussian2DFunction.Y_POSITION];
if (x < minX || x > maxX || y < minY || y > maxY)
continue;
newResults.add(peakResult);
}
newResults.end();
newResults.copySettings(results);
newResults.setBounds(new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY)));
return newResults;
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class PeakFit method showResults.
protected void showResults() {
IJ.showProgress(1.0);
if (time >= 0) {
if (silent) {
results.end();
return;
}
// Check if we are sorting
IJ.showStatus("Finalising results ...");
for (PeakResults r : results.toArray()) if (r instanceof MemoryPeakResults) {
if (((MemoryPeakResults) r).isSortAfterEnd())
IJ.showStatus("Sorting " + r.size() + " results ...");
break;
}
results.end();
String textTime = Utils.timeToString(time / 1000000.0);
String textRunTime = Utils.timeToString(runTime / 1000000.0);
int size = getSize();
String message = String.format("%s. Fitting Time = %s. Run time = %s", Utils.pleural(size, "localisation"), textTime, textRunTime);
if (resultsSettings.logProgress)
IJ.log("-=-=-=-");
IJ.log(message);
IJ.showStatus(message);
} else {
IJ.showStatus("");
}
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class PulseActivationAnalysis method runSimulation.
private void runSimulation() {
TITLE += " Simulation";
if (!showSimulationDialog())
return;
long start = System.currentTimeMillis();
RandomDataGenerator rdg = getRandomDataGenerator();
// Draw the molecule positions
Utils.showStatus("Simulating molecules ...");
float[][][] molecules = new float[3][][];
MemoryPeakResults[] results = new MemoryPeakResults[3];
Rectangle bounds = new Rectangle(0, 0, sim_size, sim_size);
for (int c = 0; c < 3; c++) {
molecules[c] = simulateMolecules(rdg, c);
// Create a dataset to store the activations
MemoryPeakResults r = new MemoryPeakResults();
r.setCalibration(new Calibration(sim_nmPerPixel, 1, 100));
r.setBounds(bounds);
r.setName(TITLE + " C" + (c + 1));
results[c] = r;
}
// Simulate activation
Utils.showStatus("Simulating activations ...");
for (int c = 0; c < 3; c++) simulateActivations(rdg, molecules, c, results);
// Combine
Utils.showStatus("Producing simulation output ...");
MemoryPeakResults r = new MemoryPeakResults();
r.setCalibration(new Calibration(sim_nmPerPixel, 1, 100));
r.setBounds(new Rectangle(0, 0, sim_size, sim_size));
r.setName(TITLE);
ImageProcessor[] images = new ImageProcessor[3];
for (int c = 0; c < 3; c++) {
ArrayList<PeakResult> list = (ArrayList<PeakResult>) results[c].getResults();
r.addAllf(list);
// Draw the unmixed activations
IJImagePeakResults image = ImagePeakResultsFactory.createPeakResultsImage(ResultsImage.LOCALISATIONS, true, true, TITLE, bounds, sim_nmPerPixel, 1, 1024.0 / sim_size, 0, ResultsMode.ADD);
image.setLiveImage(false);
image.setDisplayImage(false);
image.begin();
image.addAll(list);
image.end();
images[c] = image.getImagePlus().getProcessor();
}
displayComposite(images, TITLE);
// Add to memory. Set the composite dataset first.
MemoryPeakResults.addResults(r);
for (int c = 0; c < 3; c++) MemoryPeakResults.addResults(results[c]);
// TODO:
// Show an image of what it looks like with no unmixing, i.e. colours allocated
// from the frame
Utils.showStatus("Simulation complete: " + Utils.timeToString(System.currentTimeMillis() - start));
}
Aggregations