Search in sources :

Example 11 with ColumnDescription

use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.

the class DataSetTimeSeries method getVarDatas.

private VarData[] getVarDatas(ODEDataBlock odeDataBlock) {
    ArrayList<VarData> valValuesArray = new ArrayList<VarData>();
    ODESimData odeSimData = odeDataBlock.getODESimData();
    int rowCount = odeSimData.getRowCount();
    for (ColumnDescription column : odeSimData.getColumnDescriptions()) {
        VarData values = new VarData(column.getName(), new double[rowCount]);
        valValuesArray.add(values);
    }
    for (int i = 0; i < rowCount; i++) {
        double[] rowData = odeSimData.getRow(i);
        for (int j = 0; j < rowData.length; j++) {
            valValuesArray.get(j).values[i] = rowData[j];
        }
    }
    return valValuesArray.toArray(new VarData[0]);
}
Also used : ColumnDescription(cbit.vcell.util.ColumnDescription) ArrayList(java.util.ArrayList) ODESimData(cbit.vcell.solver.ode.ODESimData)

Example 12 with ColumnDescription

use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.

the class MergedData method getODEDataBlock.

/**
 * Insert the method's description here.
 * Creation date: (1/14/00 2:28:47 PM)
 * @return cbit.vcell.simdata.ODEDataBlock
 */
public ODEDataBlock getODEDataBlock() throws DataAccessException {
    ODESolverResultSet combinedODESolverRSet = new ODESolverResultSet();
    ODEDataBlock refDataBlock = dataSetControllerImpl.getODEDataBlock(datasetsIDList[0]);
    ODESimData refSimData = refDataBlock.getODESimData();
    // Can use dataTimes field later (for genuine SimulationData), but for now, obtain it on the fly
    double[] times = null;
    try {
        int independentVarIndex = refSimData.findColumn("t");
        if (independentVarIndex < 0) {
            independentVarIndex = refSimData.findColumn(HISTOGRAM_INDEX_NAME);
        }
        times = refSimData.extractColumn(independentVarIndex);
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
    }
    // Adding data/function columns to new resultSet
    ODESolverResultSet[] resultSetList = new ODESolverResultSet[datasetsIDList.length];
    for (int i = 0; i < datasetsIDList.length; i++) {
        ODEDataBlock dataBlock = dataSetControllerImpl.getODEDataBlock(datasetsIDList[i]);
        ODESimData simData = dataBlock.getODESimData();
        ODESolverResultSet newODErset = new ODESolverResultSet();
        // First resultSet is reference resultSet. From the second onwards, resample the resultSet wrt the reference.
        if (i > 0) {
            try {
                newODErset = resampleODEData(refSimData, simData);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("\n >>>> Could not resample data! <<<<\n");
            }
        } else {
            newODErset = simData;
        }
        resultSetList[i] = newODErset;
        // Add data columns
        String[] newVarNames = new String[newODErset.getDataColumnCount()];
        for (int j = 0; j < newODErset.getDataColumnCount(); j++) {
            // If 'time' column is present in combinedResultSet, continue with next data column
            if ((combinedODESolverRSet.findColumn("t") > -1) && (newODErset.getDataColumnDescriptions()[j].getName().equals("t"))) {
                newVarNames[j] = newODErset.getDataColumnDescriptions()[j].getName();
                continue;
            }
            // Retain 'time' column as 't', without using datasetID as prefix to avoid multiple time columns in combinedODEResultSet.
            // Adding the time column from the first dataset to combinedResultSet, since it is treated as the reference dataset.
            String newColName = null;
            if (j == 0 && newODErset.getDataColumnDescriptions()[j].getName().equals("t")) {
                newColName = newODErset.getDataColumnDescriptions()[j].getName();
            } else {
                newColName = dataSetPrefix[i] + "." + newODErset.getDataColumnDescriptions()[j].getName();
            }
            newVarNames[j] = newColName;
            ColumnDescription cd = newODErset.getDataColumnDescriptions()[j];
            if (cd instanceof ODESolverResultSetColumnDescription) {
                ODESolverResultSetColumnDescription newCD = new ODESolverResultSetColumnDescription(newColName, cd.getParameterName(), newColName);
                combinedODESolverRSet.addDataColumn(newCD);
            }
        }
        // Add function columns
        for (int j = 0; j < newODErset.getFunctionColumnCount(); j++) {
            try {
                String newColName = dataSetPrefix[i] + "." + newODErset.getFunctionColumnDescriptions()[j].getName();
                FunctionColumnDescription fcd = newODErset.getFunctionColumnDescriptions()[j];
                Expression newExp = new Expression(fcd.getExpression());
                String[] symbols = newExp.getSymbols();
                if (symbols != null && (symbols.length > 0)) {
                    for (int jj = 0; jj < symbols.length; jj++) {
                        for (int kk = 0; kk < newVarNames.length; kk++) {
                            if (newVarNames[kk].equals(dataSetPrefix[i] + "." + symbols[jj])) {
                                newExp.substituteInPlace(new Expression(symbols[jj]), new Expression(newVarNames[kk]));
                                break;
                            }
                        }
                    }
                }
                FunctionColumnDescription newFcd = new FunctionColumnDescription(newExp, newColName, fcd.getParameterName(), newColName, fcd.getIsUserDefined());
                combinedODESolverRSet.addFunctionColumn(newFcd);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
            }
        }
    }
    // Populating new dataset
    for (int i = 0; i < times.length; i++) {
        double[] newRow = new double[combinedODESolverRSet.getDataColumnCount()];
        int indx = 0;
        for (int j = 0; j < resultSetList.length; j++) {
            ODESolverResultSet resultSet = resultSetList[j];
            double[] tempRow = resultSet.getRow(i);
            int startIndx = 0;
            int arrayLen = tempRow.length;
            if (j > 0) {
                // From the second dataset onwards, we do not want to copy the time column, hence skip to
                // the next element/col in dataset, that reduces the # of elements in the row by 1.
                startIndx = 1;
                arrayLen = tempRow.length - 1;
            }
            System.arraycopy(tempRow, startIndx, newRow, indx, arrayLen);
            indx += tempRow.length;
        }
        combinedODESolverRSet.addRow(newRow);
    }
    ODEDataInfo odeDataInfo = new ODEDataInfo(getResultsInfoObject().getOwner(), getResultsInfoObject().getID(), 0);
    ODESimData odeSimData = new ODESimData(getResultsInfoObject(), combinedODESolverRSet);
    return new ODEDataBlock(odeDataInfo, odeSimData);
}
Also used : ColumnDescription(cbit.vcell.util.ColumnDescription) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) ODESimData(cbit.vcell.solver.ode.ODESimData) ExpressionException(cbit.vcell.parser.ExpressionException) Expression(cbit.vcell.parser.Expression) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 13 with ColumnDescription

use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.

the class MergedData method resampleODEData.

/**
 * Insert the method's description here.
 * Creation date: (10/11/00 1:28:51 PM)
 * @param function cbit.vcell.math.Function
 */
private ODESolverResultSet resampleODEData(ODESimData refSimdata, ODESimData simData) throws ExpressionException {
    // If simData and refSimdata times are equal, return simData without resampling.
    // Else resampling is necessary.
    double[] refTimeArray = refSimdata.extractColumn(Math.max(refSimdata.findColumn(HISTOGRAM_INDEX_NAME), refSimdata.findColumn("t")));
    double[] timeArray = simData.extractColumn(Math.max(simData.findColumn(HISTOGRAM_INDEX_NAME), simData.findColumn("t")));
    if (refTimeArray.length == timeArray.length) {
        boolean bEqual = true;
        for (int i = 0; i < refTimeArray.length; i++) {
            if (refTimeArray[i] == timeArray[i]) {
                bEqual = bEqual && true;
            } else {
                bEqual = bEqual && false;
            }
        }
        if (bEqual) {
            return simData;
        }
    }
    ODESolverResultSet newODEresultSet = new ODESolverResultSet();
    for (int i = 0; i < simData.getDataColumnCount(); i++) {
        if (simData.getDataColumnDescriptions()[i] instanceof ODESolverResultSetColumnDescription) {
            ODESolverResultSetColumnDescription colDesc = ((ODESolverResultSetColumnDescription) simData.getDataColumnDescriptions()[i]);
            newODEresultSet.addDataColumn(colDesc);
        }
    }
    for (int i = 0; i < simData.getFunctionColumnCount(); i++) {
        FunctionColumnDescription colDesc = simData.getFunctionColumnDescriptions()[i];
        newODEresultSet.addFunctionColumn(colDesc);
    }
    double[][] resampledData = new double[refTimeArray.length][simData.getDataColumnCount()];
    for (int i = 0; i < simData.getDataColumnCount(); i++) {
        ColumnDescription colDesc = simData.getDataColumnDescriptions()[i];
        // If it is the first column (time), set value in new SimData to the timeArray values in refSimData.
        if (i == 0 && colDesc.getName().equals("t")) {
            for (int j = 0; j < refTimeArray.length; j++) {
                resampledData[j][i] = refTimeArray[j];
            }
            continue;
        }
        double[] data = simData.extractColumn(i);
        int k = 0;
        for (int j = 0; j < refTimeArray.length; j++) {
            // CHECK IF refTimeArray or timeArry has to be used here,
            while ((k < timeArray.length - 2) && (refTimeArray[j] > timeArray[k + 1])) {
                k++;
            }
            // apply first order linear basis for reference data interpolation.
            resampledData[j][i] = data[k] + (data[k + 1] - data[k]) * (refTimeArray[j] - timeArray[k]) / (timeArray[k + 1] - timeArray[k]);
        }
    }
    for (int i = 0; i < refTimeArray.length; i++) {
        newODEresultSet.addRow(resampledData[i]);
    }
    return newODEresultSet;
}
Also used : ColumnDescription(cbit.vcell.util.ColumnDescription) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Aggregations

ColumnDescription (cbit.vcell.util.ColumnDescription)13 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)9 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)4 Expression (cbit.vcell.parser.Expression)4 DataSymbolMetadata (cbit.vcell.solver.DataSymbolMetadata)3 ArrayList (java.util.ArrayList)3 Constant (cbit.vcell.math.Constant)2 ODESimData (cbit.vcell.solver.ode.ODESimData)2 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)2 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1 SingleXPlot2D (cbit.plot.SingleXPlot2D)1 ODEDataInterface (cbit.vcell.client.data.ODEDataInterface)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 Domain (cbit.vcell.math.Variable.Domain)1 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 FunctionDomainException (cbit.vcell.parser.FunctionDomainException)1 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)1