Search in sources :

Example 1 with PeakResultsReader

use of uk.ac.sussex.gdsc.smlm.results.PeakResultsReader in project GDSC-SMLM by aherbert.

the class ShowResultsHeader method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    final Settings settings = Settings.load();
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Show the results header in the ImageJ log");
    gd.addFilenameField("Filename", settings.inputFilename, 30);
    gd.addCheckbox("Raw", settings.raw);
    gd.addHelp(HelpUrls.getUrl("show-results-header"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    settings.inputFilename = gd.getNextString();
    settings.raw = gd.getNextBoolean();
    settings.save();
    final PeakResultsReader reader = new PeakResultsReader(settings.inputFilename);
    final String header = reader.getHeader();
    if (header == null) {
        IJ.error(TITLE, "No header found in file: " + settings.inputFilename);
        return;
    }
    if (settings.raw) {
        // The ImageJ TextPanel class correctly stores lines with tab characters.
        // However when it is drawn in ij.text.TextCanvas using java.awt.Graphics.drawChars(...)
        // the instance of this class is sun.java2d.SunGraphics2D which omits '\t' chars.
        // This may be a problem specific to the Linux JRE.
        // TODO - Find out if this is a Linux specific bug.
        // Output the raw text. This preserves the tabs in the Cut/Copy commands.
        IJ.log(header);
        // IJ.log(header.replace("\t", " "));
        return;
    }
    // Output what information we can extract
    boolean found = false;
    found |= show("Format", reader.getFormat().toString());
    found |= show("Name", reader.getName());
    found |= show("Bounds", reader.getBounds());
    found |= show("Source", reader.getSource());
    found |= show("Calibration", reader.getCalibration());
    found |= show("PSF", reader.getPsf());
    found |= show("Configuration", reader.getConfiguration());
    if (!found) {
        IJ.error(TITLE, "No header information found in file: " + settings.inputFilename);
    }
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) PeakResultsReader(uk.ac.sussex.gdsc.smlm.results.PeakResultsReader)

Example 2 with PeakResultsReader

use of uk.ac.sussex.gdsc.smlm.results.PeakResultsReader in project GDSC-SMLM by aherbert.

the class CreateData method getSimulationResults.

private static MemoryPeakResults getSimulationResults() {
    if (benchmarkAuto) {
        // Load directly from a results file. This is mainly to be used to load simulations
        // saved to memory then saved to file.
        final PeakResultsReader r = new PeakResultsReader(benchmarkFile);
        final MemoryPeakResults results = r.getResults();
        if (results != null) {
            ResultsManager.checkCalibration(results);
            return results;
        }
    }
    // Load using a universal text file
    if (loadSettings == null) {
        loadSettings = SettingsManager.readLoadLocalisationsSettings(0).toBuilder();
    }
    // String tmp = loadSettings.getLocalisationsFilename();
    loadSettings.setLocalisationsFilename(benchmarkFile);
    // Ignore fields that are not required,
    // e.g. the dataset name
    final boolean hide = loadSettings.getHideFieldDatasetName();
    loadSettings.setHideFieldDatasetName(true);
    final LocalisationList localisations = LoadLocalisations.loadLocalisations(loadSettings);
    loadSettings.setHideFieldDatasetName(hide);
    SettingsManager.writeSettings(loadSettings.build());
    if (localisations == null || localisations.isEmpty()) {
        return null;
    }
    return localisations.toPeakResults("Dummy");
}
Also used : LocalisationList(uk.ac.sussex.gdsc.smlm.ij.plugins.LoadLocalisations.LocalisationList) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ImmutableMemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.ImmutableMemoryPeakResults) PeakResultsReader(uk.ac.sussex.gdsc.smlm.results.PeakResultsReader)

Example 3 with PeakResultsReader

use of uk.ac.sussex.gdsc.smlm.results.PeakResultsReader in project GDSC-SMLM by aherbert.

the class FilterAnalysis method readResults.

private static List<MemoryPeakResults> readResults(String inputDirectory) {
    final LastResults last = lastResults.get();
    if (last != null && last.inputDirectory.equals(inputDirectory)) {
        final GenericDialog gd = new GenericDialog(TITLE);
        gd.addMessage("Re-use results from the same directory (no to refresh)?");
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.showDialog();
        if (gd.wasOKed()) {
            return last.resultsList;
        }
    }
    final List<MemoryPeakResults> list = new LinkedList<>();
    final File[] fileList = (new File(inputDirectory)).listFiles((dir, name) -> name.endsWith(".xls") || name.endsWith(".csv") || name.endsWith(".bin"));
    if (fileList != null) {
        // Exclude directories
        for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isFile()) {
                IJ.showStatus(String.format("Reading results ... %d/%d", i + 1, fileList.length));
                IJ.showProgress(i, fileList.length);
                final PeakResultsReader reader = new PeakResultsReader(fileList[i].getPath());
                final MemoryPeakResults results = reader.getResults();
                if (results != null && results.size() > 0) {
                    list.add(results);
                }
            }
        }
    }
    ImageJUtils.finished();
    lastResults.set(new LastResults(list, inputDirectory));
    return list;
}
Also used : GenericDialog(ij.gui.GenericDialog) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) PeakResultsReader(uk.ac.sussex.gdsc.smlm.results.PeakResultsReader) File(java.io.File) LinkedList(java.util.LinkedList)

Example 4 with PeakResultsReader

use of uk.ac.sussex.gdsc.smlm.results.PeakResultsReader in project GDSC-SMLM by aherbert.

the class ResultsManager method loadInputResults.

/**
 * Load the results from the named input option. If the results are not empty then a check can be
 * made for calibration, and data using the specified units. If the calibration cannot be obtained
 * or the units are incorrect then the null will be returned.
 *
 * @param inputOption the input option
 * @param checkCalibration Set to true to ensure the results have a valid calibration
 * @param distanceUnit the required distance unit for the results
 * @param intensityUnit the required intensity unit for the results
 * @param extraOptions the extra options
 * @return the results
 */
public static MemoryPeakResults loadInputResults(String inputOption, boolean checkCalibration, DistanceUnit distanceUnit, IntensityUnit intensityUnit, LoadOption... extraOptions) {
    MemoryPeakResults results = null;
    PeakResultsReader reader = null;
    if (inputOption.equals(INPUT_NONE)) {
    // Do nothing
    } else if (inputOption.equals(INPUT_FILE)) {
        IJ.showStatus("Reading results file ...");
        reader = new PeakResultsReader(findFileName(extraOptions));
        IJ.showStatus("Reading " + reader.getFormat() + " results file ...");
        final ResultOption[] options = reader.getOptions();
        if (options.length != 0) {
            collectOptions(reader, options);
        }
        reader.setTracker(SimpleImageJTrackProgress.getInstance());
        results = reader.getResults();
        reader.getTracker().progress(1.0);
        // If the name contains a .tif suffix then create an image source
        if (results != null && results.size() > 0 && results.getName() != null && results.getName().contains(".tif") && results.getSource() == null) {
            final int index = results.getName().indexOf(".tif");
            results.setSource(new IJImageSource(results.getName().substring(0, index)));
        }
    } else {
        results = loadMemoryResults(inputOption);
    }
    try {
        if (results == null) {
            return null;
        }
        if (results.isEmpty()) {
            return results;
        }
        if (checkCalibration && !checkCalibration(results, reader)) {
            return null;
        }
        if (distanceUnit != null && results.getDistanceUnit() != distanceUnit) {
            ImageJUtils.log("Incorrect distance unit: " + results.getDistanceUnit());
            return null;
        }
        if (intensityUnit != null && results.getIntensityUnit() != intensityUnit) {
            ImageJUtils.log("Incorrect intensity unit: " + results.getDistanceUnit());
            return null;
        }
    } finally {
        IJ.showStatus("");
    }
    return results;
}
Also used : IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) PeakResultsReader(uk.ac.sussex.gdsc.smlm.results.PeakResultsReader)

Aggregations

PeakResultsReader (uk.ac.sussex.gdsc.smlm.results.PeakResultsReader)4 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)3 GenericDialog (ij.gui.GenericDialog)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)1 IJImageSource (uk.ac.sussex.gdsc.smlm.ij.IJImageSource)1 LocalisationList (uk.ac.sussex.gdsc.smlm.ij.plugins.LoadLocalisations.LocalisationList)1 ImmutableMemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.ImmutableMemoryPeakResults)1