use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit 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.IntensityUnit 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.IntensityUnit in project GDSC-SMLM by aherbert.
the class ConvertResults method showDialog.
private static boolean showDialog(MemoryPeakResults results) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Convert the current units for the results");
gd.addHelp(HelpUrls.getUrl("convert-results"));
final CalibrationReader cr = CalibrationWriter.create(results.getCalibration());
gd.addChoice("Distance_unit", SettingsManager.getDistanceUnitNames(), cr.getDistanceUnitValue());
gd.addNumericField("Calibration (nm/px)", cr.getNmPerPixel(), 2);
gd.addChoice("Intensity_unit", SettingsManager.getIntensityUnitNames(), cr.getIntensityUnitValue());
gd.addNumericField("Gain (Count/photon)", cr.getCountPerPhoton(), 2);
gd.addChoice("Angle_unit", SettingsManager.getAngleUnitNames(), cr.getAngleUnitValue());
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
final CalibrationWriter cw = results.getCalibrationWriterSafe();
final DistanceUnit distanceUnit = SettingsManager.getDistanceUnitValues()[gd.getNextChoiceIndex()];
cw.setNmPerPixel(Math.abs(gd.getNextNumber()));
final IntensityUnit intensityUnit = SettingsManager.getIntensityUnitValues()[gd.getNextChoiceIndex()];
cw.setCountPerPhoton(Math.abs(gd.getNextNumber()));
final AngleUnit angleUnit = SettingsManager.getAngleUnitValues()[gd.getNextChoiceIndex()];
// Don't set the calibration with bad values
if (distanceUnit.getNumber() > 0 && !(cw.getNmPerPixel() > 0)) {
IJ.error(TITLE, "Require positive nm/pixel for conversion");
return false;
}
if (intensityUnit.getNumber() > 0 && !(cw.getCountPerPhoton() > 0)) {
IJ.error(TITLE, "Require positive Count/photon for conversion");
return false;
}
final Calibration newCalibration = cw.getCalibration();
results.setCalibration(newCalibration);
if (!results.convertToUnits(distanceUnit, intensityUnit, angleUnit)) {
IJ.error(TITLE, "Conversion failed");
return false;
}
return true;
}
use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit in project GDSC-SMLM by aherbert.
the class CalibrationReaderTest method canGetIntensityConverter.
@Test
void canGetIntensityConverter() {
final Calibration.Builder builder = Calibration.newBuilder();
final IntensityCalibration.Builder intensityBuilder = builder.getIntensityCalibrationBuilder();
intensityBuilder.setIntensityUnit(IntensityUnit.PHOTON);
intensityBuilder.setCountPerPhoton(gain);
final Calibration c = builder.build();
final CalibrationReader reader = new CalibrationReader(c);
final TypeConverter<IntensityUnit> intensityConverter = reader.getIntensityConverter(IntensityUnit.COUNT);
Assertions.assertEquals(intensityConverter.from(), IntensityUnit.PHOTON);
Assertions.assertEquals(intensityConverter.to(), IntensityUnit.COUNT);
final TypeConverter<IntensityUnit> intensityConverter2 = CalibrationHelper.getIntensityConverter(c, IntensityUnit.COUNT);
Assertions.assertEquals(intensityConverter2.from(), IntensityUnit.PHOTON);
Assertions.assertEquals(intensityConverter2.to(), IntensityUnit.COUNT);
Assertions.assertEquals(intensityConverter.getFunction(), intensityConverter2.getFunction());
}
use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit in project GDSC-SMLM by aherbert.
the class CalibrationWriterTest method canWrite.
private static void canWrite(UniformRandomProvider rng) {
final double qe = rng.nextDouble();
final double bias = 1 + rng.nextDouble();
final double exposureTime = 1 + rng.nextDouble();
final double gain = 1 + rng.nextDouble();
final double nmPerPixel = 1 + rng.nextDouble();
final double readNoise = 1 + rng.nextDouble();
final AngleUnit angleUnit = AngleUnit.values()[rng.nextInt(AngleUnit.values().length - 1)];
final CameraType cameraType = CameraType.values()[rng.nextInt(CameraType.values().length - 1)];
final DistanceUnit distanceUnit = DistanceUnit.values()[rng.nextInt(DistanceUnit.values().length - 1)];
final IntensityUnit intensityUnit = IntensityUnit.values()[rng.nextInt(IntensityUnit.values().length - 1)];
final CalibrationWriter writer = new CalibrationWriter();
Assertions.assertEquals(writer.getQuantumEfficiency(), 0);
Assertions.assertEquals(writer.getBias(), 0);
Assertions.assertEquals(writer.getExposureTime(), 0);
Assertions.assertEquals(writer.getCountPerPhoton(), 0);
Assertions.assertEquals(writer.getNmPerPixel(), 0);
Assertions.assertEquals(writer.getReadNoise(), 0);
Assertions.assertFalse(writer.hasQuantumEfficiency());
Assertions.assertFalse(writer.hasBias());
Assertions.assertFalse(writer.hasExposureTime());
Assertions.assertFalse(writer.hasCountPerPhoton());
Assertions.assertFalse(writer.hasNmPerPixel());
Assertions.assertFalse(writer.hasReadNoise());
Assertions.assertEquals(writer.getAngleUnit(), AngleUnit.ANGLE_UNIT_NA);
Assertions.assertEquals(writer.getCameraType(), CameraType.CAMERA_TYPE_NA);
Assertions.assertEquals(writer.getDistanceUnit(), DistanceUnit.DISTANCE_UNIT_NA);
Assertions.assertEquals(writer.getIntensityUnit(), IntensityUnit.INTENSITY_UNIT_NA);
writer.setQuantumEfficiency(qe);
writer.setBias(bias);
writer.setExposureTime(exposureTime);
writer.setCountPerPhoton(gain);
writer.setNmPerPixel(nmPerPixel);
writer.setReadNoise(readNoise);
writer.setAngleUnit(angleUnit);
writer.setCameraType(cameraType);
writer.setDistanceUnit(distanceUnit);
writer.setIntensityUnit(intensityUnit);
Assertions.assertEquals(writer.getQuantumEfficiency(), qe);
Assertions.assertEquals(writer.getBias(), bias);
Assertions.assertEquals(writer.getExposureTime(), exposureTime);
Assertions.assertEquals(writer.getCountPerPhoton(), gain);
Assertions.assertEquals(writer.getNmPerPixel(), nmPerPixel);
Assertions.assertEquals(writer.getReadNoise(), readNoise);
Assertions.assertTrue(writer.hasQuantumEfficiency());
Assertions.assertTrue(writer.hasBias());
Assertions.assertTrue(writer.hasExposureTime());
Assertions.assertTrue(writer.hasCountPerPhoton());
Assertions.assertTrue(writer.hasNmPerPixel());
Assertions.assertTrue(writer.hasReadNoise());
Assertions.assertEquals(writer.getAngleUnit(), angleUnit);
Assertions.assertEquals(writer.getCameraType(), cameraType);
Assertions.assertEquals(writer.getDistanceUnit(), distanceUnit);
Assertions.assertEquals(writer.getIntensityUnit(), intensityUnit);
final CalibrationReader reader = new CalibrationReader(writer.getCalibration());
Assertions.assertEquals(reader.getQuantumEfficiency(), qe);
Assertions.assertEquals(reader.getBias(), bias);
Assertions.assertEquals(reader.getExposureTime(), exposureTime);
Assertions.assertEquals(reader.getCountPerPhoton(), gain);
Assertions.assertEquals(reader.getNmPerPixel(), nmPerPixel);
Assertions.assertEquals(reader.getReadNoise(), readNoise);
Assertions.assertTrue(reader.hasQuantumEfficiency());
Assertions.assertTrue(reader.hasBias());
Assertions.assertTrue(reader.hasExposureTime());
Assertions.assertTrue(reader.hasCountPerPhoton());
Assertions.assertTrue(reader.hasNmPerPixel());
Assertions.assertTrue(reader.hasReadNoise());
Assertions.assertEquals(reader.getAngleUnit(), angleUnit);
Assertions.assertEquals(reader.getCameraType(), cameraType);
Assertions.assertEquals(reader.getDistanceUnit(), distanceUnit);
Assertions.assertEquals(reader.getIntensityUnit(), intensityUnit);
}
Aggregations