Search in sources :

Example 6 with IntensityUnit

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;
}
Also used : IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

Example 7 with IntensityUnit

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;
}
Also used : IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

Example 8 with IntensityUnit

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;
}
Also used : AngleUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

Example 9 with IntensityUnit

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());
}
Also used : IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) DistanceCalibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.DistanceCalibration) IntensityCalibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.IntensityCalibration) AngleCalibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.AngleCalibration) IntensityCalibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.IntensityCalibration) Test(org.junit.jupiter.api.Test)

Example 10 with IntensityUnit

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);
}
Also used : AngleUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit) IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) CameraType(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)

Aggregations

IntensityUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit)10 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)6 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)4 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)3 CameraType (uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType)3 Rectangle (java.awt.Rectangle)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Calibration (uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration)2 AngleUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.AngleUnit)2 IJImageSource (uk.ac.sussex.gdsc.smlm.ij.IJImageSource)2 ReadHint (uk.ac.sussex.gdsc.smlm.results.ImageSource.ReadHint)2 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)2 RawResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.RawResultProcedure)2 TextFormat (com.google.protobuf.TextFormat)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 TIntHashSet (gnu.trove.set.hash.TIntHashSet)1