Search in sources :

Example 26 with RowColumnResultSet

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

the class RunRefSimulationFast method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    ImageTimeSeries<FloatImage> normTimeSeries = context.getData(normalizedTimeSeries);
    ROI cellROI = context.getData(cellROI_2D);
    ROI[] imageDataRois = context.getData(imageDataROIs);
    UShortImage psf = context.getData(this.psf);
    // do op
    RunRefSimulationFastOp op = new RunRefSimulationFastOp();
    RowColumnResultSet reducedData = op.runRefSimFast(cellROI, normTimeSeries, imageDataRois, psf, context.getLocalWorkspace(), clientTaskStatusSupport);
    // set output
    context.setData(reducedROIData, reducedData);
    // always D = 1,
    context.setData(refSimDiffusionRate, op.getReferenceDiffusionCoef());
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) RunRefSimulationFastOp(org.vcell.vmicro.op.RunRefSimulationFastOp) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 27 with RowColumnResultSet

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

the class GenerateReducedDataOp method generateReducedData.

public RowColumnResultSet generateReducedData(ImageTimeSeries<? extends Image> imageTimeSeries, NormalizedSampleFunction[] rois) throws Exception {
    int numROIs = rois.length;
    int numTimes = imageTimeSeries.getSizeT();
    String[] roiNames = new String[numROIs + 1];
    roiNames[0] = "t";
    for (int i = 0; i < numROIs; i++) {
        roiNames[i + 1] = rois[i].getName();
    }
    RowColumnResultSet reducedData = new RowColumnResultSet(roiNames);
    for (int t = 0; t < numTimes; t++) {
        double[] row = new double[numROIs + 1];
        row[0] = imageTimeSeries.getImageTimeStamps()[t];
        for (int r = 0; r < numROIs; r++) {
            SampleStatistics result = rois[r].sample(imageTimeSeries.getAllImages()[t]);
            row[r + 1] = result.weightedMean;
        }
        reducedData.addRow(row);
    }
    return reducedData;
}
Also used : SampleStatistics(org.vcell.vmicro.workflow.data.NormalizedSampleFunction.SampleStatistics) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 28 with RowColumnResultSet

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

the class NormalizeRawBleachDataOp method normalizeRawBleachData.

public RowColumnResultSet normalizeRawBleachData(RowColumnResultSet rawExpDataset) throws Exception {
    if (rawExpDataset.getColumnDescriptionsCount() != 2) {
        throw new Exception("expecting 2 columns in rawExpData input");
    }
    double[] rawExpTimes = rawExpDataset.extractColumn(0);
    double[] rawFluor = rawExpDataset.extractColumn(1);
    int firstPostbleachIndex = findFirstPostbleachIndex(rawFluor);
    double prebleachAvg = 0;
    for (int i = 0; i < firstPostbleachIndex; i++) {
        prebleachAvg += rawFluor[i];
    }
    prebleachAvg /= firstPostbleachIndex;
    RowColumnResultSet normExpDataset = new RowColumnResultSet(new String[] { "t", "normFluor" });
    for (int rawIndex = firstPostbleachIndex; rawIndex < rawFluor.length; rawIndex++) {
        double normTime = rawExpTimes[rawIndex] - rawExpTimes[firstPostbleachIndex];
        double normFluor = rawFluor[rawIndex] / prebleachAvg;
        normExpDataset.addRow(new double[] { normTime, normFluor });
    }
    return normExpDataset;
}
Also used : RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 29 with RowColumnResultSet

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

the class WorkflowObjectsTableModel method getValue.

private String getValue(WorkflowObject workflowObject) {
    if (workflowObject instanceof Task) {
        return "";
    } else {
        Object data = null;
        Class dataType = null;
        if (workflowObject instanceof WorkflowDataSource) {
            WorkflowDataSource dataHolder = (WorkflowDataSource) workflowObject;
            WorkflowDataSource dataSource = taskContext.getWorkflow().getDataSource((DataObject) dataHolder);
            data = taskContext.getRepository().getData(dataSource);
            dataType = dataHolder.getType();
        } else if (workflowObject instanceof DataInput) {
            DataInput dataInput = (DataInput) workflowObject;
            data = taskContext.getData(dataInput);
            dataType = dataInput.getType();
        }
        if (data instanceof RowColumnResultSet) {
            RowColumnResultSet rc = (RowColumnResultSet) data;
            int N = rc.getColumnDescriptionsCount();
            StringBuffer buffer = new StringBuffer(rc.getRowCount() + " rows of " + N + " {");
            int MAX = 3;
            for (int i = 0; i < N; i++) {
                buffer.append("\"" + rc.getColumnDescriptions(i).getDisplayName() + "\"");
                if (i >= MAX - 1) {
                    buffer.append(", ...");
                    break;
                }
                if (i < N - 1) {
                    buffer.append(", ");
                }
            }
            buffer.append("}");
            return buffer.toString();
        } else if (data instanceof String) {
            return "\"" + (String) data + "\"";
        } else if (data instanceof ROI) {
            return "ROI \"" + ((ROI) data).getROIName() + "\"";
        } else if (data instanceof ROI[]) {
            ROI[] rois = (ROI[]) data;
            int N = rois.length;
            int MAX = 3;
            StringBuffer buffer = new StringBuffer("ROI[" + N + "] { ");
            for (int i = 0; i < N; i++) {
                buffer.append("\"" + rois[i].getROIName() + "\"");
                if (i >= MAX - 1) {
                    buffer.append(", ...");
                    break;
                }
                if (i < N - 1) {
                    buffer.append(", ");
                }
            }
            buffer.append("}");
            return buffer.toString();
        } else if (data instanceof Image) {
            Image image = (Image) data;
            return image.getClass().getSimpleName() + " " + image.getISize().toString();
        } else if (data instanceof ImageTimeSeries) {
            ImageTimeSeries ts = (ImageTimeSeries) data;
            int N = ts.getSizeT();
            double[] times = ts.getImageTimeStamps();
            return ts.getType().getSimpleName() + "[" + N + "] " + ts.getISize() + " times=[" + times[0] + "," + times[N - 1] + "]";
        } else if (data != null) {
            return data.toString();
        } else {
            return "null " + dataType.getSimpleName();
        }
    }
}
Also used : Task(org.vcell.workflow.Task) Image(cbit.vcell.VirtualMicroscopy.Image) ROI(cbit.vcell.VirtualMicroscopy.ROI) WorkflowDataSource(org.vcell.workflow.WorkflowDataSource) DataInput(org.vcell.workflow.DataInput) DataObject(org.vcell.workflow.DataObject) WorkflowObject(org.vcell.workflow.WorkflowObject) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 30 with RowColumnResultSet

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

the class KenworthyWorkflowTest 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, 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 ComputeMeasurementErrorOp().computeNormalizedMeasurementError(sampleFunctions, indexOfFirstPostbleach, rawTimeSeriesImages, prebleachAvg, null);
    ErrorFunction errorFunction = new ErrorFunctionKenworthy(reducedData);
    // 
    // 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, reducedData, measurementErrors, 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, reducedData, measurementErrors, errorFunction);
    String title_u3 = "Uniform Disk Model - 3 parameters, (Rn=" + bleachRadius_ROI + ")";
    new DisplayInteractiveModelOp().displayOptModel(uniformDisk3Context, sampleFunctions, localWorkspace, title_u3, null);
    // 
    // GaussianFit parameter uniform disk model
    // 
    FloatImage prebleachBleachAreaImage = new FloatImage(prebleachAvg);
    // mask-out all but the bleach area
    prebleachBleachAreaImage.and(bleachROI.getRoiImages()[0]);
    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 : OptModelKenworthyGaussian(org.vcell.vmicro.workflow.data.OptModelKenworthyGaussian) GenerateCellROIsFromRawFrapTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp) FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) OptContext(org.vcell.vmicro.workflow.data.OptContext) OptModel(org.vcell.vmicro.workflow.data.OptModel) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) DisplayInteractiveModelOp(org.vcell.vmicro.op.display.DisplayInteractiveModelOp) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) OptModelKenworthyUniformDisk2P(org.vcell.vmicro.workflow.data.OptModelKenworthyUniformDisk2P) FitBleachSpotOp(org.vcell.vmicro.op.FitBleachSpotOp) ErrorFunctionKenworthy(org.vcell.vmicro.workflow.data.ErrorFunctionKenworthy) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) GeometryRoisAndBleachTiming(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp.GeometryRoisAndBleachTiming) NormalizedFrapDataResults(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp.NormalizedFrapDataResults) GenerateBleachRoiOp(org.vcell.vmicro.op.GenerateBleachRoiOp) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) FitBleachSpotOpResults(org.vcell.vmicro.op.FitBleachSpotOp.FitBleachSpotOpResults) GenerateNormalizedFrapDataOp(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp) OptModelKenworthyUniformDisk3P(org.vcell.vmicro.workflow.data.OptModelKenworthyUniformDisk3P)

Aggregations

RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)34 ROI (cbit.vcell.VirtualMicroscopy.ROI)10 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)7 File (java.io.File)6 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)5 CSV (cbit.vcell.math.CSV)5 UserCancelException (org.vcell.util.UserCancelException)5 Generate2DOptContextOp (org.vcell.vmicro.op.Generate2DOptContextOp)5 ErrorFunction (org.vcell.vmicro.workflow.data.ErrorFunction)5 NormalizedSampleFunction (org.vcell.vmicro.workflow.data.NormalizedSampleFunction)5 OptContext (org.vcell.vmicro.workflow.data.OptContext)5 OptModel (org.vcell.vmicro.workflow.data.OptModel)5 Image (cbit.vcell.VirtualMicroscopy.Image)4 ReferenceData (cbit.vcell.opt.ReferenceData)4 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 ComputeMeasurementErrorOp (org.vcell.vmicro.op.ComputeMeasurementErrorOp)4 GenerateReducedDataOp (org.vcell.vmicro.op.GenerateReducedDataOp)4 DisplayPlotOp (org.vcell.vmicro.op.display.DisplayPlotOp)4 DisplayTimeSeriesOp (org.vcell.vmicro.op.display.DisplayTimeSeriesOp)4