use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.
the class ODEDataViewer method updateMetadata.
private void updateMetadata() {
/* Set the target from the source */
if (getOdeSolverResultSet() == null) {
return;
}
final HashMap<String, DataSymbolMetadata> auxDataSymbolMap = new HashMap();
for (ColumnDescription columnDescription : getOdeSolverResultSet().getColumnDescriptions()) {
if (columnDescription.getName().startsWith("sens_") && columnDescription.getName().contains("_wrt_")) {
DataSymbolMetadata dataSymbolMetadata = sensitivityMetaDataParser(columnDescription.getName());
auxDataSymbolMap.put(columnDescription.getName(), dataSymbolMetadata);
}
}
// check if clienttaskdispatcher is busy, if so schedule this method to run later (workaround spurious threading problem)
if ((odeDataViewersetupTimer = ClientTaskDispatcher.getBlockingTimer(ODEDataViewer.this, null, null, odeDataViewersetupTimer, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e2) {
updateMetadata();
}
}, "ODEDataViewer Setup...")) != null) {
return;
}
try {
AsynchClientTask filterCategoriesTask = new AsynchClientTask("Calculating Filter...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (ODEDataViewer.this.getSimulationModelInfo() != null) {
SimulationModelInfo simulationModelInfo = ODEDataViewer.this.getSimulationModelInfo();
simulationModelInfo.getDataSymbolMetadataResolver().populateDataSymbolMetadata(auxDataSymbolMap);
}
}
};
AsynchClientTask firePropertyChangeTask = new AsynchClientTask("Fire Property Change...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
SimulationModelInfo simulationModelInfo = ODEDataViewer.this.getSimulationModelInfo();
ODEDataInterfaceImpl oDEDataInterfaceImpl = new ODEDataInterfaceImpl(getOdeSolverResultSet(), simulationModelInfo);
getODESolverPlotSpecificationPanel1().setMyDataInterface(oDEDataInterfaceImpl);
// new Thread(new Runnable() {
// @Override
// public void run() {
// while(ClientTaskDispatcher.isBusy()){
// try{Thread.sleep(200);}catch(Exception e){e.printStackTrace();}
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// ((Window)BeanUtils.findTypeParentOfComponent(ODEDataViewer.this, Window.class)).toFront();
// }
// });
// }
// }).start();
}
};
ClientTaskDispatcher.dispatch(ODEDataViewer.this, new Hashtable<String, Object>(), new AsynchClientTask[] { filterCategoriesTask, firePropertyChangeTask }, false, false, false, null, true);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.
the class RowColumnResultSet method createResultSetSymbolTable.
/**
* Insert the method's description here.
* Creation date: (2/19/2003 4:32:00 PM)
* @return cbit.vcell.parser.SymbolTable
*/
private VariableSymbolTable createResultSetSymbolTable(boolean bIncludeFunctions) {
//
// create symbol table for binding expression against data columns and functions (of data columns)
//
VariableSymbolTable resultSetSymbolTable = new VariableSymbolTable();
for (int i = 0; i < getColumnDescriptionsCount(); i++) {
ColumnDescription colDesc = getColumnDescriptions(i);
if (colDesc instanceof ODESolverResultSetColumnDescription) {
Domain domain = null;
VolVariable vVar = new VolVariable(colDesc.getName(), domain);
vVar.setIndex(i);
resultSetSymbolTable.addVar(vVar);
} else if (bIncludeFunctions && colDesc instanceof FunctionColumnDescription) {
FunctionColumnDescription funcColDesc = (FunctionColumnDescription) colDesc;
Domain domain = null;
Function func = new Function(funcColDesc.getName(), new Expression(funcColDesc.getExpression()), domain);
func.setIndex(i);
resultSetSymbolTable.addVar(func);
}
}
return resultSetSymbolTable;
}
use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.
the class RowColumnResultSet method extractColumn.
/**
* getVariableNames method comment.
* If column is empty, return null or an empty array?
* For now, null...
*/
public synchronized double[] extractColumn(int c) throws ExpressionException {
double[] values = null;
if (getRowCount() > 0) {
ColumnDescription colDescription = getColumnDescriptions(c);
if (colDescription instanceof FunctionColumnDescription) {
Expression exp = ((FunctionColumnDescription) colDescription).getExpression();
//
// must rebind expression due to transient nature of expression binding (see ASTIdNode.symbolTableEntry)
//
exp.bindExpression(getResultSetSymbolTableWithoutFunction());
values = new double[getRowCount()];
for (int r = 0; r < getRowCount(); r++) {
try {
values[r] = exp.evaluateVector(getRow(r));
} catch (DivideByZeroException e) {
e.printStackTrace(System.out);
values[r] = Double.NaN;
} catch (FunctionDomainException e) {
e.printStackTrace(System.out);
values[r] = Double.NaN;
}
}
} else {
values = new double[getRowCount()];
for (int r = 0; r < getRowCount(); r++) {
values[r] = getRow(r)[c];
}
}
}
return (values);
}
use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.
the class ODESolverPlotSpecificationPanel method regeneratePlot2D.
/**
* Comment
*/
private void regeneratePlot2D() throws ExpressionException, ObjectNotFoundException {
if (getMyDataInterface() == null) {
return;
}
if (!getMyDataInterface().isMultiTrialData()) {
if (getXAxisComboBox_frm().getSelectedIndex() < 0) {
return;
} else {
// double[] xData = getOdeSolverResultSet().extractColumn(getPlottableColumnIndices()[getXIndex()]);
// getUnfilteredSortedXAxisNames
double[] xData = getMyDataInterface().extractColumn((String) getXAxisComboBox_frm().getSelectedItem());
double[][] allData = new double[((DefaultListModel) getYAxisChoice().getModel()).size() + 1][xData.length];
String[] yNames = new String[((DefaultListModel) getYAxisChoice().getModel()).size()];
allData[0] = xData;
double[] yData = new double[xData.length];
double currParamValue = 0.0;
double deltaParamValue = 0.0;
// Extrapolation calculations!
if (getSensitivityParameter() != null) {
int val = getSensitivityParameterSlider().getValue();
double nominalParamValue = getSensitivityParameter().getConstantValue();
double pMax = nominalParamValue * 1.1;
double pMin = nominalParamValue * 0.9;
int iMax = getSensitivityParameterSlider().getMaximum();
int iMin = getSensitivityParameterSlider().getMinimum();
double slope = (pMax - pMin) / (iMax - iMin);
currParamValue = slope * val + pMin;
deltaParamValue = currParamValue - nominalParamValue;
getMaxLabel().setText(Double.toString(pMax));
getMinLabel().setText(Double.toString(pMin));
getCurLabel().setText(Double.toString(currParamValue));
}
if (!getLogSensCheckbox().getModel().isSelected()) {
// When log sensitivity check box is not selected.
for (int i = 0; i < allData.length - 1; i++) {
// If sensitivity analysis is enabled, extrapolate values for State vars and non-sensitivity functions
if (getSensitivityParameter() != null) {
ColumnDescription cd = getMyDataInterface().getColumnDescription((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
double[] sens = getSensValues(cd);
yData = getMyDataInterface().extractColumn(cd.getName());
// sens array != null for non-sensitivity state vars and functions, so extrapolate
if (sens != null) {
for (int j = 0; j < sens.length; j++) {
if (Math.abs(yData[j]) > 1e-6) {
// away from zero, exponential extrapolation
allData[i + 1][j] = yData[j] * Math.exp(deltaParamValue * sens[j] / yData[j]);
} else {
// around zero - linear extrapolation
allData[i + 1][j] = yData[j] + sens[j] * deltaParamValue;
}
}
// sens array == null for sensitivity state vars and functions, so don't change their original values
} else {
allData[i + 1] = getMyDataInterface().extractColumn((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
}
} else {
// No sensitivity analysis case, so do not alter the original values for any variable or function
allData[i + 1] = getMyDataInterface().extractColumn((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
}
yNames[i] = (String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i);
}
} else {
// When log sensitivity checkbox is selected.
// Get sensitivity parameter and its value to compute log sensitivity
Constant sensParam = getSensitivityParameter();
double sensParamValue = sensParam.getConstantValue();
getJLabelSensitivityParameter().setText("Sensitivity wrt Parameter " + sensParam.getName());
//
for (int i = 0; i < allData.length - 1; i++) {
// Finding sensitivity var column for each column in result set.
ColumnDescription cd = getMyDataInterface().getColumnDescription((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
String sensVarName = null;
ColumnDescription[] allColumnDescriptions = getMyDataInterface().getAllColumnDescriptions();
for (int j = 0; j < allColumnDescriptions.length; j++) {
String obj = "sens_" + cd.getName() + "_wrt_" + sensParam.getName();
if (allColumnDescriptions[j].getName().equals(obj)) {
sensVarName = obj;
break;
}
}
int sensIndex = -1;
if (sensVarName != null) {
for (int j = 0; j < ((DefaultListModel) getYAxisChoice().getModel()).getSize(); j++) {
if (((String) ((DefaultListModel) getYAxisChoice().getModel()).get(j)).equals(sensVarName)) {
sensIndex = j;
break;
}
}
}
yData = getMyDataInterface().extractColumn(cd.getName());
// If sensitivity var exists, compute log sensitivity
if (sensVarName != null) {
double[] sens = getMyDataInterface().extractColumn(sensVarName);
for (int k = 0; k < yData.length; k++) {
// Extrapolated statevars and functions
if (Math.abs(yData[k]) > 1e-6) {
// away from zero, exponential extrapolation
allData[i + 1][k] = yData[k] * Math.exp(deltaParamValue * sens[k] / yData[k]);
} else {
// around zero - linear extrapolation
allData[i + 1][k] = yData[k] + sens[k] * deltaParamValue;
}
// Log sensitivity for the state variables and functions
// default if floating point problems
double logSens = 0.0;
if (Math.abs(yData[k]) > 0) {
double tempLogSens = sens[k] * sensParamValue / yData[k];
if (tempLogSens != Double.NEGATIVE_INFINITY && tempLogSens != Double.POSITIVE_INFINITY && tempLogSens != Double.NaN) {
logSens = tempLogSens;
}
}
if (sensIndex > -1) {
allData[sensIndex + 1][k] = logSens;
}
}
// If sensitivity var does not exist, retain original value of column (var or function).
} else {
if (!cd.getName().startsWith("sens_")) {
allData[i + 1] = yData;
}
}
yNames[i] = (String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i);
}
}
String title = "";
String xLabel = (String) getXAxisComboBox_frm().getSelectedItem();
String yLabel = "";
if (yNames.length == 1) {
yLabel = yNames[0];
}
// Update Sensitivity parameter label depending on whether Log sensitivity check box is checked or not.
if (!getLogSensCheckbox().getModel().isSelected()) {
getJLabelSensitivityParameter().setText("");
}
SymbolTableEntry[] symbolTableEntries = null;
if (getSymbolTable() != null && yNames != null && yNames.length > 0) {
symbolTableEntries = new SymbolTableEntry[yNames.length];
for (int i = 0; i < yNames.length; i += 1) {
SymbolTableEntry ste = getSymbolTable().getEntry(yNames[i]);
symbolTableEntries[i] = ste;
}
}
SingleXPlot2D plot2D = new SingleXPlot2D(symbolTableEntries, getMyDataInterface().getDataSymbolMetadataResolver(), xLabel, yNames, allData, new String[] { title, xLabel, yLabel });
refreshVisiblePlots(plot2D);
// here fire "singleXPlot2D" event, ODEDataViewer's event handler listens to it.
setPlot2D(plot2D);
}
} else // end of none MultitrialData
// multitrial data
{
// a column of data get from ODESolverRestultSet, which is actually the results for a specific variable during multiple trials
double[] rowData = new double[getMyDataInterface().getRowCount()];
PlotData[] plotData = new PlotData[((DefaultListModel) getYAxisChoice().getModel()).size()];
for (int i = 0; i < plotData.length; i++) {
ColumnDescription cd = getMyDataInterface().getColumnDescription((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
rowData = getMyDataInterface().extractColumn(cd.getName());
Point2D[] histogram = generateHistogram(rowData);
double[] x = new double[histogram.length];
double[] y = new double[histogram.length];
for (int j = 0; j < histogram.length; j++) {
x[j] = histogram[j].getX();
y[j] = histogram[j].getY();
}
plotData[i] = new PlotData(x, y);
}
SymbolTableEntry[] symbolTableEntries = null;
if (getSymbolTable() != null && ((DefaultListModel) getYAxisChoice().getModel()).size() > 0) {
symbolTableEntries = new SymbolTableEntry[((DefaultListModel) getYAxisChoice().getModel()).size()];
for (int i = 0; i < symbolTableEntries.length; i += 1) {
symbolTableEntries[i] = getSymbolTable().getEntry((String) ((DefaultListModel) getYAxisChoice().getModel()).elementAt(i));
}
}
String title = "Probability Distribution of Species";
String xLabel = "Number of Particles";
String yLabel = "";
String[] yNames = new String[((DefaultListModel) getYAxisChoice().getModel()).size()];
((DefaultListModel) getYAxisChoice().getModel()).copyInto(yNames);
Plot2D plot2D = new Plot2D(symbolTableEntries, getMyDataInterface().getDataSymbolMetadataResolver(), yNames, plotData, new String[] { title, xLabel, yLabel });
refreshVisiblePlots(plot2D);
setPlot2D(plot2D);
}
}
use of cbit.vcell.util.ColumnDescription in project vcell by virtualcell.
the class ODESolverPlotSpecificationPanel method updateChoices.
/**
* Insert the method's description here.
* Creation date: (2/8/2001 4:56:15 PM)
* @param cbit.vcell.solver.ode.ODESolverResultSet
*/
private synchronized void updateChoices(ODEDataInterface oDEDataInterface) throws ExpressionException, ObjectNotFoundException {
if (oDEDataInterface == null) {
return;
}
Object xAxisSelection = getXAxisComboBox_frm().getSelectedItem();
Object[] yAxisSelections = getYAxisChoice().getSelectedValues();
ArrayList<ColumnDescription> variableColumnDescriptions = new ArrayList<ColumnDescription>();
ArrayList<ColumnDescription> sensitivityColumnDescriptions = new ArrayList<ColumnDescription>();
ColumnDescription timeColumnDescription = null;
// find TIME columnDescription
ColumnDescription[] columnDescriptions = getMyDataInterface().getAllColumnDescriptions();
for (int i = 0; i < columnDescriptions.length; i++) {
if (columnDescriptions[i].getName().equals(ReservedVariable.TIME.getName())) {
timeColumnDescription = columnDescriptions[i];
}
}
// find filtered columnDescriptions
columnDescriptions = getMyDataInterface().getFilteredColumnDescriptions();
for (int i = 0; i < columnDescriptions.length; i++) {
ColumnDescription cd = columnDescriptions[i];
// If the column is "_initConnt" generated when using concentration as initial condition, we dont' put the function in list. amended again in August, 2008.
if (cd.getParameterName() == null) {
if (!cd.getName().equals(SimDataConstants.HISTOGRAM_INDEX_NAME) && !cd.getName().contains(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_COUNT)) {
variableColumnDescriptions.add(cd);
}
} else {
sensitivityColumnDescriptions.add(cd);
}
}
sortColumnDescriptions(variableColumnDescriptions);
sortColumnDescriptions(sensitivityColumnDescriptions);
// Hack this here, Later we can use an array utility...
ArrayList<ColumnDescription> sortedColumndDescriptions = new ArrayList<ColumnDescription>();
if (timeColumnDescription != null) {
// add time first
sortedColumndDescriptions.add(timeColumnDescription);
}
boolean bMultiTrialData = oDEDataInterface.isMultiTrialData();
sortedColumndDescriptions.addAll(variableColumnDescriptions);
if (!bMultiTrialData) {
sortedColumndDescriptions.addAll(sensitivityColumnDescriptions);
}
// finally, update widgets
try {
getXAxisComboBox_frm().removeItemListener(ivjEventHandler);
getYAxisChoice().removeListSelectionListener(ivjEventHandler);
getComboBoxModelX_frm().removeAllElements();
if (!bMultiTrialData) {
// Don't put anything in X Axis, if the results of multiple trials are being displayed.
ArrayList<ColumnDescription> xColumnDescriptions = new ArrayList<ColumnDescription>(Arrays.asList(getMyDataInterface().getAllColumnDescriptions()));
sortColumnDescriptions(xColumnDescriptions);
if (timeColumnDescription != null) {
getComboBoxModelX_frm().addElement(timeColumnDescription.getName());
}
for (ColumnDescription columnDescription : xColumnDescriptions) {
if (!columnDescription.getName().equals((timeColumnDescription == null ? null : timeColumnDescription.getName()))) {
getComboBoxModelX_frm().addElement(columnDescription.getName());
}
}
}
getDefaultListModelY().removeAllElements();
for (int i = 0; i < sortedColumndDescriptions.size(); i++) {
if (sortedColumndDescriptions.get(i).getName().equals(ReservedVariable.TIME.getName())) {
continue;
}
getDefaultListModelY().addElement(sortedColumndDescriptions.get(i).getName());
}
if (sortedColumndDescriptions.size() > 0) {
// Don't put anything in X Axis, if the results of multifple trials are being displayed.
if (!bMultiTrialData) {
getXAxisComboBox_frm().setSelectedItem(xAxisSelection);
if (getXAxisComboBox_frm().getSelectedIndex() == -1) {
getXAxisComboBox_frm().setSelectedIndex(0);
}
}
if (yAxisSelections != null && yAxisSelections.length > 0) {
ArrayList<Integer> carryoverSelections = new ArrayList<Integer>();
for (int i = 0; i < getYAxisChoice().getModel().getSize(); i++) {
for (int j = 0; j < yAxisSelections.length; j++) {
if (getYAxisChoice().getModel().getElementAt(i).equals(yAxisSelections[j])) {
carryoverSelections.add(i);
break;
}
}
}
if (carryoverSelections.size() > 0) {
int[] carryoverInts = new int[carryoverSelections.size()];
for (int i = 0; i < carryoverInts.length; i++) {
carryoverInts[i] = carryoverSelections.get(i);
}
getYAxisChoice().setSelectedIndices(carryoverInts);
} else {
getYAxisChoice().setSelectedIndex((getYAxisChoice().getModel().getSize() > 1 ? 1 : 0));
}
} else {
getYAxisChoice().setSelectedIndex(sortedColumndDescriptions.size() > 1 ? 1 : 0);
}
}
} finally {
getXAxisComboBox_frm().addItemListener(ivjEventHandler);
getYAxisChoice().addListSelectionListener(ivjEventHandler);
}
regeneratePlot2D();
}
Aggregations