use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class BenchmarkFit method showDialog.
private boolean showDialog() {
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
final double sa = getSa();
gd.addMessage(String.format("Fits the benchmark image created by CreateData plugin.\nPSF width = %s, adjusted = %s", Utils.rounded(benchmarkParameters.s / benchmarkParameters.a), Utils.rounded(sa)));
// For each new benchmark width, reset the PSF width to the square pixel adjustment
if (lastS != benchmarkParameters.s) {
lastS = benchmarkParameters.s;
psfWidth = sa;
}
final String filename = SettingsManager.getSettingsFilename();
GlobalSettings settings = SettingsManager.loadSettings(filename);
fitConfig = settings.getFitEngineConfiguration().getFitConfiguration();
fitConfig.setNmPerPixel(benchmarkParameters.a);
gd.addSlider("Region_size", 2, 20, regionSize);
gd.addNumericField("PSF_width", psfWidth, 3);
String[] solverNames = SettingsManager.getNames((Object[]) FitSolver.values());
gd.addChoice("Fit_solver", solverNames, solverNames[fitConfig.getFitSolver().ordinal()]);
String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values());
gd.addChoice("Fit_function", functionNames, functionNames[fitConfig.getFitFunction().ordinal()]);
gd.addCheckbox("Offset_fit", offsetFitting);
gd.addNumericField("Start_offset", startOffset, 3);
gd.addCheckbox("Include_CoM_fit", comFitting);
gd.addCheckbox("Background_fitting", backgroundFitting);
gd.addMessage("Signal fitting can be disabled for " + FitFunction.FIXED.toString() + " function");
gd.addCheckbox("Signal_fitting", signalFitting);
gd.addCheckbox("Show_histograms", showHistograms);
gd.addCheckbox("Save_raw_data", saveRawData);
gd.showDialog();
if (gd.wasCanceled())
return false;
regionSize = (int) Math.abs(gd.getNextNumber());
psfWidth = Math.abs(gd.getNextNumber());
fitConfig.setFitSolver(gd.getNextChoiceIndex());
fitConfig.setFitFunction(gd.getNextChoiceIndex());
offsetFitting = gd.getNextBoolean();
startOffset = Math.abs(gd.getNextNumber());
comFitting = gd.getNextBoolean();
backgroundFitting = gd.getNextBoolean();
signalFitting = gd.getNextBoolean();
showHistograms = gd.getNextBoolean();
saveRawData = gd.getNextBoolean();
if (!comFitting && !offsetFitting) {
IJ.error(TITLE, "No initial fitting positions");
return false;
}
if (regionSize < 1)
regionSize = 1;
if (gd.invalidNumber())
return false;
// Initialise the correct calibration
Calibration calibration = settings.getCalibration();
calibration.setNmPerPixel(benchmarkParameters.a);
calibration.setGain(benchmarkParameters.gain);
calibration.setAmplification(benchmarkParameters.amplification);
calibration.setBias(benchmarkParameters.bias);
calibration.setEmCCD(benchmarkParameters.emCCD);
calibration.setReadNoise(benchmarkParameters.readNoise);
calibration.setExposureTime(1000);
if (!PeakFit.configureFitSolver(settings, filename, false))
return false;
if (showHistograms) {
gd = new GenericDialog(TITLE);
gd.addMessage("Select the histograms to display");
gd.addNumericField("Histogram_bins", histogramBins, 0);
double[] convert = getConversionFactors();
for (int i = 0; i < displayHistograms.length; i++) if (convert[i] != 0)
gd.addCheckbox(NAMES[i].replace(' ', '_'), displayHistograms[i]);
gd.showDialog();
if (gd.wasCanceled())
return false;
histogramBins = (int) Math.abs(gd.getNextNumber());
for (int i = 0; i < displayHistograms.length; i++) if (convert[i] != 0)
displayHistograms[i] = gd.getNextBoolean();
}
return true;
}
use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method aggregateIntoFrames.
private void aggregateIntoFrames(ArrayList<Point> points, boolean addError, double precisionInPixels, RandomGenerator[] random) {
if (myAggregateSteps < 1)
return;
MemoryPeakResults results = new MemoryPeakResults(points.size() / myAggregateSteps);
Calibration cal = new Calibration(settings.pixelPitch, 1, myAggregateSteps * 1000.0 / settings.stepsPerSecond);
results.setCalibration(cal);
results.setName(TITLE + " Aggregated");
MemoryPeakResults.addResults(results);
lastSimulatedDataset[1] = results.getName();
int id = 0;
int peak = 1;
int n = 0;
double cx = 0, cy = 0;
// Get the mean square distance
double sum = 0;
int count = 0;
PeakResult last = null;
for (Point result : points) {
final boolean newId = result.id != id;
if (n >= myAggregateSteps || newId) {
if (n != 0) {
final float[] params = new float[7];
double[] xyz = new double[] { cx / n, cy / n };
if (addError)
xyz = addError(xyz, precisionInPixels, random);
params[Gaussian2DFunction.X_POSITION] = (float) xyz[0];
params[Gaussian2DFunction.Y_POSITION] = (float) xyz[1];
params[Gaussian2DFunction.SIGNAL] = n;
params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = 1;
final float noise = 0.1f;
PeakResult r = new ExtendedPeakResult(peak, (int) params[Gaussian2DFunction.X_POSITION], (int) params[Gaussian2DFunction.Y_POSITION], n, 0, noise, params, null, peak, id);
results.add(r);
if (last != null) {
sum += last.distance2(r);
count++;
}
last = r;
n = 0;
cx = cy = 0;
peak++;
}
if (newId) {
// Increment the frame so that tracing analysis can distinguish traces
peak++;
last = null;
id = result.id;
}
}
n++;
cx += result.x;
cy += result.y;
}
// Final peak
if (n != 0) {
final float[] params = new float[7];
double[] xyz = new double[] { cx / n, cy / n };
if (addError)
xyz = addError(xyz, precisionInPixels, random);
params[Gaussian2DFunction.X_POSITION] = (float) xyz[0];
params[Gaussian2DFunction.Y_POSITION] = (float) xyz[1];
params[Gaussian2DFunction.SIGNAL] = n;
params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = 1;
final float noise = 0.1f;
PeakResult r = new ExtendedPeakResult(peak, (int) params[Gaussian2DFunction.X_POSITION], (int) params[Gaussian2DFunction.Y_POSITION], n, 0, noise, params, null, peak, id);
results.add(r);
if (last != null) {
sum += last.distance2(r);
count++;
}
}
// MSD in pixels^2 / frame
double msd = sum / count;
// Convert to um^2/second
Utils.log("Aggregated data D=%s um^2/s, Precision=%s nm, N=%d, step=%s s, mean=%s um^2, MSD = %s um^2/s", Utils.rounded(settings.diffusionRate), Utils.rounded(myPrecision), count, Utils.rounded(results.getCalibration().getExposureTime() / 1000), Utils.rounded(msd / conversionFactor), Utils.rounded((msd / conversionFactor) / (results.getCalibration().getExposureTime() / 1000)));
msdAnalysis(points);
}
use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class Configuration method refreshSettings.
private void refreshSettings(String newFilename) {
if (newFilename != null && new File(newFilename).exists()) {
YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), TITLE, "Reload settings from file");
d.setVisible(true);
if (d.yesPressed()) {
// Reload the settings and update the GUI
// XXX : This does not deal with loading settings into fields that are not displayed,
// e.g. for configuring the Fit Solvers. This could be done by writing into
// a class scope settings instance (loaded in showDialog()). However the user would not
// see all the changes that have been written, since the later dialogs are shown depending
// on what options are initially configured.
GlobalSettings settings = SettingsManager.unsafeLoadSettings(newFilename, false);
if (settings == null)
return;
FitEngineConfiguration config = settings.getFitEngineConfiguration();
FitConfiguration fitConfig = config.getFitConfiguration();
Calibration calibration = settings.getCalibration();
textNmPerPixel.setText("" + calibration.getNmPerPixel());
textGain.setText("" + calibration.getGain());
textEMCCD.setState(calibration.isEmCCD());
textExposure.setText("" + calibration.getExposureTime());
textInitialPeakStdDev0.setText("" + fitConfig.getInitialPeakStdDev0());
textInitialPeakStdDev1.setText("" + fitConfig.getInitialPeakStdDev1());
textInitialAngleD.setText("" + fitConfig.getInitialAngle());
textDataFilterType.select(config.getDataFilterType().ordinal());
textDataFilter.select(config.getDataFilter(0).ordinal());
textSmooth.setText("" + config.getSmooth(0));
textSearch.setText("" + config.getSearch());
textBorder.setText("" + config.getBorder());
textFitting.setText("" + config.getFitting());
textFitSolver.select(fitConfig.getFitSolver().ordinal());
textFitFunction.select(fitConfig.getFitFunction().ordinal());
textFailuresLimit.setText("" + config.getFailuresLimit());
textIncludeNeighbours.setState(config.isIncludeNeighbours());
textNeighbourHeightThreshold.setText("" + config.getNeighbourHeightThreshold());
textResidualsThreshold.setText("" + config.getResidualsThreshold());
textDuplicateDistance.setText("" + fitConfig.getDuplicateDistance());
textCoordinateShiftFactor.setText("" + fitConfig.getCoordinateShiftFactor());
textSignalStrength.setText("" + fitConfig.getSignalStrength());
textMinPhotons.setText("" + fitConfig.getMinPhotons());
textMinWidthFactor.setText("" + fitConfig.getMinWidthFactor());
textWidthFactor.setText("" + fitConfig.getWidthFactor());
textPrecisionThreshold.setText("" + fitConfig.getPrecisionThreshold());
}
}
}
use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class Configuration method showDialog.
/**
* Show the current properties
*/
@SuppressWarnings("unchecked")
public void showDialog() {
configurationChanged = false;
String filename = SettingsManager.getSettingsFilename();
GlobalSettings settings = SettingsManager.loadSettings(filename);
FitEngineConfiguration config = settings.getFitEngineConfiguration();
FitConfiguration fitConfig = config.getFitConfiguration();
Calibration calibration = settings.getCalibration();
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Configuration settings for the single-molecule localisation microscopy plugins");
gd.addStringField("Config_file", filename, 40);
gd.addNumericField("Calibration (nm/px)", calibration.getNmPerPixel(), 2);
gd.addNumericField("Gain", calibration.getGain(), 2);
gd.addCheckbox("EM-CCD", calibration.isEmCCD());
gd.addNumericField("Exposure_time (ms)", calibration.getExposureTime(), 2);
gd.addMessage("--- Gaussian parameters ---");
gd.addNumericField("Initial_StdDev0", fitConfig.getInitialPeakStdDev0(), 3);
gd.addNumericField("Initial_StdDev1", fitConfig.getInitialPeakStdDev1(), 3);
gd.addNumericField("Initial_Angle", fitConfig.getInitialAngle(), 3);
gd.addMessage("--- Maxima identification ---");
String[] filterTypes = SettingsManager.getNames((Object[]) DataFilterType.values());
gd.addChoice("Spot_filter_type", filterTypes, filterTypes[config.getDataFilterType().ordinal()]);
String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values());
gd.addChoice("Spot_filter", filterNames, filterNames[config.getDataFilter(0).ordinal()]);
gd.addSlider("Smoothing", 0, 2.5, config.getSmooth(0));
gd.addSlider("Search_width", 0.5, 2.5, config.getSearch());
gd.addSlider("Border", 0.5, 2.5, config.getBorder());
gd.addSlider("Fitting_width", 2, 4.5, config.getFitting());
gd.addMessage("--- Gaussian fitting ---");
Component splitLabel = gd.getMessage();
String[] solverNames = SettingsManager.getNames((Object[]) FitSolver.values());
gd.addChoice("Fit_solver", solverNames, solverNames[fitConfig.getFitSolver().ordinal()]);
String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values());
gd.addChoice("Fit_function", functionNames, functionNames[fitConfig.getFitFunction().ordinal()]);
// Parameters specific to each Fit solver are collected in a second dialog
gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours());
gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold());
gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold());
gd.addSlider("Duplicate_distance", 0, 1.5, fitConfig.getDuplicateDistance());
gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract");
gd.addCheckbox("Smart_filter", fitConfig.isSmartFilter());
gd.addCheckbox("Disable_simple_filter", fitConfig.isDisableSimpleFilter());
gd.addSlider("Shift_factor", 0.01, 2, fitConfig.getCoordinateShiftFactor());
gd.addNumericField("Signal_strength", fitConfig.getSignalStrength(), 2);
gd.addNumericField("Min_photons", fitConfig.getMinPhotons(), 0);
gd.addSlider("Min_width_factor", 0, 0.99, fitConfig.getMinWidthFactor());
gd.addSlider("Width_factor", 1.01, 5, fitConfig.getWidthFactor());
gd.addNumericField("Precision_threshold", fitConfig.getPrecisionThreshold(), 2);
// Add a mouse listener to the config file field
if (Utils.isShowGenericDialog()) {
Vector<TextField> texts = (Vector<TextField>) gd.getStringFields();
Vector<TextField> numerics = (Vector<TextField>) gd.getNumericFields();
Vector<Checkbox> checkboxes = (Vector<Checkbox>) gd.getCheckboxes();
Vector<Choice> choices = (Vector<Choice>) gd.getChoices();
int n = 0;
int t = 0;
int b = 0;
int ch = 0;
textConfigFile = texts.get(t++);
textConfigFile.addMouseListener(this);
textConfigFile.addTextListener(this);
// TODO: add a value changed listener to detect when typing a new file
textNmPerPixel = numerics.get(n++);
textGain = numerics.get(n++);
textEMCCD = checkboxes.get(b++);
textExposure = numerics.get(n++);
textInitialPeakStdDev0 = numerics.get(n++);
textInitialPeakStdDev1 = numerics.get(n++);
textInitialAngleD = numerics.get(n++);
textDataFilterType = choices.get(ch++);
textDataFilter = choices.get(ch++);
textSmooth = numerics.get(n++);
textSearch = numerics.get(n++);
textBorder = numerics.get(n++);
textFitting = numerics.get(n++);
textFitSolver = choices.get(ch++);
textFitFunction = choices.get(ch++);
textFailuresLimit = numerics.get(n++);
textIncludeNeighbours = checkboxes.get(b++);
textNeighbourHeightThreshold = numerics.get(n++);
textResidualsThreshold = numerics.get(n++);
textDuplicateDistance = numerics.get(n++);
textSmartFilter = checkboxes.get(b++);
textDisableSimpleFilter = checkboxes.get(b++);
textCoordinateShiftFactor = numerics.get(n++);
textSignalStrength = numerics.get(n++);
textMinPhotons = numerics.get(n++);
textMinWidthFactor = numerics.get(n++);
textWidthFactor = numerics.get(n++);
textPrecisionThreshold = numerics.get(n++);
updateFilterInput();
textSmartFilter.addItemListener(this);
textDisableSimpleFilter.addItemListener(this);
}
if (gd.getLayout() != null) {
GridBagLayout grid = (GridBagLayout) gd.getLayout();
int xOffset = 0, yOffset = 0;
int lastY = -1, rowCount = 0;
for (Component comp : gd.getComponents()) {
// Check if this should be the second major column
if (comp == splitLabel) {
xOffset += 2;
yOffset -= rowCount;
}
// Reposition the field
GridBagConstraints c = grid.getConstraints(comp);
if (lastY != c.gridy)
rowCount++;
lastY = c.gridy;
c.gridx = c.gridx + xOffset;
c.gridy = c.gridy + yOffset;
c.insets.left = c.insets.left + 10 * xOffset;
c.insets.top = 0;
c.insets.bottom = 0;
grid.setConstraints(comp, c);
}
if (IJ.isLinux())
gd.setBackground(new Color(238, 238, 238));
}
gd.showDialog();
if (gd.wasCanceled())
return;
filename = gd.getNextString();
calibration.setNmPerPixel(gd.getNextNumber());
calibration.setGain(gd.getNextNumber());
calibration.setEmCCD(gd.getNextBoolean());
calibration.setExposureTime(gd.getNextNumber());
fitConfig.setInitialPeakStdDev0(gd.getNextNumber());
fitConfig.setInitialPeakStdDev1(gd.getNextNumber());
fitConfig.setInitialAngleD(gd.getNextNumber());
config.setDataFilterType(gd.getNextChoiceIndex());
config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), 0);
config.setSearch(gd.getNextNumber());
config.setBorder(gd.getNextNumber());
config.setFitting(gd.getNextNumber());
fitConfig.setFitSolver(gd.getNextChoiceIndex());
fitConfig.setFitFunction(gd.getNextChoiceIndex());
config.setFailuresLimit((int) gd.getNextNumber());
config.setIncludeNeighbours(gd.getNextBoolean());
config.setNeighbourHeightThreshold(gd.getNextNumber());
config.setResidualsThreshold(gd.getNextNumber());
fitConfig.setDuplicateDistance(gd.getNextNumber());
fitConfig.setSmartFilter(gd.getNextBoolean());
fitConfig.setDisableSimpleFilter(gd.getNextBoolean());
fitConfig.setCoordinateShiftFactor(gd.getNextNumber());
fitConfig.setSignalStrength(gd.getNextNumber());
fitConfig.setMinPhotons(gd.getNextNumber());
fitConfig.setMinWidthFactor(gd.getNextNumber());
fitConfig.setWidthFactor(gd.getNextNumber());
fitConfig.setPrecisionThreshold(gd.getNextNumber());
// Check arguments
try {
Parameters.isAboveZero("nm per pixel", calibration.getNmPerPixel());
Parameters.isAboveZero("Gain", calibration.getGain());
Parameters.isAboveZero("Exposure time", calibration.getExposureTime());
Parameters.isAboveZero("Initial SD0", fitConfig.getInitialPeakStdDev0());
Parameters.isAboveZero("Initial SD1", fitConfig.getInitialPeakStdDev1());
Parameters.isPositive("Initial angle", fitConfig.getInitialAngleD());
Parameters.isAboveZero("Search_width", config.getSearch());
Parameters.isAboveZero("Fitting_width", config.getFitting());
Parameters.isPositive("Failures limit", config.getFailuresLimit());
Parameters.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
Parameters.isPositive("Residuals threshold", config.getResidualsThreshold());
Parameters.isPositive("Duplicate distance", fitConfig.getDuplicateDistance());
Parameters.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
Parameters.isPositive("Signal strength", fitConfig.getSignalStrength());
Parameters.isPositive("Min photons", fitConfig.getMinPhotons());
Parameters.isPositive("Min width factor", fitConfig.getMinWidthFactor());
Parameters.isPositive("Width factor", fitConfig.getWidthFactor());
Parameters.isPositive("Precision threshold", fitConfig.getPrecisionThreshold());
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return;
}
if (gd.invalidNumber())
return;
configurationChanged = SettingsManager.saveSettings(settings, filename);
if (configurationChanged)
SettingsManager.saveSettingsFilename(filename);
if (!PeakFit.configureSmartFilter(settings, filename))
return;
if (!PeakFit.configureDataFilter(settings, filename, false))
return;
PeakFit.configureFitSolver(settings, filename, false);
}
use of gdsc.smlm.results.Calibration in project GDSC-SMLM by aherbert.
the class CreateData method showSimulationParametersDialog.
private SimulationParameters showSimulationParametersDialog(ImagePlus imp, MemoryPeakResults results) {
int molecules = results.size();
// Get the missing parameters from the user
boolean fullSimulation = false;
double s = -1;
// Get these from the data
double[] signal = getSignal(results);
double[] limits = Maths.limits(signal);
double minSignal = limits[0];
double maxSignal = limits[1];
double signalPerFrame = Maths.sum(signal) / molecules;
double[] depths = getDepth(results);
limits = Maths.limits(depths);
double depth = Math.max(Math.abs(limits[0]), Math.abs(limits[1]));
boolean fixedDepth = Double.compare(limits[0], limits[1]) == 0;
Calibration cal = new Calibration();
// Get any calibration we have
if (results.getCalibration() != null)
cal = results.getCalibration();
// Get this from the user
double b = -1;
// This is good if we are re-running the plugin to load data.
if (simulationParameters != null && simulationParameters.isLoaded()) {
fullSimulation = simulationParameters.fullSimulation;
s = simulationParameters.s;
b = simulationParameters.b;
if (!cal.hasBias())
cal.setBias(simulationParameters.bias);
if (!cal.hasGain())
cal.setGain(simulationParameters.gain);
if (!cal.hasAmplification())
cal.setAmplification(simulationParameters.amplification);
if (!cal.hasReadNoise())
cal.setReadNoise(simulationParameters.readNoise);
if (!cal.hasEMCCD())
cal.setEmCCD(simulationParameters.emCCD);
if (!cal.hasNmPerPixel())
cal.setNmPerPixel(simulationParameters.a);
}
// Show a dialog to confirm settings
GenericDialog gd = new GenericDialog(TITLE);
StringBuilder sb = new StringBuilder();
sb.append("Results contain ").append(Utils.pleural(molecules, "molecule")).append('\n');
sb.append("Min signal = ").append(Utils.rounded(minSignal)).append(" ADU\n");
sb.append("Max signal = ").append(Utils.rounded(maxSignal)).append(" ADU\n");
sb.append("Av signal = ").append(Utils.rounded(signalPerFrame)).append(" ADU\n");
if (fixedDepth)
sb.append("Fixed depth = ").append(Utils.rounded(depth)).append('\n');
gd.addMessage(sb.toString());
gd.addCheckbox("Flourophore_simulation", fullSimulation);
gd.addNumericField("Gaussian_SD", s, 3, 8, "nm");
gd.addNumericField("Pixel_pitch", cal.getNmPerPixel(), 3, 8, "nm");
gd.addNumericField("Background", b, 3, 8, "photon");
gd.addNumericField("Total_gain", cal.getGain(), 3, 8, "ADU/photon");
gd.addNumericField("Amplification", cal.getAmplification(), 3, 8, "ADU/e-");
gd.addCheckbox("EM-CCD", cal.isEmCCD());
gd.addNumericField("Read_noise", cal.getReadNoise(), 3, 8, "ADU");
gd.addNumericField("Bias", cal.getBias(), 3, 8, "pixel");
if (!fixedDepth) {
gd.addNumericField("Depth", depth, 3, 8, "pixel");
}
gd.showDialog();
if (gd.wasCanceled())
return null;
fullSimulation = gd.getNextBoolean();
s = gd.getNextNumber();
cal.setNmPerPixel(gd.getNextNumber());
b = gd.getNextNumber();
cal.setGain(gd.getNextNumber());
cal.setAmplification(gd.getNextNumber());
cal.setEmCCD(gd.getNextBoolean());
cal.setReadNoise(gd.getNextNumber());
cal.setBias(gd.getNextNumber());
double myDepth = depth;
if (!fixedDepth) {
myDepth = gd.getNextNumber();
if (myDepth < depth) {
IJ.error(TITLE, String.format("Input depth is smaller than the depth guessed from the data: %f < %f", myDepth, depth));
return null;
}
depth = myDepth;
}
// Validate settings
try {
Parameters.isAboveZero("Gaussian_SD", s);
Parameters.isAboveZero("Pixel_pitch", cal.getNmPerPixel());
Parameters.isPositive("Background", b);
Parameters.isAboveZero("Total_gain", cal.getGain());
Parameters.isAboveZero("Amplification", cal.getAmplification());
Parameters.isPositive("Read_noise", cal.getReadNoise());
Parameters.isPositive("Bias", cal.getBias());
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return null;
}
// Store calibration
results.setCalibration(cal);
double gain = cal.getGain();
double a = cal.getNmPerPixel();
double bias = cal.getBias();
double readNoise = cal.getReadNoise();
double amplification = cal.getAmplification();
boolean emCCD = cal.isEmCCD();
// Convert ADU values to photons
minSignal /= gain;
maxSignal /= gain;
signalPerFrame /= gain;
// Convert +/- depth to total depth in nm
depth *= 2 * a;
// Compute total background variance in photons
double backgroundVariance = b;
// Do not add EM-CCD noise factor. The Mortensen formula also includes this factor
// so this is "double-counting" the EM-CCD.
//if (emCCD)
// backgroundVariance *= 2;
// Read noise is in ADUs. Convert to Photons to get contribution to background variance
double readNoiseInPhotons = readNoise / gain;
// Get the expected value at each pixel in photons. Assuming a Poisson distribution this
// is equal to the total variance at the pixel.
double b2 = backgroundVariance + readNoiseInPhotons * readNoiseInPhotons;
SimulationParameters p = new SimulationParameters(molecules, fullSimulation, s, a, minSignal, maxSignal, signalPerFrame, depth, fixedDepth, bias, emCCD, gain, amplification, readNoise, b, b2);
p.loaded = true;
return p;
}
Aggregations