use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class ExportMonitorPanelTest method main.
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
JFrame frame = new javax.swing.JFrame();
ExportMonitorPanel aExportMonitorPanel;
aExportMonitorPanel = new ExportMonitorPanel();
frame.setContentPane(aExportMonitorPanel);
frame.setSize(aExportMonitorPanel.getSize());
frame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
frame.show();
java.awt.Insets insets = frame.getInsets();
frame.setSize(frame.getWidth() + insets.left + insets.right, frame.getHeight() + insets.top + insets.bottom);
VCSimulationDataIdentifier vcSimDataId = new VCSimulationDataIdentifier(new VCSimulationIdentifier(new KeyValue("234"), null), 1);
aExportMonitorPanel.addExportEvent(new ExportEvent(aExportMonitorPanel, 123456789L, null, vcSimDataId.getID(), vcSimDataId.getSimulationKey(), ExportEvent.EXPORT_PROGRESS, "CSV", "", new Double(0.47), null, null), "bogus [application: model]");
aExportMonitorPanel.addExportEvent(new ExportEvent(aExportMonitorPanel, 987654321L, null, vcSimDataId.getID(), vcSimDataId.getSimulationKey(), ExportEvent.EXPORT_COMPLETE, "GIF", "http://nrcam.uchc.edu/export/987654321.zip", new Double(1), null, null), "simulation [application: model]");
frame.pack();
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JPanel");
exception.printStackTrace(System.out);
}
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class RunRefSimulationFastOp method runRefSimulation.
private RowColumnResultSet runRefSimulation(ROI cellROI, ROI[] imageDataROIs, UShortImage psf, FloatImage initRefConc, double experimentalRecoveryTime, LocalWorkspace localWorkspace, ClientTaskStatusSupport progressListener) throws Exception {
User owner = LocalWorkspace.getDefaultOwner();
KeyValue simKey = LocalWorkspace.createNewKeyValue();
//
// save first image from normalized time series as the initial concentration field data
//
ExternalDataInfo initialConcentrationExtData = createNewExternalDataInfo(localWorkspace, INITCONC_EXTDATA_NAME);
Extent extent = initRefConc.getExtent();
Origin origin = initRefConc.getOrigin();
ISize isize = new ISize(initRefConc.getNumX(), initRefConc.getNumY(), initRefConc.getNumZ());
saveExternalData(initRefConc, INITCONC_EXTDATA_VARNAME, initialConcentrationExtData.getExternalDataIdentifier(), localWorkspace);
FieldFunctionArguments initConditionFFA = new FieldFunctionArguments(INITCONC_EXTDATA_NAME, INITCONC_EXTDATA_VARNAME, new Expression(0.0), VariableType.VOLUME);
//
// save ROIs as a multivariate field data
//
ExternalDataInfo roiExtData = createNewExternalDataInfo(localWorkspace, ROI_EXTDATA_NAME);
saveROIsAsExternalData(imageDataROIs, localWorkspace, roiExtData.getExternalDataIdentifier());
ArrayList<FieldFunctionArguments> roiFFAs = new ArrayList<FieldFunctionArguments>();
for (ROI roi : imageDataROIs) {
roiFFAs.add(new FieldFunctionArguments(ROI_EXTDATA_NAME, ROI_MASK_NAME_PREFIX + roi.getROIName(), new Expression(0.0), VariableType.VOLUME));
}
//
// save PSF as a field data
//
ExternalDataInfo psfExtData = createNewExternalDataInfo(localWorkspace, PSF_EXTDATA_NAME);
savePsfAsExternalData(psf, PSF_EXTDATA_VARNAME, psfExtData.getExternalDataIdentifier(), localWorkspace);
FieldFunctionArguments psfFFA = new FieldFunctionArguments(PSF_EXTDATA_NAME, PSF_EXTDATA_VARNAME, new Expression(0.0), VariableType.VOLUME);
TimeBounds timeBounds = getEstimatedRefTimeBound(experimentalRecoveryTime);
double timeStepVal = REFERENCE_DIFF_DELTAT;
Expression chirpedDiffusionRate = new Expression(REFERENCE_DIFF_RATE_COEFFICIENT + "*(t+" + REFERENCE_DIFF_DELTAT + ")");
BioModel bioModel = createRefSimBioModel(simKey, owner, origin, extent, cellROI, timeStepVal, timeBounds, VAR_NAME, new Expression(initConditionFFA.infix()), psfFFA, chirpedDiffusionRate);
if (progressListener != null) {
progressListener.setMessage("Running Reference Simulation...");
}
// run simulation
Simulation simulation = bioModel.getSimulation(0);
ROIDataGenerator roiDataGenerator = getROIDataGenerator(localWorkspace, imageDataROIs);
simulation.getMathDescription().getPostProcessingBlock().addDataGenerator(roiDataGenerator);
runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), simulation, initialConcentrationExtData.getExternalDataIdentifier(), roiExtData.getExternalDataIdentifier(), psfExtData.getExternalDataIdentifier(), progressListener, true);
KeyValue referenceSimKeyValue = simulation.getVersion().getVersionKey();
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(referenceSimKeyValue, LocalWorkspace.getDefaultOwner());
VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, 0);
File hdf5File = new File(localWorkspace.getDefaultSimDataDirectory(), vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
// get post processing info (time points, variable sizes)
DataOperation.DataProcessingOutputInfoOP dataOperationInfo = new DataOperation.DataProcessingOutputInfoOP(null, /*no vcDataIdentifier OK*/
false, null);
DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(dataOperationInfo, hdf5File);
// get post processing data
DataOperation.DataProcessingOutputDataValuesOP dataOperationDataValues = new DataOperation.DataProcessingOutputDataValuesOP(null, /*no vcDataIdentifier OK*/
ROI_EXTDATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null);
DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataOperationDataValues, hdf5File);
//
// delete the simulation files
//
//
// remove reference simulation files and field data files
//
File userDir = new File(localWorkspace.getDefaultSimDataDirectory());
File[] oldSimFilesToDelete = getSimulationFileNames(userDir, referenceSimKeyValue);
for (int i = 0; oldSimFilesToDelete != null && i < oldSimFilesToDelete.length; i++) {
oldSimFilesToDelete[i].delete();
}
deleteCanonicalExternalData(localWorkspace, initialConcentrationExtData.getExternalDataIdentifier());
deleteCanonicalExternalData(localWorkspace, roiExtData.getExternalDataIdentifier());
deleteCanonicalExternalData(localWorkspace, roiExtData.getExternalDataIdentifier());
// get ref sim time points (distorted by time dilation acceleration)
double[] rawRefDataTimePoints = dataProcessingOutputInfo.getVariableTimePoints();
// get shifted time points
double[] correctedRefDataTimePoints = shiftTimeForBaseDiffRate(rawRefDataTimePoints);
double[][] refData = dataProcessingOutputDataValues.getDataValues();
//
// for rowColumnResultSet with { "t", "roi1", .... , "roiN" } for reference data
//
int numROIs = imageDataROIs.length;
String[] columnNames = new String[numROIs + 1];
columnNames[0] = "t";
for (int i = 0; i < numROIs; i++) {
columnNames[i + 1] = imageDataROIs[i].getROIName();
}
RowColumnResultSet reducedData = new RowColumnResultSet(columnNames);
for (int i = 0; i < correctedRefDataTimePoints.length; i++) {
double[] row = new double[numROIs + 1];
row[0] = correctedRefDataTimePoints[i];
double[] roiData = refData[i];
for (int j = 0; j < numROIs; j++) {
// roiData[0] is the average over the cell .. postbleach this shouldn't change for pure diffusion
row[j + 1] = roiData[j + 1];
}
reducedData.addRow(row);
}
return reducedData;
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class RunSimulation2DOp method runRefSimulation.
public ImageTimeSeries<FloatImage> runRefSimulation(LocalWorkspace localWorkspace, Simulation simulation, String varName, ClientTaskStatusSupport progressListener) throws Exception {
User owner = LocalWorkspace.getDefaultOwner();
KeyValue simKey = LocalWorkspace.createNewKeyValue();
runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), simulation, progressListener);
Extent extent = simulation.getMathDescription().getGeometry().getExtent();
Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
VCDataIdentifier vcDataIdentifier = new VCSimulationDataIdentifier(new VCSimulationIdentifier(simKey, owner), 0);
CartesianMesh mesh = localWorkspace.getDataSetControllerImpl().getMesh(vcDataIdentifier);
ISize isize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
FloatImage[] solutionImages = new FloatImage[dataTimes.length];
for (int i = 0; i < dataTimes.length; i++) {
SimDataBlock simDataBlock = localWorkspace.getDataSetControllerImpl().getSimDataBlock(null, vcDataIdentifier, varName, dataTimes[i]);
double[] doubleData = simDataBlock.getData();
float[] floatPixels = new float[doubleData.length];
for (int j = 0; j < doubleData.length; j++) {
floatPixels[j] = (float) doubleData[j];
}
solutionImages[i] = new FloatImage(floatPixels, origin, extent, isize.getX(), isize.getY(), isize.getZ());
}
ImageTimeSeries<FloatImage> solution = new ImageTimeSeries<FloatImage>(FloatImage.class, solutionImages, dataTimes, 1);
return solution;
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class RunRefSimulationOp method runRefSimulation.
private static ImageTimeSeries<FloatImage> runRefSimulation(LocalWorkspace localWorkspace, ROI cellROI, double timeStepVal, TimeBounds timeBounds, FloatImage initRefConc, double baseDiffusionRate, ClientTaskStatusSupport progressListener) throws Exception {
String INITCONC_EXTDATA_NAME = "initConc";
String INITCONC_EXTDATA_VARNAME = "conc";
String VAR_NAME = "species";
User owner = LocalWorkspace.getDefaultOwner();
KeyValue simKey = LocalWorkspace.createNewKeyValue();
ExternalDataInfo initialConcentrationExtData = createNewExternalDataInfo(localWorkspace, INITCONC_EXTDATA_NAME);
Extent extent = initRefConc.getExtent();
Origin origin = initRefConc.getOrigin();
ISize isize = new ISize(initRefConc.getNumX(), initRefConc.getNumY(), initRefConc.getNumZ());
saveExternalData(initRefConc, INITCONC_EXTDATA_VARNAME, initialConcentrationExtData.getExternalDataIdentifier(), localWorkspace);
FieldFunctionArguments initConditionFFA = new FieldFunctionArguments(INITCONC_EXTDATA_NAME, INITCONC_EXTDATA_VARNAME, new Expression(0.0), VariableType.VOLUME);
BioModel bioModel = createRefSimBioModel(simKey, owner, origin, extent, cellROI, timeStepVal, timeBounds, VAR_NAME, new Expression(initConditionFFA.infix()), baseDiffusionRate);
if (progressListener != null) {
progressListener.setMessage("Running Reference Simulation...");
}
// run simulation
runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), bioModel.getSimulation(0), initialConcentrationExtData.getExternalDataIdentifier(), progressListener, true);
VCDataIdentifier vcDataIdentifier = new VCSimulationDataIdentifier(new VCSimulationIdentifier(simKey, owner), 0);
double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
FloatImage[] solutionImages = new FloatImage[dataTimes.length];
for (int i = 0; i < dataTimes.length; i++) {
SimDataBlock simDataBlock = localWorkspace.getDataSetControllerImpl().getSimDataBlock(null, vcDataIdentifier, VAR_NAME, dataTimes[i]);
double[] doubleData = simDataBlock.getData();
float[] floatPixels = new float[doubleData.length];
for (int j = 0; j < doubleData.length; j++) {
floatPixels[j] = (float) doubleData[j];
}
solutionImages[i] = new FloatImage(floatPixels, origin, extent, isize.getX(), isize.getY(), isize.getZ());
}
ImageTimeSeries<FloatImage> solution = new ImageTimeSeries<FloatImage>(FloatImage.class, solutionImages, dataTimes, 1);
return solution;
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class NagiosVCellMonitor method checkVCell.
private CheckResults checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int criticalTimeout, int monitorPort) throws Exception {
SimulationStatusPersistent lastSimStatus = null;
String vcellVersion = null;
TreeMap<VCELL_CHECK_LEVEL, Long> levelTimesMillisec = new TreeMap<NagiosVCellMonitor.VCELL_CHECK_LEVEL, Long>();
long startTime = System.currentTimeMillis();
VCellConnection vcellConnection = null;
try {
if (rmiHostName == null || rmiPort == -1) {
throw new UnexpectedTestStateException("Host name/ip and rmiPort required for testing, rmihostname=" + rmiHostName + " rmiport=" + rmiPort);
}
String rmiUrl = "//" + rmiHostName + ":" + rmiPort + "/" + rmiBootstrapStubName;
VCellBootstrap vcellBootstrap = null;
try {
vcellBootstrap = (VCellBootstrap) Naming.lookup(rmiUrl);
} catch (Exception e) {
throw new UnexpectedTestStateException("Error during bootstrap lookup, " + e.getClass().getSimpleName() + " " + e.getMessage());
}
vcellVersion = vcellBootstrap.getVCellSoftwareVersion();
levelTimesMillisec.put(VCELL_CHECK_LEVEL.RMI_ONLY_0, System.currentTimeMillis() - startTime);
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.CONNECT_1.ordinal()) {
if (vcellNagiosPassword == null) {
throw new UnexpectedTestStateException("vcellNagios Password required for " + VCELL_CHECK_LEVEL.CONNECT_1.toString() + " and above");
}
UserLoginInfo userLoginInfo = new UserLoginInfo(VCELL_NAGIOS_USER, new DigestedPassword(vcellNagiosPassword));
vcellConnection = vcellBootstrap.getVCellConnection(userLoginInfo);
levelTimesMillisec.put(VCELL_CHECK_LEVEL.CONNECT_1, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.RMI_ONLY_0));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
levelTimesMillisec.put(VCELL_CHECK_LEVEL.INFOS_2, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.CONNECT_1));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.LOAD_3.ordinal()) {
KeyValue bioModelKey = null;
final String testModelName = "Solver Suite 5.1 (BETA only ode)";
for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
if (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && bioModelInfo.getVersion().getName().equals(testModelName)) {
bioModelKey = bioModelInfo.getVersion().getVersionKey();
break;
}
}
BigString bioModelXML = vcellConnection.getUserMetaDbServer().getBioModelXML(bioModelKey);
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModel.refreshDependencies();
levelTimesMillisec.put(VCELL_CHECK_LEVEL.LOAD_3, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.INFOS_2));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.DATA_4.ordinal()) {
final String testSimContextName = "non-spatial ODE";
SimulationContext simulationContext = bioModel.getSimulationContext(testSimContextName);
final String testSimName = "Copy of combined ida/cvode";
Simulation simulation = simulationContext.getSimulation(testSimName);
if (simulation == null) {
throw new UnexpectedTestStateException("Couldn't find sim '" + testSimName + "' for " + checkLevel.toString());
}
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
ArrayList<AnnotatedFunction> outputFunctionsList = simulationContext.getOutputFunctionContext().getOutputFunctionsList();
OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
double[] times = vcellConnection.getDataSetController().getDataSetTimes(vcSimulationDataIdentifier);
ODESimData odeSimData = vcellConnection.getDataSetController().getODEData(vcSimulationDataIdentifier);
levelTimesMillisec.put(VCELL_CHECK_LEVEL.DATA_4, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.LOAD_3));
if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
KeyValue copy1Key = null;
KeyValue copy2Key = null;
VCSimulationIdentifier testRunSimID = null;
try {
if (simulationContext.getSimulations().length != 1) {
throw new UnexpectedTestStateException("Expecting only 1 sim to be copied for " + checkLevel.toString());
}
SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(simulation.getVersion().getVersionKey());
if (!simulationStatus.isCompleted()) {
throw new UnexpectedTestStateException("Expecting completed sim to copy for " + checkLevel.toString());
}
String copyModelName = testModelName + "_" + rmiHostName + "_rmi" + rmiPort + "_siteprt" + monitorPort;
boolean bForceCleanup = true;
while (true) {
boolean bMessy = false;
for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
if (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && bioModelInfo.getVersion().getName().equals(copyModelName)) {
bMessy = true;
if (bForceCleanup) {
try {
vcellConnection.getUserMetaDbServer().deleteBioModel(bioModelInfo.getVersion().getVersionKey());
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new MessyTestEnvironmentException("Messy test environment, not expecting " + copyModelName + " and couldn't cleanup");
}
}
}
if (!bMessy) {
break;
}
// get new vcInfoContainer without cleaned-up model
vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
bForceCleanup = false;
}
BigString copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModelAs(bioModelXML, copyModelName, null);
BioModel copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
copy1Key = copyBioModel.getVersion().getVersionKey();
copyBioModel.refreshDependencies();
Simulation copySim = copyBioModel.getSimulationContext(testSimContextName).copySimulation(copyBioModel.getSimulationContext(testSimContextName).getSimulation(testSimName));
final String copyTestSimName = "test";
copySim.setName(copyTestSimName);
copyBioModel.refreshDependencies();
copyBioModelXMLStr = new BigString(XmlHelper.bioModelToXML(copyBioModel));
copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModel(copyBioModelXMLStr, null);
copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
copy2Key = copyBioModel.getVersion().getVersionKey();
copyBioModel.refreshDependencies();
Simulation newSimulation = copyBioModel.getSimulationContext(testSimContextName).getSimulation(copyTestSimName);
simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
if (simulationStatus != null && !simulationStatus.isNeverRan()) {
throw new UnexpectedTestStateException("Expecting new sim to have 'never ran' status for " + checkLevel.toString());
}
testRunSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
vcellConnection.getSimulationController().startSimulation(testRunSimID, 1);
lastSimStatus = simulationStatus;
MessageEvent[] messageEvents = null;
while (simulationStatus == null || (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed())) {
Thread.sleep(200);
if (((System.currentTimeMillis() - startTime) / 1000) > criticalTimeout) {
vcellConnection.getSimulationController().stopSimulation(testRunSimID);
vcellConnection.getMessageEvents();
break;
}
simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
lastSimStatus = simulationStatus;
}
if (simulationStatus != null && simulationStatus.isFailed()) {
throw new Exception("time " + ((System.currentTimeMillis() - startTime) / 1000) + ", Sim execution failed key:" + testRunSimID.getSimulationKey() + " sim " + newSimulation.getName() + " model " + copyBioModel.getVersion().getName() + " messg " + simulationStatus.getFailedMessage());
}
messageEvents = vcellConnection.getMessageEvents();
}
} finally {
try {
if (copy1Key != null) {
vcellConnection.getUserMetaDbServer().deleteBioModel(copy1Key);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if (copy2Key != null) {
vcellConnection.getUserMetaDbServer().deleteBioModel(copy2Key);
}
} catch (Exception e) {
e.printStackTrace();
}
if (testRunSimID != null) {
deleteSimData(testRunSimID);
}
}
levelTimesMillisec.put(VCELL_CHECK_LEVEL.RUN_5, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.DATA_4));
}
}
}
}
}
return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, null);
} catch (Exception e) {
return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, e);
} finally {
vcellConnection = null;
}
}
Aggregations