use of org.vcell.vmicro.workflow.data.OptModelOneDiff 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;
}
use of org.vcell.vmicro.workflow.data.OptModelOneDiff 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);
}
Aggregations