use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.
the class ClientSimManager method showSimulationResults0.
private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
// Create the AsynchClientTasks
ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
taskList.add(new AsynchClientTaskFunction(h -> {
h.put(H_LOCAL_SIM, isLocal);
h.put(H_VIEWER_TYPE, viewerType);
}, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
if (simWindow == null && (viewerType == ViewerType.NativeViewer_only)) {
try {
// make the manager and wire it up
DataViewerController dataViewerController = null;
if (!isLocal) {
dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
// For changes in time or variable
documentWindowManager.addDataListener(dataViewerController);
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
DataManager dataManager = null;
if (sim.isSpatial()) {
dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
} else {
dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
}
dataViewerController = new SimResultsViewerController(dataManager, sim);
dataSetControllerImpl.addDataJobListener(documentWindowManager);
}
// make the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
if (dataViewerControllers == null) {
dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
}
dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
}
}
};
taskList.add(retrieveResultsTask);
AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
if (failures != null && failures.containsKey(sim)) {
continue;
}
final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
if (simWindow != null) {
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
if (childWindow == null) {
childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
childWindow.pack();
childWindow.setIsCenteredOnParent();
childWindow.show();
}
setFinalWindow(hashTable, childWindow);
simWindow.setLocalState(localState);
} else {
// wire it up the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
Throwable ex = (failures == null ? null : failures.get(sim));
if (viewerController != null && ex == null) {
// no failure
DataViewer viewer = viewerController.createViewer();
getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
documentWindowManager.addExportListener(viewer);
// For data related activities such as calculating statistics
documentWindowManager.addDataJobListener(viewer);
viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
viewer.setDataViewerManager(documentWindowManager);
SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
documentWindowManager.addResultsFrame(newWindow);
setFinalWindow(hashTable, viewer);
newWindow.setLocalState(localState);
}
}
}
StringBuffer failMessage = new StringBuffer();
if (failures != null) {
if (!failures.isEmpty()) {
failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
Enumeration<Simulation> en = failures.keys();
while (en.hasMoreElements()) {
Simulation sim = en.nextElement();
Throwable exc = (Throwable) failures.get(sim);
failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
}
}
}
if (failMessage.length() > 0) {
PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
}
}
};
if (viewerType == ViewerType.NativeViewer_only) {
taskList.add(displayResultsTask);
}
// Dispatch the tasks using the ClientTaskDispatcher.
AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
taskList.toArray(taskArray);
return taskArray;
}
use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.
the class ODETimePlotMultipleScansPanel method updateScanParamChoices.
/**
* Insert the method's description here.
* Creation date: (10/18/2005 12:44:06 AM)
*/
private void updateScanParamChoices() {
AsynchClientTask task1 = new AsynchClientTask("get ode results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
int[] jobIndexes = scanChoiceTable.getSelectedRows();
VCSimulationIdentifier vcSimulationIdentifier = simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
int plotCount = jobIndexes.length * variableNames.length;
SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotCount];
double[][] dataValues = new double[plotCount + 1][];
PlotData[] plotDatas = new PlotData[plotCount];
String[] plotNames = new String[plotCount];
int plotIndex = 0;
dataValues[0] = null;
for (int ji = 0; ji < jobIndexes.length; ji++) {
int jobIndex = jobIndexes[ji];
final VCDataIdentifier vcdid = new VCSimulationDataIdentifier(vcSimulationIdentifier, jobIndex);
ODEDataManager odeDatamanager = ((ODEDataManager) dataManager).createNewODEDataManager(vcdid);
ODESolverResultSet odeSolverResultSet = odeDatamanager.getODESolverResultSet();
if (ji == 0) {
plotPane.setStepViewVisible(simulation.getSolverTaskDescription().getSolverDescription().isNonSpatialStochasticSolver(), odeSolverResultSet.isMultiTrialData());
hashTable.put("bMultiTrial", new Boolean(odeSolverResultSet.isMultiTrialData()));
}
double[] tdata = null;
if (!odeSolverResultSet.isMultiTrialData()) {
int tcol = odeSolverResultSet.findColumn(xVarColumnName);
tdata = odeSolverResultSet.extractColumn(tcol);
if (dataValues[0] == null) {
dataValues[0] = tdata;
}
}
for (int v = 0; v < variableNames.length; v++) {
String varname = variableNames[v];
int varcol = odeSolverResultSet.findColumn(varname);
double[] vdata = odeSolverResultSet.extractColumn(varcol);
if (!odeSolverResultSet.isMultiTrialData()) {
dataValues[plotIndex + 1] = vdata;
// plotNames[plotIndex] = varname + " -- " + JOB_PLOT_NAME + " " + jobIndex;
plotDatas[plotIndex] = new PlotData(tdata, vdata);
// symbolTableEntries[plotIndex] = simulation.getMathDescription().getVariable(varname);
} else {
Point2D[] histogram = ODESolverPlotSpecificationPanel.generateHistogram(vdata);
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();
}
plotDatas[plotIndex] = new PlotData(x, y);
}
plotNames[plotIndex] = varname + " -- " + JOB_PLOT_NAME + " " + jobIndex;
symbolTableEntries[plotIndex] = simulation.getMathDescription().getVariable(varname);
plotIndex++;
}
}
hashTable.put("dataValues", dataValues);
hashTable.put("plotDatas", plotDatas);
hashTable.put("plotNames", plotNames);
hashTable.put("symbolTableEntries", symbolTableEntries);
}
};
AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
double[][] dataValues = (double[][]) hashTable.get("dataValues");
PlotData[] plotDatas = (PlotData[]) hashTable.get("plotDatas");
String[] plotNames = (String[]) hashTable.get("plotNames");
SymbolTableEntry[] symbolTableEntries = (SymbolTableEntry[]) hashTable.get("symbolTableEntries");
if (plotDatas == null || plotDatas.length == 0 || (plotDatas.length == 1 && plotDatas[0] == null) || plotNames == null) {
plotPane.setPlot2D(null);
return;
}
Plot2D plot2D = null;
if (hashTable.get("bMultiTrial") instanceof Boolean && (Boolean) hashTable.get("bMultiTrial")) {
plot2D = new Plot2D(symbolTableEntries, null, plotNames, plotDatas, new String[] { "Probability Distribution of Species", "Number of Particles", "" });
}
// else if(simulation.getSolverTaskDescription().getOutputTimeSpec() instanceof DefaultOutputTimeSpec)
// {
plot2D = new Plot2D(symbolTableEntries, null, plotNames, plotDatas, new String[] { "Plot", xVarColumnName, /*ReservedVariable.TIME.getName()*/
"" });
// }
// else
// {
// plot2D = new SingleXPlot2D(symbolTableEntries, null, ReservedVariable.TIME.getName(), plotNames, dataValues);
// }
plotPane.setPlot2D(plot2D);
plotPane.setHDF5ParamScanParamNames(scanParams);
plotPane.setHDF5ParamScanParamValues(values);
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.
the class SimResultsViewer method updateScanParamChoices.
private void updateScanParamChoices(final String message, ListReset listReset) {
if ((paramScanChoiceTimer = ClientTaskDispatcher.getBlockingTimer(this, null, null, paramScanChoiceTimer, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e2) {
updateScanParamChoices(message, listReset);
}
}, message)) != null) {
return;
}
int selectedJobIndex = getSelectedParamScanJobIndex();
// update viewer
if (selectedJobIndex == -1) {
if (isODEData) {
if (listReset != null && odeDataViewer != null && odeDataViewer.getVcDataIdentifier() != null) {
listReset.reset(odeDataViewer.getVcDataIdentifier());
} else {
odeDataViewer.setOdeSolverResultSet(null);
}
} else {
if (listReset != null && pdeDataViewer != null && pdeDataViewer.getPdeDataContext() != null && pdeDataViewer.getPdeDataContext().getVCDataIdentifier() != null) {
listReset.reset(pdeDataViewer.getPdeDataContext().getVCDataIdentifier());
} else {
pdeDataViewer.setPdeDataContext(null);
}
}
return;
}
final VCSimulationDataIdentifier vcdid = new VCSimulationDataIdentifier(getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), selectedJobIndex);
if (isODEData) {
AsynchClientTask task1 = new AsynchClientTask("get ode results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
ODEDataManager odeDatamanager = ((ODEDataManager) dataManager).createNewODEDataManager(vcdid);
hashTable.put("odeDatamanager", odeDatamanager);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (e.getMessage() != null && e.getMessage().contains("no results are available yet")) {
throw UserCancelException.CANCEL_GENERIC;
}
throw e;
}
}
};
AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) == null && hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_USER) == null) {
ODEDataManager odeDatamanager = (ODEDataManager) hashTable.get("odeDatamanager");
odeDataViewer.setOdeSolverResultSet(odeDatamanager.getODESolverResultSet());
odeDataViewer.setVcDataIdentifier(vcdid);
} else {
odeDataViewer.setOdeSolverResultSet(null);
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
} else {
AsynchClientTask task1 = new AsynchClientTask("get pde results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
PDEDataManager pdeDatamanager = ((PDEDataManager) dataManager).createNewPDEDataManager(vcdid, null);
PDEDataContext newPDEDC = pdeDatamanager.getPDEDataContext();
PDEDataContext oldPDEDC = pdeDataViewer.getPdeDataContext();
hashTable.put("newPDEDC", newPDEDC);
if (oldPDEDC != null && oldPDEDC.getTimePoints().length <= newPDEDC.getTimePoints().length) {
DataIdentifier setDid = (newPDEDC.getDataIdentifier() == null ? newPDEDC.getDataIdentifiers()[0] : newPDEDC.getDataIdentifier());
if (Arrays.asList(newPDEDC.getDataIdentifiers()).contains(oldPDEDC.getDataIdentifier())) {
setDid = oldPDEDC.getDataIdentifier();
newPDEDC.setVariableAndTime(setDid, newPDEDC.getTimePoints()[BeanUtils.firstIndexOf(oldPDEDC.getTimePoints(), oldPDEDC.getTimePoint())]);
}
}
}
};
AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) == null) {
ClientPDEDataContext newPDEDC = (ClientPDEDataContext) hashTable.get("newPDEDC");
pdeDataViewer.setPdeDataContext(newPDEDC);
pdeDataViewer.setSimNameSimDataID(new ExportSpecs.SimNameSimDataID(getSimulation().getName(), getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), SimResultsViewer.getParamScanInfo(getSimulation(), vcdid.getJobIndex())));
} else {
if (listReset != null && pdeDataViewer != null && pdeDataViewer.getPdeDataContext() != null && pdeDataViewer.getPdeDataContext().getVCDataIdentifier() != null) {
listReset.reset(pdeDataViewer.getPdeDataContext().getVCDataIdentifier());
} else {
pdeDataViewer.setPdeDataContext(null);
pdeDataViewer.setSimNameSimDataID(null);
}
}
}
};
// AsynchClientTask refreshTask = new AsynchClientTask("",AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
// @Override
// public void run(Hashtable<String, Object> hashTable) throws Exception {
// ((ArrayList<AsynchClientTask>)hashTable.get(ClientTaskDispatcher.INTERMEDIATE_TASKS)).addAll(Arrays.asList(pdeDataViewer.getRefreshTasks()));
// }
// };
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 /*,refreshTask*/
});
}
}
use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.
the class SimResultsViewer method createODEDataViewer.
/**
* Insert the method's description here.
* Creation date: (6/11/2004 2:33:44 PM)
* @return javax.swing.JPanel
* @throws DataAccessException
*/
private DataViewer createODEDataViewer() throws DataAccessException {
odeDataViewer = new ODEDataViewer();
odeDataViewer.setSimulation(getSimulation());
ODESolverResultSet odesrs = ((ODEDataManager) dataManager).getODESolverResultSet();
odeDataViewer.setOdeSolverResultSet(odesrs);
odeDataViewer.setNFSimMolecularConfigurations(((ODEDataManager) dataManager).getNFSimMolecularConfigurations());
odeDataViewer.setVcDataIdentifier(dataManager.getVCDataIdentifier());
if (getSimulation() != null) {
String ownerName = generateHDF5DescrOwner(getSimulation());
odeDataViewer.setHDF5DescriptionText(ownerName + ":" + simulation.getName());
}
// odeDataViewer.setXVarName(odeDataViewer.getODESolverPlotSpecificationPanel1().getXAxisComboBox_frm().getSelectedItem().toString());
//
// Example code for reading stats data from Stochastic multitrial non-histogram
//
FileFormat hdf5FileFormat = null;
File to = null;
try {
if (odeDataViewer.getOdeSolverResultSet() instanceof ODESimData) {
byte[] hdf5FileBytes = ((ODESimData) odeDataViewer.getOdeSolverResultSet()).getHdf5FileBytes();
if (hdf5FileBytes != null) {
to = File.createTempFile("odeStats_" + getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), ".hdf5");
Files.write(hdf5FileBytes, to);
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.createInstance(to.getAbsolutePath(), FileFormat.READ);
// open the file and retrieve the file structure
hdf5FileFormat.open();
Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) hdf5FileFormat.getRootNode()).getUserObject();
List<HObject> postProcessMembers = ((Group) root).getMemberList();
for (HObject nextHObject : postProcessMembers) {
// System.out.println(nextHObject.getName()+"\n"+nextHObject.getClass().getName());
H5ScalarDS h5ScalarDS = (H5ScalarDS) nextHObject;
h5ScalarDS.init();
try {
long[] dims = h5ScalarDS.getDims();
System.out.println("---" + nextHObject.getName() + " " + nextHObject.getClass().getName() + " Dimensions=" + Arrays.toString(dims));
Object obj = h5ScalarDS.read();
if (dims.length == 2) {
// dims[0]=numTimes (will be the same as 'SimTimes' data length)
// dims[1]=numVars (will be the same as 'VarNames' data length)
// if name='StatMean' this is the same as the default data saved in the odeSolverresultSet
double[] columns = new double[(int) dims[1]];
for (int row = 0; row < dims[0]; row++) {
System.arraycopy(obj, row * columns.length, columns, 0, columns.length);
System.out.println(Arrays.toString(columns));
}
} else {
if (obj instanceof double[]) {
System.out.println(Arrays.toString((double[]) obj));
} else {
System.out.println(Arrays.toString((String[]) obj));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (hdf5FileFormat != null) {
try {
hdf5FileFormat.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (to != null) {
try {
to.delete();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return odeDataViewer;
}
use of cbit.vcell.simdata.ODEDataManager in project vcell by virtualcell.
the class MergedDatasetViewer method createDataViewer.
/**
* Insert the method's description here.
* Creation date: (6/11/2004 2:33:44 PM)
* @return javax.swing.JPanel
*/
private DataViewer createDataViewer() {
try {
if (isODEData) {
ODEDataManager odeDataManager = (ODEDataManager) dataManager;
odeDataViewer = new ODEDataViewer();
odeDataViewer.setOdeSolverResultSet(odeDataManager.getODESolverResultSet());
odeDataViewer.setVcDataIdentifier(dataManager.getVCDataIdentifier());
return odeDataViewer;
} else {
PDEDataManager pdeDataManager = (PDEDataManager) dataManager;
pdeDataViewer = new PDEDataViewer();
pdeDataViewer.setPdeDataContext(pdeDataManager.getPDEDataContext());
return pdeDataViewer;
}
} catch (org.vcell.util.DataAccessException exc) {
DialogUtils.showErrorDialog(this, "Could not fetch requested data.\nJCompare may have failed.\n" + exc.getMessage());
exc.printStackTrace();
}
return null;
}
Aggregations