use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit in project GDSC-SMLM by aherbert.
the class CalibrationReaderTest method canGetAngleConverter.
@Test
void canGetAngleConverter() {
final Calibration.Builder builder = Calibration.newBuilder();
final AngleCalibration.Builder psfBuilder = builder.getAngleCalibrationBuilder();
psfBuilder.setAngleUnit(AngleUnit.RADIAN);
final Calibration c = builder.build();
final CalibrationReader reader = new CalibrationReader(c);
final TypeConverter<AngleUnit> angleConverter = reader.getAngleConverter(AngleUnit.DEGREE);
Assertions.assertEquals(angleConverter.from(), AngleUnit.RADIAN);
Assertions.assertEquals(angleConverter.to(), AngleUnit.DEGREE);
final TypeConverter<AngleUnit> angleConverter2 = CalibrationHelper.getAngleConverter(c, AngleUnit.DEGREE);
Assertions.assertEquals(angleConverter2.from(), AngleUnit.RADIAN);
Assertions.assertEquals(angleConverter2.to(), AngleUnit.DEGREE);
Assertions.assertEquals(angleConverter.getFunction(), angleConverter2.getFunction());
}
use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit 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.AngleUnit in project GDSC-SMLM by aherbert.
the class AngleUnitTest method check.
private static void check(ExpectedUnit<AngleUnit>... expectedUnits) {
final int n = expectedUnits.length;
TypeConverter<AngleUnit> conv;
for (int i = 0; i < n; i++) {
final AngleUnit u1 = expectedUnits[i].unit;
final double v1 = expectedUnits[i].value;
for (int j = 0; j < n; j++) {
final AngleUnit u2 = expectedUnits[j].unit;
conv = UnitConverterUtils.createConverter(u1, u2);
final double o = conv.convert(v1);
Assertions.assertEquals(expectedUnits[j].value, o, 1e-5, () -> u1 + " to " + u2);
}
}
}
use of uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit 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