Search in sources :

Example 11 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class DataSetControllerImpl method getSimDataBlock.

/**
 * This method was created by a SmartGuide.
 * @return double[]
 * @param varName java.lang.String
 * @param time double
 */
public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdID, String varName, double time) throws DataAccessException {
    VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<ENTER>>");
    try {
        // 
        // check if already cached for non-function variables
        // 
        VCData simData = getVCData(vcdID);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got VCData");
        long dataBlockTimeStamp = simData.getDataBlockTimeStamp(PDE_DATA, time);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got dataBlockTimeStamp");
        PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), varName, time, dataBlockTimeStamp);
        SimDataBlock simDataBlock = null;
        AnnotatedFunction function = getFunction(outputContext, vcdID, varName);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got function");
        if (function == null) {
            simDataBlock = (cacheTable0 != null ? cacheTable0.get(pdeDataInfo) : null);
            if (simDataBlock == null) {
                simDataBlock = simData.getSimDataBlock(outputContext, varName, time);
                if (simDataBlock != null && dataCachingEnabled) {
                    // cacheTable.put(pdeDataInfo,simDataBlock);
                    if (cacheTable0 != null) {
                        try {
                            cacheTable0.put(pdeDataInfo, simDataBlock);
                        } catch (CacheException e) {
                            // if can't cache the data, it is ok
                            e.printStackTrace();
                        }
                    }
                }
            }
        } else {
            if (simData instanceof SimulationData) {
                function = ((SimulationData) simData).simplifyFunction(function);
            }
            VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") evaluating function");
            simDataBlock = evaluateFunction(outputContext, vcdID, simData, function, time);
        }
        CartesianMesh mesh = getMesh(vcdID);
        if (mesh != null && mesh.isChomboMesh()) {
            for (int i = 0; i < simDataBlock.getData().length; i++) {
                if (simDataBlock.getData()[i] == 1.23456789e300) {
                    simDataBlock.getData()[i] = Double.NaN;
                }
            }
        }
        if (simDataBlock != null) {
            VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-simDataBlock not null>>");
            return simDataBlock;
        } else {
            String msg = "failure reading " + varName + " at t=" + time + " for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
            if (lg.isWarnEnabled())
                lg.warn("DataSetControllerImpl.getDataBlockValues(): " + msg);
            VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
            throw new DataAccessException(msg);
        }
    } catch (MathException e) {
        lg.error(e.getMessage(), e);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
        throw new DataAccessException(e.getMessage());
    } catch (IOException e) {
        lg.error(e.getMessage(), e);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
        throw new DataAccessException(e.getMessage());
    } catch (ExpressionException e) {
        lg.error(e.getMessage(), e);
        VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")  <<EXIT-Exception>>");
        throw new DataAccessException(e.getMessage());
    }
}
Also used : CacheException(org.vcell.util.CacheException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) CartesianMesh(cbit.vcell.solvers.CartesianMesh) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 12 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class DataSetControllerImpl method getSpecialTimeSeriesValues.

private TimeSeriesJobResults getSpecialTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdID, TimeSeriesJobSpec timeSeriesJobSpec, TimeInfo timeInfo) throws Exception {
    String[] variableNames = timeSeriesJobSpec.getVariableNames();
    CartesianMesh mesh = getMesh(vcdID);
    // Automatically 'special' (non-optimized timedata retrieval) if isAllowOptimizedTimeDataRetrieval() == false
    boolean bIsSpecial = !isAllowOptimizedTimeDataRetrieval();
    if (!bIsSpecial) {
        VCData simData = getVCData(vcdID);
        // 
        // Gradient and FieldData functions are special.
        // They have to be evaluated using the 'full data' method using evaluateFunction(...).
        // They cannot be evaluated using the fast findFunctionIndexes(...) method.
        // Also if the 'roi' is a significant fraction of the whole dataset then
        // the 'full data' method of evaluation is more efficient
        // a guess for best efficiency
        final double SIGNIFICANT_ROI_FRACTION = .2;
        final int ABSOLUTE_SIZE_LIMIT = 10000;
        for (int i = 0; i < variableNames.length; i += 1) {
            DataSetIdentifier dsi = (DataSetIdentifier) simData.getEntry(variableNames[i]);
            if (dsi.getVariableType().equals(VariableType.VOLUME)) {
                if (timeSeriesJobSpec.getIndices()[i].length > mesh.getNumVolumeElements() * SIGNIFICANT_ROI_FRACTION) {
                    bIsSpecial = true;
                    break;
                }
            } else if (dsi.getVariableType().equals(VariableType.MEMBRANE)) {
                if (timeSeriesJobSpec.getIndices()[i].length > mesh.getNumMembraneElements() * SIGNIFICANT_ROI_FRACTION) {
                    bIsSpecial = true;
                    break;
                }
            }
            AnnotatedFunction functionFromVarName = getFunction(outputContext, vcdID, variableNames[i]);
            if (functionFromVarName != null) {
                FieldFunctionArguments[] fieldFunctionArgumentsArr = FieldUtilities.getFieldFunctionArguments(functionFromVarName.getExpression());
                if (hasGradient(functionFromVarName.getExpression()) || (fieldFunctionArgumentsArr != null && fieldFunctionArgumentsArr.length > 0)) {
                    bIsSpecial = true;
                    break;
                }
                // check function absolute size limit
                Expression exp = functionFromVarName.getExpression();
                String[] funcSymbols = exp.getSymbols();
                int varCount = 0;
                if (funcSymbols != null) {
                    for (int j = 0; j < funcSymbols.length; j++) {
                        SymbolTableEntry ste = exp.getSymbolBinding(funcSymbols[j]);
                        if (ste instanceof DataSetIdentifier) {
                            varCount += 1;
                        }
                    }
                }
                varCount = Math.max(varCount, 1);
                if (varCount * timeSeriesJobSpec.getIndices()[i].length > ABSOLUTE_SIZE_LIMIT) {
                    bIsSpecial = true;
                    break;
                }
            } else if (timeSeriesJobSpec.getIndices()[i].length > ABSOLUTE_SIZE_LIMIT) {
                bIsSpecial = true;
                break;
            }
        }
    }
    if (!bIsSpecial) {
        return null;
    }
    TimeSeriesJobResults tsjr = null;
    if (timeSeriesJobSpec.isCalcTimeStats()) {
        throw new RuntimeException("Time Stats Not yet implemented for 'special' data");
    } else if (timeSeriesJobSpec.isCalcSpaceStats()) {
        // Get spatial statistics at each time point
        SpatialStatsInfo ssi = calcSpatialStatsInfo(outputContext, timeSeriesJobSpec, vcdID);
        double[][] /*time*/
        argMin = new double[variableNames.length][timeInfo.desiredTimeValues.length];
        double[][] argMax = new double[variableNames.length][timeInfo.desiredTimeValues.length];
        double[][] argUnweightedMean = new double[variableNames.length][timeInfo.desiredTimeValues.length];
        double[][] argWeightedMean = new double[variableNames.length][timeInfo.desiredTimeValues.length];
        double[][] argUnweightedSum = new double[variableNames.length][timeInfo.desiredTimeValues.length];
        double[][] argWeightedSum = new double[variableNames.length][timeInfo.desiredTimeValues.length];
        double[] /*varName*/
        argTotalSpace = new double[variableNames.length];
        double[][][] indicesForVarForOneTimepoint = new double[1][][];
        for (int varNameIndex = 0; varNameIndex < variableNames.length; varNameIndex += 1) {
            int[] dataIndices = timeSeriesJobSpec.getIndices()[varNameIndex];
            indicesForVarForOneTimepoint[0] = new double[dataIndices.length + 1][1];
            for (int timeIndex = 0; timeIndex < timeInfo.desiredTimeValues.length; timeIndex += 1) {
                indicesForVarForOneTimepoint[0][0] = new double[] { timeInfo.desiredTimeValues[timeIndex] };
                int num = varNameIndex * timeInfo.desiredTimeValues.length + timeIndex;
                int denom = variableNames.length * timeInfo.desiredTimeValues.length;
                double progressTime = 100.0 * (double) num / (double) denom;
                fireDataJobEventIfNecessary(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_PROGRESS, vcdID, new Double(progressTime), null, null);
                SimDataBlock simDatablock = getSimDataBlock(outputContext, vcdID, variableNames[varNameIndex], timeInfo.desiredTimeValues[timeIndex]);
                double[] data = simDatablock.getData();
                // Put indices in format expected by calcStats (SHOULD BE CHANGED)
                for (int dataIndex = 0; dataIndex < dataIndices.length; dataIndex += 1) {
                    indicesForVarForOneTimepoint[0][dataIndex + 1][0] = data[dataIndices[dataIndex]];
                }
                if (timeSeriesJobSpec.getCrossingMembraneIndices() != null && timeSeriesJobSpec.getCrossingMembraneIndices().length > 0) {
                    adjustMembraneAdjacentVolumeValues(outputContext, indicesForVarForOneTimepoint[0], true, simDatablock, timeSeriesJobSpec.getIndices()[varNameIndex], timeSeriesJobSpec.getCrossingMembraneIndices()[varNameIndex], vcdID, variableNames[varNameIndex], mesh, timeInfo);
                }
                tsjr = calculateStatisticsFromWhole(timeSeriesJobSpec, indicesForVarForOneTimepoint, indicesForVarForOneTimepoint[0][0], ssi);
                argMin[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getMinimums()[0][0];
                argMax[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getMaximums()[0][0];
                argUnweightedMean[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getUnweightedMean()[0][0];
                if (((TSJobResultsSpaceStats) tsjr).getWeightedMean() == null) {
                    argWeightedMean = null;
                } else {
                    argWeightedMean[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getWeightedMean()[0][0];
                }
                argUnweightedSum[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getUnweightedSum()[0][0];
                if (((TSJobResultsSpaceStats) tsjr).getWeightedSum() == null) {
                    argWeightedSum = null;
                } else {
                    argWeightedSum[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getWeightedSum()[0][0];
                }
                if (((TSJobResultsSpaceStats) tsjr).getTotalSpace() == null) {
                    argTotalSpace = null;
                } else {
                    argTotalSpace[varNameIndex] = ((TSJobResultsSpaceStats) tsjr).getTotalSpace()[0];
                }
            }
        }
        tsjr = new TSJobResultsSpaceStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), timeInfo.desiredTimeValues, argMin, argMax, argUnweightedMean, argWeightedMean, argUnweightedSum, argWeightedSum, argTotalSpace);
    } else {
        // Get the values for for all the variables and indices
        double[][][] varIndicesTimesArr = new double[variableNames.length][][];
        for (int varNameIndex = 0; varNameIndex < variableNames.length; varNameIndex += 1) {
            int[] dataIndices = timeSeriesJobSpec.getIndices()[varNameIndex];
            varIndicesTimesArr[varNameIndex] = new double[dataIndices.length + 1][timeInfo.desiredTimeValues.length];
            varIndicesTimesArr[varNameIndex][0] = timeInfo.desiredTimeValues;
            for (int timeIndex = 0; timeIndex < timeInfo.desiredTimeValues.length; timeIndex += 1) {
                int num = varNameIndex * timeInfo.desiredTimeValues.length + timeIndex;
                int denom = variableNames.length * timeInfo.desiredTimeValues.length;
                double progressTime = 100.0 * (double) num / (double) denom;
                fireDataJobEventIfNecessary(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_PROGRESS, vcdID, new Double(progressTime), null, null);
                SimDataBlock simDatablock = getSimDataBlock(outputContext, vcdID, variableNames[varNameIndex], timeInfo.desiredTimeValues[timeIndex]);
                double[] data = simDatablock.getData();
                for (int dataIndex = 0; dataIndex < dataIndices.length; dataIndex += 1) {
                    varIndicesTimesArr[varNameIndex][dataIndex + 1][timeIndex] = data[dataIndices[dataIndex]];
                }
                if (timeSeriesJobSpec.getCrossingMembraneIndices() != null && timeSeriesJobSpec.getCrossingMembraneIndices().length > 0) {
                    adjustMembraneAdjacentVolumeValues(outputContext, varIndicesTimesArr[varNameIndex], true, simDatablock, timeSeriesJobSpec.getIndices()[varNameIndex], timeSeriesJobSpec.getCrossingMembraneIndices()[varNameIndex], vcdID, variableNames[varNameIndex], mesh, timeInfo);
                }
            }
        }
        tsjr = new TSJobResultsNoStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), timeInfo.desiredTimeValues, varIndicesTimesArr);
    }
    return tsjr;
}
Also used : FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) TimeSeriesJobResults(org.vcell.util.document.TimeSeriesJobResults) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 13 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class DataSetControllerImpl method getFunction.

public AnnotatedFunction getFunction(OutputContext outputContext, VCDataIdentifier vcdID, String variableName) throws DataAccessException {
    try {
        VCData vcData = getVCData(vcdID);
        AnnotatedFunction annotatedFunction = vcData.getFunction(outputContext, variableName);
        checkFieldDataExists(annotatedFunction, vcdID.getOwner());
        return annotatedFunction;
    } catch (IOException e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException(e.getMessage());
    }
}
Also used : IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 14 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class DataSetControllerImpl method getDataProcessingOutput.

public static DataOperationResults getDataProcessingOutput(DataOperation dataOperation, File dataProcessingOutputFileHDF5) throws Exception {
    DataOperationResults dataProcessingOutputResults = null;
    FileFormat hdf5FileFormat = null;
    try {
        if (dataProcessingOutputFileHDF5.exists()) {
            // retrieve an instance of H5File
            FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
            if (fileFormat == null) {
                throw new Exception("Cannot find HDF5 FileFormat.");
            }
            // open the file with read-only access
            hdf5FileFormat = fileFormat.open(dataProcessingOutputFileHDF5.getAbsolutePath(), FileFormat.READ);
            hdf5FileFormat.setMaxMembers(Simulation.MAX_LIMIT_SPATIAL_TIMEPOINTS);
            // open the file and retrieve the file structure
            hdf5FileFormat.open();
            Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) hdf5FileFormat.getRootNode()).getUserObject();
            if (dataOperation instanceof DataProcessingOutputInfoOP) {
                DataProcessingHelper dataProcessingHelper = new DataProcessingHelper();
                iterateHDF5(root, "", dataProcessingHelper);
                dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputInfo(dataOperation.getVCDataIdentifier(), dataProcessingHelper.getVarNames(), dataProcessingHelper.getVarISizes(), dataProcessingHelper.times, dataProcessingHelper.getVarUnits(), dataProcessingHelper.getPostProcessDataTypes(), dataProcessingHelper.getVarOrigins(), dataProcessingHelper.getVarExtents(), dataProcessingHelper.getVarStatValues());
                // map function names to PostProcess state variable name
                ArrayList<String> postProcessImageVarNames = new ArrayList<String>();
                for (int i = 0; i < ((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getVariableNames().length; i++) {
                    String variableName = ((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getVariableNames()[i];
                    if (((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getPostProcessDataType(variableName).equals(DataOperationResults.DataProcessingOutputInfo.PostProcessDataType.image)) {
                        postProcessImageVarNames.add(variableName);
                    }
                }
                HashMap<String, String> mapFunctionNameToStateVarName = null;
                if (((DataProcessingOutputInfoOP) dataOperation).getOutputContext() != null) {
                    mapFunctionNameToStateVarName = new HashMap<String, String>();
                    for (int i = 0; i < ((DataProcessingOutputInfoOP) dataOperation).getOutputContext().getOutputFunctions().length; i++) {
                        AnnotatedFunction annotatedFunction = ((DataProcessingOutputInfoOP) dataOperation).getOutputContext().getOutputFunctions()[i];
                        if (annotatedFunction.getFunctionType().equals(VariableType.POSTPROCESSING)) {
                            String[] symbols = annotatedFunction.getExpression().flatten().getSymbols();
                            // Find any PostProcess state var that matches a symbol in the function
                            for (int j = 0; j < symbols.length; j++) {
                                if (postProcessImageVarNames.contains(symbols[j])) {
                                    mapFunctionNameToStateVarName.put(annotatedFunction.getName(), symbols[j]);
                                    break;
                                }
                            }
                        }
                    }
                }
                if (mapFunctionNameToStateVarName != null && mapFunctionNameToStateVarName.size() > 0) {
                    dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputInfo(((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults), mapFunctionNameToStateVarName);
                }
            } else {
                OutputContext outputContext = dataOperation.getOutputContext();
                String[] variableNames = null;
                DataIndexHelper dataIndexHelper = null;
                TimePointHelper timePointHelper = null;
                if (dataOperation instanceof DataOperation.DataProcessingOutputDataValuesOP) {
                    variableNames = new String[] { ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getVariableName() };
                    dataIndexHelper = ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getDataIndexHelper();
                    timePointHelper = ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getTimePointHelper();
                } else if (dataOperation instanceof DataOperation.DataProcessingOutputTimeSeriesOP) {
                    variableNames = ((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getTimeSeriesJobSpec().getVariableNames();
                    TimeSeriesJobSpec timeSeriesJobSpec = ((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getTimeSeriesJobSpec();
                    double[] specificTimepoints = extractTimeRange(((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getAllDatasetTimes(), timeSeriesJobSpec.getStartTime(), timeSeriesJobSpec.getEndTime());
                    timePointHelper = TimePointHelper.createSpecificTimePointHelper(specificTimepoints);
                    timeSeriesJobSpec.initIndices();
                    dataIndexHelper = DataIndexHelper.createSpecificDataIndexHelper(timeSeriesJobSpec.getIndices()[0]);
                } else {
                    throw new Exception("Unknown Dataoperation " + dataOperation.getClass().getName());
                }
                if (variableNames.length != 1) {
                    throw new Exception("Only 1 variable request at a time");
                }
                AnnotatedFunction[] annotatedFunctions = (outputContext == null ? null : outputContext.getOutputFunctions());
                AnnotatedFunction foundFunction = null;
                if (annotatedFunctions != null) {
                    for (int i = 0; i < annotatedFunctions.length; i++) {
                        if (annotatedFunctions[i].getName().equals(variableNames[0])) {
                            foundFunction = annotatedFunctions[i];
                            break;
                        }
                    }
                }
                double[] alltimes = null;
                if (foundFunction != null) {
                    DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(dataOperation.getVCDataIdentifier(), false, dataOperation.getOutputContext()), dataProcessingOutputFileHDF5);
                    alltimes = dataProcessingOutputInfo.getVariableTimePoints();
                    FunctionHelper functionHelper = getPostProcessStateVariables(foundFunction, dataProcessingOutputInfo);
                    DataProcessingHelper dataProcessingHelper = new DataProcessingHelper(functionHelper.postProcessStateVars, timePointHelper, dataIndexHelper);
                    iterateHDF5(root, "", dataProcessingHelper);
                    dataProcessingOutputResults = evaluatePostProcessFunction(dataProcessingOutputInfo, functionHelper.postProcessStateVars, dataProcessingHelper.specificDataValues, dataIndexHelper, timePointHelper, functionHelper.flattenedBoundExpression, variableNames[0]);
                } else {
                    DataProcessingHelper dataProcessingHelper = new DataProcessingHelper(new String[] { variableNames[0] }, timePointHelper, dataIndexHelper);
                    iterateHDF5(root, "", dataProcessingHelper);
                    alltimes = dataProcessingHelper.times;
                    if (dataProcessingHelper.specificDataValues == null) {
                        throw new Exception("Couldn't find postprocess data as specified for var=" + variableNames[0]);
                    }
                    dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputDataValues(dataOperation.getVCDataIdentifier(), variableNames[0], timePointHelper, dataIndexHelper, dataProcessingHelper.specificDataValues[0]);
                }
                if (dataOperation instanceof DataOperation.DataProcessingOutputTimeSeriesOP) {
                    TimeSeriesJobResults timeSeriesJobResults = null;
                    DataProcessingOutputTimeSeriesOP dataProcessingOutputTimeSeriesOP = (DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation;
                    // [time][data]
                    double[][] dataValues = ((DataOperationResults.DataProcessingOutputDataValues) dataProcessingOutputResults).getDataValues();
                    double[] desiredTimes = (timePointHelper.isAllTimePoints() ? alltimes : timePointHelper.getTimePoints());
                    double[][][] timeSeriesFormatedValuesArr = new double[variableNames.length][dataIndexHelper.getDataIndexes().length + 1][desiredTimes.length];
                    for (int i = 0; i < timeSeriesFormatedValuesArr.length; i++) {
                        // var
                        for (int j = 0; j < timeSeriesFormatedValuesArr[i].length; j++) {
                            // index
                            if (j == 0) {
                                timeSeriesFormatedValuesArr[i][j] = desiredTimes;
                                continue;
                            }
                            for (int k = 0; k < timeSeriesFormatedValuesArr[i][j].length; k++) {
                                // time
                                // assume 1 variable for now
                                timeSeriesFormatedValuesArr[i][j][k] = dataValues[k][j - 1];
                            }
                        }
                    }
                    if (dataProcessingOutputTimeSeriesOP.getTimeSeriesJobSpec().isCalcSpaceStats()) {
                        SpatialStatsInfo spatialStatsInfo = new SpatialStatsInfo();
                        spatialStatsInfo.bWeightsValid = false;
                        timeSeriesJobResults = calculateStatisticsFromWhole(dataProcessingOutputTimeSeriesOP.getTimeSeriesJobSpec(), timeSeriesFormatedValuesArr, timePointHelper.getTimePoints(), spatialStatsInfo);
                    } else {
                        timeSeriesJobResults = new TSJobResultsNoStats(variableNames, new int[][] { dataIndexHelper.getDataIndexes() }, timePointHelper.getTimePoints(), timeSeriesFormatedValuesArr);
                    }
                    dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputTimeSeriesValues(dataOperation.getVCDataIdentifier(), timeSeriesJobResults);
                }
            }
        } else {
            throw new FileNotFoundException("Data Processing Output file '" + dataProcessingOutputFileHDF5.getPath() + "' not found");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (hdf5FileFormat != null) {
            try {
                hdf5FileFormat.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return dataProcessingOutputResults;
}
Also used : Group(ncsa.hdf.object.Group) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ArrayList(java.util.ArrayList) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) FileNotFoundException(java.io.FileNotFoundException) FileFormat(ncsa.hdf.object.FileFormat) DataProcessingOutputInfoOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP) DataIndexHelper(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP.DataIndexHelper) DataProcessingOutputTimeSeriesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputTimeSeriesOP) TimeSeriesJobResults(org.vcell.util.document.TimeSeriesJobResults) TimePointHelper(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP.TimePointHelper) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CacheException(org.vcell.util.CacheException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileNotFoundException(java.io.FileNotFoundException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) DataProcessingOutputTimeSeriesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputTimeSeriesOP) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 15 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class ODESimData method readIDADataFile.

public static ODESimData readIDADataFile(VCDataIdentifier vcdId, File dataFile, int keepMost, File functionsFile) throws DataAccessException {
    // read ida file
    System.out.println("reading ida file : " + dataFile);
    ODESimData odeSimData = new ODESimData();
    odeSimData.formatID = IDA_DATA_FORMAT_ID;
    odeSimData.mathName = vcdId.getID();
    BufferedReader bufferedReader = null;
    try {
        bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile)));
        // Read header
        String line = bufferedReader.readLine();
        if (line == null) {
            // throw exception
            return null;
        }
        StringTokenizer st = new StringTokenizer(line, ":");
        while (st.hasMoreTokens()) {
            odeSimData.addDataColumn(new ODESolverResultSetColumnDescription(st.nextToken()));
        }
        // Read data
        while ((line = bufferedReader.readLine()) != null) {
            st = new StringTokenizer(line);
            double[] values = new double[odeSimData.getDataColumnCount()];
            int count = 0;
            while (st.hasMoreTokens()) {
                values[count++] = Double.valueOf(st.nextToken()).doubleValue();
            }
            if (count == odeSimData.getDataColumnCount()) {
                odeSimData.addRow(values);
            } else {
                break;
            }
        }
    // 
    } catch (Exception e) {
        e.printStackTrace(System.out);
        return null;
    } finally {
        try {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace(System.out);
        }
    }
    if (!odeSimData.getColumnDescriptions(0).getName().equals(SimDataConstants.HISTOGRAM_INDEX_NAME)) {
        Vector<AnnotatedFunction> funcList;
        try {
            funcList = FunctionFileGenerator.readFunctionsFile(functionsFile, vcdId.getID());
            for (AnnotatedFunction func : funcList) {
                try {
                    Expression expression = new Expression(func.getExpression());
                    odeSimData.addFunctionColumn(new FunctionColumnDescription(expression, func.getName(), null, func.getName(), false));
                } catch (ExpressionException e) {
                    throw new RuntimeException("Could not add function " + func.getName() + " to annotatedFunctionList");
                }
            }
        } catch (FileNotFoundException e1) {
            e1.printStackTrace(System.out);
            throw new DataAccessException(e1.getMessage());
        } catch (IOException e1) {
            e1.printStackTrace(System.out);
            throw new DataAccessException(e1.getMessage());
        }
    }
    if (keepMost > 0) {
        odeSimData.trimRows(keepMost);
    }
    return odeSimData;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) ExpressionException(cbit.vcell.parser.ExpressionException) StringTokenizer(java.util.StringTokenizer) Expression(cbit.vcell.parser.Expression) BufferedReader(java.io.BufferedReader) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Aggregations

AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)61 DataAccessException (org.vcell.util.DataAccessException)21 ExpressionException (cbit.vcell.parser.ExpressionException)20 Expression (cbit.vcell.parser.Expression)17 ArrayList (java.util.ArrayList)17 Simulation (cbit.vcell.solver.Simulation)15 IOException (java.io.IOException)15 OutputContext (cbit.vcell.simdata.OutputContext)14 MathException (cbit.vcell.math.MathException)12 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)12 SimulationContext (cbit.vcell.mapping.SimulationContext)11 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)10 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 FileNotFoundException (java.io.FileNotFoundException)8 Domain (cbit.vcell.math.Variable.Domain)7 VariableType (cbit.vcell.math.VariableType)7 XmlParseException (cbit.vcell.xml.XmlParseException)7 PropertyVetoException (java.beans.PropertyVetoException)7 File (java.io.File)7