use of ncsa.hdf.object.h5.H5ScalarDS in project vcell by virtualcell.
the class DataSetControllerImpl method iterateHDF5.
private static void iterateHDF5(HObject hObject, String indent, DataProcessingHelper dataProcessingHelper) throws Exception {
if (hObject instanceof Group) {
Group group = ((Group) hObject);
printInfo(group, indent);
if (group.getName().equals("/") || group.getName().equals(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_POSTPROCESSING)) {
List<HObject> postProcessMembers = ((Group) hObject).getMemberList();
for (HObject nextHObject : postProcessMembers) {
iterateHDF5(nextHObject, indent + " ", dataProcessingHelper);
}
} else if (group.getName().equals(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_VARIABLESTATISTICS) && dataProcessingHelper.isInfoOnly()) {
populateStatNamesAndUnits(hObject, dataProcessingHelper);
List<HObject> statDataAtEachTime = group.getMemberList();
dataProcessingHelper.statValues = new double[dataProcessingHelper.statVarNames.length][statDataAtEachTime.size()];
for (HObject nextStatData : statDataAtEachTime) {
printInfo(nextStatData, indent + " ");
// always get stats data when ask for info
processDims(nextStatData, dataProcessingHelper, false);
double[] stats = (double[]) dataProcessingHelper.tempData;
int timeIndex = Integer.parseInt(nextStatData.getName().substring("time".length()));
for (int j = 0; j < stats.length; j++) {
dataProcessingHelper.statValues[j][timeIndex] = stats[j];
}
}
} else {
// must be image data
if (dataProcessingHelper.isInfoOnly()) {
dataProcessingHelper.imageNames = new ArrayList<String>();
dataProcessingHelper.imageISize = new ArrayList<ISize>();
dataProcessingHelper.imageOrigin = new ArrayList<Origin>();
dataProcessingHelper.imageExtent = new ArrayList<Extent>();
Origin imgDataOrigin;
Extent imgDataExtent;
HashMap<String, String> attrHashMap = getHDF5Attributes(group);
if (attrHashMap.size() == 2) {
imgDataOrigin = new Origin(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINX)), 0, 0);
// this is 1D, however the extentY, Z cannot take 0
imgDataExtent = new Extent(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTX)), 1, 1);
} else if (attrHashMap.size() == 4) {
imgDataOrigin = new Origin(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINY)), 0);
// this is 2D, however the extentZ cannot take 0
imgDataExtent = new Extent(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTY)), 1);
} else if (attrHashMap.size() == 6) {
imgDataOrigin = new Origin(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINY)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINZ)));
imgDataExtent = new Extent(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTY)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTZ)));
} else {
throw new Exception("Unexpected number of origin/extent values");
}
dataProcessingHelper.imageNames.add(hObject.getName());
dataProcessingHelper.imageOrigin.add(imgDataOrigin);
dataProcessingHelper.imageExtent.add(imgDataExtent);
// get ISize
processDims((H5ScalarDS) (((Group) hObject).getMemberList()).get(0), dataProcessingHelper, true);
long[] dims = dataProcessingHelper.tempDims;
ISize isize = new ISize((int) dims[0], (int) (dims.length > 1 ? dims[1] : 1), (int) (dims.length > 2 ? dims[2] : 1));
dataProcessingHelper.imageISize.add(isize);
} else {
int currentVarNameIndex = -1;
for (int i = 0; i < dataProcessingHelper.specificVarNames.length; i++) {
if (group.getName().equals(dataProcessingHelper.specificVarNames[i])) {
currentVarNameIndex = i;
break;
}
}
if (currentVarNameIndex == -1) {
// skip this group
return;
}
dataProcessingHelper.specificDataValues[currentVarNameIndex] = new double[(dataProcessingHelper.specificTimePointHelper.isAllTimePoints() ? dataProcessingHelper.times.length : dataProcessingHelper.specificTimePointHelper.getTimePoints().length)][];
List<HObject> imageDataAtEachTime = ((Group) hObject).getMemberList();
int foundTimePointIndex = 0;
for (HObject nextImageData : imageDataAtEachTime) {
// if(dataProcessingHelper.isInfoOnly()){
// printInfo(nextImageData,indent+" ");
// processDims(nextImageData, dataProcessingHelper,true);
// long[] dims = dataProcessingHelper.tempDims;
// ISize isize = new ISize((int)dims[0], (int)(dims.length>1?dims[1]:1), (int)(dims.length>2?dims[2]:1));
// dataProcessingHelper.imageISize.add(isize);
// break;//only need 1st one for info
// }else{
int hdf5GroupTimeIndex = Integer.parseInt(nextImageData.getName().substring(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_TIMEPREFIX.length()));
if (dataProcessingHelper.specificTimePointHelper.isAllTimePoints() || dataProcessingHelper.specificTimePointHelper.getTimePoints()[foundTimePointIndex] == dataProcessingHelper.times[hdf5GroupTimeIndex]) {
int timeIndex = (dataProcessingHelper.specificTimePointHelper.isAllTimePoints() ? hdf5GroupTimeIndex : foundTimePointIndex);
processDims(nextImageData, dataProcessingHelper, false);
long[] dims = dataProcessingHelper.tempDims;
ISize isize = new ISize((int) dims[0], (int) (dims.length > 1 ? dims[1] : 1), (int) (dims.length > 2 ? dims[2] : 1));
if (dataProcessingHelper.specificDataIndexHelper.isAllDataIndexes()) {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex] = (double[]) dataProcessingHelper.tempData;
} else if (dataProcessingHelper.specificDataIndexHelper.isSingleSlice()) {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex] = new double[isize.getX() * isize.getY()];
System.arraycopy((double[]) dataProcessingHelper.tempData, dataProcessingHelper.specificDataIndexHelper.getSliceIndex() * (isize.getX() * isize.getY()), dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex], 0, isize.getX() * isize.getY());
} else {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex] = new double[dataProcessingHelper.specificDataIndexHelper.getDataIndexes().length];
for (int i = 0; i < dataProcessingHelper.specificDataIndexHelper.getDataIndexes().length; i++) {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex][i] = ((double[]) dataProcessingHelper.tempData)[dataProcessingHelper.specificDataIndexHelper.getDataIndexes()[i]];
}
}
foundTimePointIndex++;
if (!dataProcessingHelper.specificTimePointHelper.isAllTimePoints() && foundTimePointIndex == dataProcessingHelper.specificTimePointHelper.getTimePoints().length) {
// break out after we get our data
break;
}
}
// }
}
}
}
} else if (hObject instanceof Dataset) {
Dataset dataset = (Dataset) hObject;
printInfo(dataset, indent);
if (dataset.getName().equals(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_TIMES)) {
processDims(hObject, dataProcessingHelper, false);
dataProcessingHelper.times = (double[]) dataProcessingHelper.tempData;
}
} else if (hObject instanceof Datatype) {
printInfo(hObject, indent);
} else {
printInfo(hObject, indent);
}
}
Aggregations