Search in sources :

Example 1 with ExportRawTimeSeriesToVFrapOp

use of org.vcell.vmicro.op.ExportRawTimeSeriesToVFrapOp 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 2 with ExportRawTimeSeriesToVFrapOp

use of org.vcell.vmicro.op.ExportRawTimeSeriesToVFrapOp in project vcell by virtualcell.

the class ExportRawTimeSeriesToVFrap method compute0.

@Override
protected void compute0(TaskContext context, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // get inputs
    File outputFile = context.getData(vfrapFile);
    ImageTimeSeries imageTimeSeries = context.getData(rawTimeSeriesImages);
    // validate that imageTimeSeries is of type ImageTimeSeries<UShortImage>
    Image[] images = imageTimeSeries.getAllImages();
    UShortImage[] usImages = new UShortImage[images.length];
    for (int i = 0; i < usImages.length; i++) {
        if (!(images[i] instanceof UShortImage)) {
            throw new Exception("type mismatch, expecting only UShortImages in time series");
        }
        usImages[i] = (UShortImage) images[i];
    }
    ImageTimeSeries<UShortImage> ushortImageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, usImages, imageTimeSeries.getImageTimeStamps(), imageTimeSeries.getSizeZ());
    ExportRawTimeSeriesToVFrapOp op = new ExportRawTimeSeriesToVFrapOp();
    op.exportToVFRAP(outputFile, ushortImageTimeSeries, clientTaskStatusSupport);
    // write output (just boolean "done" flag)
    context.setData(written, true);
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Image(cbit.vcell.VirtualMicroscopy.Image) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ExportRawTimeSeriesToVFrapOp(org.vcell.vmicro.op.ExportRawTimeSeriesToVFrapOp) File(java.io.File) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Aggregations

UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)2 File (java.io.File)2 ExportRawTimeSeriesToVFrapOp (org.vcell.vmicro.op.ExportRawTimeSeriesToVFrapOp)2 ImageException (cbit.image.ImageException)1 Image (cbit.vcell.VirtualMicroscopy.Image)1 CSV (cbit.vcell.math.CSV)1 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)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 Origin (org.vcell.util.Origin)1 GenerateReducedDataOp (org.vcell.vmicro.op.GenerateReducedDataOp)1 DisplayPlotOp (org.vcell.vmicro.op.display.DisplayPlotOp)1