use of uk.ac.sussex.gdsc.smlm.results.PeakResultsList in project GDSC-SMLM by aherbert.
the class PeakFit method createFitEngine.
/**
* Creates a fitting engine using the current configuration.
*
* @param numberOfThreads the number of threads
* @param queue the queue
* @param queueSize the queue size
* @return The fiting engine
*/
public FitEngine createFitEngine(int numberOfThreads, FitQueue queue, int queueSize) {
// Ensure thread safety
final PeakResultsList list = (numberOfThreads > 1) ? results.getThreadSafeList() : results;
// Reduce to single object for speed
final PeakResults r = (results.numberOfOutputs() == 1) ? list.toArray()[0] : list;
// Update the configuration
if (!updateFitConfiguration(config)) {
return null;
}
final FitEngine engine = FitEngine.create(config, r, numberOfThreads, queue, queueSize);
// Write settings out to the IJ log
if (resultsSettings.getLogProgress()) {
IJ.log(LOG_SPACER);
IJ.log("Peak Fit");
IJ.log(LOG_SPACER);
ImageJUtils.log("Initial Peak SD = %s,%s", MathUtils.rounded(fitConfig.getInitialXSd()), MathUtils.rounded(fitConfig.getInitialYSd()));
final SpotFilter spotFilter = engine.getSpotFilter();
IJ.log("Spot Filter = " + spotFilter.getDescription());
final int w = 2 * engine.getFitting() + 1;
ImageJUtils.log("Fit window = %d x %d", w, w);
if (!fitConfig.isDisableSimpleFilter()) {
IJ.log("Coordinate shift = " + MathUtils.rounded(config.getFitConfiguration().getCoordinateShift()));
IJ.log("Signal strength = " + MathUtils.rounded(fitConfig.getSignalStrength()));
}
if (fitConfig.isDirectFilter()) {
IJ.log("Smart filter = " + fitConfig.getSmartFilter().getDescription());
}
if (extraOptions) {
IJ.log("Noise = " + MathUtils.rounded(fitConfig.getNoise()));
}
IJ.log("Width factor = " + MathUtils.rounded(fitConfig.getMaxWidthFactor()));
IJ.log(LOG_SPACER);
}
return engine;
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResultsList in project GDSC-SMLM by aherbert.
the class TcPalmAnalysis method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "No localisations in memory");
return;
}
// Only allow 1 instance to run
if (!instanceLock.acquire()) {
final Window w = WindowManager.getWindow(TITLE);
if (w != null) {
w.toFront();
return;
}
// Fall through to allow the plugin to run. This may still have concurrency issues if
// another version is running but the window is not currently showing/registered with
// the window manager. Perhaps show a dialog asking to continue.
}
if (!showDialog()) {
instanceLock.release();
return;
}
// Load the results
results = ResultsManager.loadInputResults(settings.getInputOption(), false, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
instanceLock.release();
return;
}
// Allocate singles an id for analysis.
results = results.copyAndAssignZeroIds();
dataCalibration = new DataCalibration(results.getCalibration());
// Show a super-resolution image where clusters can be selected.
final Rectangle bounds = results.getBounds(true);
final PeakResultsList resultsList = new PeakResultsList();
resultsList.copySettings(results);
ResultsManager.addImageResults(resultsList, settings.getResultsImageSettings(), bounds, 0);
resultsList.begin();
resultsList.addAll(results.toArray());
resultsList.end();
image = (ImageJImagePeakResults) resultsList.getOutput(0);
// Note: Setting the lut name in the image only has an effect if the image is not showing
// thus the lut is applied afterwards.
final ImagePlus imp = image.getImagePlus();
if (TextUtils.isNotEmpty(image.getLutName())) {
imp.setLut(LutHelper.createLut(LutColour.forName(image.getLutName()), true));
}
// Set-up analysis processing:
// Store latest image ROI bounds and analysis settings.
// ConcurrentMonoStack to store next image ROI bounds and analysis settings.
// When image is clicked submit for analysis.
// When settings are changed submit for analysis.
// Submit for analysis checks if ROI is area ROI. if so it:
// - adds current settings to the next analysis monostack
// - acquires a softlock and if available submits a runnable to do the analysis until
// the monostack is empty
lock = new SoftLock();
workQueue = new ConcurrentMonoStack<>();
// Use the current ROI (which may remain from previous plugin execution)
previous = new Work(0, imp.getRoi(), settings.build());
executor = Executors.newSingleThreadExecutor();
// Create the bounds and activation times for each cluster
clusterData = createClusterData(results);
// Add interactive monitor to the image where clusters can be selected.
// For all selected clusters show on an Activations-vs-Time plot.
final RoiListener roiListener = new RoiListener() {
@Override
public void roiModified(ImagePlus imp2, int id) {
if (imp2 != null && imp.getID() == imp2.getID()) {
addWork(imp.getRoi());
}
}
};
Roi.addRoiListener(roiListener);
// Add monitor for the selection of clusters in the current clusters table
clusterSelectedListener = new ClusterSelectedListener();
// Initialise the loop view
loopImage = new LoopImage().setSettings(previous.settings).setColourMap(colourMap);
// steepness parameter: local window size (sec) and activation rate (per sec)
try {
showAnalysisDialog();
} finally {
Roi.removeRoiListener(roiListener);
// Remove the action from the single instance of the current clusters table
removeListener(currentGroupsTable.get());
removeListener(currentClustersTable.get());
removeListener(allClustersTable.get());
executor.shutdown();
instanceLock.release();
SettingsManager.writeSettings(settings);
}
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResultsList in project GDSC-SMLM by aherbert.
the class ResultsManager method run.
@Override
public void run(String arg) {
extraOptions = ImageJUtils.isExtraOptions();
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if ("load".equals(arg)) {
batchLoad();
return;
}
if ("save".equals(arg)) {
batchSave();
return;
}
if (StringUtils.startsWith(arg, "clear")) {
runClearMemory(arg);
return;
}
if (!showDialog()) {
return;
}
final MemoryPeakResults results = loadResults(settings.inputOption);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return;
}
IJ.showStatus("Loaded " + TextUtils.pleural(results.size(), "result"));
boolean saved = false;
if (resultsSettings.getResultsInMemorySettings().getInMemory() && fileInput) {
if (!addResultsToMemory(results, settings.inputFilename)) {
IJ.showStatus("");
return;
}
saved = true;
}
if (resultsSettings.getResultsTableSettings().getResultsTableFormatValue() <= 0 && resultsSettings.getResultsImageSettings().getImageTypeValue() <= 0 && TextUtils.isNullOrEmpty(resultsSettings.getResultsFileSettings().getResultsFilename())) {
// No outputs. Error if results were not saved to memory
if (!saved) {
IJ.error(TITLE, "No output selected");
}
return;
}
final Rectangle bounds = results.getBounds(true);
final boolean showDeviations = resultsSettings.getShowDeviations() && canShowDeviations(results);
final boolean showEndFrame = canShowEndFrame(results);
final boolean showId = canShowId(results);
final boolean showCategory = canShowCategory(results);
// Display the configured output
final PeakResultsList outputList = new PeakResultsList();
outputList.copySettings(results);
final int tableFormat = resultsSettings.getResultsTableSettings().getResultsTableFormatValue();
if (tableFormat == ResultsTableFormat.IMAGEJ_VALUE) {
addImageJTableResults(outputList, resultsSettings.getResultsTableSettings(), showDeviations, showEndFrame, results.is3D(), showId, showCategory);
} else if (tableFormat == ResultsTableFormat.INTERACTIVE_VALUE) {
showInteractiveTable(results, resultsSettings.getResultsTableSettings());
}
addImageResults(outputList, resultsSettings.getResultsImageSettings(), bounds, (extraOptions) ? FLAG_EXTRA_OPTIONS : 0);
addFileResults(outputList, showDeviations, showEndFrame, showId, showCategory);
if (outputList.numberOfOutputs() == 0) {
// This occurs when only using the interactive table
IJ.showStatus("Processed " + TextUtils.pleural(results.size(), "result"));
return;
}
IJ.showStatus("Processing outputs ...");
// Reduce to single object for speed
final PeakResults output = (outputList.numberOfOutputs() == 1) ? outputList.toArray()[0] : outputList;
output.begin();
// Note: We could add a batch iterator to the MemoryPeakResults.
// However the speed increase will be marginal as the main time
// taken is in processing the outputs.
// Process in batches to provide progress
final Counter progress = new Counter();
final int totalProgress = results.size();
final int batchSize = Math.max(100, totalProgress / 10);
final FixedPeakResultList batch = new FixedPeakResultList(batchSize);
IJ.showProgress(0);
results.forEach((PeakResultProcedureX) result -> {
batch.add(result);
if (batch.size == batchSize) {
if (IJ.escapePressed()) {
batch.clear();
return true;
}
output.addAll(batch.results);
batch.clear();
IJ.showProgress(progress.incrementAndGet(batchSize), totalProgress);
}
return false;
});
// Will be empty if interrupted
if (batch.isNotEmpty()) {
output.addAll(batch.toArray());
}
IJ.showProgress(1);
output.end();
if (output.size() == results.size()) {
IJ.showStatus("Processed " + TextUtils.pleural(results.size(), "result"));
} else {
IJ.showStatus(String.format("A %d/%s", output.size(), TextUtils.pleural(results.size(), "result")));
}
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResultsList in project GDSC-SMLM by aherbert.
the class PeakFit method initialiseImage.
/**
* Initialise a new image.
*
* <p>Does not set-up for fitting. This can be done using a subsequent call to
* {@link #initialiseFitting()}.
*
* <p>This mechanism allows additional result outputs to be added after initialisation using
* {@link #addPeakResults(PeakResults)}.
*
* @param imageSource The image source
* @param bounds The region to process from the image
* @param ignoreBoundsForNoise Set to true if the bounds should be ignored when computing the
* noise estimate for each frame
* @return True if the image was valid and the initialisation was successful
*/
public boolean initialiseImage(ImageSource imageSource, Rectangle bounds, boolean ignoreBoundsForNoise) {
// Initialise for image processing
if (!setSource(imageSource)) {
return false;
}
if (bounds == null) {
// No region so no need to ignore the bounds.
this.bounds = new Rectangle(0, 0, source.getWidth(), source.getHeight());
this.ignoreBoundsForNoise = false;
} else {
// The bounds must fit in the image
try {
imageSource.checkBounds(bounds);
} catch (final IllegalArgumentException ex) {
return false;
}
this.bounds = bounds;
this.ignoreBoundsForNoise = ignoreBoundsForNoise;
}
results = new PeakResultsList();
time = 0;
return true;
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResultsList in project GDSC-SMLM by aherbert.
the class PulseActivationAnalysis method createOutput.
private PeakResultsList createOutput(int channel) {
final PeakResultsList outputList = new PeakResultsList();
outputList.copySettings(results);
if (settings.channels > 1) {
outputList.setName(results.getName() + " " + title + " C" + channel);
} else {
outputList.setName(results.getName() + " " + title);
}
// Store the set in memory
final MemoryPeakResults memoryResults = new MemoryPeakResults(this.results.size());
outputList.addOutput(memoryResults);
MemoryPeakResults.addResults(memoryResults);
// Draw the super-resolution image
final Rectangle bounds = results.getBounds(true);
addImageResults(outputList, results.getName(), bounds, results.getNmPerPixel(), resultsSettingsBuilder.getResultsImageSettings());
outputList.begin();
return outputList;
}
Aggregations