use of org.vcell.vmicro.workflow.data.ExternalDataInfo 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.ExternalDataInfo in project vcell by virtualcell.
the class RunRefSimulationFastOp method createNewExternalDataInfo.
private ExternalDataInfo createNewExternalDataInfo(LocalContext localWorkspace, String extDataIDName) {
File targetDir = new File(localWorkspace.getDefaultSimDataDirectory());
KeyValue key = LocalWorkspace.createNewKeyValue();
User owner = LocalWorkspace.getDefaultOwner();
ExternalDataIdentifier newImageDataExtDataID = new ExternalDataIdentifier(key, owner, extDataIDName);
String filename = new File(targetDir, newImageDataExtDataID.getID() + SimDataConstants.LOGFILE_EXTENSION).getAbsolutePath();
ExternalDataInfo newImageDataExtDataInfo = new ExternalDataInfo(newImageDataExtDataID, filename);
return newImageDataExtDataInfo;
}
use of org.vcell.vmicro.workflow.data.ExternalDataInfo in project vcell by virtualcell.
the class RunRefSimulationOp method runRefSimulation.
private static ImageTimeSeries<FloatImage> runRefSimulation(LocalWorkspace localWorkspace, ROI cellROI, double timeStepVal, TimeBounds timeBounds, FloatImage initRefConc, double baseDiffusionRate, ClientTaskStatusSupport progressListener) throws Exception {
String INITCONC_EXTDATA_NAME = "initConc";
String INITCONC_EXTDATA_VARNAME = "conc";
String VAR_NAME = "species";
User owner = LocalWorkspace.getDefaultOwner();
KeyValue simKey = LocalWorkspace.createNewKeyValue();
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);
BioModel bioModel = createRefSimBioModel(simKey, owner, origin, extent, cellROI, timeStepVal, timeBounds, VAR_NAME, new Expression(initConditionFFA.infix()), baseDiffusionRate);
if (progressListener != null) {
progressListener.setMessage("Running Reference Simulation...");
}
// run simulation
runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), bioModel.getSimulation(0), initialConcentrationExtData.getExternalDataIdentifier(), progressListener, true);
VCDataIdentifier vcDataIdentifier = new VCSimulationDataIdentifier(new VCSimulationIdentifier(simKey, owner), 0);
double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
FloatImage[] solutionImages = new FloatImage[dataTimes.length];
for (int i = 0; i < dataTimes.length; i++) {
SimDataBlock simDataBlock = localWorkspace.getDataSetControllerImpl().getSimDataBlock(null, vcDataIdentifier, VAR_NAME, dataTimes[i]);
double[] doubleData = simDataBlock.getData();
float[] floatPixels = new float[doubleData.length];
for (int j = 0; j < doubleData.length; j++) {
floatPixels[j] = (float) doubleData[j];
}
solutionImages[i] = new FloatImage(floatPixels, origin, extent, isize.getX(), isize.getY(), isize.getZ());
}
ImageTimeSeries<FloatImage> solution = new ImageTimeSeries<FloatImage>(FloatImage.class, solutionImages, dataTimes, 1);
return solution;
}
use of org.vcell.vmicro.workflow.data.ExternalDataInfo in project vcell by virtualcell.
the class RunRefSimulationOp method createNewExternalDataInfo.
private static ExternalDataInfo createNewExternalDataInfo(LocalWorkspace localWorkspace, String extDataIDName) {
File targetDir = new File(localWorkspace.getDefaultSimDataDirectory());
KeyValue key = LocalWorkspace.createNewKeyValue();
User owner = LocalWorkspace.getDefaultOwner();
ExternalDataIdentifier newImageDataExtDataID = new ExternalDataIdentifier(key, owner, extDataIDName);
String filename = new File(targetDir, newImageDataExtDataID.getID() + SimDataConstants.LOGFILE_EXTENSION).getAbsolutePath();
ExternalDataInfo newImageDataExtDataInfo = new ExternalDataInfo(newImageDataExtDataID, filename);
return newImageDataExtDataInfo;
}
Aggregations