use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method resetParametersFromFitting.
private void resetParametersFromFitting() {
final FitEngineConfiguration config = BenchmarkSpotFit.getFitEngineConfiguration();
settings.failCount = config.getFailuresLimit();
settings.duplicateDistance = config.getDuplicateDistance();
settings.duplicateDistanceAbsolute = config.getDuplicateDistanceAbsolute();
residualsThreshold = settings.residualsThreshold = (BenchmarkSpotFit.getComputeDoublets()) ? BenchmarkSpotFit.getMultiFilter().residualsThreshold : 1;
}
use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.
the class ConfigurationTemplate method createInlineTemplates.
private static Map<String, Template> createInlineTemplates() {
final Map<String, Template> inlineTemplates = new LinkedHashMap<>();
// Add the default.
// This will be a simple least squares estimator applicable to non-calibrated data.
final FitEngineConfiguration config = FitEngineConfiguration.create();
addInlineTemplate(inlineTemplates, "Default", config);
return inlineTemplates;
}
use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.
the class PeakFit method configureDataFilter.
/**
* Show a dialog to configure the data filter. The data filter type and the first data filter must
* ALREADY be set in the configuration. The subsequent filters are then configured, e.g. for
* difference and jury filters.
*
* <p>The updated settings are saved to the settings file. An error message is shown if the dialog
* is cancelled or the configuration is invalid.
*
* <p>If the configuration is for a per-pixel camera type (e.g. sCMOS) then the camera model will
* be loaded using the configured camera model name. This will be used to validate the filter to
* check the filter supports the per-pixel camera type.
*
* @param config the config
* @param flags the flags
* @return True if the configuration succeeded
*/
public static boolean configureDataFilter(final FitEngineConfiguration config, int flags) {
// Check we have at least the first filter.
if (config.getDataFiltersCount() == 0) {
throw new IllegalStateException("No primary filter is configured");
}
int filterCount;
switch(config.getDataFilterType()) {
case JURY:
filterCount = Integer.MAX_VALUE;
break;
case DIFFERENCE:
filterCount = 2;
break;
case SINGLE:
default:
filterCount = 1;
break;
}
int numberOfFilters = 1;
final String[] filterNames = SettingsManager.getDataFilterMethodNames();
final DataFilterMethod[] filterValues = SettingsManager.getDataFilterMethodValues();
final FitEngineConfigurationProvider fitEngineConfigurationProvider = () -> config;
for (int i = 1; i < filterCount; i++) {
final int filter = i + 1;
final int ii = i;
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
if (filter == filterCount) {
// This is maximum filter count so no continue option
ImageJUtils.addMessage(gd, "Configure the %s filter.", FitProtosHelper.getName(config.getDataFilterType()));
} else {
gd.enableYesNoCancel("Add", "Continue");
ImageJUtils.addMessage(gd, "Configure the %s filter.\nClick continue to proceed with the current set of %d.", FitProtosHelper.getName(config.getDataFilterType()), i);
}
final String fieldName = "Spot_filter" + filter;
if (IJ.isMacro()) {
// Use blank default value so bad macro parameters return nothing
gd.addStringField(fieldName, "");
} else {
gd.addChoice(fieldName, filterNames, filterNames[config.getDataFilterMethod(ii, config.getDataFilterMethod(ii - 1)).ordinal()]);
}
addRelativeParameterOptions(gd, new RelativeParameterProvider(0, 4.5, "Smoothing" + filter, fitEngineConfigurationProvider, true) {
@Override
void setAbsolute(boolean absolute) {
// Get the current settings
final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
final DataFilterMethod m = c.getDataFilterMethod(ii);
final double smooth = c.getDataFilterParameter(ii).getValue();
// Reset with the new absolute value
c.setDataFilter(m, smooth, absolute, ii);
}
@Override
boolean isAbsolute() {
final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
return c.getDataFilterParameterAbsolute(ii, c.getDataFilterParameterAbsolute(ii - 1));
}
@Override
double getValue() {
final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
return c.getDataFilterParameterValue(ii, c.getDataFilterParameterValue(ii - 1));
}
});
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
if (gd.wasOKed()) {
int filterIndex = -1;
if (IJ.isMacro()) {
final String filterName = gd.getNextString();
for (int j = 0; j < filterNames.length; j++) {
if (filterNames[j].equals(filterName)) {
filterIndex = j;
break;
}
}
if (filterIndex < 0) {
break;
}
} else {
filterIndex = gd.getNextChoiceIndex();
}
// Note: The absolute flag is set in extra options
config.setDataFilter(filterValues[filterIndex], Math.abs(gd.getNextNumber()), i);
gd.collectOptions();
numberOfFilters++;
} else {
break;
}
}
config.setNumberOfFilters(numberOfFilters);
if (BitFlagUtils.anyNotSet(flags, FLAG_NO_SAVE)) {
saveFitEngineSettings(config);
}
final FitConfiguration fitConfig = config.getFitConfiguration();
final CalibrationReader calibration = fitConfig.getCalibrationReader();
if (calibration.isScmos()) {
fitConfig.setCameraModel(CameraModelManager.load(fitConfig.getCameraModelName()));
}
try {
config.createSpotFilter();
} catch (final IllegalStateException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
return true;
}
Aggregations