Search in sources :

Example 1 with ResultsFileSettings

use of uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings in project GDSC-SMLM by aherbert.

the class ResultsManager method addFileResults.

private void addFileResults(PeakResultsList resultsList, boolean showDeviations, boolean showEndFrame, boolean showId, boolean showCategory) {
    final ResultsFileSettings resultsFileSettings = this.resultsSettings.getResultsFileSettings();
    if (!TextUtils.isNullOrEmpty(resultsFileSettings.getResultsFilename())) {
        // Remove extension
        final String resultsFilename = FileUtils.replaceExtension(resultsFileSettings.getResultsFilename(), ResultsProtosHelper.getExtension(resultsFileSettings.getFileFormat()));
        if (fileInput && settings.inputFilename.equals(resultsFilename)) {
            IJ.log(TITLE + ": Input and output files are the same, skipping output ...");
            return;
        }
        // Update
        this.resultsSettings.getResultsFileSettingsBuilder().setResultsFilename(resultsFilename);
        SettingsManager.writeSettings(this.resultsSettings.build());
        // Check if file exists
        final File file = new File(resultsFilename);
        if (file.exists()) {
            final YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), TITLE, "Overwrite existing file?\n" + resultsFilename);
            if (!d.yesPressed()) {
                return;
            }
        }
        addFileResults(resultsList, resultsFileSettings, resultsFilename, showDeviations, showEndFrame, showId, showCategory);
    }
}
Also used : ResultsFileSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings) YesNoCancelDialog(ij.gui.YesNoCancelDialog) File(java.io.File)

Example 2 with ResultsFileSettings

use of uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings in project GDSC-SMLM by aherbert.

the class ResultsManager method batchSave.

/**
 * Batch save a set of results files.
 */
private void batchSave() {
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "No localisations in memory");
        return;
    }
    final MultiDialog md = createMultiDialog(TITLE);
    md.setSelected(lastSelected.get());
    md.setHelpUrl(HelpUrls.getUrl("batch-save-results"));
    md.showDialog();
    if (md.wasCancelled()) {
        return;
    }
    final List<String> selected = md.getSelectedResults();
    if (selected.isEmpty()) {
        return;
    }
    lastSelected.set(selected);
    resultsSettings = SettingsManager.readResultsSettings(0).toBuilder();
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    addFileResultsOptions(gd, resultsSettings, FLAG_RESULTS_DIRECTORY | FLAG_NO_SECTION_HEADER);
    gd.addHelp(HelpUrls.getUrl("batch-save-results"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    gd.collectOptions();
    final ResultsFileSettings.Builder b = resultsSettings.getResultsFileSettingsBuilder();
    final String dir = gd.getNextString();
    b.setFileFormatValue(gd.getNextChoiceIndex());
    b.setResultsDirectory(dir);
    SettingsManager.writeSettings(resultsSettings);
    if (!new File(dir).exists()) {
        IJ.error(TITLE, "Output directory does not exist");
        return;
    }
    final ResultsFileSettings resultsFileSettings = resultsSettings.getResultsFileSettings();
    if (resultsFileSettings.getFileFormatValue() <= 0) {
        IJ.error(TITLE, "No output file format");
        return;
    }
    int count = 0;
    for (final String name : selected) {
        final MemoryPeakResults r = MemoryPeakResults.getResults(name);
        if (r != null && save(resultsFileSettings, r)) {
            count++;
        }
    }
    IJ.showStatus("Saved " + TextUtils.pleural(count, "dataset"));
}
Also used : ResultsFileSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) File(java.io.File) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Example 3 with ResultsFileSettings

use of uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings in project GDSC-SMLM by aherbert.

the class PeakFit method addFileResults.

private void addFileResults(PeakResultsList resultsList) {
    final ResultsFileSettings resultsFileSettings = this.resultsSettings.getResultsFileSettings();
    if (resultsFileSettings.getFileFormat().getNumber() > 0) {
        String resultsFilename = null;
        if (resultsFileSettings.getResultsDirectory() != null && new File(resultsFileSettings.getResultsDirectory()).exists()) {
            resultsFilename = resultsFileSettings.getResultsDirectory() + File.separatorChar + source.getName() + ".results." + ResultsProtosHelper.getExtension(resultsFileSettings.getFileFormat());
        // This is used for running via other code calling PeakFit methods,
        // i.e. not as an ImageJ plugin.
        } else if (pluginFlags == 0) {
            resultsFilename = resultsFileSettings.getResultsFilename();
        }
        final PeakResults r = ResultsManager.addFileResults(resultsList, resultsFileSettings, resultsFilename, this.resultsSettings.getShowDeviations(), getShowEndFrame(), false, false);
        if (r instanceof FilePeakResults) {
            final FilePeakResults fr = (FilePeakResults) r;
            fr.setSortAfterEnd(Prefs.getThreads() > 1);
        }
    }
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) FilePeakResults(uk.ac.sussex.gdsc.smlm.results.FilePeakResults) ImageJTablePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) ResultsFileSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings) File(java.io.File) FilePeakResults(uk.ac.sussex.gdsc.smlm.results.FilePeakResults)

Aggregations

File (java.io.File)3 ResultsFileSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings)3 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)2 YesNoCancelDialog (ij.gui.YesNoCancelDialog)1 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)1 MultiDialog (uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)1 ImageJImagePeakResults (uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults)1 ImageJTablePeakResults (uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults)1 FilePeakResults (uk.ac.sussex.gdsc.smlm.results.FilePeakResults)1 PeakResults (uk.ac.sussex.gdsc.smlm.results.PeakResults)1