Search in sources :

Example 1 with OptModelTwoDiffWithPenalty

use of org.vcell.vmicro.workflow.data.OptModelTwoDiffWithPenalty in project vcell by virtualcell.

the class VFrapProcess method compute.

public static VFrapProcessResults compute(ImageTimeSeries rawTimeSeriesImages, double bleachThreshold, double cellThreshold, LocalWorkspace localWorkspace, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    GenerateCellROIsFromRawFrapTimeSeriesOp generateCellROIs = new GenerateCellROIsFromRawFrapTimeSeriesOp();
    GeometryRoisAndBleachTiming geometryAndTiming = generateCellROIs.generate(rawTimeSeriesImages, cellThreshold);
    GenerateNormalizedFrapDataOp generateNormalizedFrapData = new GenerateNormalizedFrapDataOp();
    NormalizedFrapDataResults normalizedFrapResults = generateNormalizedFrapData.generate(rawTimeSeriesImages, geometryAndTiming.backgroundROI_2D, geometryAndTiming.indexOfFirstPostbleach);
    GenerateBleachRoiOp generateROIs = new GenerateBleachRoiOp();
    ROI bleachROI = generateROIs.generateBleachRoi(normalizedFrapResults.normalizedFrapData.getAllImages()[0], geometryAndTiming.cellROI_2D, bleachThreshold);
    GenerateDependentImageROIsOp generateDependentROIs = new GenerateDependentImageROIsOp();
    ROI[] dataROIs = generateDependentROIs.generate(geometryAndTiming.cellROI_2D, bleachROI);
    NormalizedSampleFunction[] roiSampleFunctions = new NormalizedSampleFunction[dataROIs.length];
    for (int i = 0; i < dataROIs.length; i++) {
        roiSampleFunctions[i] = NormalizedSampleFunction.fromROI(dataROIs[i]);
    }
    GenerateReducedDataOp generateReducedNormalizedData = new GenerateReducedDataOp();
    RowColumnResultSet reducedData = generateReducedNormalizedData.generateReducedData(normalizedFrapResults.normalizedFrapData, roiSampleFunctions);
    ComputeMeasurementErrorOp computeMeasurementError = new ComputeMeasurementErrorOp();
    RowColumnResultSet measurementError = computeMeasurementError.computeNormalizedMeasurementError(roiSampleFunctions, geometryAndTiming.indexOfFirstPostbleach, rawTimeSeriesImages, normalizedFrapResults.prebleachAverage, clientTaskStatusSupport);
    GenerateTrivial2DPsfOp psf_2D = new GenerateTrivial2DPsfOp();
    UShortImage psf = psf_2D.generateTrivial2D_Psf();
    // RunRefSimulationOp runRefSimulationFull = new RunRefSimulationOp();
    // GenerateReducedROIDataOp generateReducedRefSimData = new GenerateReducedROIDataOp();
    RunRefSimulationFastOp runRefSimulationFast = new RunRefSimulationFastOp();
    RowColumnResultSet refData = runRefSimulationFast.runRefSimFast(geometryAndTiming.cellROI_2D, normalizedFrapResults.normalizedFrapData, dataROIs, psf, localWorkspace, clientTaskStatusSupport);
    final double refDiffusionRate = 1.0;
    double[] refSimTimePoints = refData.extractColumn(0);
    int numRois = refData.getDataColumnCount() - 1;
    int numRefSimTimes = refData.getRowCount();
    double[][] refSimData = new double[numRois][numRefSimTimes];
    for (int roi = 0; roi < numRois; roi++) {
        double[] roiData = refData.extractColumn(roi + 1);
        for (int t = 0; t < numRefSimTimes; t++) {
            refSimData[roi][t] = roiData[t];
        }
    }
    ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
    OptModelOneDiff optModelOneDiff = new OptModelOneDiff(refSimData, refSimTimePoints, refDiffusionRate);
    Generate2DOptContextOp generate2DOptContextOne = new Generate2DOptContextOp();
    OptContext optContextOneDiff = generate2DOptContextOne.generate2DOptContext(optModelOneDiff, reducedData, measurementError, errorFunction);
    RunProfileLikelihoodGeneralOp runProfileLikelihoodOne = new RunProfileLikelihoodGeneralOp();
    ProfileData[] profileDataOne = runProfileLikelihoodOne.runProfileLikihood(optContextOneDiff, clientTaskStatusSupport);
    // OptModelTwoDiffWithoutPenalty optModelTwoDiffWithoutPenalty = new OptModelTwoDiffWithoutPenalty(refSimData, refSimTimePoints, refDiffusionRate);
    // Generate2DOptContextOp generate2DOptContextTwoWithoutPenalty = new Generate2DOptContextOp();
    // OptContext optContextTwoDiffWithoutPenalty = generate2DOptContextTwoWithoutPenalty.generate2DOptContext(optModelTwoDiffWithoutPenalty, reducedData, measurementError);
    // RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithoutPenalty = new RunProfileLikelihoodGeneralOp();
    // ProfileData[] profileDataTwoWithoutPenalty = runProfileLikelihoodTwoWithoutPenalty.runProfileLikihood(optContextTwoDiffWithoutPenalty, clientTaskStatusSupport);
    OptModelTwoDiffWithPenalty optModelTwoDiffWithPenalty = new OptModelTwoDiffWithPenalty(refSimData, refSimTimePoints, refDiffusionRate);
    Generate2DOptContextOp generate2DOptContextTwoWithPenalty = new Generate2DOptContextOp();
    OptContext optContextTwoDiffWithPenalty = generate2DOptContextTwoWithPenalty.generate2DOptContext(optModelTwoDiffWithPenalty, reducedData, measurementError, errorFunction);
    RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithPenalty = new RunProfileLikelihoodGeneralOp();
    ProfileData[] profileDataTwoWithPenalty = runProfileLikelihoodTwoWithPenalty.runProfileLikihood(optContextTwoDiffWithPenalty, clientTaskStatusSupport);
    // 
    // SLOW WAY
    // 
    // runRefSimulationFull.cellROI_2D,generateCellROIs.cellROI_2D);
    // runRefSimulationFull.normalizedTimeSeries,generateNormalizedFrapData.normalizedFrapData);
    // workflow.addTask(runRefSimulationFull);
    // generateReducedRefSimData.imageTimeSeries,runRefSimulationFull.refSimTimeSeries);
    // generateReducedRefSimData.imageDataROIs,generateDependentROIs.imageDataROIs);
    // workflow.addTask(generateReducedRefSimData);
    // DataHolder<RowColumnResultSet> reducedROIData = generateReducedRefSimData.reducedROIData;
    // DataHolder<Double> refSimDiffusionRate = runRefSimulationFull.refSimDiffusionRate;
    VFrapProcessResults results = new VFrapProcessResults(dataROIs, geometryAndTiming.cellROI_2D, bleachROI, normalizedFrapResults.normalizedFrapData, reducedData, profileDataOne, profileDataTwoWithPenalty);
    return results;
}
Also used : OptModelOneDiff(org.vcell.vmicro.workflow.data.OptModelOneDiff) GenerateCellROIsFromRawFrapTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp) GenerateDependentImageROIsOp(org.vcell.vmicro.op.GenerateDependentImageROIsOp) RunProfileLikelihoodGeneralOp(org.vcell.vmicro.op.RunProfileLikelihoodGeneralOp) ErrorFunctionNoiseWeightedL2(org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2) OptContext(org.vcell.vmicro.workflow.data.OptContext) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) OptModelTwoDiffWithPenalty(org.vcell.vmicro.workflow.data.OptModelTwoDiffWithPenalty) GenerateTrivial2DPsfOp(org.vcell.vmicro.op.GenerateTrivial2DPsfOp) 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) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ProfileData(org.vcell.optimization.ProfileData) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) RunRefSimulationFastOp(org.vcell.vmicro.op.RunRefSimulationFastOp) GenerateNormalizedFrapDataOp(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp)

Example 2 with OptModelTwoDiffWithPenalty

use of org.vcell.vmicro.workflow.data.OptModelTwoDiffWithPenalty in project vcell by virtualcell.

the class GenerateRefSimOptModel method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    RowColumnResultSet refSimDataset = context.getData(refSimData);
    double[] refSimTimePoints = refSimDataset.extractColumn(0);
    int numRois = refSimDataset.getDataColumnCount() - 1;
    int numRefSimTimes = refSimDataset.getRowCount();
    double[][] refSimData = new double[numRois][numRefSimTimes];
    for (int roi = 0; roi < numRois; roi++) {
        double[] roiData = refSimDataset.extractColumn(roi + 1);
        for (int t = 0; t < numRefSimTimes; t++) {
            refSimData[roi][t] = roiData[t];
        }
    }
    ModelType modelType = ModelType.valueOf(context.getData(this.modelType));
    OptModel optModel = null;
    Double refSimDiff = context.getData(refSimDiffusionRate);
    switch(modelType) {
        case DiffOne:
            {
                optModel = new OptModelOneDiff(refSimData, refSimTimePoints, refSimDiff);
                break;
            }
        case DiffTwoWithoutPenalty:
            {
                optModel = new OptModelTwoDiffWithoutPenalty(refSimData, refSimTimePoints, refSimDiff);
                break;
            }
        case DiffTwoWithPenalty:
            {
                optModel = new OptModelTwoDiffWithPenalty(refSimData, refSimTimePoints, refSimDiff);
                break;
            }
        default:
            {
                throw new RuntimeException("model type " + modelType + " not supported");
            }
    }
    context.setData(this.optModel, optModel);
}
Also used : OptModelOneDiff(org.vcell.vmicro.workflow.data.OptModelOneDiff) OptModelTwoDiffWithPenalty(org.vcell.vmicro.workflow.data.OptModelTwoDiffWithPenalty) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) OptModel(org.vcell.vmicro.workflow.data.OptModel) OptModelTwoDiffWithoutPenalty(org.vcell.vmicro.workflow.data.OptModelTwoDiffWithoutPenalty)

Aggregations

RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)2 OptModelOneDiff (org.vcell.vmicro.workflow.data.OptModelOneDiff)2 OptModelTwoDiffWithPenalty (org.vcell.vmicro.workflow.data.OptModelTwoDiffWithPenalty)2 ROI (cbit.vcell.VirtualMicroscopy.ROI)1 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)1 ProfileData (org.vcell.optimization.ProfileData)1 ComputeMeasurementErrorOp (org.vcell.vmicro.op.ComputeMeasurementErrorOp)1 Generate2DOptContextOp (org.vcell.vmicro.op.Generate2DOptContextOp)1 GenerateBleachRoiOp (org.vcell.vmicro.op.GenerateBleachRoiOp)1 GenerateCellROIsFromRawFrapTimeSeriesOp (org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp)1 GeometryRoisAndBleachTiming (org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp.GeometryRoisAndBleachTiming)1 GenerateDependentImageROIsOp (org.vcell.vmicro.op.GenerateDependentImageROIsOp)1 GenerateNormalizedFrapDataOp (org.vcell.vmicro.op.GenerateNormalizedFrapDataOp)1 NormalizedFrapDataResults (org.vcell.vmicro.op.GenerateNormalizedFrapDataOp.NormalizedFrapDataResults)1 GenerateReducedDataOp (org.vcell.vmicro.op.GenerateReducedDataOp)1 GenerateTrivial2DPsfOp (org.vcell.vmicro.op.GenerateTrivial2DPsfOp)1 RunProfileLikelihoodGeneralOp (org.vcell.vmicro.op.RunProfileLikelihoodGeneralOp)1 RunRefSimulationFastOp (org.vcell.vmicro.op.RunRefSimulationFastOp)1 ErrorFunction (org.vcell.vmicro.workflow.data.ErrorFunction)1 ErrorFunctionNoiseWeightedL2 (org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2)1