use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class SimulationData method getParticleDataBlock.
/**
* This method was created in VisualAge.
* @return cbit.vcell.simdata.ParticleDataBlock
* @param double time
*/
public synchronized ParticleDataBlock getParticleDataBlock(double time) throws DataAccessException, IOException {
refreshLogFile();
File particleFile = getParticleDataFile(time);
if (particleFile == null) {
throw new DataAccessException("particle data doesn't exist for time = " + time);
}
File zipFile = null;
try {
zipFile = getPDEDataZipFile(time);
} catch (DataAccessException ex) {
zipFile = null;
}
ParticleDataBlock particleDataBlock = new ParticleDataBlock(vcDataId.getOwner(), vcDataId.getID(), time, particleFile, zipFile);
return particleDataBlock;
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class SimulationData method getSimDataBlock.
/**
* This method was created in VisualAge.
* @return cbit.vcell.simdata.DataBlock
* @param user cbit.vcell.server.User
* @param simID java.lang.String
*/
public synchronized SimDataBlock getSimDataBlock(OutputContext outputContext, String varName, double time) throws DataAccessException, IOException {
refreshLogFile();
try {
getFunctionDataIdentifiers(outputContext);
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
try {
if (isPostProcessing(outputContext, varName)) {
PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(), vcDataId.getID(), varName, time, lastDataProcessingOutputInfoTime);
DataProcessingOutputDataValuesOP dataProcessingOutputDataValuesOP = new DataProcessingOutputDataValuesOP(vcDataId, varName, TimePointHelper.createSingleTimeTimePointHelper(extractClosestPostProcessTime(time)), DataIndexHelper.createAllDataIndexesDataIndexHelper(), outputContext, null);
DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataProcessingOutputDataValuesOP, getDataProcessingOutputSourceFileHDF5());
return new SimDataBlock(pdeDataInfo, dataProcessingOutputDataValues.getDataValues()[0], /*1 time only*/
VariableType.POSTPROCESSING);
}
} catch (Exception e) {
// ignore
e.printStackTrace();
}
File pdeFile = getPDEDataFile(time);
if (pdeFile == null) {
return null;
}
DataSet dataSet = getPDEDataSet(pdeFile, time);
File zipFile = null;
try {
zipFile = getPDEDataZipFile(time);
} catch (DataAccessException ex) {
zipFile = null;
}
long lastModified = getLastModified(pdeFile, zipFile);
DataSetIdentifier dsi = getDataSetIdentifier(varName);
if (dsi == null) {
throw new DataAccessException("data not found for variable " + varName);
}
final String varNameInDataSet = dsi.getQualifiedName();
double[] data = dataSet.getData(varNameInDataSet, zipFile, time, amplistorHelper.solverDataType);
int varTypeInt = dataSet.getVariableTypeInteger(varNameInDataSet);
VariableType variableType = null;
try {
variableType = VariableType.getVariableTypeFromInteger(varTypeInt);
} catch (IllegalArgumentException e) {
e.printStackTrace(System.out);
System.out.println("invalid varTypeInt = " + varTypeInt + " for variable " + varName + " at time " + time);
try {
variableType = SimulationData.getVariableTypeFromLength(getMesh(), data.length);
} catch (MathException ex) {
ex.printStackTrace(System.out);
throw new DataAccessException(ex.getMessage());
}
}
PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(), vcDataId.getID(), varName, time, lastModified);
if (data != null) {
return new SimDataBlock(pdeDataInfo, data, variableType);
} else {
return null;
}
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class SimulationData method removeAllResults.
/**
* This method was created in VisualAge.
*/
private synchronized void removeAllResults(File logFile, File meshFile) {
//
// remove data files
//
double[] times = null;
try {
times = getDataTimes();
} catch (DataAccessException exc) {
System.out.println("<<EXCEPTION>> SimResults:removeAllResults() " + exc.getMessage());
}
//
if (isODEData) {
File odeFile = null;
try {
odeFile = getODEDataFile();
} catch (DataAccessException e) {
System.out.println("<<EXCEPTION>> SimResults:removeAllResults() removing .ode file: " + e.getMessage());
}
if (odeFile != null && odeFile.exists()) {
odeFile.delete();
}
} else {
//
if (times != null) {
for (int i = 0; i < times.length; i++) {
File zipFile = null;
try {
zipFile = getPDEDataZipFile(times[i]);
} catch (DataAccessException exc) {
System.out.println("<<EXCEPTION>> SimResults:removeAllResults() removing .zip file " + exc.getMessage());
}
if (zipFile != null && zipFile.exists()) {
zipFile.delete();
}
File dataFile = null;
try {
dataFile = getPDEDataFile(times[i]);
} catch (DataAccessException exc) {
System.out.println("<<EXCEPTION>> SimResults:removeAllResults() removing .sim file " + exc.getMessage());
}
if (dataFile != null && dataFile.exists()) {
dataFile.delete();
}
File particleFile = null;
try {
particleFile = getParticleDataFile(times[i]);
} catch (DataAccessException exc) {
System.out.println("<<EXCEPTION>> SimResults:removeAllResults() removing .particle file " + exc.getMessage());
}
if (particleFile != null && particleFile.exists()) {
particleFile.delete();
}
}
}
}
//
if (logFile != null) {
if (logFile.exists()) {
logFile.delete();
}
}
//
if (meshFile != null) {
if (meshFile.exists()) {
meshFile.delete();
}
}
//
// clear cached info
//
dataFilenames = null;
zipFilenames = null;
dataTimes = null;
chomboFileIterationIndices = null;
annotatedFunctionList.removeAllElements();
mesh = null;
logFileLastModified = 0;
logFileLength = 0;
meshFileLastModified = 0;
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class SimulationData method getSimDataTimeSeries0.
/**
* This method was created in VisualAge.
* @return cbit.vcell.simdata.DataBlock
* @param user cbit.vcell.server.User
* @param simID java.lang.String
*/
synchronized double[][][] getSimDataTimeSeries0(OutputContext outputContext, String[] varNames, int[][] indexes, boolean[] wantsThisTime, DataSetControllerImpl.SpatialStatsInfo spatialStatsInfo, DataSetControllerImpl.ProgressListener progressListener) throws DataAccessException, IOException {
refreshLogFile();
try {
getFunctionDataIdentifiers(outputContext);
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
int resultsCounter = 0;
for (int i = 0; i < wantsThisTime.length; i += 1) {
if (wantsThisTime[i]) {
resultsCounter += 1;
}
}
// min,max,mean,wmean
final int NUM_STATS = 4;
// Create results buffer
// [timePoints][varNames][dataIndexes]
double[][][] results = new double[resultsCounter][][];
for (int i = 0; i < results.length; i += 1) {
results[i] = new double[varNames.length][];
for (int j = 0; j < results[i].length; j += 1) {
if (spatialStatsInfo != null) {
// min,max.mean,wmean
results[i][j] = new double[NUM_STATS];
} else {
results[i][j] = new double[indexes[j].length];
}
}
}
try {
if (varNames.length > 0 && isPostProcessing(outputContext, varNames[0])) {
double[] specificTimePoints = new double[results.length];
int counter = 0;
for (int i = 0; i < dataProcessingOutputInfo.getVariableTimePoints().length; i++) {
if (wantsThisTime[i]) {
specificTimePoints[counter] = dataProcessingOutputInfo.getVariableTimePoints()[i];
counter++;
}
}
// PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(),vcDataId.getID(),varName,time,lastDataProcessingOutputInfoTime);
for (int i = 0; i < varNames.length; i++) {
DataProcessingOutputDataValuesOP dataProcessingOutputDataValuesOP = new DataProcessingOutputDataValuesOP(vcDataId, varNames[i], TimePointHelper.createSpecificTimePointHelper(specificTimePoints), DataIndexHelper.createSpecificDataIndexHelper(indexes[i]), outputContext, null);
DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataProcessingOutputDataValuesOP, getDataProcessingOutputSourceFileHDF5());
for (int j = 0; j < specificTimePoints.length; j++) {
results[j][i] = dataProcessingOutputDataValues.getDataValues()[j];
}
}
return results;
}
} catch (Exception e) {
// ignore
e.printStackTrace();
}
String[] varNamesInDataSet = new String[varNames.length];
for (int i = 0; i < varNamesInDataSet.length; i++) {
varNamesInDataSet[i] = getDataSetIdentifier(varNames[i]).getQualifiedName();
}
// Setup parameters for SimDataReader
double[] tempDataTimes = dataTimes.clone();
String[] tempZipFileNames = null;
if (bZipFormat2) {
tempZipFileNames = new String[tempDataTimes.length];
}
String[] tempSimDataFileNames = new String[tempDataTimes.length];
for (int i = 0; i < tempDataTimes.length; i += 1) {
if (bZipFormat2 || bZipFormat1) {
if (bZipFormat2) {
tempZipFileNames[i] = getPDEDataZipFile(tempDataTimes[i]).getAbsolutePath();
}
tempSimDataFileNames[i] = dataFilenames[i];
} else {
// userDirectory.getAbsolutePath()+"\\"+dataFilenames[i];//getPDEDataFile(dataTimes[i]).getAbsolutePath();
tempSimDataFileNames[i] = amplistorHelper.getFile(dataFilenames[i]).getName();
}
}
SimDataReader sdr = null;
double[][] singleTimePointResultsBuffer = new double[varNamesInDataSet.length][];
for (int i = 0; i < singleTimePointResultsBuffer.length; i += 1) {
singleTimePointResultsBuffer[i] = new double[indexes[i].length];
}
// In case sim files have been updated since "wantsThisTime" was calculated
if (wantsThisTime.length < tempDataTimes.length) {
double[] tempTempDataTimes = new double[wantsThisTime.length];
System.arraycopy(tempDataTimes, 0, tempTempDataTimes, 0, wantsThisTime.length);
tempDataTimes = tempTempDataTimes;
String[] tempTempZipFileNames = new String[wantsThisTime.length];
System.arraycopy(tempZipFileNames, 0, tempTempZipFileNames, 0, wantsThisTime.length);
tempZipFileNames = tempTempZipFileNames;
String[] tempTempSimDataFileNames = new String[wantsThisTime.length];
System.arraycopy(tempSimDataFileNames, 0, tempTempSimDataFileNames, 0, wantsThisTime.length);
tempSimDataFileNames = tempTempSimDataFileNames;
}
try {
sdr = new SimDataReader(wantsThisTime, tempDataTimes, tempZipFileNames, tempSimDataFileNames, varNamesInDataSet, indexes, isChombo());
int counter = 0;
int progressCounter = 0;
while (sdr.hasMoreData()) {
sdr.getNextDataAtCurrentTime(singleTimePointResultsBuffer);
// Copy data to timeSeries format
if (wantsThisTime[counter]) {
for (int i = 0; i < varNamesInDataSet.length; i += 1) {
if (spatialStatsInfo != null) {
results[progressCounter][i] = calcSpaceStats(singleTimePointResultsBuffer[i], i, spatialStatsInfo);
} else {
for (int j = 0; j < indexes[i].length; j += 1) {
results[progressCounter][i][j] = singleTimePointResultsBuffer[i][j];
}
}
}
progressCounter += 1;
if (progressListener != null) {
progressListener.updateProgress(100.0 * (double) progressCounter / (double) resultsCounter);
}
}
counter += 1;
}
return results;
} catch (DataAccessException e) {
throw e;
} catch (IOException e) {
throw e;
} catch (Throwable e) {
throw new DataAccessException(e.getMessage(), e);
} finally {
if (sdr != null) {
sdr.close();
}
}
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class SimulationData method getVarAndFunctionDataIdentifiers.
/**
* This method was created in VisualAge.
* @return java.lang.String[]
*/
public synchronized DataIdentifier[] getVarAndFunctionDataIdentifiers(OutputContext outputContext) throws IOException, DataAccessException {
// Is this zip format?
boolean bIsChombo = false;
try {
bIsChombo = isChombo();
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
}
File zipFile1 = getZipFile(bIsChombo, null);
File zipFile2 = getZipFile(bIsChombo, 0);
bZipFormat1 = false;
bZipFormat2 = false;
if (zipFile1.exists()) {
bZipFormat1 = true;
} else if (zipFile2.exists()) {
bZipFormat2 = true;
}
refreshLogFile();
if (!isComsol()) {
try {
refreshMeshFile();
} catch (MathException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
}
if (!isRulesData && !getIsODEData() && !isComsol() && dataFilenames != null) {
// read variables only when I have never read the file since variables don't change
if (dataSetIdentifierList.size() == 0) {
File file = getPDEDataFile(0.0);
DataSet dataSet = getPDEDataSet(file, 0.0);
String[] varNames = dataSet.getDataNames();
int[] varTypeInts = dataSet.getVariableTypeIntegers();
if (varNames == null) {
return null;
}
dataSetIdentifierList.clear();
for (int i = 0; i < varNames.length; i++) {
VariableType varType = null;
try {
varType = VariableType.getVariableTypeFromInteger(varTypeInts[i]);
} catch (IllegalArgumentException e) {
if (LG.isEnabledFor(Level.WARN)) {
LG.warn("Exception typing " + varNames[i] + " has unsupported type " + varTypeInts[i] + ": " + e.getMessage());
}
varType = SimulationData.getVariableTypeFromLength(mesh, dataSet.getDataLength(varNames[i]));
}
Domain domain = Variable.getDomainFromCombinedIdentifier(varNames[i]);
String varName = Variable.getNameFromCombinedIdentifier(varNames[i]);
dataSetIdentifierList.addElement(new DataSetIdentifier(varName, varType, domain));
}
refreshDataProcessingOutputInfo(outputContext);
if (dataProcessingOutputInfo != null) {
for (int i = 0; i < dataProcessingOutputInfo.getVariableNames().length; i++) {
if (dataProcessingOutputInfo.getPostProcessDataType(dataProcessingOutputInfo.getVariableNames()[i]).equals(DataProcessingOutputInfo.PostProcessDataType.image)) {
dataSetIdentifierList.addElement(new DataSetIdentifier(dataProcessingOutputInfo.getVariableNames()[i], VariableType.POSTPROCESSING, null));
}
}
}
}
// always read functions file since functions might change
getFunctionDataIdentifiers(outputContext);
}
if ((isRulesData || getIsODEData()) && dataSetIdentifierList.size() == 0) {
ODEDataBlock odeDataBlock = getODEDataBlock();
if (odeDataBlock == null) {
throw new DataAccessException("Results are not availabe yet. Please try again later.");
}
ODESimData odeSimData = odeDataBlock.getODESimData();
int colCount = odeSimData.getColumnDescriptionsCount();
// assume index=0 is time "t"
int DATA_OFFSET = 1;
dataSetIdentifierList.clear();
for (int i = 0; i < (colCount - DATA_OFFSET); i++) {
String varName = odeSimData.getColumnDescriptions(i + DATA_OFFSET).getDisplayName();
// TODO domain
Domain domain = null;
dataSetIdentifierList.addElement(new DataSetIdentifier(varName, VariableType.NONSPATIAL, domain));
}
}
if (isComsol() && dataSetIdentifierList.size() == 0) {
ComsolSimFiles comsolSimFiles = getComsolSimFiles();
if (comsolSimFiles.simTaskXMLFile != null) {
try {
String xmlString = FileUtils.readFileToString(comsolSimFiles.simTaskXMLFile);
SimulationTask simTask = XmlHelper.XMLToSimTask(xmlString);
Enumeration<Variable> variablesEnum = simTask.getSimulation().getMathDescription().getVariables();
while (variablesEnum.hasMoreElements()) {
Variable var = variablesEnum.nextElement();
if (var instanceof VolVariable) {
dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), VariableType.VOLUME, var.getDomain()));
} else if (var instanceof MemVariable) {
dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), VariableType.MEMBRANE, var.getDomain()));
} else if (var instanceof Function) {
VariableType varType = VariableType.UNKNOWN;
if (var.getDomain() != null && var.getDomain().getName() != null) {
SubDomain subDomain = simTask.getSimulation().getMathDescription().getSubDomain(var.getDomain().getName());
if (subDomain instanceof CompartmentSubDomain) {
varType = VariableType.VOLUME;
} else if (subDomain instanceof MembraneSubDomain) {
varType = VariableType.MEMBRANE;
} else if (subDomain instanceof FilamentSubDomain) {
throw new RuntimeException("filament subdomains not supported");
} else if (subDomain instanceof PointSubDomain) {
varType = VariableType.POINT_VARIABLE;
}
}
dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), varType, var.getDomain()));
} else if (var instanceof Constant) {
System.out.println("ignoring Constant " + var.getName());
} else if (var instanceof InsideVariable) {
System.out.println("ignoring InsideVariable " + var.getName());
} else if (var instanceof OutsideVariable) {
System.out.println("ignoring OutsideVariable " + var.getName());
} else {
throw new RuntimeException("unexpected variable " + var.getName() + " of type " + var.getClass().getName());
}
}
} catch (XmlParseException | ExpressionException e) {
e.printStackTrace();
throw new RuntimeException("failed to read sim task file, msg: " + e.getMessage(), e);
}
}
}
DataIdentifier[] dis = new DataIdentifier[dataSetIdentifierList.size()];
for (int i = 0; i < dataSetIdentifierList.size(); i++) {
DataSetIdentifier dsi = (DataSetIdentifier) dataSetIdentifierList.elementAt(i);
String displayName = dsi.getName();
if (dsi.isFunction()) {
AnnotatedFunction f = null;
for (int j = 0; j < annotatedFunctionList.size(); j++) {
AnnotatedFunction function = (AnnotatedFunction) annotatedFunctionList.elementAt(j);
if (function.getName().equals(dsi.getName())) {
f = function;
break;
}
}
if (f != null) {
displayName = f.getDisplayName();
}
}
dis[i] = new DataIdentifier(dsi.getName(), dsi.getVariableType(), dsi.getDomain(), dsi.isFunction(), displayName);
}
return dis;
}
Aggregations