use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class PDEDataViewer method snapshotROI.
private void snapshotROI() {
final AsynchClientTask createSnapshotTask = new AsynchClientTask("Creating Snapshot...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (getClientTaskStatusSupport() != null) {
getClientTaskStatusSupport().setMessage("Waiting for data to refresh...");
}
getPdeDataContext().waitWhileBusy();
if (getClientTaskStatusSupport() != null) {
getClientTaskStatusSupport().setMessage("Creating Snapshot...");
}
final double[] dataValues = getPdeDataContext().getDataValues();
final VariableType variableType = getPdeDataContext().getDataIdentifier().getVariableType();
final boolean isVolumeType = (variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION));
final BitSet snapshotROI = new BitSet(dataValues.length);
for (int i = 0; i < dataValues.length; i++) {
boolean bInDomain = (getPDEDataContextPanel1().getDataInfoProvider() == null ? true : getPDEDataContextPanel1().getDataInfoProvider().isDefined(i));
snapshotROI.set(i, bInDomain && (dataValues[i] == 1.0));
}
final String variableName = getPdeDataContext().getVariableName();
final double timePoint = getPdeDataContext().getTimePoint();
// Do the following so the 'progress' spinner will go away (if showing) when the message is displayed.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (snapshotROI.cardinality() == 0) {
PopupGenerator.showWarningDialog(PDEDataViewer.this, (isVolumeType ? "Volume" : "Membrane") + " snapshot ROI cannot be updated.\n" + "No data values for variable '" + variableName + "'\n" + "at time '" + timePoint + "' have values equal to 1.0." + " Add a function that evaluates to 1 at the points to be included in the ROI (user defined funtions can be added from the 'Simulation' panel), " + " then choose the new function name in the Simulation results viewer and press 'Snapshot ROI' again.", new String[] { "OK" }, "OK");
return;
} else {
if (isVolumeType) {
volumeSnapshotROI = snapshotROI;
volumeSnapshotROIDescription = "Variable='" + variableName + "', Timepoint= " + timePoint;
} else {
membraneSnapshotROI = snapshotROI;
membraneSnapshotROIDescription = "Variable='" + variableName + "', Timepoint= " + timePoint;
}
PopupGenerator.showWarningDialog(PDEDataViewer.this, (isVolumeType ? "Volume" : "Membrane") + " snapshot ROI updated using " + "Variable '" + variableName + "' at " + "Time '" + timePoint + "' (where values = 1.0).\n" + "ROI includes " + snapshotROI.cardinality() + " points. (total size= " + dataValues.length + ")\n" + "Snapshot ROI is available for use by choosing a variable/function name and pressing 'Statistics'.", new String[] { "OK" }, "OK");
}
}
});
}
};
if (getPdeDataContext().isBusy()) {
// Show wait dialog
ClientTaskDispatcher.dispatch(PDEDataViewer.this, new Hashtable<String, Object>(), new AsynchClientTask[] { createSnapshotTask }, false, false, null, true);
} else {
// Not show wait dialog
ClientTaskDispatcher.dispatch(PDEDataViewer.this, new Hashtable<String, Object>(), new AsynchClientTask[] { createSnapshotTask });
}
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class PDEDataViewer method roiAction.
private void roiAction() {
BeanUtils.setCursorThroughout(this, Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
final String[] ROI_COLUMN_NAMES = new String[] { "ROI source", "ROI source name", "ROI Description" };
final Vector<Object> auxInfoV = new Vector<Object>();
final DataIdentifier dataIdentifier = getPdeDataContext().getDataIdentifier();
VariableType variableType = dataIdentifier.getVariableType();
final boolean isVolume = variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION);
DefaultTableModel tableModel = new DefaultTableModel() {
public boolean isCellEditable(int row, int column) {
return false;
}
};
for (int i = 0; i < ROI_COLUMN_NAMES.length; i++) {
tableModel.addColumn(ROI_COLUMN_NAMES[i]);
}
// Add Snapshot ROI
if ((isVolume ? volumeSnapshotROI : membraneSnapshotROI) != null) {
tableModel.addRow(new Object[] { (isVolume ? "Volume" : "Membrane") + " Variables and Functions", "Snapshot", (isVolume ? volumeSnapshotROIDescription : membraneSnapshotROIDescription) + ", (values = 1.0)" });
auxInfoV.add((isVolume ? volumeSnapshotROI : membraneSnapshotROI));
}
// Add user ROIs
SpatialSelection[] userROIArr = getPDEDataContextPanel1().fetchSpatialSelections(true, false);
for (int i = 0; userROIArr != null && i < userROIArr.length; i += 1) {
String descr = null;
boolean bPoint = false;
if (isVolume) {
if (userROIArr[i] instanceof SpatialSelectionVolume) {
Curve curve = ((SpatialSelectionVolume) userROIArr[i]).getCurveSelectionInfo().getCurve();
descr = curve.getDescription();
if (curve instanceof SinglePoint) {
bPoint = true;
}
}
} else {
if (userROIArr[i] instanceof SpatialSelectionMembrane) {
SampledCurve selectionSource = ((SpatialSelectionMembrane) userROIArr[i]).getSelectionSource();
descr = selectionSource.getDescription();
if (selectionSource instanceof SinglePoint) {
bPoint = true;
}
}
}
// Add Area User ROI
BitSet fillBitSet = null;
if (userROIArr[i] instanceof SpatialSelectionVolume) {
fillBitSet = getFillROI((SpatialSelectionVolume) userROIArr[i]);
if (fillBitSet != null) {
tableModel.addRow(new Object[] { "User Defined", descr, "Area Enclosed Volume ROI" });
auxInfoV.add(fillBitSet);
}
}
// Add Point and Line User ROI
if (fillBitSet == null) {
tableModel.addRow(new Object[] { "User Defined", descr, (bPoint ? "Point" : "Line") + (isVolume ? " Volume" : " Membrane") + " ROI " });
auxInfoV.add(userROIArr[i]);
}
}
// Add sorted Geometry ROI
final CartesianMesh cartesianMesh = getPdeDataContext().getCartesianMesh();
HashMap<Integer, ?> regionMapSubvolumesHashMap = (isVolume ? cartesianMesh.getVolumeRegionMapSubvolume() : cartesianMesh.getMembraneRegionMapSubvolumesInOut());
Set<?> regionMapSubvolumesEntrySet = regionMapSubvolumesHashMap.entrySet();
Iterator<?> regionMapSubvolumesEntryIter = regionMapSubvolumesEntrySet.iterator();
TreeSet<Object[]> sortedGeomROITreeSet = new TreeSet<Object[]>(new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
int result = ((String) ((Object[]) o1[0])[1]).compareToIgnoreCase((String) ((Object[]) o2[0])[1]);
if (result == 0) {
result = (((Entry<Integer, ?>) o1[1]).getKey()).compareTo(((Entry<Integer, ?>) o2[1]).getKey());
}
return result;
}
});
while (regionMapSubvolumesEntryIter.hasNext()) {
Entry<Integer, ?> regionMapSubvolumesEntry = (Entry<Integer, ?>) regionMapSubvolumesEntryIter.next();
sortedGeomROITreeSet.add(new Object[] { new Object[] { "Geometry", (isVolume ? getSimulationModelInfo().getVolumeNamePhysiology(((Integer) regionMapSubvolumesEntry.getValue())) : getSimulationModelInfo().getMembraneName(((int[]) regionMapSubvolumesEntry.getValue())[0], ((int[]) regionMapSubvolumesEntry.getValue())[1], false)), (isVolume ? "(svID=" + regionMapSubvolumesEntry.getValue() + " " : "(") + "vrID=" + regionMapSubvolumesEntry.getKey() + ") Predefined " + (isVolume ? "volume" : "membrane") + " region" }, regionMapSubvolumesEntry });
}
Iterator<Object[]> sortedGeomROIIter = sortedGeomROITreeSet.iterator();
while (sortedGeomROIIter.hasNext()) {
Object[] sortedGeomROIObjArr = (Object[]) sortedGeomROIIter.next();
tableModel.addRow((Object[]) sortedGeomROIObjArr[0]);
auxInfoV.add(sortedGeomROIObjArr[1]);
}
final ScrollTable roiTable = new ScrollTable();
roiTable.setModel(tableModel);
roiTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
roiTable.setPreferredScrollableViewportSize(new Dimension(500, 200));
final JPanel mainJPanel = new JPanel();
BoxLayout mainBL = new BoxLayout(mainJPanel, BoxLayout.Y_AXIS);
mainJPanel.setLayout(mainBL);
MiniTimePanel timeJPanel = new MiniTimePanel();
ActionListener okAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (((Double) timeJPanel.jcb_time_begin.getSelectedItem()).compareTo((Double) timeJPanel.jcb_time_end.getSelectedItem()) > 0) {
PopupGenerator.showErrorDialog(PDEDataViewer.this, "Selected 'Begin Time' must be less than or equal to 'End Time'");
return;
}
int[] selectedRows = roiTable.getSelectedRows();
if (selectedRows != null) {
try {
BitSet dataBitSet = new BitSet(getPdeDataContext().getDataValues().length);
for (int i = 0; i < selectedRows.length; i++) {
Object auxInfo = auxInfoV.elementAt(selectedRows[i]);
if (auxInfo instanceof BitSet) {
dataBitSet.or((BitSet) auxInfo);
} else if (auxInfo instanceof SpatialSelectionMembrane) {
int[] roiIndexes = ((SpatialSelectionMembrane) auxInfo).getIndexSamples().getSampledIndexes();
for (int j = 0; j < roiIndexes.length; j += 1) {
dataBitSet.set(roiIndexes[j], true);
}
} else if (auxInfo instanceof SpatialSelectionVolume) {
int[] roiIndexes = ((SpatialSelectionVolume) auxInfo).getIndexSamples(0, 1).getSampledIndexes();
for (int j = 0; j < roiIndexes.length; j += 1) {
dataBitSet.set(roiIndexes[j], true);
}
} else if (auxInfo instanceof Entry) {
Entry<Integer, Integer> entry = (Entry<Integer, Integer>) auxInfo;
if (isVolume) {
int volumeRegionID = entry.getKey();
dataBitSet.or(cartesianMesh.getVolumeROIFromVolumeRegionID(volumeRegionID));
} else {
int membraneRegionID = entry.getKey();
dataBitSet.or(cartesianMesh.getMembraneROIFromMembraneRegionID(membraneRegionID));
}
} else if (auxInfo instanceof BitSet) {
dataBitSet.or((BitSet) auxInfo);
} else {
throw new Exception("ROI table, Unknown data type: " + auxInfo.getClass().getName());
}
}
TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { dataIdentifier.getName() }, new BitSet[] { dataBitSet }, ((Double) timeJPanel.jcb_time_begin.getSelectedItem()).doubleValue(), 1, ((Double) timeJPanel.jcb_time_end.getSelectedItem()).doubleValue(), true, false, VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieve data for '" + dataIdentifier + "'", PDEDataViewer.this, getPdeDataContext());
AsynchClientTask task2 = new AsynchClientTask("Showing stat for '" + dataIdentifier + "'", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) hashTable.get(StringKey_timeSeriesJobResults);
plotSpaceStats(tsJobResultsSpaceStats);
}
};
ClientTaskDispatcher.dispatch(PDEDataViewer.this, hash, new AsynchClientTask[] { task1, task2 }, true, true, null);
} catch (Exception e1) {
e1.printStackTrace();
PopupGenerator.showErrorDialog(PDEDataViewer.this, "ROI Error.\n" + e1.getMessage(), e1);
}
}
BeanUtils.disposeParentWindow(mainJPanel);
}
};
ActionListener cancelAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
BeanUtils.disposeParentWindow(mainJPanel);
}
};
OkCancelSubPanel okCancelJPanel = new OkCancelSubPanel(okAction, cancelAction);
roiTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (roiTable.getSelectedRows() != null && roiTable.getSelectedRows().length > 0) {
okCancelJPanel.okButton.setEnabled(true);
} else {
okCancelJPanel.okButton.setEnabled(false);
}
}
});
mainJPanel.add(timeJPanel);
mainJPanel.add(roiTable.getEnclosingScrollPane());
mainJPanel.add(okCancelJPanel);
// showComponentInFrame(mainJPanel,
// "Calculate "+(isVolume?"volume":"membrane")+" statistics for '"+getPdeDataContext().getVariableName()+"'."+
// " Choose times and 1 or more ROI(s).");
Frame dialogOwner = JOptionPane.getFrameForComponent(this);
JOptionPane inputDialog = new JOptionPane(mainJPanel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[0]);
final JDialog d = inputDialog.createDialog(dialogOwner, "Calculate " + (isVolume ? "volume" : "membrane") + " statistics for '" + getPdeDataContext().getVariableName() + "'." + " Choose times and 1 or more ROI(s).");
d.setResizable(true);
try {
DialogUtils.showModalJDialogOnTop(d, PDEDataViewer.this);
} finally {
d.dispose();
}
} finally {
BeanUtils.setCursorThroughout(this, Cursor.getDefaultCursor());
}
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class SmoldynFileWriter method writeDataProcessor.
private void writeDataProcessor() throws DataAccessException, IOException, MathException, DivideByZeroException, ExpressionException {
Simulation simulation = simTask.getSimulation();
DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
if (dpi == null) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + DataProcessingInstructions.ROI_TIME_SERIES);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
} else {
FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in data processing instructions");
}
File userDirectory = outputFile.getParentFile();
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simTask.getSimulationJob().getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + dpi.getScriptName());
StringTokenizer st = new StringTokenizer(dpi.getScriptInput(), "\n\r");
while (st.hasMoreTokens()) {
String str = st.nextToken();
if (str.trim().length() > 0) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " " + str);
}
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
}
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class PdeTimePlotMultipleVariablesPanel method initialize.
private void initialize() {
VariableType varType = multiTimePlotHelper.getPdeDatacontext().getDataIdentifier().getVariableType();
String varName = multiTimePlotHelper.getPdeDatacontext().getVariableName();
String[] plotNames = new String[pointVector.size()];
final SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotNames.length];
DefaultListModel<String> pointListModel = new DefaultListModel<String>();
for (int i = 0; i < pointVector.size(); i++) {
Coordinate tp = null;
if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector.get(i);
tp = ssv.getCurveSelectionInfo().getCurve().getBeginningCoordinate();
} else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector.get(i);
double midU = ssm.getCurveSelectionInfo().getCurveUfromSelectionU(.5);
tp = ((SampledCurve) ssm.getCurveSelectionInfo().getCurve()).coordinateFromNormalizedU(midU);
}
plotNames[i] = varName + " at P[" + i + "]";
String point = "P[" + i + "] (" + niceCoordinateString(tp) + ")";
pointListModel.addElement(point);
if (multiTimePlotHelper.getsimulation() != null) {
symbolTableEntries[0] = multiTimePlotHelper.getsimulation().getMathDescription().getEntry(varName);
} else {
System.out.println("PdeTimePlotMultipleVariablesPanel.initialize() adding artificial symbol table entries for field data");
SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(new String[] { varName });
symbolTableEntries[0] = simpleSymbolTable.getEntry(varName);
}
}
pointJList.setModel(pointListModel);
pointJList.setForeground(variableJList.getForeground());
pointJList.setVisibleRowCount(3);
pointJList.setBackground(getBackground());
pointJList.setSelectionBackground(getBackground());
pointJList.setSelectionForeground(Color.black);
plotPane = new PlotPane();
double[][] plotDatas = tsJobResultsNoStats.getTimesAndValuesForVariable(varName);
Plot2D plot2D = new SingleXPlot2D(symbolTableEntries, multiTimePlotHelper.getDataSymbolMetadataResolver(), ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
plotPane.setPlot2D(plot2D);
DataIdentifier[] dis = (multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() != null ? multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() : DataIdentifier.collectSortedSimilarDataTypes(multiTimePlotHelper.getVariableType(), multiTimePlotHelper.getPdeDatacontext().getDataIdentifiers()));
Arrays.sort(dis, new Comparator<DataIdentifier>() {
public int compare(DataIdentifier o1, DataIdentifier o2) {
int bEqualIgnoreCase = o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
if (bEqualIgnoreCase == 0) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
return bEqualIgnoreCase;
}
});
variableJList.setListData(dis);
initVariableListSelected(variableJList, multiTimePlotHelper.getPdeDatacontext().getDataIdentifier());
variableJList.setCellRenderer(multiTimePlotHelper.getListCellRenderer());
setLayout(new GridBagLayout());
JLabel label = new JLabel("Selected Points");
label.setFont(label.getFont().deriveFont(Font.BOLD));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new java.awt.Insets(15, 10, 4, 4);
add(label, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.gridheight = 4;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new java.awt.Insets(0, 4, 0, 0);
add(plotPane, gbc);
JScrollPane sp = new JScrollPane(pointJList);
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.weighty = 0.5;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new java.awt.Insets(4, 10, 4, 4);
add(sp, gbc);
label = new JLabel("Y Axis");
label.setFont(label.getFont().deriveFont(Font.BOLD));
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new java.awt.Insets(4, 10, 4, 4);
add(label, gbc);
sp = new JScrollPane(variableJList);
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 3;
gbc.weightx = 0.2;
gbc.weighty = 1;
gbc.insets = new java.awt.Insets(4, 10, 50, 4);
gbc.fill = java.awt.GridBagConstraints.BOTH;
add(sp, gbc);
variableJList.addListSelectionListener(eventHandler);
multiTimePlotHelper.addPropertyChangeListener(eventHandler);
}
use of cbit.vcell.math.VariableType in project vcell by virtualcell.
the class PdeTimePlotMultipleVariablesPanel method showTimePlot.
public void showTimePlot() {
if ((plotChangeTimer = ClientTaskDispatcher.getBlockingTimer(this, multiTimePlotHelper.getPdeDatacontext(), null, plotChangeTimer, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e2) {
showTimePlot();
}
}, "PdeTimePlotMultipleVariablesPanel update...")) != null) {
return;
}
VariableType varType = multiTimePlotHelper.getVariableType();
Object[] selectedValues = variableJList.getSelectedValues();
DataIdentifier[] selectedDataIdentifiers = new DataIdentifier[selectedValues.length];
System.arraycopy(selectedValues, 0, selectedDataIdentifiers, 0, selectedValues.length);
if (selectedDataIdentifiers.length > 1) {
for (DataIdentifier selectedDataIdentifier : selectedDataIdentifiers) {
if (!selectedDataIdentifier.getVariableType().getVariableDomain().equals(varType.getVariableDomain())) {
PopupGenerator.showErrorDialog(this, "Please choose VOLUME variables or MEMBRANE variables only");
variableJList.clearSelection();
variableJList.setSelectedValue(multiTimePlotHelper.getPdeDatacontext().getVariableName(), true);
return;
}
}
}
try {
final int numSelectedVariables = selectedDataIdentifiers.length;
final int numSelectedSpatialPoints = pointVector.size();
int[][] indices = new int[numSelectedVariables][numSelectedSpatialPoints];
//
for (int i = 0; i < numSelectedSpatialPoints; i++) {
for (int v = 0; v < numSelectedVariables; v++) {
if (selectedDataIdentifiers[v].getVariableType().equals(varType)) {
if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector.get(i);
indices[v][i] = ssv.getIndex(0);
} else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector.get(i);
indices[v][i] = ssm.getIndex(0);
}
} else {
if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector2.get(i);
indices[v][i] = ssv.getIndex(0);
} else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector2.get(i);
indices[v][i] = ssm.getIndex(0);
}
}
}
}
final String[] selectedVarNames = new String[numSelectedVariables];
for (int i = 0; i < selectedVarNames.length; i++) {
selectedVarNames[i] = selectedDataIdentifiers[i].getName();
}
final double[] timePoints = multiTimePlotHelper.getPdeDatacontext().getTimePoints();
TimeSeriesJobSpec tsjs = new TimeSeriesJobSpec(selectedVarNames, indices, null, timePoints[0], 1, timePoints[timePoints.length - 1], VCDataJobID.createVCDataJobID(multiTimePlotHelper.getUser(), true));
if (!tsjs.getVcDataJobID().isBackgroundTask()) {
throw new RuntimeException("Use getTimeSeries(...) if not a background job");
}
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(PDEDataViewer.StringKey_timeSeriesJobSpec, tsjs);
AsynchClientTask task1 = new PDEDataViewer.TimeSeriesDataRetrievalTask("Retrieving Data", multiTimePlotHelper, multiTimePlotHelper.getPdeDatacontext());
AsynchClientTask task2 = new AsynchClientTask("showing time plot", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(PDEDataViewer.StringKey_timeSeriesJobResults);
int plotCount = numSelectedVariables * numSelectedSpatialPoints;
SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotCount];
String[] plotNames = new String[plotCount];
double[][] plotDatas = new double[1 + plotCount][];
plotDatas[0] = timePoints;
int plotIndex = 0;
for (int v = 0; v < numSelectedVariables; v++) {
String varName = selectedVarNames[v];
double[][] data = tsJobResultsNoStats.getTimesAndValuesForVariable(varName);
for (int i = 1; i < data.length; i++) {
symbolTableEntries[plotIndex] = multiTimePlotHelper.getsimulation().getMathDescription().getEntry(varName);
plotNames[plotIndex] = varName + " at P[" + (i - 1) + "]";
plotDatas[plotIndex + 1] = data[i];
plotIndex++;
}
}
Plot2D plot2D = new SingleXPlot2D(symbolTableEntries, multiTimePlotHelper.getDataSymbolMetadataResolver(), ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
plotPane.setPlot2D(plot2D);
}
};
ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1, task2 }, false, true, true, null, false);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
Aggregations