Search in sources :

Example 1 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class NeighbourAnalysis method saveTraces.

private void saveTraces(Trace[] traces) {
    String[] path = Utils.decodePath(filename);
    OpenDialog chooser = new OpenDialog("Traces_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        filename = chooser.getDirectory() + chooser.getFileName();
        // Remove extension and replace with .xls
        int index = filename.lastIndexOf('.');
        if (index > 0) {
            filename = filename.substring(0, index);
        }
        filename += ".xls";
        boolean showDeviations = (!results.getResults().isEmpty() && results.getHead().paramsStdDev != null);
        FilePeakResults traceResults = new FilePeakResults(filename, showDeviations);
        traceResults.copySettings(results);
        traceResults.begin();
        if (!traceResults.isActive()) {
            IJ.error(TITLE, "Failed to write to file: " + filename);
            return;
        }
        traceResults.addComment(createSettingsComment());
        for (Trace trace : traces) // addTrace(...) does a sort on the results
        traceResults.addCluster(trace);
        traceResults.end();
    }
}
Also used : Trace(gdsc.smlm.results.Trace) OpenDialog(ij.io.OpenDialog) FilePeakResults(gdsc.smlm.results.FilePeakResults)

Example 2 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class FilterAnalysis method readFilterSets.

@SuppressWarnings("unchecked")
private List<FilterSet> readFilterSets() {
    GlobalSettings gs = SettingsManager.loadSettings();
    FilterSettings filterSettings = gs.getFilterSettings();
    String[] path = Utils.decodePath(filterSettings.filterSetFilename);
    OpenDialog chooser = new OpenDialog("Filter_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        IJ.showStatus("Reading filters ...");
        filterSettings.filterSetFilename = chooser.getDirectory() + chooser.getFileName();
        BufferedReader input = null;
        try {
            FileInputStream fis = new FileInputStream(filterSettings.filterSetFilename);
            input = new BufferedReader(new UnicodeReader(fis, null));
            Object o = XStreamWrapper.getInstance().fromXML(input);
            if (o != null && o instanceof List<?>) {
                SettingsManager.saveSettings(gs);
                return (List<FilterSet>) o;
            }
            IJ.log("No filter sets defined in the specified file: " + filterSettings.filterSetFilename);
        } catch (Exception e) {
            IJ.log("Unable to load the filter sets from file: " + e.getMessage());
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                // Ignore
                }
            }
            IJ.showStatus("");
        }
    }
    return null;
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) UnicodeReader(gdsc.core.utils.UnicodeReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) OpenDialog(ij.io.OpenDialog) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) FilterSettings(gdsc.smlm.ij.settings.FilterSettings)

Example 3 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class DriftCalculator method getDriftFilename.

private boolean getDriftFilename() {
    String[] path = Utils.decodePath(driftFilename);
    OpenDialog chooser = new OpenDialog("Drift_file", path[0], path[1]);
    if (chooser.getFileName() == null)
        return false;
    driftFilename = chooser.getDirectory() + chooser.getFileName();
    Utils.replaceExtension(driftFilename, "tsv");
    return true;
}
Also used : OpenDialog(ij.io.OpenDialog)

Example 4 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class CreateData method saveImage.

/**
	 * Save the image to a TIFF file
	 * 
	 * @param imp
	 */
private void saveImage(ImagePlus imp) {
    if (!settings.saveImage)
        return;
    String[] path = Utils.decodePath(settings.imageFilename);
    OpenDialog chooser = new OpenDialog("Image_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        settings.imageFilename = chooser.getDirectory() + chooser.getFileName();
        settings.imageFilename = Utils.replaceExtension(settings.imageFilename, "tiff");
        FileSaver fs = new FileSaver(imp);
        boolean ok;
        if (imp.getStackSize() > 1)
            ok = fs.saveAsTiffStack(settings.imageFilename);
        else
            ok = fs.saveAsTiff(settings.imageFilename);
        if (!ok)
            IJ.log("Failed to save image to file: " + settings.imageFilename);
    }
}
Also used : FileSaver(ij.io.FileSaver) OpenDialog(ij.io.OpenDialog)

Example 5 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class CreateData method saveLocalisations.

/**
	 * Save the localisations to a text file
	 * 
	 * @param localisations
	 */
private void saveLocalisations(List<LocalisationModel> localisations) {
    if (!settings.saveLocalisations)
        return;
    sortLocalisationsByTime(localisations);
    //		Collections.sort(localisations, new Comparator<LocalisationModel>(){
    //
    //			public int compare(LocalisationModel o1, LocalisationModel o2)
    //			{
    //				int cellx1 = (int)(o1.getX() / settings.cellSize);
    //				int cellx2 = (int)(o2.getX() / settings.cellSize);
    //				int result = cellx2 - cellx1;
    //				if (result != 0)
    //					return result;
    //				int celly1 = (int)(o1.getY() / settings.cellSize);
    //				int celly2 = (int)(o2.getY() / settings.cellSize);
    //				result = celly2 - celly1;
    //				if (result != 0)
    //					return result;
    //				return (o1.getZ() == o2.getZ()) ? 0 : (o1.getZ() == 0) ? -1 : 1;
    //			}});
    String[] path = Utils.decodePath(settings.localisationsFilename);
    OpenDialog chooser = new OpenDialog("Localisations_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        settings.localisationsFilename = chooser.getDirectory() + chooser.getFileName();
        settings.localisationsFilename = Utils.replaceExtension(settings.localisationsFilename, "xls");
        BufferedWriter output = null;
        try {
            output = new BufferedWriter(new FileWriter(settings.localisationsFilename));
            output.write(createResultsFileHeader());
            output.write("#T\tId\tX\tY\tZ\tIntensity");
            output.newLine();
            for (LocalisationModel l : localisations) {
                StringBuffer sb = new StringBuffer();
                sb.append(l.getTime()).append("\t");
                sb.append(l.getId()).append("\t");
                sb.append(IJ.d2s(l.getX(), 6)).append("\t");
                sb.append(IJ.d2s(l.getY(), 6)).append("\t");
                sb.append(IJ.d2s(l.getZ(), 6)).append("\t");
                sb.append(l.getIntensity());
                output.write(sb.toString());
                output.newLine();
            }
        } catch (Exception e) {
            // Q. Add better handling of errors?
            e.printStackTrace();
            IJ.log("Failed to save localisations to file: " + settings.localisationsFilename);
        } finally {
            if (output != null) {
                try {
                    output.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : LocalisationModel(gdsc.smlm.model.LocalisationModel) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IOException(java.io.IOException) NullArgumentException(org.apache.commons.math3.exception.NullArgumentException) OpenDialog(ij.io.OpenDialog) BufferedWriter(java.io.BufferedWriter)

Aggregations

OpenDialog (ij.io.OpenDialog)34 IOException (java.io.IOException)13 ImagePlus (ij.ImagePlus)6 FormatException (loci.formats.FormatException)6 BufferedWriter (java.io.BufferedWriter)5 File (java.io.File)5 NullArgumentException (org.apache.commons.math3.exception.NullArgumentException)4 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)3 FilePeakResults (gdsc.smlm.results.FilePeakResults)3 AmiraMeshDecoder (amira.AmiraMeshDecoder)2 FilterSettings (gdsc.smlm.ij.settings.FilterSettings)2 FileSaver (ij.io.FileSaver)2 Layer (ini.trakem2.display.Layer)2 Patch (ini.trakem2.display.Patch)2 YesNoDialog (ini.trakem2.display.YesNoDialog)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 ArrayList (java.util.ArrayList)2