Search in sources :

Example 6 with FitEngineConfiguration

use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class ConfigurationTemplateTest method canCreateResourceTemplate.

@Test
void canCreateResourceTemplate() throws IOException {
    // This is not really a test.
    // It creates some templates so that they can be put in the resources folder.
    final File tmpFile = File.createTempFile("template", ".json.txt");
    tmpFile.deleteOnExit();
    final FitEngineConfiguration config = new FitEngineConfiguration();
    final FitConfiguration fitConfig = config.getFitConfiguration();
    fitConfig.setMaxIterations(150);
    fitConfig.setMinWidthFactor(0.2);
    fitConfig.setMinWidthFactor(5);
    fitConfig.setSmartFilter(true);
    fitConfig.setDirectFilter(new MultiFilter2(0, 22, 0.56, 2.55, 3.3, 0, 31, 0, 0));
    config.setSearch(0.607);
    config.setBorder(1);
    config.setFitting(3);
    config.setFailuresLimit(3);
    config.setIncludeNeighbours(true);
    config.setNeighbourHeightThreshold(0.3);
    config.setResidualsThreshold(0.4);
    config.setDataFilterType(DataFilterType.SINGLE);
    config.setDataFilter(DataFilterMethod.GAUSSIAN, 0.425, false, 0);
    // System.out.println(tmpFile.getPath());
    final TemplateSettings.Builder builder = TemplateSettings.newBuilder();
    builder.setFitEngineSettings(config.getFitEngineSettings());
    Assertions.assertTrue(SettingsManager.toJson(builder.build(), tmpFile, SettingsManager.FLAG_JSON_WHITESPACE));
}
Also used : TemplateSettings(uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) MultiFilter2(uk.ac.sussex.gdsc.smlm.results.filter.MultiFilter2) File(java.io.File) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test)

Example 7 with FitEngineConfiguration

use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PsfCreator method loadConfiguration.

private boolean loadConfiguration() {
    final Configuration configPlugin = new Configuration();
    // PSF which is not allowed to be non-Gaussian.
    if (!PsfHelper.isGaussian2D(settings.getPsf())) {
        settings.setPsf(PsfProtosHelper.getDefaultPsf(PSFType.TWO_AXIS_GAUSSIAN_2D));
    }
    config = new FitEngineConfiguration(settings.getFitEngineSettings(), settings.getCalibration(), settings.getPsf());
    final boolean save = false;
    if (!configPlugin.showDialog(config, save)) {
        IJ.error(TITLE, "No fit configuration loaded");
        return false;
    }
    config = configPlugin.getFitEngineConfiguration();
    config.configureOutputUnits();
    config.setResidualsThreshold(1);
    fitConfig = config.getFitConfiguration();
    nmPerPixel = fitConfig.getCalibrationReader().getNmPerPixel();
    if (settings.getRadius() < 5 * Math.max(fitConfig.getInitialXSd(), fitConfig.getInitialYSd())) {
        settings.setRadius(5 * Math.max(fitConfig.getInitialXSd(), fitConfig.getInitialYSd()));
        ImageJUtils.log("Radius is less than 5 * PSF standard deviation, increasing to %s", MathUtils.rounded(settings.getRadius()));
    }
    boxRadius = (int) Math.ceil(settings.getRadius());
    settings.setFitEngineSettings(config.getFitEngineSettings());
    settings.setCalibration(fitConfig.getCalibration());
    settings.setPsf(fitConfig.getPsf());
    SettingsManager.writeSettings(settings);
    return true;
}
Also used : FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration)

Example 8 with FitEngineConfiguration

use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PeakFit method addDataFilterOptions.

/**
 * Adds the data filter options for the first filter. Adds to the dialog: <ul> <li>a choice of
 * filter type (e.g. single, difference, etc)</li> <li>a choice of primary filter (e.g. mean,
 * Gaussian, etc)</li> <li>a single slider for the primary filter parameter</li> </ul>
 *
 * @param gd the dialog
 * @param fitEngineConfigurationProvider the fit engine configuration provider
 */
public static void addDataFilterOptions(final ExtendedGenericDialog gd, final FitEngineConfigurationProvider fitEngineConfigurationProvider) {
    final int n = 0;
    final DataFilterMethod defaultFilterMethod = DataFilterMethod.GAUSSIAN;
    final double defaultFilterSmoothing = 0.5;
    final FitEngineConfiguration config = fitEngineConfigurationProvider.getFitEngineConfiguration();
    gd.addChoice("Spot_filter_type", SettingsManager.getDataFilterTypeNames(), config.getDataFilterType().ordinal());
    gd.addChoice("Spot_filter", SettingsManager.getDataFilterMethodNames(), config.getDataFilterMethod(n, defaultFilterMethod).ordinal());
    addRelativeParameterOptions(gd, new RelativeParameterProvider(0, 2.5, "Smoothing", fitEngineConfigurationProvider, true) {

        @Override
        void setAbsolute(boolean absolute) {
            final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
            final DataFilterMethod m = c.getDataFilterMethod(n, defaultFilterMethod);
            final double smooth = c.getDataFilterParameterValue(n, defaultFilterSmoothing);
            c.setDataFilter(m, smooth, absolute, n);
        }

        @Override
        boolean isAbsolute() {
            return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterAbsolute(n, false);
        }

        @Override
        double getValue() {
            return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterValue(n, defaultFilterSmoothing);
        }
    });
}
Also used : FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) DataFilterMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.DataFilterMethod)

Example 9 with FitEngineConfiguration

use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PsfDrift method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if ("hwhm".equals(arg)) {
        showHwhm();
        return;
    }
    // Build a list of suitable images
    final List<String> titles = createImageList(true);
    if (titles.isEmpty()) {
        IJ.error(TITLE, "No suitable PSF images");
        return;
    }
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    settings = Settings.load();
    fitConfig = fitConfigRef.get().createCopy();
    gd.addMessage("Select the input PSF image");
    gd.addChoice("PSF", titles.toArray(new String[0]), settings.title);
    gd.addCheckbox("Use_offset", settings.useOffset);
    gd.addNumericField("Scale", settings.scale, 2);
    gd.addNumericField("z_depth", settings.zDepth, 2, 6, "nm");
    gd.addNumericField("Grid_size", settings.gridSize, 0);
    gd.addSlider("Recall_limit", 0.01, 1, settings.recallLimit);
    gd.addSlider("Region_size", 2, 20, settings.regionSize);
    gd.addCheckbox("Background_fitting", settings.backgroundFitting);
    PeakFit.addPsfOptions(gd, fitConfig);
    gd.addChoice("Fit_solver", SettingsManager.getFitSolverNames(), FitProtosHelper.getName(fitConfig.getFitSolver()));
    // We need these to set bounds for any bounded fitters
    gd.addSlider("Min_width_factor", 0, 0.99, fitConfig.getMinWidthFactor());
    gd.addSlider("Width_factor", 1, 4.5, fitConfig.getMaxWidthFactor());
    gd.addCheckbox("Offset_fit", settings.offsetFitting);
    gd.addNumericField("Start_offset", settings.startOffset, 3);
    gd.addCheckbox("Include_CoM_fit", settings.comFitting);
    gd.addCheckbox("Use_sampling", settings.useSampling);
    gd.addNumericField("Photons", settings.photons, 0);
    gd.addSlider("Photon_limit", 0, 1, settings.photonLimit);
    gd.addSlider("Smoothing", 0, 0.5, settings.smoothing);
    gd.addHelp(HelpUrls.getUrl("psf-drift"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    settings.title = gd.getNextChoice();
    settings.useOffset = gd.getNextBoolean();
    settings.scale = gd.getNextNumber();
    settings.zDepth = gd.getNextNumber();
    settings.gridSize = (int) gd.getNextNumber();
    settings.recallLimit = gd.getNextNumber();
    settings.regionSize = (int) Math.abs(gd.getNextNumber());
    settings.backgroundFitting = gd.getNextBoolean();
    fitConfig.setPsfType(PeakFit.getPsfTypeValues()[gd.getNextChoiceIndex()]);
    // Some enum values are not supported
    fitConfig.setFitSolver(SettingsManager.getFitSolverValues()[gd.getNextChoiceIndex()]);
    fitConfig.setMinWidthFactor(gd.getNextNumber());
    fitConfig.setMaxWidthFactor(gd.getNextNumber());
    settings.offsetFitting = gd.getNextBoolean();
    settings.startOffset = Math.abs(gd.getNextNumber());
    settings.comFitting = gd.getNextBoolean();
    settings.useSampling = gd.getNextBoolean();
    settings.photons = Math.abs(gd.getNextNumber());
    settings.photonLimit = Math.abs(gd.getNextNumber());
    settings.smoothing = Math.abs(gd.getNextNumber());
    settings.save();
    fitConfigRef.set(fitConfig);
    gd.collectOptions();
    if (!settings.comFitting && !settings.offsetFitting) {
        IJ.error(TITLE, "No initial fitting positions");
        return;
    }
    if (settings.regionSize < 1) {
        settings.regionSize = 1;
    }
    if (gd.invalidNumber()) {
        return;
    }
    imp = WindowManager.getImage(settings.title);
    if (imp == null) {
        IJ.error(TITLE, "No PSF image for image: " + settings.title);
        return;
    }
    psfSettings = getPsfSettings(imp);
    if (psfSettings == null) {
        IJ.error(TITLE, "No PSF settings for image: " + settings.title);
        return;
    }
    // Configure the fit solver. We must wrap the settings with a
    // FitEngineConfiguration to pass to the PeakFit method
    final FitEngineSettings fitEngineSettings = FitProtosHelper.defaultFitEngineSettings;
    final FitEngineConfiguration config = new FitEngineConfiguration(fitEngineSettings, SettingsManager.readCalibration(0), PsfProtosHelper.defaultOneAxisGaussian2DPSF);
    config.getFitConfiguration().setFitSettings(fitConfig.getFitSettings());
    if (!PeakFit.configurePsfModel(config)) {
        return;
    }
    if (!PeakFit.configureFitSolver(config, IJImageSource.getBounds(imp), null, PeakFit.FLAG_NO_SAVE)) {
        return;
    }
    // Update configuration
    fitConfig = config.getFitConfiguration();
    fitConfigRef.set(fitConfig);
    computeDrift();
}
Also used : FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) FitEngineSettings(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.FitEngineSettings)

Example 10 with FitEngineConfiguration

use of uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration in project GDSC-SMLM by aherbert.

the class PsfEstimator method setup.

@Override
public int setup(String arg, ImagePlus imp) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    extraOptions = ImageJUtils.isExtraOptions();
    if (imp == null) {
        IJ.noImage();
        return DONE;
    }
    settings = SettingsManager.readPsfEstimatorSettings(0).toBuilder();
    // Reset
    if (IJ.controlKeyDown()) {
        config = new FitEngineConfiguration();
        final Calibration calibration = SettingsManager.readCalibration(0);
        config.getFitConfiguration().setCalibration(calibration);
        config.getFitConfiguration().setPsfType(PSFType.TWO_AXIS_AND_THETA_GAUSSIAN_2D);
    } else {
        config = SettingsManager.readFitEngineConfiguration(0);
    }
    final Roi roi = imp.getRoi();
    if (roi != null && roi.getType() != Roi.RECTANGLE) {
        IJ.error("Rectangular ROI required");
        return DONE;
    }
    return showDialog(imp);
}
Also used : FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) Roi(ij.gui.Roi)

Aggregations

FitEngineConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration)26 FitConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitConfiguration)9 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)6 TemplateSettings (uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings)4 ImagePlus (ij.ImagePlus)3 Checkbox (java.awt.Checkbox)3 BasePoint (uk.ac.sussex.gdsc.core.match.BasePoint)3 DataFilterMethod (uk.ac.sussex.gdsc.smlm.data.config.FitProtos.DataFilterMethod)3 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)3 MultiPathFilter (uk.ac.sussex.gdsc.smlm.results.filter.MultiPathFilter)3 ImageListener (ij.ImageListener)2 Choice (java.awt.Choice)2 Rectangle (java.awt.Rectangle)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NonBlockingExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)2 Calibration (uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration)2 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)2 FitEngineSettings (uk.ac.sussex.gdsc.smlm.data.config.FitProtos.FitEngineSettings)2 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)2 DirectFilter (uk.ac.sussex.gdsc.smlm.results.filter.DirectFilter)2