use of uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis in project GDSC-SMLM by aherbert.
the class TraceDiffusion method fitJumpDistance.
/**
* Fit the jump distance histogram.
*
* <p>Update the plot by adding the fit line(s).
*
* @param jumpDistances (in um^2)
* @param jdHistogram the jump distance histogram
* @return The fitted coefficients and fractions
*/
private double[][] fitJumpDistance(StoredDataStatistics jumpDistances, double[][] jdHistogram) {
final double msd = jumpDistances.getMean();
final double meanDistance = Math.sqrt(msd) * 1e3;
// TODO:
// Q. Should the beta be expressed using the mean-distance or MSD?
// Q. Should it be normalised to the frame length. If not then the beta will be invariant on
// jump distance length
beta = meanDistance / precision;
// Set the minimum diffusion coefficient using the precision:
// Note: 4D = MSD
// 4D = precision^2
// D = precision^2 / 4
// D = (precision/2)^2
// Extra 1000 factor to convert nm to um
final double minD = MathUtils.pow2(precision / 2000.0);
ImageJUtils.log("Jump Distance analysis : N = %d, Time = %d frames (%s seconds). " + "MSD = %s um^2/jump, Mean Distance = %s nm/jump, Precision = %s nm, " + "Beta = %s, minD = %s um^2/jump", jumpDistances.getN(), clusteringSettings.getJumpDistance(), MathUtils.rounded(clusteringSettings.getJumpDistance() * exposureTime, 4), MathUtils.rounded(msd, 4), MathUtils.rounded(meanDistance, 4), MathUtils.rounded(precision, 4), MathUtils.rounded(beta, 4), MathUtils.rounded(minD, 4));
final Logger logger = ImageJPluginLoggerHelper.getLogger(getClass());
if (settings.debugFitting) {
logger.setLevel(Level.FINE);
}
final JumpDistanceAnalysis jd = new JumpDistanceAnalysis(logger);
jd.setFitRestarts(clusteringSettings.getFitRestarts());
jd.setMinFraction(settings.minFraction);
jd.setMinDifference(settings.minDifference);
jd.setMinN(myMinN);
jd.setMaxN(settings.maxN);
jd.setMinD(minD);
jd.setSignificanceLevel(settings.significanceLevel);
// Update the plot with the fit
jd.setCurveLogger(this);
// Set the calibration
jd.setN(clusteringSettings.getJumpDistance());
jd.setDeltaT(exposureTime);
if (clusteringSettings.getPrecisionCorrection()) {
jd.setError(precision, true);
}
jd.setMsdCorrection(clusteringSettings.getMsdCorrection());
double[][] fit;
if (clusteringSettings.getMle()) {
fit = jd.fitJumpDistancesMle(jumpDistances.getValues(), jdHistogram);
} else {
fit = jd.fitJumpDistanceHistogram(jumpDistances.getMean(), jdHistogram);
}
// Get the raw fitted D and convert it to a calibrated D*
if (fit != null) {
fit[0] = jd.calculateApparentDiffusionCoefficient(fit[0]);
// Check the largest D
checkTraceSettings(fit[0][0]);
fitValue = jd.getLastFitValue();
}
return fit;
}
Aggregations