use of uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method createRankById.
private static float[] createRankById(MemoryPeakResults results) {
if (results.hasId()) {
final TFloatArrayList list = new TFloatArrayList(results.size());
results.forEach((PeakResultProcedure) r -> list.add(r.getId()));
return list.toArray();
}
return null;
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure in project GDSC-SMLM by aherbert.
the class PeakResultsReader method simplifyTwoAxis.
/**
* Simplify two axis Gaussian 2D data.
*
* @param results the results
* @param removeTheta the remove theta flag
*/
private void simplifyTwoAxis(MemoryPeakResults results, boolean removeTheta) {
final int[] indices = PsfHelper.getGaussian2DWxWyIndices(psf);
final int isx = indices[0];
final int isy = indices[1];
// Columns to remove
int remove = (removeTheta) ? 1 : 0;
// New PSF type
PSFType psfType;
// Determine if sy is redundant
if (results.forEach((PeakResultProcedureX) peakResult -> peakResult.getParameter(isx) != peakResult.getParameter(isy))) {
if (!removeTheta) {
// Already a TwoAxis Gaussian
return;
}
// Otherwise this was a TwoAxisAndTheta with 1 column to remove
// so it should be simplified
psfType = PSFType.TWO_AXIS_GAUSSIAN_2D;
} else {
// sy is redundant so remove another column
psfType = PSFType.ONE_AXIS_GAUSSIAN_2D;
remove++;
}
// Update the PSF
final PSF.Builder builder = psf.toBuilder();
builder.setPsfType(psfType);
psf = builder.build();
results.setPsf(psf);
// Update the results.
// We can directly manipulate the params array
final int newLength = results.getf(0).getNumberOfParameters() - remove;
if (deviations) {
results.forEach((PeakResultProcedure) peakResult -> {
peakResult.resizeParameters(newLength);
peakResult.resizeParameterDeviations(newLength);
});
} else {
results.forEach((PeakResultProcedure) peakResult -> peakResult.resizeParameters(newLength));
}
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method getCoordinates.
private static TIntObjectHashMap<UniqueIdPeakResult[]> getCoordinates(MemoryPeakResults results) {
final TIntObjectHashMap<UniqueIdPeakResult[]> coords = new TIntObjectHashMap<>();
if (results.size() > 0) {
// Do not use HashMap directly to build the coords object since there
// will be many calls to getEntry(). Instead sort the results and use
// a new list for each time point
results.sort();
final Counter uniqueId = new Counter();
final FrameCounter counter = new FrameCounter();
final LocalList<PeakResult> tmp = new LocalList<>();
// Add the results to the lists
results.forEach((PeakResultProcedure) result -> {
if (counter.advanceAndReset(result.getFrame()) && !tmp.isEmpty()) {
coords.put(counter.previousFrame(), tmp.toArray(new UniqueIdPeakResult[0]));
tmp.clear();
}
tmp.add(new UniqueIdPeakResult(tmp.size(), uniqueId.getAndIncrement(), result));
});
if (!tmp.isEmpty()) {
coords.put(counter.currentFrame(), tmp.toArray(new UniqueIdPeakResult[0]));
}
}
return coords;
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure 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.procedures.PeakResultProcedure 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;
}
Aggregations