use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class ChomboSimpleDataViewer method retrieveVariablesAndTimes.
private void retrieveVariablesAndTimes() {
AsynchClientTask task0 = new AsynchClientTask("clear", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
DefaultComboBoxModel dcm = new DefaultComboBoxModel();
timeComboBox.setModel(dcm);
DefaultListModel dlm = new DefaultListModel();
varList.setModel(dlm);
solTableModel.clear();
meshMetricsTableModel.clear();
meanTextField.setText(null);
maxErrorTextField.setText(null);
sumVolFracTextField.setText(null);
l2ErrorTextField.setText(null);
}
};
AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
String simId = simIdField.getText().trim();
if (simId == null || simId.length() == 0) {
throw new RuntimeException("Please provide a simulation id.");
}
String username = userNameTextField.getText().trim();
if (username == null || username.length() == 0) {
throw new RuntimeException("Please provide a user name.");
}
VCSimulationDataIdentifier vcDataId = new VCSimulationDataIdentifier(new VCSimulationIdentifier(new KeyValue(simId), new User(username, null)), 0);
SimDataInfoHolder simDataInfoHolder = null;
String datadir = dataDirTextField.getText();
if (datadir == null || datadir.length() == 0) {
simDataInfoHolder = createSimulationDataFromRemote(username, vcDataId);
datadir = simDataInfoHolder.userDir.getParent();
dataDirTextField.setText(datadir);
} else {
simDataInfoHolder = createSimulationDataFromDir(new File(datadir), username, vcDataId);
}
simData = simDataInfoHolder.simData;
simData.readVarAndFunctionDataIdentifiers();
usernames.add(username);
userNameTextField.setAutoCompletionWords(usernames);
datadirs.add(datadir);
dataDirTextField.setAutoCompletionWords(datadirs);
simIds.add(simId);
simIdField.setAutoCompletionWords(simIds);
}
};
AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
double[] times = simData.getDataTimes();
DefaultComboBoxModel dcm = new DefaultComboBoxModel();
for (double t : times) {
dcm.addElement(t);
}
timeComboBox.setModel(dcm);
meshMetricsTableModel.setData(simData.getChomboMesh().getMetricsColumnNames(), simData.getChomboMesh().getMetricsNumbers());
List<DataSetIdentifier> dsiList = simData.getDataSetIdentifiers();
DefaultListModel dlm = new DefaultListModel();
for (DataSetIdentifier dsi : dsiList) {
dlm.addElement(dsi);
}
varList.setModel(dlm);
if (times.length > 0) {
timeComboBox.setSelectedIndex(0);
}
if (dsiList.size() > 0) {
varList.setSelectedIndex(0);
}
meshMetricsTableModel.refreshTable();
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task0, task1, task2 }, false);
}
use of cbit.vcell.solver.VCSimulationDataIdentifier 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 {
ODEDataManager odeDatamanager = ((ODEDataManager) dataManager).createNewODEDataManager(vcdid);
hashTable.put("odeDatamanager", odeDatamanager);
}
};
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) {
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.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class VCellClientDataServiceImpl method getVCSimulationDataIdentifier.
public VCSimulationDataIdentifier getVCSimulationDataIdentifier(SimulationDataSetRef simulationDataSetRef) throws FileNotFoundException {
User user = new User(simulationDataSetRef.getUsername(), new KeyValue(simulationDataSetRef.getUserkey()));
KeyValue simKeyValue = new KeyValue(simulationDataSetRef.getSimId());
VCSimulationIdentifier vcSimulationIdentifier = new VCSimulationIdentifier(simKeyValue, user);
if (simulationDataSetRef.isIsLocal()) {
File primaryDir = ResourceUtil.getLocalRootDir();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(user, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
VCSimulationDataIdentifier simulationDataIdentifier = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
return simulationDataIdentifier;
} else {
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, simulationDataSetRef.getJobIndex());
return vcSimulationDataIdentifier;
}
}
use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class VCellClientDataServiceImpl method displayPostProcessingDataInVCell.
@Override
public void displayPostProcessingDataInVCell(SimulationDataSetRef simulationDataSetRef) throws NumberFormatException, DataAccessException {
User vcUser = vcellClient.getRequestManager().getDocumentManager().getUser();
VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(new KeyValue(simulationDataSetRef.getSimId()), vcUser);
ClientDocumentManager clientDocumentManager = (ClientDocumentManager) vcellClient.getClientServerManager().getDocumentManager();
SimulationOwner simulationOwner = null;
if (simulationDataSetRef.isMathModel) {
simulationOwner = clientDocumentManager.getMathModel(new KeyValue(simulationDataSetRef.getModelId()));
} else {
BioModel bioModel = clientDocumentManager.getBioModel(new KeyValue(simulationDataSetRef.getModelId()));
simulationOwner = bioModel.getSimulationContext(simulationDataSetRef.getSimulationContextName());
}
ArrayList<AnnotatedFunction> outputFunctionsList = simulationOwner.getOutputFunctionContext().getOutputFunctionsList();
OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
VCSimulationDataIdentifier vcSimDataId = new VCSimulationDataIdentifier(vcSimId, simulationDataSetRef.getJobIndex());
PDEDataManager pdeDataManager = (PDEDataManager) vcellClient.getRequestManager().getDataManager(outputContext, vcSimDataId, true);
final ClientPDEDataContext newClientPDEDataContext = pdeDataManager.getPDEDataContext();
// this was the code before the windows refactoring; appears to just always get the first window???
// Enumeration<TopLevelWindowManager> windowManagers = vcellClient.getMdiManager().getWindowManagers();
// final Window window = FindWindow.getWindow(windowManagers.nextElement().getComponent());
Optional<TopLevelWindowManager> first = vcellClient.getMdiManager().getWindowManagers().stream().findFirst();
VCAssert.assertTrue(first.isPresent(), "window manager not present?");
final Window window = getWindow(first.get().getComponent());
AsynchClientTask task = new AsynchClientTask("Display Post Processing Statistics", AsynchClientTask.TASKTYPE_SWING_NONBLOCKING, false, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
DataProcessingResultsPanel dataProcessingResultsPanel = new DataProcessingResultsPanel();
dataProcessingResultsPanel.update(newClientPDEDataContext);
DialogUtils.showComponentOKCancelDialog(window, dataProcessingResultsPanel, "Post Processing Statistics");
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
Vector<AsynchClientTask> tasksV = new Vector<AsynchClientTask>();
tasksV.add(task);
AsynchClientTask[] tasks = new AsynchClientTask[tasksV.size()];
tasksV.copyInto(tasks);
ClientTaskDispatcher.dispatch(window, hash, tasks, true);
}
use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class HybridSolverTester method makeAltCSV.
private static void makeAltCSV(AltArgsHelper altArgsHelper, FileWriter fw, int runIndex, File userSimDataDir) throws Exception {
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(new KeyValue(altArgsHelper.simID), altArgsHelper.user);
boolean bInit = runIndex == 0;
ArrayList<Double> simTimes = new ArrayList<Double>();
StringTokenizer st = null;
if (altArgsHelper.times.equals("all")) {
} else {
st = new StringTokenizer(altArgsHelper.times, ":");
while (st.hasMoreTokens()) {
double timePoint = Double.parseDouble(st.nextToken());
simTimes.add(timePoint);
}
}
SimLocHelper simLocHelper0 = null;
ArrayList<String> simVars = new ArrayList<String>();
st = new StringTokenizer(altArgsHelper.varnames, ":");
while (st.hasMoreTokens()) {
String var = st.nextToken();
simVars.add(var);
}
int jobCounter = 0;
final int TIME_SPACE_EXTRA = 0;
double[][][] trialData = null;
while (true) {
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimID, jobCounter);
SimulationData simData = null;
DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = null;
try {
simData = new SimulationData(vcSimulationDataIdentifier, userSimDataDir, null, null);
dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(vcSimulationDataIdentifier, true, null), new File(userSimDataDir, SimulationData.createCanonicalPostProcessFileName(vcSimulationDataIdentifier)));
} catch (FileNotFoundException e) {
if (jobCounter == 0) {
System.out.println("found no trials matching SimID=" + altArgsHelper.simID + " in user dir " + userSimDataDir.getAbsolutePath());
} else {
System.out.println("found " + jobCounter + " trials in dir " + userSimDataDir.getAbsolutePath() + " matching SimID=" + altArgsHelper.simID);
}
break;
} catch (Exception e) {
e.printStackTrace();
}
if (dataProcessingOutputInfo == null) {
System.out.println("No postprocessing found for " + jobCounter + " trials in dir " + userSimDataDir.getAbsolutePath() + " matching SimID=" + altArgsHelper.simID);
jobCounter++;
continue;
}
if (simLocHelper0 == null && !altArgsHelper.dataIndexes.equals(POSTPROC)) {
simLocHelper0 = calcSimLocs(altArgsHelper.dataIndexes, simData.getMesh());
}
if (jobCounter == 0) {
double[] allDatasetTimes = simData.getDataTimes();
if (altArgsHelper.times.equals("all")) {
for (double thisTime : allDatasetTimes) {
simTimes.add(thisTime);
}
} else {
// Convert user input times to actual data times
for (int times = 0; times < simTimes.size(); times++) {
double masterDelta = Double.POSITIVE_INFINITY;
double timePoint = -1;
for (int j = 0; j < allDatasetTimes.length; j++) {
double tempDelta = Math.abs(simTimes.get(times) - allDatasetTimes[j]);
if (tempDelta < masterDelta) {
masterDelta = tempDelta;
timePoint = allDatasetTimes[j];
if (tempDelta == 0) {
break;
}
}
}
System.out.println("User time=" + simTimes.get(times) + " converted to dataset time=" + timePoint);
simTimes.set(times, timePoint);
}
}
trialData = new double[simTimes.size()][(simLocHelper0 == null ? 1 : simLocHelper0.boxToLocs.size())][simVars.size()];
}
if (bInit && jobCounter == 0) {
// print state vars
DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
for (int j = 0; j < dataIdentifiers.length; j++) {
System.out.println(dataIdentifiers[j]);
}
printheader(altArgsHelper, simTimes, simLocHelper0, simVars, fw, TIME_SPACE_EXTRA);
}
for (int times = 0; times < simTimes.size(); times++) {
double timePoint = simTimes.get(times);
for (int vars = 0; vars < simVars.size(); vars++) {
double[] data = null;
if (altArgsHelper.dataIndexes.equals(POSTPROC)) {
data = dataProcessingOutputInfo.getVariableStatValues().get(simVars.get(vars) + "_average");
} else {
SimDataBlock simDataBlock = simData.getSimDataBlock(null, simVars.get(vars), timePoint);
data = simDataBlock.getData();
}
for (int locs = 0; locs < trialData[times].length; locs++) {
double val;
if (simLocHelper0 != null && simLocHelper0.boxToLocs.get(locs).size() == 1) {
// point
// System.out.println("pointIndex="+simLocHelper.boxToLocs.get(locs).get(0));
val = data[simLocHelper0.boxToLocs.get(locs).get(0)];
} else if (simLocHelper0 != null) {
// box, calculate the average, could be concentration or counts
double accum = 0;
for (Integer locIndex : simLocHelper0.boxToLocs.get(locs)) {
// System.out.println("boxIndex="+locIndex);
accum += data[locIndex];
}
val = accum / simLocHelper0.boxToLocs.get(locs).size();
} else {
// PostProcess
if (times < data.length) {
val = data[times];
} else {
val = Double.NaN;
}
}
trialData[times][locs][vars] = val;
}
}
}
fw.write("r=" + runIndex + " s=" + jobCounter + ",");
for (int times = 0; times < simTimes.size(); times++) {
for (int locs = 0; locs < trialData[times].length; locs++) {
for (int vars = 0; vars < simVars.size(); vars++) {
// System.out.println("job="+jobCounter+" time="+simTimes.get(times)+" loc="+simLocHelper.boxToID.get(locs)+" var="+simVars.get(vars)+" data="+trialData[times][locs][vars]);
boolean isNan = Double.isNaN(trialData[times][locs][vars]);
fw.write((isNan ? "" : trialData[times][locs][vars]) + ",");
}
fw.write(",");
}
for (int timeSpace = 0; timeSpace < TIME_SPACE_EXTRA; timeSpace++) {
fw.write(",");
}
}
fw.write("\n");
jobCounter++;
}
fw.flush();
}
Aggregations