use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.
the class PeakResultConversionHelper method getConverters.
/**
* Gets the converters for the peak results parameters. This includes the standard parameters and
* any additional parameters defined in the PSF. If a parameter unit type is undefined then an
* identity converter is created.
*
* @return the converters
*/
public Converter[] getConverters() {
final LocalList<Converter> list = new LocalList<>(5);
getIntensityConverter();
getDistanceConverter();
list.add(intensityConverter);
list.add(intensityConverter);
list.add(distanceConverter);
list.add(distanceConverter);
list.add(distanceConverter);
if (psf != null) {
try {
for (final PSFParameter p : PsfHelper.getParameters(psf)) {
switch(p.getUnit()) {
case DISTANCE:
list.add(distanceConverter);
break;
case INTENSITY:
list.add(intensityConverter);
break;
case ANGLE:
list.add(getAngleConverter());
break;
default:
list.add(new IdentityTypeConverter<>(p.getUnit()));
}
}
} catch (final ConfigurationException ex) {
// Ignore
}
}
return list.toArray(new Converter[0]);
}
use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.
the class PeakResultConversionHelper method getUnitNames.
/**
* Gets the unit names for the peak results parameters. This includes the standard parameters and
* any additional parameters defined in the PSF. If a parameter unit is undefined then an empty
* string is returned.
*
* @return the converters
*/
public String[] getUnitNames() {
final LocalList<String> list = new LocalList<>(5);
getIntensityConverter();
getDistanceConverter();
final String safeIntensityUnit = (intensityConverter.to() != null) ? UnitHelper.getShortName(intensityConverter.to()) : "";
final String safeDistanceUnit = (distanceConverter.to() != null) ? UnitHelper.getShortName(distanceConverter.to()) : "";
String safeAngleUnit = null;
list.add(safeIntensityUnit);
list.add(safeIntensityUnit);
list.add(safeDistanceUnit);
list.add(safeDistanceUnit);
list.add(safeDistanceUnit);
if (psf != null) {
try {
for (final PSFParameter p : PsfHelper.getParameters(psf)) {
switch(p.getUnit()) {
case DISTANCE:
list.add(safeDistanceUnit);
break;
case INTENSITY:
list.add(safeIntensityUnit);
break;
case ANGLE:
safeAngleUnit = getOrCreateAngleUnit(safeAngleUnit);
list.add(safeAngleUnit);
break;
default:
list.add("");
}
}
} catch (final ConfigurationException ex) {
// Ignore
}
}
return list.toArray(new String[0]);
}
use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.
the class PsfEstimator method estimatePsf.
private int estimatePsf() {
log("Estimating PSF ... Press escape to abort");
final PeakFit fitter = createFitter();
// Use the fit configuration to generate a Gaussian function to test what is being evaluated
final Gaussian2DFunction gf = config.getFitConfiguration().createGaussianFunction(1, 1, 1);
ignore[ANGLE] = !gf.evaluatesAngle();
ignore[X] = !gf.evaluatesSD0();
ignore[Y] = !gf.evaluatesSD1();
final double[] params = new double[] { gf.evaluatesAngle() ? initialPeakAngle : 0, gf.evaluatesSD0() ? initialPeakStdDev0 : 0, gf.evaluatesSD1() ? initialPeakStdDev1 : 0, 0, 0 };
final double[] paramsDev = new double[3];
final boolean[] identical = new boolean[4];
final double[] p = new double[] { Double.NaN, Double.NaN, Double.NaN, Double.NaN };
final TextWindow resultsWindow = createResultsWindow();
addToResultTable(resultsWindow, 0, 0, params, paramsDev, p);
if (!calculateStatistics(fitter, params, paramsDev)) {
return (ImageJUtils.isInterrupted()) ? ABORTED : INSUFFICIENT_PEAKS;
}
if (!addToResultTable(resultsWindow, 1, size(), params, paramsDev, p)) {
return BAD_ESTIMATE;
}
boolean tryAgain = false;
int iteration = 2;
for (; ; ) {
if (!calculateStatistics(fitter, params, paramsDev)) {
return (ImageJUtils.isInterrupted()) ? ABORTED : INSUFFICIENT_PEAKS;
}
try {
for (int i = 0; i < 3; i++) {
getP(i, p, identical);
}
if (!ignore[Y]) {
getPairedP(sampleNew[X], sampleNew[Y], XY, p, identical);
}
if (!addToResultTable(resultsWindow, iteration++, size(), params, paramsDev, p)) {
return BAD_ESTIMATE;
}
if ((ignore[ANGLE] || identical[ANGLE] || identical[XY]) && (ignore[X] || identical[X]) && (ignore[Y] || identical[Y])) {
tryAgain = checkAngleSignificance() || checkXySignificance(identical);
// Update recommended values. Only use if significant
params[X] = sampleNew[X].getMean();
params[Y] = (!ignore[Y] && !identical[XY]) ? sampleNew[Y].getMean() : params[X];
params[ANGLE] = (!ignore[ANGLE]) ? sampleNew[ANGLE].getMean() : 0;
// update starting configuration
initialPeakAngle = (float) params[ANGLE];
initialPeakStdDev0 = (float) params[X];
initialPeakStdDev1 = (float) params[Y];
if (settings.getUpdatePreferences()) {
config.getFitConfiguration().setInitialPeakStdDev0((float) params[X]);
try {
config.getFitConfiguration().setInitialPeakStdDev1((float) params[Y]);
config.getFitConfiguration().setInitialAngle((float) params[ANGLE]);
} catch (final IllegalStateException | ConfigurationException ex) {
// Ignore this as the current PSF is not a 2 axis and theta Gaussian PSF
}
}
break;
}
if (IJ.escapePressed()) {
IJ.beep();
IJ.showStatus("Aborted");
return ABORTED;
}
} catch (final Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error while estimating the PSF", ex);
return EXCEPTION;
}
}
return (tryAgain) ? TRY_AGAIN : COMPLETE;
}
use of uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException in project GDSC-SMLM by aherbert.
the class PsfEstimator method showDialog.
/**
* Show dialog.
*
* @param imp the imp
* @return the int
*/
private int showDialog(ImagePlus imp) {
// Keep class variables for the parameters we are fitting
final FitConfiguration fitConfig = config.getFitConfiguration();
initialPeakStdDev0 = 1;
initialPeakStdDev1 = 1;
initialPeakAngle = 0;
try {
initialPeakStdDev0 = fitConfig.getInitialXSd();
initialPeakStdDev1 = fitConfig.getInitialYSd();
initialPeakAngle = fitConfig.getInitialAngle();
} catch (final IllegalStateException | ConfigurationException ex) {
// Ignore this as the current PSF is not a 2 axis and theta Gaussian PSF
}
if (!extraOptions) {
interlacedData = false;
integrateFrames = 1;
}
this.imp = imp;
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("psf-estimator"));
gd.addMessage("Estimate 2D Gaussian to fit maxima");
gd.addNumericField("Initial_StdDev0", initialPeakStdDev0, 3);
gd.addNumericField("Initial_StdDev1", initialPeakStdDev1, 3);
gd.addNumericField("Initial_Angle", initialPeakAngle, 3);
gd.addNumericField("Number_of_peaks", settings.getNumberOfPeaks(), 0);
// pValue sets the smallest significance level probability level at which they are said to be
// different.
// i.e. p <= pValue they are different
// lower pValue means harder to be found different.
// lower pValue means easier to be found the same.
gd.addNumericField("p-Value", settings.getPValue(), 4);
gd.addCheckbox("Update_preferences", settings.getUpdatePreferences());
gd.addCheckbox("Log_progress", settings.getDebugPsfEstimator());
gd.addCheckbox("Iterate", settings.getIterate());
gd.addCheckbox("Show_histograms", settings.getShowHistograms());
gd.addNumericField("Histogram_bins", settings.getHistogramBins(), 0);
PeakFit.addCameraOptions(gd, fitConfig);
PeakFit.addPsfOptions(gd, fitConfig);
final PeakFit.SimpleFitEngineConfigurationProvider provider = new PeakFit.SimpleFitEngineConfigurationProvider(config);
PeakFit.addDataFilterOptions(gd, provider);
PeakFit.addSearchOptions(gd, provider);
PeakFit.addBorderOptions(gd, provider);
PeakFit.addFittingOptions(gd, provider);
if (extraOptions) {
pluginSettings = Settings.load();
gd.addCheckbox("Interlaced_data", pluginSettings.interlacedData);
gd.addSlider("Integrate_frames", 1, 5, pluginSettings.integrateFrames);
}
gd.addMessage("--- Gaussian fitting ---");
gd.addChoice("Fit_solver", SettingsManager.getFitSolverNames(), FitProtosHelper.getName(fitConfig.getFitSolver()));
// Parameters specific to each Fit solver are collected in a second dialog
gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
gd.addNumericField("Pass_rate", config.getPassRate(), 2);
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.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, 4.5, fitConfig.getMaxWidthFactor());
PeakFit.addPrecisionOptions(gd, new PeakFit.SimpleFitConfigurationProvider(fitConfig));
gd.showDialog();
if (gd.wasCanceled() || !readDialog(gd)) {
return DONE;
}
return FLAGS;
}
Aggregations