use of ncsa.hdf.hdf5lib.exceptions.HDF5Exception in project vcell by virtualcell.
the class VH5Path method walk.
/**
* find next object in sequence
* @param hobj previous element in sequence
* @param steps name of each step
* @param index current step
* @return next object path, if present
* @throws HDF5Exception
*/
private static Object walk(Object hobj, String[] steps, int index) throws Exception {
final boolean isLastIndex = lastIndex(index, steps);
final String finding = steps[index];
Group g = BeanUtils.downcast(Group.class, hobj);
if (g != null) {
List<HObject> ml = g.getMemberList();
for (HObject sub : ml) {
// String full = sub.getFullName();
if (finding.equals(sub.getName())) {
if (isLastIndex) {
return sub;
}
return walk(sub, steps, index + 1);
}
}
}
H5CompoundDS cds = BeanUtils.downcast(H5CompoundDS.class, hobj);
if (cds != null) {
cds.read();
String[] mn = cds.getMemberNames();
for (int i = 0; i < mn.length; i++) {
if (finding.equals(mn[i])) {
Object c = cds.read();
Vector<?> vec = BeanUtils.downcast(Vector.class, c);
if (vec != null) {
VCAssert.assertTrue(i < vec.size(), "Disconnect between H5CompoundDS.getMemberNames( ) and returned Vector");
Object child = vec.get(i);
if (isLastIndex) {
return child;
}
} else {
throw new UnsupportedOperationException("Unsupported H5CompoundDS subtype " + className(c));
}
}
}
}
if (isLastIndex) {
DataFormat df = BeanUtils.downcast(DataFormat.class, hobj);
if (df != null && df.hasAttribute()) {
try {
@SuppressWarnings("unchecked") List<Object> meta = df.getMetadata();
for (Object o : meta) {
Attribute a = BeanUtils.downcast(Attribute.class, o);
if (a != null) {
if (finding.equals(a.getName())) {
return a.getValue();
}
} else {
lg.warn(concat(steps, finding) + " fetching metadata unexpected type " + className(o));
}
}
} catch (Exception e) {
throw new RuntimeException(concat(steps, finding) + " fetching metadata", e);
}
}
}
return null;
}
use of ncsa.hdf.hdf5lib.exceptions.HDF5Exception in project vcell by virtualcell.
the class ASCIIExporter method exportPDEData.
/**
* This method was created in VisualAge.
* @throws IOException
*/
private List<ExportOutput> exportPDEData(OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, final VCDataIdentifier orig_vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs, GeometrySpecs geometrySpecs, ASCIISpecs asciiSpecs, String contextName, FileDataContainerManager fileDataContainerManager) throws DataAccessException, IOException {
ExportSpecs.SimNameSimDataID[] simNameSimDataIDs = asciiSpecs.getSimNameSimDataIDs();
Vector<ExportOutput[]> exportOutputV = new Vector<ExportOutput[]>();
double progressCounter = 0;
final int SIM_COUNT = simNameSimDataIDs.length;
final int PARAMSCAN_COUNT = (asciiSpecs.getExportMultipleParamScans() != null ? asciiSpecs.getExportMultipleParamScans().length : 1);
final int endTimeIndex = timeSpecs.getEndTimeIndex();
final int beginTimeIndex = timeSpecs.getBeginTimeIndex();
final int TIME_COUNT = endTimeIndex - beginTimeIndex + 1;
double TOTAL_EXPORTS_OPS = 0;
switch(geometrySpecs.getModeID()) {
case GEOMETRY_SELECTIONS:
TOTAL_EXPORTS_OPS = SIM_COUNT * PARAMSCAN_COUNT * variableSpecs.getVariableNames().length * (geometrySpecs.getCurves().length + (geometrySpecs.getPointCount() > 0 ? 1 : 0));
break;
case GEOMETRY_SLICE:
TOTAL_EXPORTS_OPS = SIM_COUNT * PARAMSCAN_COUNT * variableSpecs.getVariableNames().length * TIME_COUNT;
break;
}
File hdf5TempFile = null;
if (asciiSpecs.getCSVRoiLayout() == ASCIISpecs.csvRoiLayout.time_sim_var) {
exportOutputV.add(new ExportOutput[] { sofyaFormat(outputContext, jobID, user, dataServerImpl, orig_vcdID, variableSpecs, timeSpecs, geometrySpecs, asciiSpecs, contextName, fileDataContainerManager) });
} else {
try {
// Used if HDF5 format
int hdf5FileID = -1;
if (asciiSpecs.isHDF5()) {
hdf5TempFile = File.createTempFile("pde", ".hdf5");
System.out.println("======== hdf5 file location: " + hdf5TempFile.getAbsolutePath());
hdf5FileID = H5.H5Fcreate(hdf5TempFile.getAbsolutePath(), HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
// TreeMap<VCDataIdentifier,TreeMap<String,PointsCurvesSlices>> simsVarnamesDataMap = new TreeMap<VCDataIdentifier,TreeMap<String,PointsCurvesSlices>>();
PointsCurvesSlices[][] pointsCurvesSlices = new PointsCurvesSlices[SIM_COUNT][variableSpecs.getVariableNames().length];
for (int i = 0; i < pointsCurvesSlices.length; i++) {
for (int j = 0; j < pointsCurvesSlices[i].length; j++) {
pointsCurvesSlices[i][j] = new PointsCurvesSlices();
}
}
for (int v = 0; v < SIM_COUNT; v++) {
int simJobIndex = simNameSimDataIDs[v].getDefaultJobIndex();
VCDataIdentifier vcdID = simNameSimDataIDs[v].getVCDataIdentifier(simJobIndex);
// 3. simNameSimDataIDs[v].getExportParamScanInfo() != null and asciiSpecs.getExportMultipleParamScans() != null, parameter scan use simNameSimDataIDs[v].getExportParamScanInfo().getParamScanJobIndexes() loop through
for (int ps = 0; ps < PARAMSCAN_COUNT; ps++) {
if (asciiSpecs.getExportMultipleParamScans() != null) {
simJobIndex = simNameSimDataIDs[v].getExportParamScanInfo().getParamScanJobIndexes()[asciiSpecs.getExportMultipleParamScans()[ps]];
vcdID = simNameSimDataIDs[v].getVCDataIdentifier(simJobIndex);
}
// Get times for each sim{paramscan} because they may be different
final double[] allTimes = dataServerImpl.getDataSetTimes(user, vcdID);
if (allTimes.length <= beginTimeIndex || allTimes.length <= endTimeIndex) {
throw new DataAccessException("Sim '" + simNameSimDataIDs[v].getSimulationName() + "' id=" + vcdID.getID() + " simJob=" + simJobIndex + ", time array length=" + allTimes.length + " has no endTimeIndex=" + endTimeIndex);
}
String paramScanInfo = "";
if (simNameSimDataIDs[v].getExportParamScanInfo() != null) {
for (int i = 0; i < simNameSimDataIDs[v].getExportParamScanInfo().getParamScanConstantNames().length; i++) {
String psName = simNameSimDataIDs[v].getExportParamScanInfo().getParamScanConstantNames()[i];
paramScanInfo = paramScanInfo + " '" + psName + "'=" + simNameSimDataIDs[v].getExportParamScanInfo().getParamScanConstantValues()[simJobIndex][i];
}
}
// Used if HDF5 format
int hdf5GroupID = -1;
if (asciiSpecs.isHDF5()) {
hdf5GroupID = H5.H5Gcreate(hdf5FileID, vcdID.toString(), HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
String simID = vcdID.getID();
String dataType = ".csv";
FileDataContainerID fileDataContainerID_header = fileDataContainerManager.getNewFileDataContainerID();
SimulationDescription simulationDescription = new SimulationDescription(outputContext, user, dataServerImpl, vcdID, false, null);
fileDataContainerManager.append(fileDataContainerID_header, "\"" + "Model: '" + contextName + "'\"\n\"Simulation: '" + simNameSimDataIDs[v].getSimulationName() + "' (" + paramScanInfo + ")\"\n" + simulationDescription.getHeader(dataType));
CartesianMesh mesh = dataServerImpl.getMesh(user, vcdID);
if (hdf5GroupID != -1) {
double[] subTimes = new double[endTimeIndex - beginTimeIndex + 1];
for (int st = beginTimeIndex; st <= endTimeIndex; st++) {
subTimes[st - beginTimeIndex] = allTimes[st];
}
// Hdf5Utils.writeHDF5Dataset(hdf5GroupID, PCS.TIMES.name(), new long[] {subTimes.length}, subTimes,false);
Hdf5Utils.insertDoubles(hdf5GroupID, PCS.TIMES.name(), new long[] { subTimes.length }, subTimes);
// Hdf5Utils.writeHDF5Dataset(hdf5GroupID, PCS.TIMEBOUNDS.name(), new long[] {2}, new int[] {beginTimeIndex,endTimeIndex},false);
Hdf5Utils.insertInts(hdf5GroupID, PCS.TIMEBOUNDS.name(), new long[] { 2 }, new int[] { beginTimeIndex, endTimeIndex });
}
switch(geometrySpecs.getModeID()) {
case GEOMETRY_SELECTIONS:
{
// Set mesh on SpatialSelection because mesh is transient field because it's too big for messaging
SpatialSelection[] spatialSelections = geometrySpecs.getSelections();
for (int i = 0; i < spatialSelections.length; i++) {
if (spatialSelections[i].getMesh() == null) {
spatialSelections[i].setMesh(mesh);
} else if (!spatialSelections[i].getMesh().getISize().compareEqual(mesh.getISize()) || spatialSelections[i].getMesh().getNumMembraneElements() != mesh.getNumMembraneElements()) {
// check just sizes not areas,normals,etc...
// This will throw fail message
spatialSelections[i].setMesh(mesh);
}
// int hdf5DatasetID = -1;
// int hdf5DataspaceID = -1;
// if(hdf5GroupID != -1) {
// long[] dims = new long[spatialSelections[i].getMesh().getGeometryDimension()];
// String s = "";
// for(int j=0; j<dims.length;j++) {
// if(j!=0) {
// s+="x";
// }
// dims[j] = (j==0?spatialSelections[j].getMesh().getISize().getX():(j==1?spatialSelections[j].getMesh().getISize().getY():spatialSelections[j].getMesh().getISize().getZ()));
// s+=dims[j];
// }
// hdf5DataspaceID = H5.H5Screate_simple(dims.length, dims, null);
// hdf5DataspaceIDs.add(H5.H5Dcreate(hdf5GroupID, dims.length+"D java double "+s,HDF5Constants.H5T_NATIVE_DOUBLE, hdf5DataspaceID,HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT));
// }
}
Vector<ExportOutput> outputV = new Vector<ExportOutput>();
if (geometrySpecs.getPointCount() > 0) {
// assemble single point data together (uses more compact formatting)
String dataID = "_Points_vars(" + geometrySpecs.getPointCount() + ")_times(" + (endTimeIndex - beginTimeIndex + 1) + ")";
// StringBuilder data1 = new StringBuilder(data.toString());
ExportOutput exportOutput1 = new ExportOutput(true, dataType, simID, dataID, /* + variableSpecs.getVariableNames()[i]*/
fileDataContainerManager);
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), fileDataContainerID_header);
// Used if HDF5 format
int hdf5GroupPointID = -1;
if (asciiSpecs.isHDF5()) {
hdf5GroupPointID = H5.H5Gcreate(hdf5GroupID, "Points", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
for (int varNameIndx = 0; varNameIndx < variableSpecs.getVariableNames().length; varNameIndx++) {
// Used if HDF5 format
int hdf5GroupVarID = -1;
if (asciiSpecs.isHDF5()) {
hdf5GroupVarID = H5.H5Gcreate(hdf5GroupPointID, variableSpecs.getVariableNames()[varNameIndx], HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), getPointsTimeSeries(pointsCurvesSlices[v][varNameIndx], hdf5GroupVarID, outputContext, user, dataServerImpl, vcdID, variableSpecs.getVariableNames()[varNameIndx], geometrySpecs, allTimes, beginTimeIndex, endTimeIndex, asciiSpecs.getSwitchRowsColumns(), fileDataContainerManager));
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
progressCounter++;
exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "CSV", progressCounter / TOTAL_EXPORTS_OPS);
if (hdf5GroupVarID != -1) {
H5.H5Gclose(hdf5GroupVarID);
}
}
outputV.add(exportOutput1);
if (hdf5GroupPointID != -1) {
H5.H5Gclose(hdf5GroupPointID);
}
}
if (geometrySpecs.getCurves().length != 0) {
// assemble curve (non-single point) data together
String dataID = "_Curves_vars(" + (geometrySpecs.getCurves().length) + ")_times(" + (endTimeIndex - beginTimeIndex + 1) + ")";
// StringBuilder data1 = new StringBuilder(data.toString());
ExportOutput exportOutput1 = new ExportOutput(true, dataType, simID, dataID, /* + variableSpecs.getVariableNames()[i]*/
fileDataContainerManager);
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), fileDataContainerID_header);
// Used if HDF5 format
int hdf5GroupPointID = -1;
if (asciiSpecs.isHDF5()) {
hdf5GroupPointID = H5.H5Gcreate(hdf5GroupID, "Curves", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
for (int varNameIndx = 0; varNameIndx < variableSpecs.getVariableNames().length; varNameIndx++) {
// Used if HDF5 format
int hdf5GroupVarID = -1;
if (asciiSpecs.isHDF5()) {
hdf5GroupVarID = H5.H5Gcreate(hdf5GroupPointID, variableSpecs.getVariableNames()[varNameIndx], HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
pointsCurvesSlices[v][varNameIndx].data.put(PCS.CURVES, new TreeMap<String, TreeMap<PCS, Object>>());
for (int s = 0; s < geometrySpecs.getCurves().length; s++) {
if (!GeometrySpecs.isSinglePoint(geometrySpecs.getCurves()[s])) {
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), getCurveTimeSeries(hdf5GroupVarID, pointsCurvesSlices[v][varNameIndx], outputContext, user, dataServerImpl, vcdID, variableSpecs.getVariableNames()[varNameIndx], geometrySpecs.getCurves()[s], allTimes, beginTimeIndex, endTimeIndex, asciiSpecs.getSwitchRowsColumns(), fileDataContainerManager));
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
progressCounter++;
exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "CSV", progressCounter / TOTAL_EXPORTS_OPS);
}
}
if (hdf5GroupVarID != -1) {
H5.H5Gclose(hdf5GroupVarID);
}
}
outputV.add(exportOutput1);
if (hdf5GroupPointID != -1) {
H5.H5Gclose(hdf5GroupPointID);
}
}
exportOutputV.add(outputV.toArray(new ExportOutput[0]));
break;
}
case GEOMETRY_SLICE:
case GEOMETRY_FULL:
{
int sliceNumber = geometrySpecs.getSliceNumber();
if (geometrySpecs.getModeID() == GEOMETRY_FULL) {
sliceNumber = -1;
}
String dataID = "_Slice_" + Coordinate.getNormalAxisPlaneName(geometrySpecs.getAxis()) + "_" + sliceNumber + "_";
ExportOutput[] output = new ExportOutput[variableSpecs.getVariableNames().length * TIME_COUNT];
SliceHelper sliceHelper = new SliceHelper(TIME_COUNT, (hdf5GroupID != -1), Coordinate.getNormalAxisPlaneName(geometrySpecs.getAxis()), sliceNumber, asciiSpecs.getSwitchRowsColumns(), mesh);
for (int j = 0; j < variableSpecs.getVariableNames().length; j++) {
sliceHelper.setHDF5GroupVarID(hdf5GroupID, variableSpecs.getVariableNames()[j]);
for (int i = 0; i < TIME_COUNT; i++) {
StringBuilder inset = new StringBuilder(Integer.toString(i + beginTimeIndex));
inset.reverse();
inset.append("000");
inset.setLength(4);
inset.reverse();
String dataID1 = dataID + variableSpecs.getVariableNames()[j] + "_" + inset.toString();
ExportOutput exportOutput1 = new ExportOutput(true, dataType, simID, dataID1, /* + variableSpecs.getVariableNames()[i]*/
fileDataContainerManager);
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), fileDataContainerID_header);
fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), getSlice(sliceHelper, mesh, allTimes, outputContext, user, dataServerImpl, vcdID, variableSpecs.getVariableNames()[j], i + beginTimeIndex, Coordinate.getNormalAxisPlaneName(geometrySpecs.getAxis()), sliceNumber, asciiSpecs.getSwitchRowsColumns(), fileDataContainerManager));
output[j * TIME_COUNT + i] = exportOutput1;
// if(sliceHelper.hdf5GroupVarID != -1) {
// if(sliceHelper.isMembrane) {
//
// }else {
// //Select next section of destination to copy-to
// H5.H5Sselect_hyperslab(sliceHelper.hdf5DataspaceIDValues, HDF5Constants.H5S_SELECT_SET, new long[] {0,0,i}, null, new long[] {sliceHelper.sizeXYZ[sliceHelper.outerSizeIndex],sliceHelper.sizeXYZ[sliceHelper.innerSizeIndex],1},null);
// //Copy from extracted sliceData to hdf5 file dataset
// H5.H5Dwrite_double(sliceHelper.hdf5DatasetIDValues, HDF5Constants.H5T_NATIVE_DOUBLE, sliceHelper.hdf5DataspaceIDSlice, sliceHelper.hdf5DataspaceIDValues, HDF5Constants.H5P_DEFAULT, sliceHelper.sliceData);
// H5.H5Sselect_none(sliceHelper.hdf5DataspaceIDValues);
// }
// }
progressCounter++;
exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "CSV", progressCounter / TOTAL_EXPORTS_OPS);
}
sliceHelper.closeHDF5GroupAndValues();
}
if (hdf5GroupID != -1) {
H5.H5Sclose(sliceHelper.hdf5DataspaceIDSlice);
}
exportOutputV.add(output);
break;
}
default:
{
throw new DataAccessException("Unexpected geometry modeID");
}
}
if (hdf5GroupID != -1) {
H5.H5Gclose(hdf5GroupID);
}
}
}
if (hdf5FileID != -1) {
H5.H5Fclose(hdf5FileID);
}
} catch (HDF5Exception e) {
e.printStackTrace();
throw new DataAccessException("HDF5 error:" + e.getMessage(), e);
}
}
if (asciiSpecs.isHDF5()) {
VCDataIdentifier vcdID = simNameSimDataIDs[0].getVCDataIdentifier(0);
final ExportOutput exportOutput = new ExportOutput(true, ".hdf5", vcdID.getID(), "" + jobID, fileDataContainerManager);
fileDataContainerManager.append(exportOutput.getFileDataContainerID(), hdf5TempFile.getAbsolutePath());
return Arrays.asList(new ExportOutput[] { exportOutput });
}
if (exportOutputV.size() == 1) {
// geometry_slice
return Arrays.asList(exportOutputV.elementAt(0));
}
// geometry_selections (all are same length as first element)
ArrayList<ExportOutput> combinedExportOutput = new ArrayList<>();
for (int i = 0; i < exportOutputV.elementAt(0).length; i++) {
String DATATYPE = exportOutputV.elementAt(0)[i].getDataType();
String DATAID = exportOutputV.elementAt(0)[i].getDataID();
ExportOutput eo = new ExportOutput(true, DATATYPE, "MultiSimulation", DATAID, fileDataContainerManager);
// FileDataContainer container = fileDataContainerManager.getFileDataContainer(combinedExportOutput[i].getFileDataContainerID());
for (int j = 0; j < exportOutputV.size(); j++) {
fileDataContainerManager.append(eo.getFileDataContainerID(), exportOutputV.elementAt(j)[i].getFileDataContainerID());
fileDataContainerManager.append(eo.getFileDataContainerID(), "\n");
}
combinedExportOutput.add(eo);
}
return combinedExportOutput;
}
Aggregations