use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit in project GDSC-SMLM by aherbert.
the class Fire method initialise.
/**
* Initialise this instance with localisation results for the FIRE computation.
*
* @param results the results
* @param results2 the second set of results (can be null)
*/
public void initialise(MemoryPeakResults results, MemoryPeakResults results2) {
this.results = verify(results);
this.results2 = verify(results2);
if (this.results == null) {
return;
}
nmPerUnit = 1;
DistanceUnit unit = null;
units = "unknown";
final CalibrationReader cal = results.getCalibrationReader();
if (cal != null) {
try {
nmPerUnit = cal.getDistanceConverter(DistanceUnit.NM).convert(1);
units = UnitHelper.getShortName(DistanceUnit.NM);
unit = DistanceUnit.NM;
} catch (final ConversionException ex) {
IJ.log(pluginTitle + " Warning: Ignoring invalid distance calibration for primary results");
}
} else {
IJ.log(pluginTitle + " Warning: No calibration exists for primary results");
}
// Calibration must match between datasets
if (this.results2 != null) {
CalibrationReader cal2 = results.getCalibrationReader();
if (unit == null) {
if (cal2 != null) {
IJ.log(pluginTitle + " Warning: Ignoring calibration for secondary results since no calibration" + " exists for primary results");
}
} else {
// The calibration must match
try {
// Try to create a converter and check it is the same conversion
if (cal2 != null && cal2.getDistanceConverter(DistanceUnit.NM).convert(1) != nmPerUnit) {
// Set to null to mark invalid
cal2 = null;
}
} catch (final ConversionException ex) {
// Set to null to mark invalid
cal2 = null;
} finally {
if (cal2 == null) {
this.results = null;
IJ.error(pluginTitle, "Error: Calibration between the two input datasets does not match");
}
}
}
}
// Use the float data bounds. This prevents problems if the data is far from the origin.
dataBounds = results.getDataBounds(null);
if (this.results2 != null) {
final Rectangle2D dataBounds2 = results.getDataBounds(null);
dataBounds = dataBounds.createUnion(dataBounds2);
}
}
use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit in project GDSC-SMLM by aherbert.
the class AbstractPeakResults method isCalibratedForPrecision.
/**
* Checks if the results have a valid calibration to compute the localisation precision. This
* requires the pixel size and camera gain, or alternatively the units to be in nm and photons,
* and camera CCD type.
*
* @return true, if is calibrated for precision
*/
public boolean isCalibratedForPrecision() {
if (calibration != null) {
if (!calibrationReader.isCcdCamera()) {
return false;
}
final DistanceUnit du = calibrationReader.getDistanceUnit();
final IntensityUnit iu = calibrationReader.getIntensityUnit();
if (du == DistanceUnit.NM && iu == IntensityUnit.PHOTON) {
return true;
}
return isCalibrated();
}
return false;
}
use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit in project GDSC-SMLM by aherbert.
the class AbstractPeakResults method isCalibrated.
/**
* Checks if the results have a basic calibration. This requires the pixel size and camera gain
* with the distance and intensity units.
*
* @return true, if is calibrated
*/
public boolean isCalibrated() {
if (calibration != null) {
final DistanceUnit du = calibrationReader.getDistanceUnit();
final IntensityUnit iu = calibrationReader.getIntensityUnit();
// @formatter:off
return (du != null && calibrationReader.getNmPerPixel() > 0) && (iu != null && calibrationReader.getCountPerPhoton() > 0);
// @formatter:on
}
return false;
}
use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit 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.data.config.UnitProtos.DistanceUnit 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;
});
}
Aggregations