Search in sources :

Example 1 with CSV

use of cbit.vcell.math.CSV in project vcell by virtualcell.

the class ReferenceDataPanel method updateReferenceDataFromFile.

/**
 * Comment
 */
private void updateReferenceDataFromFile() {
    try {
        VCFileChooser fileChooser = new VCFileChooser();
        fileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_CSV);
        // Set the default file filter...
        fileChooser.setFileFilter(FileFilters.FILE_FILTER_CSV);
        // remove all selector
        fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
        File defaultPath = null;
        if (getUserPreferences() != null) {
            defaultPath = getUserPreferences().getCurrentDialogPath();
            if (defaultPath != null) {
                fileChooser.setCurrentDirectory(defaultPath);
            }
        }
        fileChooser.setDialogTitle("Import Data File");
        if (fileChooser.showOpenDialog(this) != javax.swing.JFileChooser.APPROVE_OPTION) {
            // user didn't choose save
            throw UserCancelException.CANCEL_FILE_SELECTION;
        } else {
            File selectedFile = fileChooser.getSelectedFile();
            if (selectedFile == null) {
                // no file selected (no name given)
                throw UserCancelException.CANCEL_FILE_SELECTION;
            } else {
                if (getUserPreferences() != null) {
                    File newPath = selectedFile.getParentFile();
                    if (!newPath.equals(defaultPath)) {
                        getUserPreferences().setCurrentDialogPath(newPath);
                    }
                }
                CSV csv = new CSV();
                RowColumnResultSet rowColumnResultSet = csv.importFrom(new java.io.FileReader(selectedFile));
                double[] weights = new double[rowColumnResultSet.getDataColumnCount()];
                java.util.Arrays.fill(weights, 1.0);
                ReferenceData referenceData = new SimpleReferenceData(rowColumnResultSet, weights);
                updateReferenceData(referenceData);
            }
        }
    } catch (UserCancelException e) {
    // ignore
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof ParseException) {
            showHelp((ParseException) e);
        } else {
            DialogUtils.showErrorDialog(this, e.getMessage(), e);
        }
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) CSV(cbit.vcell.math.CSV) VCFileChooser(org.vcell.util.gui.VCFileChooser) UserCancelException(org.vcell.util.UserCancelException) ParseException(java.text.ParseException) File(java.io.File) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ParseException(java.text.ParseException) UserCancelException(org.vcell.util.UserCancelException) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 2 with CSV

use of cbit.vcell.math.CSV in project vcell by virtualcell.

the class BrownianDynamicsTest method main.

public static void main(String[] args) {
    try {
        Options commandOptions = new Options();
        Option noiseOption = new Option(OPTION_NOISE, false, "sampled images use Poisson statistics for photons, default is to count particles");
        commandOptions.addOption(noiseOption);
        Option psfOption = new Option(OPTION_PSF, false, "sampled images are convolve with microscope psf, default is to bin");
        commandOptions.addOption(psfOption);
        Option imageFileOption = new Option(OPTION_IMAGEFILE, true, "file to store image time series");
        imageFileOption.setArgName("filename");
        imageFileOption.setValueSeparator('=');
        commandOptions.addOption(imageFileOption);
        Option plotFileOption = new Option(OPTION_PLOTFILE, true, "file to store CSV time series (reduced data for ROIs)");
        plotFileOption.setArgName("filename");
        plotFileOption.setValueSeparator('=');
        commandOptions.addOption(plotFileOption);
        Option displayImageOption = new Option(OPTION_DISPLAY_IMAGE, false, "display image time series");
        commandOptions.addOption(displayImageOption);
        Option displayPlotOption = new Option(OPTION_DISPLAY_PLOT, false, "display plot of bleach roi");
        commandOptions.addOption(displayPlotOption);
        Option extentOption = new Option(OPTION_EXTENT, true, "extent of entire domain (default " + DEFAULT_EXTENT_SCALE + ")");
        extentOption.setArgName("extent");
        extentOption.setValueSeparator('=');
        commandOptions.addOption(extentOption);
        Option imageSizeOption = new Option(OPTION_IMAGE_SIZE, true, "num pixels in x and y (default " + DEFAULT_IMAGE_SIZE + ")");
        imageSizeOption.setArgName("numPixels");
        imageSizeOption.setValueSeparator('=');
        commandOptions.addOption(imageSizeOption);
        Option numParticlesOption = new Option(OPTION_NUM_PARTICLES, true, "num particles (default " + DEFAULT_NUM_PARTICLES + ")");
        numParticlesOption.setArgName("num");
        numParticlesOption.setValueSeparator('=');
        commandOptions.addOption(numParticlesOption);
        Option diffusionOption = new Option(OPTION_DIFFUSION, true, "diffusion rate (default " + DEFAULT_DIFFUSION + ")");
        diffusionOption.setArgName("rate");
        diffusionOption.setValueSeparator('=');
        commandOptions.addOption(diffusionOption);
        Option bleachRadiusOption = new Option(OPTION_BLEACH_RADIUS, true, "bleach radius (default " + DEFAULT_BLEACH_RADIUS + ")");
        bleachRadiusOption.setArgName("radius");
        bleachRadiusOption.setValueSeparator('=');
        commandOptions.addOption(bleachRadiusOption);
        Option psfRadiusOption = new Option(OPTION_PSF_RADIUS, true, "psf radius (default " + DEFAULT_PSF_RADIUS + ")");
        psfRadiusOption.setArgName("radius");
        psfRadiusOption.setValueSeparator('=');
        commandOptions.addOption(psfRadiusOption);
        Option bleachDurationOption = new Option(OPTION_BLEACH_DURATION, true, "psf radius (default " + DEFAULT_BLEACH_DURATION + ")");
        bleachDurationOption.setArgName("duration");
        bleachDurationOption.setValueSeparator('=');
        commandOptions.addOption(bleachDurationOption);
        Option endTimeOption = new Option(OPTION_ENDTIME, true, "end time (default " + DEFAULT_ENDTIME + ")");
        endTimeOption.setArgName("time");
        endTimeOption.setValueSeparator('=');
        commandOptions.addOption(endTimeOption);
        CommandLine cmdLine = null;
        try {
            Parser parser = new BasicParser();
            cmdLine = parser.parse(commandOptions, args);
        } catch (ParseException e1) {
            e1.printStackTrace();
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp("BrownianDynamicsTest", commandOptions);
            System.exit(2);
        }
        boolean bNoise = cmdLine.hasOption(OPTION_NOISE);
        boolean bConvolve = cmdLine.hasOption(OPTION_PSF);
        File imageFile = null;
        if (cmdLine.hasOption(OPTION_IMAGEFILE)) {
            imageFile = new File(cmdLine.getOptionValue(OPTION_IMAGEFILE));
        }
        File plotFile = null;
        if (cmdLine.hasOption(OPTION_PLOTFILE)) {
            plotFile = new File(cmdLine.getOptionValue(OPTION_PLOTFILE));
        }
        boolean bDisplayImage = cmdLine.hasOption(OPTION_DISPLAY_IMAGE);
        boolean bDisplayPlot = cmdLine.hasOption(OPTION_DISPLAY_PLOT);
        double extentScale = DEFAULT_EXTENT_SCALE;
        if (cmdLine.hasOption(OPTION_EXTENT)) {
            extentScale = Double.parseDouble(cmdLine.getOptionValue(OPTION_EXTENT));
        }
        int imageSize = DEFAULT_IMAGE_SIZE;
        if (cmdLine.hasOption(OPTION_IMAGE_SIZE)) {
            imageSize = Integer.parseInt(cmdLine.getOptionValue(OPTION_IMAGE_SIZE));
        }
        int numParticles = DEFAULT_NUM_PARTICLES;
        if (cmdLine.hasOption(OPTION_NUM_PARTICLES)) {
            numParticles = Integer.parseInt(cmdLine.getOptionValue(OPTION_NUM_PARTICLES));
        }
        double diffusionRate = DEFAULT_DIFFUSION;
        if (cmdLine.hasOption(OPTION_DIFFUSION)) {
            diffusionRate = Double.parseDouble(cmdLine.getOptionValue(OPTION_DIFFUSION));
        }
        double bleachRadius = DEFAULT_BLEACH_RADIUS;
        if (cmdLine.hasOption(OPTION_BLEACH_RADIUS)) {
            bleachRadius = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_RADIUS));
        }
        double psfRadius = DEFAULT_PSF_RADIUS;
        if (cmdLine.hasOption(OPTION_PSF_RADIUS)) {
            psfRadius = Double.parseDouble(cmdLine.getOptionValue(OPTION_PSF_RADIUS));
        }
        double bleachDuration = DEFAULT_BLEACH_DURATION;
        if (cmdLine.hasOption(OPTION_BLEACH_DURATION)) {
            bleachDuration = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_DURATION));
        }
        double endTime = DEFAULT_ENDTIME;
        if (cmdLine.hasOption(OPTION_ENDTIME)) {
            endTime = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_DURATION));
        }
        // 
        // hard coded parameters
        // 
        Origin origin = new Origin(0, 0, 0);
        Extent extent = new Extent(extentScale, extentScale, 1);
        int numX = imageSize;
        int numY = imageSize;
        double psfVar = psfRadius * psfRadius;
        BrownianDynamicsTest test = new BrownianDynamicsTest();
        ImageTimeSeries<UShortImage> rawTimeSeries = test.generateTestData(origin, extent, numX, numY, numParticles, diffusionRate, psfVar, bleachRadius * bleachRadius, bNoise, bConvolve, bleachDuration, endTime);
        // 
        if (imageFile != null) {
            new ExportRawTimeSeriesToVFrapOp().exportToVFRAP(imageFile, rawTimeSeries, null);
        }
        // 
        if (bDisplayImage) {
            new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeries, "time series", null);
        }
        // 
        // compute reduced data if needed for plotting or saving.
        // 
        RowColumnResultSet reducedData = null;
        if (bDisplayPlot || plotFile != null) {
            double muX = origin.getX() + 0.5 * extent.getX();
            double muY = origin.getY() + 0.5 * extent.getY();
            double sigma = Math.sqrt(psfVar);
            NormalizedSampleFunction gaussian = NormalizedSampleFunction.fromGaussian("psf", origin, extent, new ISize(numX, numY, 1), muX, muY, sigma);
            reducedData = new GenerateReducedDataOp().generateReducedData(rawTimeSeries, new NormalizedSampleFunction[] { gaussian });
        }
        // 
        if (plotFile != null) {
            FileOutputStream fos = new FileOutputStream(plotFile);
            new CSV().exportTo(fos, reducedData);
        }
        if (bDisplayPlot) {
            new DisplayPlotOp().displayPlot(reducedData, "bleached roi", null);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Origin(org.vcell.util.Origin) Options(org.apache.commons.cli.Options) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) HelpFormatter(org.apache.commons.cli.HelpFormatter) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) CSV(cbit.vcell.math.CSV) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ExportRawTimeSeriesToVFrapOp(org.vcell.vmicro.op.ExportRawTimeSeriesToVFrapOp) ImageException(cbit.image.ImageException) ParseException(org.apache.commons.cli.ParseException) Parser(org.apache.commons.cli.Parser) BasicParser(org.apache.commons.cli.BasicParser) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) FileOutputStream(java.io.FileOutputStream) Option(org.apache.commons.cli.Option) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Example 3 with CSV

use of cbit.vcell.math.CSV in project vcell by virtualcell.

the class ImportTimeSeriesFromCSV method compute0.

@Override
protected void compute0(TaskContext context, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    CSV csv = new CSV();
    File inputFile = new File(context.getData(csvFile));
    RowColumnResultSet resultSet = csv.importFrom(new FileReader(inputFile));
    context.setData(timeSeries, resultSet);
}
Also used : CSV(cbit.vcell.math.CSV) FileReader(java.io.FileReader) File(java.io.File) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 4 with CSV

use of cbit.vcell.math.CSV in project vcell by virtualcell.

the class ReferenceDataPanel method showEditor.

/**
 * Comment
 */
private void showEditor() {
    ReferenceData referenceData = fieldParameterEstimationTask.getModelOptimizationSpec().getReferenceData();
    if (referenceData != null) {
        geteditorTextArea().setText(((SimpleReferenceData) referenceData).getCSV());
    } else {
        geteditorTextArea().setText("t, data1, data2\n0.0, 0.1, 0.21\n0.1, 0.15, 0.31\n0.2, 0.16, 0.44");
    }
    geteditorTextArea().setCaretPosition(0);
    try {
        int retVal = DialogUtils.showComponentOKCancelDialog(this, geteditorPanel(), "time series data editor");
        if (retVal == javax.swing.JOptionPane.OK_OPTION) {
            RowColumnResultSet rc = (new CSV()).importFrom(new java.io.StringReader(geteditorTextArea().getText()));
            double[] weights = new double[rc.getDataColumnCount()];
            java.util.Arrays.fill(weights, 1.0);
            SimpleReferenceData simpleRefData = new SimpleReferenceData(rc, weights);
            updateReferenceData(simpleRefData);
        }
    } catch (ParseException e) {
        e.printStackTrace();
        showHelp(e);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        DialogUtils.showErrorDialog(this, e.getMessage(), e);
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) CSV(cbit.vcell.math.CSV) ParseException(java.text.ParseException) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ParseException(java.text.ParseException) UserCancelException(org.vcell.util.UserCancelException) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 5 with CSV

use of cbit.vcell.math.CSV in project vcell by virtualcell.

the class KenworthyParticleTest method main.

public static void main(String[] args) {
    try {
        File baseDir = new File(".");
        // File baseDir = new File("/Users/schaff/Documents/workspace/VCell_5.4");
        // initialize computing environment
        // 
        File workingDirectory = new File(baseDir, "workingDir");
        LocalWorkspace localWorkspace = new LocalWorkspace(workingDirectory);
        // 
        // analyze raw data (from file?) using Keyworthy method.
        // 
        // File vfrapFile = new File(baseDir, "vfrapPaper/rawData/sim3/workflow.txt.save");
        File vfrapFile = new File(baseDir, "tryit.vfrap");
        ImageTimeSeries<UShortImage> fluorTimeSeriesImages = new ImportRawTimeSeriesFromVFrapOp().importRawTimeSeriesFromVFrap(vfrapFile);
        RowColumnResultSet reducedData = new CSV().importFrom(new FileReader(new File(baseDir, "tryit.csv")));
        analyzeKeyworthy(fluorTimeSeriesImages, reducedData, localWorkspace);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : LocalWorkspace(org.vcell.vmicro.workflow.data.LocalWorkspace) CSV(cbit.vcell.math.CSV) ImportRawTimeSeriesFromVFrapOp(org.vcell.vmicro.op.ImportRawTimeSeriesFromVFrapOp) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) FileReader(java.io.FileReader) File(java.io.File) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Aggregations

CSV (cbit.vcell.math.CSV)5 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)5 File (java.io.File)4 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)2 ReferenceData (cbit.vcell.opt.ReferenceData)2 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)2 FileReader (java.io.FileReader)2 ParseException (java.text.ParseException)2 UserCancelException (org.vcell.util.UserCancelException)2 ImageException (cbit.image.ImageException)1 FileOutputStream (java.io.FileOutputStream)1 BasicParser (org.apache.commons.cli.BasicParser)1 CommandLine (org.apache.commons.cli.CommandLine)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 Parser (org.apache.commons.cli.Parser)1 Extent (org.vcell.util.Extent)1 ISize (org.vcell.util.ISize)1