Search in sources :

Example 1 with ExternalDataInfo

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;
}
Also used : Origin(org.vcell.util.Origin) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) TimeBounds(cbit.vcell.solver.TimeBounds) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) DataOperation(cbit.vcell.simdata.DataOperation) ExternalDataInfo(org.vcell.vmicro.workflow.data.ExternalDataInfo) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ROI(cbit.vcell.VirtualMicroscopy.ROI) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ROIDataGenerator(org.vcell.vmicro.workflow.data.ROIDataGenerator) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File)

Example 2 with ExternalDataInfo

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;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) ExternalDataInfo(org.vcell.vmicro.workflow.data.ExternalDataInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) File(java.io.File)

Example 3 with ExternalDataInfo

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;
}
Also used : Origin(org.vcell.util.Origin) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) ExternalDataInfo(org.vcell.vmicro.workflow.data.ExternalDataInfo) Extent(org.vcell.util.Extent) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ISize(org.vcell.util.ISize) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimDataBlock(cbit.vcell.simdata.SimDataBlock) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) File(java.io.File) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 4 with ExternalDataInfo

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;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) ExternalDataInfo(org.vcell.vmicro.workflow.data.ExternalDataInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) File(java.io.File)

Aggregations

File (java.io.File)4 KeyValue (org.vcell.util.document.KeyValue)4 User (org.vcell.util.document.User)4 ExternalDataInfo (org.vcell.vmicro.workflow.data.ExternalDataInfo)4 BioModel (cbit.vcell.biomodel.BioModel)2 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)2 Expression (cbit.vcell.parser.Expression)2 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)2 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)2 Extent (org.vcell.util.Extent)2 ISize (org.vcell.util.ISize)2 Origin (org.vcell.util.Origin)2 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)2 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)1 ROI (cbit.vcell.VirtualMicroscopy.ROI)1 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)1 DataOperation (cbit.vcell.simdata.DataOperation)1 DataOperationResults (cbit.vcell.simdata.DataOperationResults)1 SimDataBlock (cbit.vcell.simdata.SimDataBlock)1 Simulation (cbit.vcell.solver.Simulation)1