use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType in project GDSC-SMLM by aherbert.
the class CreateData method addCameraOptions.
private void addCameraOptions(final ExtendedGenericDialog gd) {
gd.addChoice("Camera_type", SettingsManager.getCameraTypeNames(), CalibrationProtosHelper.getName(settings.getCameraType()), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer field) {
settings.setCameraType(SettingsManager.getCameraTypeValues()[field]);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final CameraType cameraType = settings.getCameraType();
final boolean isCcd = CalibrationProtosHelper.isCcdCameraType(cameraType);
final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE, null);
if (isCcd) {
if (cameraType == CameraType.EMCCD) {
egd.addNumericField("EM_gain", settings.getEmGain(), 2);
}
egd.addNumericField("Camera_gain", settings.getCameraGain(), 4, 6, "count/electron");
egd.addNumericField("Quantum_efficiency", settings.getQuantumEfficiency(), 2, 6, "electron/photon");
egd.addNumericField("Read_noise", settings.getReadNoise(), 2, 6, "electron");
egd.addNumericField("Bias", settings.getBias(), 0, 6, "count");
} else if (cameraType == CameraType.SCMOS) {
final String[] models = CameraModelManager.listCameraModels(true);
egd.addChoice("Camera_model_name", models, settings.getCameraModelName());
egd.addNumericField("Quantum_efficiency", settings.getQuantumEfficiency(), 2, 6, "electron/photon");
} else {
IJ.error("Unsupported camera type " + CalibrationProtosHelper.getName(cameraType));
return false;
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
if (isCcd) {
if (cameraType == CameraType.EMCCD) {
settings.setEmGain(Math.abs(egd.getNextNumber()));
}
settings.setCameraGain(Math.abs(egd.getNextNumber()));
settings.setQuantumEfficiency(Math.abs(egd.getNextNumber()));
settings.setReadNoise(Math.abs(egd.getNextNumber()));
settings.setBias(Math.abs((int) egd.getNextNumber()));
} else if (cameraType == CameraType.SCMOS) {
settings.setCameraModelName(egd.getNextChoice());
settings.setQuantumEfficiency(Math.abs(egd.getNextNumber()));
}
return true;
}
});
}
use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType in project GDSC-SMLM by aherbert.
the class PeakFit method addCameraOptions.
/**
* Adds the camera options.
*
* @param gd the dialog
* @param options the options
* @param calibrationProvider the calibration provider
*/
public static void addCameraOptions(final ExtendedGenericDialog gd, final int options, final CalibrationProvider calibrationProvider) {
final CalibrationReader calibration = new CalibrationReader(calibrationProvider.getCalibration());
gd.addChoice("Camera_type", SettingsManager.getCameraTypeNames(), CalibrationProtosHelper.getName(calibration.getCameraType()), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer field) {
final CalibrationWriter calibration = new CalibrationWriter(calibrationProvider.getCalibration());
final CameraType t = SettingsManager.getCameraTypeValues()[field];
if (calibration.getCameraType() != t) {
calibration.setCameraType(t);
calibrationProvider.saveCalibration(calibration.getCalibration());
}
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final CalibrationWriter calibration = new CalibrationWriter(calibrationProvider.getCalibration());
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Camera type options", null);
if (calibration.isCcdCamera()) {
egd.addNumericField("Camera_bias", calibration.getBias(), 2, 6, "Count");
if (BitFlagUtils.anyNotSet(options, FLAG_NO_GAIN)) {
egd.addNumericField("Gain", calibration.getCountPerPhoton(), 4, 6, "Count/photon");
}
if (BitFlagUtils.anyNotSet(options, FLAG_NO_READ_NOISE)) {
egd.addNumericField("Read_noise", calibration.getReadNoise(), 4, 6, "Count");
}
if (BitFlagUtils.areSet(options, FLAG_QUANTUM_EFFICIENCY)) {
egd.addNumericField("Quantum_efficiency", calibration.getQuantumEfficiency(), 4, 6, "electron/photon");
}
} else if (calibration.isScmos()) {
final String[] models = CameraModelManager.listCameraModels(true);
egd.addChoice("Camera_model_name", models, calibration.getCameraModelName());
if (BitFlagUtils.areSet(options, FLAG_QUANTUM_EFFICIENCY)) {
egd.addNumericField("Quantum_efficiency", calibration.getQuantumEfficiency(), 4, 6, "electron/photon");
}
} else {
IJ.error("Unsupported camera type " + CalibrationProtosHelper.getName(calibration.getCameraType()));
return false;
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
final Calibration old = calibration.getCalibration();
if (calibration.isCcdCamera()) {
calibration.setBias(Math.abs(egd.getNextNumber()));
if (BitFlagUtils.anyNotSet(options, FLAG_NO_GAIN)) {
calibration.setCountPerPhoton(Math.abs(egd.getNextNumber()));
}
if (BitFlagUtils.anyNotSet(options, FLAG_NO_READ_NOISE)) {
calibration.setReadNoise(Math.abs(egd.getNextNumber()));
}
if (BitFlagUtils.areSet(options, FLAG_QUANTUM_EFFICIENCY)) {
calibration.setQuantumEfficiency(Math.abs(egd.getNextNumber()));
}
} else if (calibration.isScmos()) {
// Note: Since this does not go through the FitConfiguration object the
// camera model is not invalidated. However any code using this function
// should later call configureFitSolver(...) which will set the camera model
// using the camera model name.
calibration.setCameraModelName(egd.getNextChoice());
if (BitFlagUtils.areSet(options, FLAG_QUANTUM_EFFICIENCY)) {
calibration.setQuantumEfficiency(Math.abs(egd.getNextNumber()));
}
}
final Calibration current = calibration.getCalibration();
final boolean changed = !old.equals(current);
if (changed) {
calibrationProvider.saveCalibration(current);
}
return changed;
}
});
}
use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType 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