use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class HybridSolverTester method main.
public static void main(java.lang.String[] args) {
VCMongoMessage.enabled = false;
boolean bAlternate = false;
if (args.length == 12) {
bAlternate = true;
} else if (args.length != 5) {
System.out.println("usage: HybridSolverTest userid SimID times(delimited by :) dataIndexes(delimited by :) varNames(delimited by :) numRuns outputFileDirectory bCalclOnly dbPassword useridKey rmiServer rmiPort");
System.out.println("usage: HybridSolverTest userid SimID all postproc varNames(delimited by :) numRuns outputFileDirectory bCalclOnly dbPassword useridKey rmiServer rmiPort");
System.out.println("usage: HybridSolverTest mathVCMLFileName startingTrialNo numTrials varNames(delimited by :) bPrintTime vcellSite(rel,beta,...)");
System.exit(1);
}
FileWriter fw = null;
try {
if (bAlternate) {
AltArgsHelper altArgsHelper = new AltArgsHelper(args[0], args[1], args[2], args[3], args[4], Integer.parseInt(args[5]), new File(args[6]), Boolean.parseBoolean(args[7]), args[8], args[9], args[10], args[11]);
// final String user = args[0];
// final String simID = args[1];
// final int numRuns = Integer.parseInt(args[5]);
//
// final String simPrefix = "SimID_"+simID+"_";
// File userSimDataDir = new File("\\\\cfs02\\raid\\vcell\\users\\"+user);
// File outputDir = new File(args[6]);
// boolean bCalcOnly = Boolean.parseBoolean(args[7]);
// String dbPassword = args[8];
// String useridKey = args[9];
// String rmiServer = args[10];
// String rmiPort = args[11];
VCSimulationIdentifier vcSimulationIdentifier = new VCSimulationIdentifier(new KeyValue(altArgsHelper.simID), altArgsHelper.user);
UserLoginInfo userLoginInfo = new UserLoginInfo(altArgsHelper.user.getName(), new DigestedPassword(altArgsHelper.dbPassword));
File[] trialList = null;
VCellConnectionHelper vCellConnectionHelper = null;
File emptyFile = File.createTempFile("hstempty", null);
try {
if (!altArgsHelper.bCalcOnly) {
// String rmiUrl = "//" + "rmi-alpha.cam.uchc.edu" + ":" + "40106" + "/"+"VCellBootstrapServer";
// String rmiUrl = "//" + "rmi-alpha.cam.uchc.edu" + ":" + "40112" + "/"+"VCellBootstrapServer";
String rmiUrl = "//" + altArgsHelper.rmiServer + ".cam.uchc.edu" + ":" + altArgsHelper.rmiPort + "/" + "VCellBootstrapServer";
vCellConnectionHelper = new VCellConnectionHelper(userLoginInfo, rmiUrl);
for (int runIndex = 0; runIndex < altArgsHelper.numRuns; runIndex++) {
System.out.println("----- Starting run " + (runIndex + 1) + " of " + altArgsHelper.numRuns);
runSim(userLoginInfo, vcSimulationIdentifier, vCellConnectionHelper);
if (trialList == null) {
System.out.println("Sim ran, getting trial list for " + altArgsHelper.simPrefix + " please wait...");
trialList = altArgsHelper.userSimDataDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
// }
return pathname.getName().startsWith(altArgsHelper.simPrefix) && !pathname.getName().endsWith(".simtask.xml");
}
});
}
System.out.println("----- Copying run " + (runIndex + 1) + " of " + altArgsHelper.numRuns);
File outputRunDir = makeOutputRunDir(altArgsHelper.outputDir, runIndex);
for (int j = 0; j < trialList.length; j++) {
File localCopyFile = new File(outputRunDir, trialList[j].getName());
try {
// copy remote sim data file to local
FileUtils.copyFile(trialList[j], localCopyFile);
// delete remote
trialList[j].delete();
} catch (Exception e) {
System.out.println("failed to copy '" + trialList[j].getAbsolutePath() + "', error=" + e.getMessage() + ". Putting empty file as placeholder");
try {
// copy empty file to local in place of problematic remote sim data file, later analysis will skip it
FileUtils.copyFile(emptyFile, localCopyFile);
} catch (Exception e2) {
System.out.println("Faild to copy file and failed to copy empty, " + e2.getMessage());
}
}
}
}
}
// calc stats
String dateStr = dateFormat.format(new Date());
String outPrefix = altArgsHelper.simID + "_" + dateStr + "_0";
File outputFile = new File(altArgsHelper.outputDir, outPrefix + ".csv");
while (outputFile.exists()) {
outPrefix = TokenMangler.getNextEnumeratedToken(outPrefix);
outputFile = new File(altArgsHelper.outputDir, outPrefix + ".csv");
}
fw = new FileWriter(outputFile);
fw.write("\"" + altArgsHelper.toString() + "\"\n");
for (int runIndex = 0; runIndex < altArgsHelper.numRuns; runIndex++) {
makeAltCSV(altArgsHelper, fw, runIndex, makeOutputRunDir(altArgsHelper.outputDir, runIndex));
}
fw.close();
} finally {
if (!altArgsHelper.bCalcOnly) {
File[] straglers = altArgsHelper.userSimDataDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().startsWith(altArgsHelper.simPrefix);
}
});
if (straglers != null) {
for (int i = 0; i < straglers.length; i++) {
straglers[i].delete();
}
}
}
}
} else {
String site = args[5];
HybridSolverTester hst = new HybridSolverTester(args[0], Integer.parseInt(args[1]), Integer.parseInt(args[2]), args[3], Boolean.parseBoolean(args[4]));
hst.runHybridTest(site);
}
} catch (Exception e) {
e.printStackTrace(System.out);
System.exit(1);
} finally {
if (fw != null) {
try {
fw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of org.vcell.util.document.KeyValue 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 org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class TestCaseAddPanel method applyTestCaseInfo.
/**
* Comment
*/
private void applyTestCaseInfo() throws Exception {
fieldNewTestCaseArr = null;
if (getMathModelInfo() == null && getbioModelInfo() == null) {
throw new Exception("Nothing selected, choose either a MathModel or a BioModel/App combination before setting TestCaseInfo");
// return;
}
if (getMathModelInfo() != null && getbioModelInfo() != null) {
throw new Exception("must choose either a MathModel or a BioModel/App combination (BUT NOT BOTH)");
// return;
}
// testcaseinfo TYPE
String type = null;
if (getExactRadioButton().isSelected()) {
type = TestCaseNew.EXACT;
} else if (getIvjExactRadioButtonSteady().isSelected()) {
type = TestCaseNew.EXACT_STEADY;
} else if (getConstructedRadioButton().isSelected()) {
type = TestCaseNew.CONSTRUCTED;
} else if (getRegressionRadioButton().isSelected()) {
type = TestCaseNew.REGRESSION;
} else {
throw new Exception("Solution Type Not Chosen");
}
String annotation = null;
annotation = getAnnotationTextArea().getText();
if (getMathModelInfo() != null) {
//
// math model selected
//
TestCaseNewMathModel mathTestCase = new TestCaseNewMathModel(null, getMathModelInfo(), type, annotation, null);
setNewTestCaseArr(new TestCaseNewMathModel[] { mathTestCase });
} else {
//
if (getappNameArr() == null) {
throw new Exception("no application(s) selected");
}
if (!type.equals(TestCaseNew.REGRESSION)) {
throw new Exception("BioModel/App test case must be of type 'REGRESSION'");
}
org.vcell.util.document.KeyValue[] appKeyArr = null;
try {
for (int i = 0; i < getappNameArr().length; i++) {
if (appKeyArr == null) {
appKeyArr = new KeyValue[getappNameArr().length];
}
appKeyArr[i] = getTestingFrameworkWindowManager().getSimContextKey(getbioModelInfo(), getappNameArr()[i]);
}
} catch (org.vcell.util.DataAccessException e) {
e.printStackTrace(System.out);
throw new Exception("Exception while retrieving BioModel SimContextKey");
}
if (appKeyArr == null) {
throw new Exception("BioModel/App test case cannot be created, selected application(s), not found in BioModel");
}
TestCaseNewBioModel[] bioTestCaseArr = new TestCaseNewBioModel[appKeyArr.length];
for (int i = 0; i < bioTestCaseArr.length; i++) {
bioTestCaseArr[i] = new TestCaseNewBioModel(null, getbioModelInfo(), getappNameArr()[i], appKeyArr[i], type, annotation, null);
}
setNewTestCaseArr(bioTestCaseArr);
}
}
use of org.vcell.util.document.KeyValue 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 org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class RunRefSimulationFastOp method createNewExternalDataInfo.
private ExternalDataInfo createNewExternalDataInfo(LocalContext localWorkspace, String extDataIDName) {
File targetDir = new File(localWorkspace.getDefaultSimDataDirectory());
KeyValue key = LocalWorkspace.createNewKeyValue();
User owner = LocalWorkspace.getDefaultOwner();
ExternalDataIdentifier newImageDataExtDataID = new ExternalDataIdentifier(key, owner, extDataIDName);
String filename = new File(targetDir, newImageDataExtDataID.getID() + SimDataConstants.LOGFILE_EXTENSION).getAbsolutePath();
ExternalDataInfo newImageDataExtDataInfo = new ExternalDataInfo(newImageDataExtDataID, filename);
return newImageDataExtDataInfo;
}
Aggregations