use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceExporter method export.
private void export(MemoryPeakResults results) {
// Copy to allow manipulation
results = results.copy();
// Strip results with no trace Id
results.removeIf(result -> result.getId() <= 0);
// Sort by ID then time
results.sort(IdFramePeakResultComparator.INSTANCE);
// Split traces with big jumps and long tracks into smaller tracks
results = splitTraces(results);
results = splitLongTraces(results);
// Count each ID and remove short traces
int id = 0;
int count = 0;
int tracks = 0;
int maxLength = 0;
final TIntHashSet remove = new TIntHashSet();
for (int i = 0, size = results.size(); i < size; i++) {
final PeakResult result = results.get(i);
if (result.getId() != id) {
if (count < settings.minLength) {
remove.add(id);
} else {
tracks++;
maxLength = Math.max(maxLength, count);
}
count = 0;
id = result.getId();
}
count += getLength(result);
}
// Final ID
if (count < settings.minLength) {
remove.add(id);
} else {
tracks++;
maxLength = Math.max(maxLength, count);
}
if (!remove.isEmpty()) {
results.removeIf(result -> remove.contains(result.getId()));
results.sort(IdFramePeakResultComparator.INSTANCE);
}
if (settings.wobble > 0) {
// Just leave any exceptions to trickle up and kill the plugin
final TypeConverter<DistanceUnit> c = results.getDistanceConverter(DistanceUnit.NM);
final double w = c.convertBack(settings.wobble);
final UniformRandomProvider rng = UniformRandomProviders.create();
final NormalizedGaussianSampler gauss = SamplerUtils.createNormalizedGaussianSampler(rng);
final boolean is3D = results.is3D();
results.forEach((PeakResultProcedure) peakResult -> {
peakResult.setXPosition((float) (peakResult.getXPosition() + w * gauss.sample()));
peakResult.setYPosition((float) (peakResult.getYPosition() + w * gauss.sample()));
if (is3D) {
peakResult.setZPosition((float) (peakResult.getZPosition() + w * gauss.sample()));
}
});
}
if (settings.format == 2) {
exportVbSpt(results);
} else if (settings.format == 1) {
exportAnaDda(results);
} else {
exportSpotOn(results);
}
ImageJUtils.log("Exported %s: %s in %s", results.getName(), TextUtils.pleural(results.size(), "localisation"), TextUtils.pleural(tracks, "track"));
if (settings.showTraceLengths) {
// We store and index (count-1)
final int[] h = new int[maxLength];
id = 0;
for (int i = 0, size = results.size(); i < size; i++) {
final PeakResult result = results.get(i);
if (result.getId() != id) {
h[count - 1]++;
count = 0;
id = result.getId();
}
count += getLength(result);
}
h[count - 1]++;
final String title = TITLE + ": " + results.getName();
final Plot plot = new Plot(title, "Length", "Frequency");
plot.addPoints(SimpleArrayUtils.newArray(h.length, 1, 1.0f), SimpleArrayUtils.toFloat(h), Plot.BAR);
plot.setLimits(SimpleArrayUtils.findIndex(h, i -> i != 0), maxLength + 1, 0, Double.NaN);
ImageJUtils.display(title, plot);
}
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceExporter method splitLongTraces.
private MemoryPeakResults splitLongTraces(MemoryPeakResults results) {
if (settings.maxLength < 1) {
// Disabled
return results;
}
final MemoryPeakResults results2 = new MemoryPeakResults(results.size());
results2.copySettings(results);
int nextId = results.getLast().getId();
int id = 0;
int idOut = 0;
// The length that has been output under the current ID
int length = 0;
for (int i = 0, size = results.size(); i < size; i++) {
final PeakResult r = results.get(i);
if (r.getId() != id) {
id = r.getId();
idOut = id;
length = 0;
} else if (length >= settings.maxLength) {
idOut = ++nextId;
length = 0;
}
final AttributePeakResult r2 = new AttributePeakResult(r);
r2.setId(idOut);
results2.add(r2);
length += getLength(r);
}
return results2;
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceExporter method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
final MemoryResultsList items = new MemoryResultsList(MemoryPeakResults::hasId);
if (items.isEmpty()) {
IJ.error(TITLE, "No traced localisations in memory");
return;
}
// Get input options
if (!showDialog()) {
return;
}
final ArrayList<MemoryPeakResults> allResults = new ArrayList<>();
// Pick multiple input datasets together using a list box.
if (!showMultiDialog(allResults, items)) {
return;
}
for (final MemoryPeakResults results : allResults) {
export(results);
}
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method extractPulses.
@Nullable
private static Pulse[] extractPulses(MemoryPeakResults results) {
if (results == null) {
return null;
}
final Pulse[] pulses = new Pulse[results.size()];
final Counter i = new Counter();
results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> pulses[i.getAndIncrement()] = new Pulse(x, y, result.getFrame(), result.getEndFrame()));
return pulses;
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method refresh.
private static WindowAndPainter refresh(AtomicReference<WindowAndPainter> ref, boolean pairs, TextWindow resultsWindow, MemoryPeakResults results1) {
// Produce a pairs output
final WindowAndPainter wap = ConcurrencyUtils.refresh(ref, // Test the window is showing
w -> ImageJUtils.isShowing(w.textWindow), // Create
() -> {
final String title = TITLE + ((pairs) ? " Pairs" : " Triples");
final String header = pairs ? createPairsHeader() : createTriplesHeader();
final TextWindow window = new TextWindow(title, header, "", 900, 300);
// Position relative to results window
final Point p = resultsWindow.getLocation();
p.y += resultsWindow.getHeight();
window.setLocation(p);
final CoordinateProvider coordinateProvider = line -> {
// Extract the startT and x,y coordinates from the first pulse in the line
final int[] index = { 0, 5, 12 };
final String[] fields = line.split("\t");
for (final int i : index) {
if (i < fields.length) {
if (fields[i].equals("-")) {
continue;
}
final int startT = Integer.parseInt(fields[i]);
final double x = Double.parseDouble(fields[i + 2]);
final double y = Double.parseDouble(fields[i + 3]);
return new double[] { startT, x, y };
}
}
return null;
};
final ImageRoiPainter painter = new ImageRoiPainter(window.getTextPanel(), results1.getSource().getOriginal().getName(), coordinateProvider);
final WindowAndPainter result = new WindowAndPainter(window, painter);
// Free memory on close
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent event) {
ref.compareAndSet(result, null);
super.windowClosed(event);
}
});
return result;
});
wap.textWindow.getTextPanel().clear();
wap.painter.setTitle(results1.getSource().getOriginal().getName());
return wap;
}
Aggregations