use of org.vcell.vmicro.workflow.data.ROIDataGenerator in project vcell by virtualcell.
the class RunRefSimulationFastOp method runRefSimulation.
private RowColumnResultSet runRefSimulation(ROI cellROI, ROI[] imageDataROIs, UShortImage psf, FloatImage initRefConc, double experimentalRecoveryTime, LocalWorkspace localWorkspace, ClientTaskStatusSupport progressListener) throws Exception {
User owner = LocalWorkspace.getDefaultOwner();
KeyValue simKey = LocalWorkspace.createNewKeyValue();
//
// save first image from normalized time series as the initial concentration field data
//
ExternalDataInfo initialConcentrationExtData = createNewExternalDataInfo(localWorkspace, INITCONC_EXTDATA_NAME);
Extent extent = initRefConc.getExtent();
Origin origin = initRefConc.getOrigin();
ISize isize = new ISize(initRefConc.getNumX(), initRefConc.getNumY(), initRefConc.getNumZ());
saveExternalData(initRefConc, INITCONC_EXTDATA_VARNAME, initialConcentrationExtData.getExternalDataIdentifier(), localWorkspace);
FieldFunctionArguments initConditionFFA = new FieldFunctionArguments(INITCONC_EXTDATA_NAME, INITCONC_EXTDATA_VARNAME, new Expression(0.0), VariableType.VOLUME);
//
// save ROIs as a multivariate field data
//
ExternalDataInfo roiExtData = createNewExternalDataInfo(localWorkspace, ROI_EXTDATA_NAME);
saveROIsAsExternalData(imageDataROIs, localWorkspace, roiExtData.getExternalDataIdentifier());
ArrayList<FieldFunctionArguments> roiFFAs = new ArrayList<FieldFunctionArguments>();
for (ROI roi : imageDataROIs) {
roiFFAs.add(new FieldFunctionArguments(ROI_EXTDATA_NAME, ROI_MASK_NAME_PREFIX + roi.getROIName(), new Expression(0.0), VariableType.VOLUME));
}
//
// save PSF as a field data
//
ExternalDataInfo psfExtData = createNewExternalDataInfo(localWorkspace, PSF_EXTDATA_NAME);
savePsfAsExternalData(psf, PSF_EXTDATA_VARNAME, psfExtData.getExternalDataIdentifier(), localWorkspace);
FieldFunctionArguments psfFFA = new FieldFunctionArguments(PSF_EXTDATA_NAME, PSF_EXTDATA_VARNAME, new Expression(0.0), VariableType.VOLUME);
TimeBounds timeBounds = getEstimatedRefTimeBound(experimentalRecoveryTime);
double timeStepVal = REFERENCE_DIFF_DELTAT;
Expression chirpedDiffusionRate = new Expression(REFERENCE_DIFF_RATE_COEFFICIENT + "*(t+" + REFERENCE_DIFF_DELTAT + ")");
BioModel bioModel = createRefSimBioModel(simKey, owner, origin, extent, cellROI, timeStepVal, timeBounds, VAR_NAME, new Expression(initConditionFFA.infix()), psfFFA, chirpedDiffusionRate);
if (progressListener != null) {
progressListener.setMessage("Running Reference Simulation...");
}
// run simulation
Simulation simulation = bioModel.getSimulation(0);
ROIDataGenerator roiDataGenerator = getROIDataGenerator(localWorkspace, imageDataROIs);
simulation.getMathDescription().getPostProcessingBlock().addDataGenerator(roiDataGenerator);
runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), simulation, initialConcentrationExtData.getExternalDataIdentifier(), roiExtData.getExternalDataIdentifier(), psfExtData.getExternalDataIdentifier(), progressListener, true);
KeyValue referenceSimKeyValue = simulation.getVersion().getVersionKey();
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(referenceSimKeyValue, LocalWorkspace.getDefaultOwner());
VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, 0);
File hdf5File = new File(localWorkspace.getDefaultSimDataDirectory(), vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
// get post processing info (time points, variable sizes)
DataOperation.DataProcessingOutputInfoOP dataOperationInfo = new DataOperation.DataProcessingOutputInfoOP(null, /*no vcDataIdentifier OK*/
false, null);
DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(dataOperationInfo, hdf5File);
// get post processing data
DataOperation.DataProcessingOutputDataValuesOP dataOperationDataValues = new DataOperation.DataProcessingOutputDataValuesOP(null, /*no vcDataIdentifier OK*/
ROI_EXTDATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null);
DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataOperationDataValues, hdf5File);
//
// delete the simulation files
//
//
// remove reference simulation files and field data files
//
File userDir = new File(localWorkspace.getDefaultSimDataDirectory());
File[] oldSimFilesToDelete = getSimulationFileNames(userDir, referenceSimKeyValue);
for (int i = 0; oldSimFilesToDelete != null && i < oldSimFilesToDelete.length; i++) {
oldSimFilesToDelete[i].delete();
}
deleteCanonicalExternalData(localWorkspace, initialConcentrationExtData.getExternalDataIdentifier());
deleteCanonicalExternalData(localWorkspace, roiExtData.getExternalDataIdentifier());
deleteCanonicalExternalData(localWorkspace, roiExtData.getExternalDataIdentifier());
// get ref sim time points (distorted by time dilation acceleration)
double[] rawRefDataTimePoints = dataProcessingOutputInfo.getVariableTimePoints();
// get shifted time points
double[] correctedRefDataTimePoints = shiftTimeForBaseDiffRate(rawRefDataTimePoints);
double[][] refData = dataProcessingOutputDataValues.getDataValues();
//
// for rowColumnResultSet with { "t", "roi1", .... , "roiN" } for reference data
//
int numROIs = imageDataROIs.length;
String[] columnNames = new String[numROIs + 1];
columnNames[0] = "t";
for (int i = 0; i < numROIs; i++) {
columnNames[i + 1] = imageDataROIs[i].getROIName();
}
RowColumnResultSet reducedData = new RowColumnResultSet(columnNames);
for (int i = 0; i < correctedRefDataTimePoints.length; i++) {
double[] row = new double[numROIs + 1];
row[0] = correctedRefDataTimePoints[i];
double[] roiData = refData[i];
for (int j = 0; j < numROIs; j++) {
// roiData[0] is the average over the cell .. postbleach this shouldn't change for pure diffusion
row[j + 1] = roiData[j + 1];
}
reducedData.addRow(row);
}
return reducedData;
}
use of org.vcell.vmicro.workflow.data.ROIDataGenerator in project vcell by virtualcell.
the class RunRefSimulationFastOp method getROIDataGenerator.
private ROIDataGenerator getROIDataGenerator(LocalContext localWorkspace, ROI[] rois) throws ImageException, IOException {
// create ROI image
short[] roiFieldData = null;
if (rois.length > 0) {
Origin origin = new Origin(0, 0, 0);
Extent extent = rois[0].getRoiImages()[0].getExtent();
ISize isize = rois[0].getISize();
int numROIX = rois[0].getISize().getX();
int numROIY = rois[0].getISize().getY();
roiFieldData = new short[numROIX * numROIY];
short regionCounter = 1;
for (int roiIdx = 0; roiIdx < rois.length; roiIdx++) {
short[] roiImg = rois[roiIdx].getPixelsXYZ();
for (int pixelIdx = 0; pixelIdx < (numROIX * numROIY); pixelIdx++) {
if (roiImg[pixelIdx] > 0) {
roiFieldData[pixelIdx] = regionCounter;
}
}
regionCounter++;
}
// create field data
int NumTimePoints = 1;
// 8 rois integrated into 1 image
int NumChannels = 1;
short[][][] pixData = new short[NumTimePoints][NumChannels][];
pixData[0][0] = roiFieldData;
// get extental data id
VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
CartesianMesh simpleCartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
ExternalDataIdentifier newROIExtDataID = createNewExternalDataInfo(localWorkspace, ROI_SUMDATA_NAME).getExternalDataIdentifier();
try {
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = simpleCartesianMesh;
fdos.shortSpecData = pixData;
fdos.specEDI = newROIExtDataID;
fdos.varNames = new String[] { "roiSumDataVar" };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new ROIDataGenerator(ROI_EXTDATA_NAME, /*name*/
new int[] { 0 }, /* volumePoints*/
new int[0], /* membranePoints*/
regionCounter, /*numRegions*/
0, /*zSlice*/
newROIExtDataID.getKey(), /* fieldDataKey, sample image*/
new FieldFunctionArguments(ROI_SUMDATA_NAME, ROI_SUMDATA_VARNAME, new Expression(0), VariableType.VOLUME), /*FieldFunctionArguments, sample image*/
false);
}
return null;
}
Aggregations