use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TrackPopulationAnalysis method showInputDialog.
private boolean showInputDialog(List<MemoryPeakResults> combinedResults) {
// Show a list box containing all the clustered results.
// This should remember the last set of chosen items.
final MultiDialog md = ResultsManager.createMultiDialog(TITLE, MemoryPeakResults::hasId);
md.setSelected(settings.input);
md.setHelpUrl(HelpUrls.getUrl("track-population-analysis"));
md.showDialog();
if (md.wasCancelled()) {
return false;
}
final List<String> selected = md.getSelectedResults();
if (selected.isEmpty()) {
IJ.error(TITLE, "No results were selected");
return false;
}
settings.input = selected;
for (final String name : selected) {
final MemoryPeakResults r = MemoryPeakResults.getResults(name);
if (r != null) {
combinedResults.add(r);
}
}
// Check calibration exists for the first set of results
if (combinedResults.isEmpty() || !checkCalibration(combinedResults.get(0))) {
return false;
}
// Check the calibration is the same for the rest
final CalibrationReader cal = combinedResults.get(0).getCalibrationReader();
final double nmPerPixel = cal.getNmPerPixel();
final double exposureTime = cal.getExposureTime();
final DistanceUnit distanceUnit = cal.getDistanceUnit();
for (int i = 1; i < combinedResults.size(); i++) {
final MemoryPeakResults results = combinedResults.get(i);
if (!results.hasCalibration() || results.getCalibrationReader().getExposureTime() != exposureTime || results.getNmPerPixel() != nmPerPixel || results.getDistanceUnit() != distanceUnit) {
IJ.error(TITLE, "The exposure time, pixel pitch and distance unit must match across all the results");
return false;
}
}
return true;
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TranslateResults method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
final TranslateResultsSettings.Builder settings = SettingsManager.readTranslateResultsSettings(0).toBuilder();
// Show a dialog allowing the results set to be filtered
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select a dataset to translate");
ResultsManager.addInput(gd, settings.getInputOption(), InputSource.MEMORY);
gd.addNumericField("x", settings.getDx(), 3);
gd.addNumericField("y", settings.getDy(), 3);
gd.addNumericField("z", settings.getDz(), 3);
gd.addChoice("Distance_unit", SettingsManager.getDistanceUnitNames(), settings.getDistanceUnitValue());
gd.addHelp(HelpUrls.getUrl("translate-results"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
settings.setInputOption(ResultsManager.getInputSource(gd));
settings.setDx(gd.getNextNumber());
settings.setDy(gd.getNextNumber());
settings.setDz(gd.getNextNumber());
settings.setDistanceUnitValue(gd.getNextChoiceIndex());
SettingsManager.writeSettings(settings);
final MemoryPeakResults results = ResultsManager.loadInputResults(settings.getInputOption(), false, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
return;
}
TypeConverter<DistanceUnit> converter;
try {
converter = results.getDistanceConverter(settings.getDistanceUnit());
} catch (final DataException ex) {
IJ.error(TITLE, "Unit conversion error: " + ex.getMessage());
return;
}
final float x = (float) converter.convertBack(settings.getDx());
final float y = (float) converter.convertBack(settings.getDy());
final float z = (float) converter.convertBack(settings.getDz());
// Reset the 2D bounds
if (x != 0 || y != 0) {
results.setBounds(null);
}
results.forEach((PeakResultProcedure) peakResult -> {
final float[] params = peakResult.getParameters();
params[PeakResult.X] += x;
params[PeakResult.Y] += y;
params[PeakResult.Z] += z;
});
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceMolecules method convertToClusterPoints.
/**
* Convert a list of peak results into points for the clustering engine.
*
* @param results the results
* @return the list of clusters
*/
public static List<ClusterPoint> convertToClusterPoints(MemoryPeakResults results) {
final ArrayList<ClusterPoint> points = new ArrayList<>(results.size());
final Counter counter = new Counter();
results.forEach((PeakResultProcedure) result -> points.add(ClusterPoint.newTimeClusterPoint(counter.getAndIncrement(), result.getXPosition(), result.getYPosition(), result.getIntensity(), result.getFrame(), result.getEndFrame())));
return points;
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class SpotAnalysis method saveTraces.
private void saveTraces() {
if (!onFrames.isEmpty() && updated) {
final GenericDialog gd = new GenericDialog(PLUGIN_TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage("The list contains unsaved selected frames.\n \nDo you want to continue?");
gd.showDialog();
if (!gd.wasOKed()) {
return;
}
}
// For all spots in the results window, get the ID and then save the traces to memory
if (!ImageJUtils.isShowing(resultsWindow)) {
return;
}
// Create a results set in memory
final MemoryPeakResults results = new MemoryPeakResults();
results.setName(PLUGIN_TITLE);
results.begin();
MemoryPeakResults.addResults(results);
final ArrayList<TraceResult> traceResults = new ArrayList<>(resultsWindow.getTextPanel().getLineCount());
for (int i = 0; i < resultsWindow.getTextPanel().getLineCount(); i++) {
final String line = resultsWindow.getTextPanel().getLine(i);
try (Scanner s = new Scanner(line)) {
s.useDelimiter("\t");
int id = -1;
double signal = -1;
// Be careful as the text panel may not contain what we expect, i.e. empty lines, etc
if (s.hasNextInt()) {
id = s.nextInt();
try {
// cx
s.nextDouble();
// cy
s.nextDouble();
signal = s.nextDouble();
} catch (final NoSuchElementException ex) {
// Ignore
}
}
if (id != -1 && signal != -1) {
final Trace trace = traces.get(id);
if (trace != null) {
results.addAll(trace.getPoints());
traceResults.add(new TraceResult(new Spot(id, signal), trace));
}
}
}
}
results.end();
saveTracesToFile(traceResults);
IJ.showStatus("Saved traces");
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class SpotAnalysis method addCandidateFrames.
private void addCandidateFrames(String title) {
for (final MemoryPeakResults r : MemoryPeakResults.getAllResults()) {
if (r.getSource() instanceof IJImageSource && r.getSource().getName().equals(title)) {
final float minx = areaBounds.x;
final float maxx = minx + areaBounds.width;
final float miny = areaBounds.y;
final float maxy = miny + areaBounds.height;
r.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
if (result.getXPosition() >= minx && result.getXPosition() <= maxx && result.getYPosition() >= miny && result.getYPosition() <= maxy) {
candidateFrames.add(result.getFrame());
}
});
}
}
}
Aggregations