Search in sources :

Example 1 with DisplayPlotOp

use of org.vcell.vmicro.op.display.DisplayPlotOp in project vcell by virtualcell.

the class DisplayPlot method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // get input
    String titleString = context.getDataWithDefault(title, "no title");
    RowColumnResultSet plotdata = context.getData(plotData);
    // do op
    DisplayPlotOp op = new DisplayPlotOp();
    op.displayPlot(plotdata, titleString, null);
    // set output
    context.setData(displayed, true);
}
Also used : DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 2 with DisplayPlotOp

use of org.vcell.vmicro.op.display.DisplayPlotOp in project vcell by virtualcell.

the class WorkflowObjectsPanel method displayData.

private void displayData(TaskContext taskContext, WorkflowObject workflowObject) {
    if (workflowObject instanceof DataInput || workflowObject instanceof DataOutput) {
        String title = parametersFunctionsTableModel.getName(workflowObject);
        WindowListener listener = new WindowAdapter() {
        };
        Object data = null;
        if (workflowObject instanceof WorkflowDataSource) {
            WorkflowDataSource dataHolder = (WorkflowDataSource) workflowObject;
            data = taskContext.getRepository().getData(dataHolder);
        } else if (workflowObject instanceof DataInput) {
            DataInput dataInput = (DataInput) workflowObject;
            data = taskContext.getData(dataInput);
        }
        if (data instanceof RowColumnResultSet) {
            RowColumnResultSet rc = (RowColumnResultSet) data;
            try {
                new DisplayPlotOp().displayPlot(rc, title, listener);
            } catch (ExpressionException e) {
                e.printStackTrace();
            }
        } else if (data instanceof ROI) {
            ROI roi = (ROI) data;
            Image image = roi.getRoiImages()[0];
            new DisplayImageOp().displayImage(image, title, listener);
        } else if (data instanceof ProfileData[]) {
            ProfileData[] profileData = (ProfileData[]) data;
            new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(profileData, title, listener);
        } else if (data instanceof Image) {
            Image image = (Image) data;
            new DisplayImageOp().displayImage(image, title, listener);
        } else if (data instanceof ImageTimeSeries) {
            ImageTimeSeries imageTimeSeries = (ImageTimeSeries) data;
            try {
                DisplayTimeSeries.displayImageTimeSeries(imageTimeSeries, title, listener);
            } catch (ImageException | IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : DataOutput(org.vcell.workflow.DataOutput) DisplayProfileLikelihoodPlotsOp(org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp) WindowListener(java.awt.event.WindowListener) ImageException(cbit.image.ImageException) WindowAdapter(java.awt.event.WindowAdapter) ProfileData(org.vcell.optimization.ProfileData) IOException(java.io.IOException) Image(cbit.vcell.VirtualMicroscopy.Image) ROI(cbit.vcell.VirtualMicroscopy.ROI) WorkflowDataSource(org.vcell.workflow.WorkflowDataSource) ExpressionException(cbit.vcell.parser.ExpressionException) DataInput(org.vcell.workflow.DataInput) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) WorkflowObject(org.vcell.workflow.WorkflowObject) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 3 with DisplayPlotOp

use of org.vcell.vmicro.op.display.DisplayPlotOp 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 4 with DisplayPlotOp

use of org.vcell.vmicro.op.display.DisplayPlotOp in project vcell by virtualcell.

the class PhotoactivationExperimentTest method analyzePhotoactivation.

/**
 * Fits raw image time series data to uniform disk models (with Guassian or Uniform fluorescence).
 *
 * @param rawTimeSeriesImages
 * @param localWorkspace
 * @throws Exception
 */
private static void analyzePhotoactivation(ImageTimeSeries<UShortImage> rawTimeSeriesImages, LocalWorkspace localWorkspace) throws Exception {
    // 
    // correct the timestamps (1 per second).
    // 
    double[] timeStamps = rawTimeSeriesImages.getImageTimeStamps();
    for (int i = 0; i < timeStamps.length; i++) {
        timeStamps[i] = i;
    }
    new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeriesImages, "raw images", (WindowListener) null);
    ImageTimeSeries<UShortImage> blurredRaw = blurTimeSeries(rawTimeSeriesImages);
    new DisplayTimeSeriesOp().displayImageTimeSeries(blurredRaw, "blurred raw images", (WindowListener) null);
    double cellThreshold = 0.4;
    GeometryRoisAndActivationTiming cellROIresults = new GenerateCellROIsFromRawPhotoactivationTimeSeriesOp().generate(blurredRaw, cellThreshold);
    ROI backgroundROI = cellROIresults.backgroundROI_2D;
    ROI cellROI = cellROIresults.cellROI_2D;
    int indexOfFirstPostactivation = cellROIresults.indexOfFirstPostactivation;
    boolean backgroundSubtract = false;
    boolean normalizeByPreActivation = false;
    NormalizedPhotoactivationDataResults normResults = new GenerateNormalizedPhotoactivationDataOp().generate(rawTimeSeriesImages, backgroundROI, indexOfFirstPostactivation, backgroundSubtract, normalizeByPreActivation);
    ImageTimeSeries<FloatImage> normalizedTimeSeries = normResults.normalizedPhotoactivationData;
    FloatImage preactivationAvg = normResults.preactivationAverageImage;
    FloatImage normalizedPostactivation = normalizedTimeSeries.getAllImages()[0];
    new DisplayTimeSeriesOp().displayImageTimeSeries(normalizedTimeSeries, "normalized images", (WindowListener) null);
    // 
    // create a single bleach ROI by thresholding
    // 
    double activatedThreshold = 1000;
    ROI activatedROI = new GenerateActivationRoiOp().generateActivatedRoi(blurredRaw.getAllImages()[indexOfFirstPostactivation], cellROI, activatedThreshold);
    new DisplayImageOp().displayImage(activatedROI.getRoiImages()[0], "activated roi", null);
    new DisplayImageOp().displayImage(cellROI.getRoiImages()[0], "cell roi", null);
    new DisplayImageOp().displayImage(backgroundROI.getRoiImages()[0], "background roi", null);
    {
        // 
        // only use bleach ROI for fitting etc.
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau = new Parameter("tau", 0.001, 200.0, 1.0, 0.1);
        Parameter f_init = new Parameter("f_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_final = new Parameter("f_final", 0.01, 4000, 1.0, 0.5);
        Parameter[] parameters = new Parameter[] { tau, f_init, f_final };
        OptModel optModel = new OptModel("photoactivation (activated roi)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau = newParams[0];
                double max = newParams[1];
                double offset = newParams[2];
                double[][] solution = new double[1][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[0][i] = offset + (max - offset) * Math.exp(-t / tau);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated ROI only", null);
    }
    {
        // 
        // only activation ROI for chemistry, cellROI for bleaching
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI), NormalizedSampleFunction.fromROI(cellROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data (2)", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error (2)", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau_active = new Parameter("tau_active", 0.001, 200.0, 1.0, 0.1);
        Parameter f_active_init = new Parameter("f_active_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_active_amplitude = new Parameter("f_active_amplitude", 0.01, 4000, 1.0, 0.5);
        Parameter f_cell_init = new Parameter("f_cell_init", 0.01, 4000, 1.0, 0.1);
        Parameter f_cell_amplitude = new Parameter("f_cell_amplitude", 0.01, 4000, 1.0, 0.1);
        Parameter tau_cell = new Parameter("tau_cell", 0.00001, 200, 1.0, 1);
        Parameter[] parameters = new Parameter[] { tau_active, f_active_init, f_active_amplitude, tau_cell, f_cell_init, f_cell_amplitude };
        OptModel optModel = new OptModel("photoactivation (activated and cell rois)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau_active = newParams[0];
                double max_active = newParams[1];
                double amplitude_active = newParams[2];
                double tau_cell = newParams[3];
                double max_cell = newParams[4];
                double amplitude_cell = newParams[5];
                final int ACTIVE_ROI = 0;
                final int CELL_ROI = 1;
                final int NUM_ROIS = 2;
                double[][] solution = new double[NUM_ROIS][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[ACTIVE_ROI][i] = (max_active - amplitude_active) + (amplitude_active) * Math.exp(-t / tau_active) * Math.exp(-t / tau_cell);
                    solution[CELL_ROI][i] = (max_cell - amplitude_cell) + (amplitude_cell) * Math.exp(-t / tau_cell);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunctionNoiseWeightedL2 errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated and cell ROIs", null);
    }
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) GenerateCellROIsFromRawPhotoactivationTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp) ErrorFunctionNoiseWeightedL2(org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2) OptContext(org.vcell.vmicro.workflow.data.OptContext) OptModel(org.vcell.vmicro.workflow.data.OptModel) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) NormalizedPhotoactivationDataResults(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp.NormalizedPhotoactivationDataResults) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) GeometryRoisAndActivationTiming(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp.GeometryRoisAndActivationTiming) DisplayInteractiveModelOp(org.vcell.vmicro.op.display.DisplayInteractiveModelOp) GenerateActivationRoiOp(org.vcell.vmicro.op.GenerateActivationRoiOp) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) Parameter(cbit.vcell.opt.Parameter) GenerateNormalizedPhotoactivationDataOp(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp)

Example 5 with DisplayPlotOp

use of org.vcell.vmicro.op.display.DisplayPlotOp in project vcell by virtualcell.

the class KenworthyParticleTest method analyzeKeyworthy.

/**
 * Fits raw image time series data to uniform disk models (with Guassian or Uniform fluorescence).
 *
 * @param rawTimeSeriesImages
 * @param localWorkspace
 * @throws Exception
 */
private static void analyzeKeyworthy(ImageTimeSeries<UShortImage> rawTimeSeriesImages, RowColumnResultSet reducedData, LocalWorkspace localWorkspace) throws Exception {
    new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeriesImages, "raw images", (WindowListener) null);
    // double cellThreshold = 0.5;
    // GeometryRoisAndBleachTiming cellROIresults = new GenerateCellROIsFromRawFrapTimeSeriesOp().generate(rawTimeSeriesImages, cellThreshold);
    // ROI backgroundROI = cellROIresults.backgroundROI_2D;
    // ROI cellROI = cellROIresults.cellROI_2D;
    // int indexOfFirstPostbleach = cellROIresults.indexOfFirstPostbleach;
    // 
    // new DisplayImageOp().displayImage(backgroundROI.getRoiImages()[0], "background ROI", null);
    // new DisplayImageOp().displayImage(cellROI.getRoiImages()[0], "cell ROI", null);
    // 
    // NormalizedFrapDataResults normResults = new GenerateNormalizedFrapDataOp().generate(rawTimeSeriesImages, backgroundROI, indexOfFirstPostbleach);
    // ImageTimeSeries<FloatImage> normalizedTimeSeries = normResults.normalizedFrapData;
    // FloatImage prebleachAvg = normResults.prebleachAverage;
    // FloatImage normalizedPostbleach = normalizedTimeSeries.getAllImages()[0];
    // 
    // 
    // new DisplayTimeSeriesOp().displayImageTimeSeries(normalizedTimeSeries, "normalized images", (WindowListener)null);
    // //
    // // create a single bleach ROI by thresholding
    // //
    // double bleachThreshold = 0.80;
    // ROI bleachROI = new GenerateBleachRoiOp().generateBleachRoi(normalizedPostbleach, cellROI, bleachThreshold);
    // 
    // //
    // // only use bleach ROI for fitting etc.
    // //
    // //		ROI[] dataROIs = new ROI[] { bleachROI };
    // 
    // //
    // // fit 2D Gaussian to normalized data to determine center, radius and K factor of bleach (assuming exp(-exp
    // //
    // FitBleachSpotOpResults fitSpotResults = new FitBleachSpotOp().fit(NormalizedSampleFunction.fromROI(bleachROI), normalizedTimeSeries.getAllImages()[0]);
    // double bleachFactorK_GaussianFit = fitSpotResults.bleachFactorK_GaussianFit;
    // double bleachRadius_GaussianFit = fitSpotResults.bleachRadius_GaussianFit;
    // double bleachRadius_ROI = fitSpotResults.bleachRadius_ROI;
    // double centerX_GaussianFit = fitSpotResults.centerX_GaussianFit;
    // double centerX_ROI = fitSpotResults.centerX_ROI;
    // double centerY_GaussianFit = fitSpotResults.centerY_GaussianFit;
    // double centerY_ROI = fitSpotResults.centerY_ROI;
    // 
    // NormalizedSampleFunction[] sampleFunctions = new NormalizedSampleFunction[] {
    // NormalizedSampleFunction.fromROI(bleachROI)
    // };
    // 
    // get reduced data and errors for each ROI
    // 
    // RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, sampleFunctions);
    RowColumnResultSet measurementErrors = new RowColumnResultSet(new String[] { reducedData.getColumnDescriptions()[0].getName(), reducedData.getColumnDescriptions()[1].getName() });
    for (int i = 0; i < reducedData.getRowCount(); i++) {
        double[] row = new double[] { reducedData.getRow(i)[0], Math.sqrt(reducedData.getRow(i)[1]) };
        measurementErrors.addRow(row);
    }
    new DisplayPlotOp().displayPlot(reducedData, "raw reduced data", null);
    new DisplayPlotOp().displayPlot(measurementErrors, "raw reduced noise", null);
    // 
    // find large drop and determine first post-bleach timepoint.
    // 
    double largestDrop = -1000000;
    int indexLargestDrop = -1;
    for (int i = 1; i < reducedData.getRowCount(); i++) {
        double drop = reducedData.getRow(i - 1)[1] - reducedData.getRow(i)[1];
        if (drop > largestDrop) {
            indexLargestDrop = i;
            largestDrop = drop;
        }
    }
    System.out.println("index of first postbleach is " + indexLargestDrop);
    // 
    // normalize data and noise and start with first post-bleach index;
    // 
    RowColumnResultSet normalizedReducedData = new RowColumnResultSet(new String[] { reducedData.getColumnDescriptions()[0].getName(), reducedData.getColumnDescriptions()[1].getName() });
    RowColumnResultSet normalizedNoiseData = new RowColumnResultSet(new String[] { reducedData.getColumnDescriptions()[0].getName(), reducedData.getColumnDescriptions()[1].getName() });
    for (int i = indexLargestDrop; i < reducedData.getRowCount(); i++) {
        double timeAfterBleach = reducedData.getRow(i)[0] - reducedData.getRow(indexLargestDrop)[0];
        double normalizedData = reducedData.getRow(i)[1] / reducedData.getRow(0)[1];
        double[] newDataRow = new double[] { timeAfterBleach, normalizedData };
        normalizedReducedData.addRow(newDataRow);
        double normalizedNoise = measurementErrors.getRow(i)[1] / reducedData.getRow(0)[1];
        double[] newNoiseRow = new double[] { timeAfterBleach, normalizedNoise };
        normalizedNoiseData.addRow(newNoiseRow);
    }
    new DisplayPlotOp().displayPlot(normalizedReducedData, "normalized reduced data", null);
    new DisplayPlotOp().displayPlot(normalizedNoiseData, "normalized reduced noise", null);
    NormalizedSampleFunction[] sampleFunctions = new NormalizedSampleFunction[] { NormalizedSampleFunction.createUniform("psf", null, null, new ISize(10, 10, 1)) };
    ErrorFunction errorFunction = new ErrorFunctionKenworthy(normalizedReducedData);
    // ErrorFunction errorFunction = new ErrorFunctionMeanSquared();
    double bleachRadius_ROI = 2;
    // 
    // 2 parameter uniform disk model
    // 
    OptModel uniformDisk2OptModel = new OptModelKenworthyUniformDisk2P(bleachRadius_ROI);
    String title_u2 = "Uniform Disk Model - 2 parameters, (Rn=" + bleachRadius_ROI + ")";
    OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(uniformDisk2OptModel, normalizedReducedData, normalizedNoiseData, errorFunction);
    new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, sampleFunctions, localWorkspace, title_u2, null);
    // 
    // 3 parameter uniform disk model
    // 
    OptModel uniformDisk3OptModel = new OptModelKenworthyUniformDisk3P(bleachRadius_ROI);
    OptContext uniformDisk3Context = new Generate2DOptContextOp().generate2DOptContext(uniformDisk3OptModel, normalizedReducedData, normalizedNoiseData, errorFunction);
    String title_u3 = "Uniform Disk Model - 3 parameters, (Rn=" + bleachRadius_ROI + ")";
    new DisplayInteractiveModelOp().displayOptModel(uniformDisk3Context, sampleFunctions, localWorkspace, title_u3, null);
    ProfileData[] profileData = new RunProfileLikelihoodGeneralOp().runProfileLikihood(uniformDisk3Context, null);
    new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(profileData, "3param model", null);
// 
// GaussianFit parameter uniform disk model
// 
// FloatImage prebleachBleachAreaImage = new FloatImage(prebleachAvg);
// prebleachBleachAreaImage.and(bleachROI.getRoiImages()[0]); // mask-out all but the bleach area
// double prebleachAvgInROI = prebleachBleachAreaImage.getImageStatistics().meanValue;
// OptModel gaussian2OptModel = new OptModelKenworthyGaussian(prebleachAvgInROI, bleachFactorK_GaussianFit, bleachRadius_GaussianFit, bleachRadius_ROI);
// OptContext gaussianDisk2Context = new Generate2DOptContextOp().generate2DOptContext(gaussian2OptModel, reducedData, measurementErrors, errorFunction);
// String title_g2 = "Gaussian Disk Model - 2 parameters (prebleach="+prebleachAvgInROI+",K="+bleachFactorK_GaussianFit+",Re="+bleachRadius_GaussianFit+",Rnom="+bleachRadius_ROI+")";
// new DisplayInteractiveModelOp().displayOptModel(gaussianDisk2Context, sampleFunctions, localWorkspace, title_g2, null);
}
Also used : DisplayProfileLikelihoodPlotsOp(org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp) ISize(org.vcell.util.ISize) RunProfileLikelihoodGeneralOp(org.vcell.vmicro.op.RunProfileLikelihoodGeneralOp) ProfileData(org.vcell.optimization.ProfileData) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) OptContext(org.vcell.vmicro.workflow.data.OptContext) OptModel(org.vcell.vmicro.workflow.data.OptModel) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) DisplayInteractiveModelOp(org.vcell.vmicro.op.display.DisplayInteractiveModelOp) OptModelKenworthyUniformDisk2P(org.vcell.vmicro.workflow.data.OptModelKenworthyUniformDisk2P) ErrorFunctionKenworthy(org.vcell.vmicro.workflow.data.ErrorFunctionKenworthy) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) OptModelKenworthyUniformDisk3P(org.vcell.vmicro.workflow.data.OptModelKenworthyUniformDisk3P)

Aggregations

RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)5 DisplayPlotOp (org.vcell.vmicro.op.display.DisplayPlotOp)5 DisplayTimeSeriesOp (org.vcell.vmicro.op.display.DisplayTimeSeriesOp)3 ImageException (cbit.image.ImageException)2 ROI (cbit.vcell.VirtualMicroscopy.ROI)2 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)2 ProfileData (org.vcell.optimization.ProfileData)2 ISize (org.vcell.util.ISize)2 Generate2DOptContextOp (org.vcell.vmicro.op.Generate2DOptContextOp)2 GenerateReducedDataOp (org.vcell.vmicro.op.GenerateReducedDataOp)2 DisplayImageOp (org.vcell.vmicro.op.display.DisplayImageOp)2 DisplayInteractiveModelOp (org.vcell.vmicro.op.display.DisplayInteractiveModelOp)2 DisplayProfileLikelihoodPlotsOp (org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp)2 ErrorFunction (org.vcell.vmicro.workflow.data.ErrorFunction)2 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)1 Image (cbit.vcell.VirtualMicroscopy.Image)1 CSV (cbit.vcell.math.CSV)1 Parameter (cbit.vcell.opt.Parameter)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 WindowAdapter (java.awt.event.WindowAdapter)1