use of ncsa.hdf.object.HObject in project vcell by virtualcell.
the class DataSetControllerImpl method printInfo.
private static void printInfo(HObject hObject, String indent) throws Exception {
if (true) {
return;
}
System.out.println(indent + hObject.getName() + ":" + hObject.getClass().getName());
List metaDatas = hObject.getMetadata();
for (Object metaData : metaDatas) {
if (metaData instanceof Attribute) {
Attribute attribute = (Attribute) metaData;
System.out.println(indent + "metadata=" + attribute.getName() + " " + attribute.getType().getDatatypeDescription());
} else {
System.out.println(indent + "metadata=" + metaData.getClass().getName());
}
}
}
use of ncsa.hdf.object.HObject 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);
}
}
use of ncsa.hdf.object.HObject in project vcell by virtualcell.
the class DataSet method readHdf5SolutionMetaData.
private void readHdf5SolutionMetaData(InputStream is) throws Exception {
File tempFile = null;
FileFormat solFile = null;
try {
tempFile = createTempHdf5File(is);
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
solFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
List<HObject> solGroups = rootGroup.getMemberList();
for (HObject memberGroup : solGroups) {
if (memberGroup instanceof Group && memberGroup.getName().equals("solution")) {
Group solGroup = (Group) memberGroup;
List<HObject> memberList = solGroup.getMemberList();
for (HObject member : memberList) {
if (!(member instanceof Dataset)) {
continue;
}
Dataset dataset = (Dataset) member;
String dsname = dataset.getName();
int vt = -1;
String domain = null;
List<Attribute> solAttrList = dataset.getMetadata();
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
if (attrName.equals("variable type")) {
Object obj = attr.getValue();
vt = ((int[]) obj)[0];
} else if (attrName.equals("domain")) {
Object obj = attr.getValue();
domain = ((String[]) obj)[0];
}
}
long[] dims = dataset.getDims();
String varName = domain == null ? dsname : domain + Variable.COMBINED_IDENTIFIER_SEPARATOR + dsname;
dataBlockList.addElement(DataBlock.createDataBlock(varName, vt, (int) dims[0], 0));
}
break;
}
}
} finally {
try {
if (solFile != null) {
solFile.close();
}
if (tempFile != null) {
if (!tempFile.delete()) {
System.err.println("couldn't delete temp file " + tempFile);
}
}
} catch (Exception e) {
// ignore
}
}
}
use of ncsa.hdf.object.HObject in project vcell by virtualcell.
the class DataSet method readMBSDataMetadata.
private void readMBSDataMetadata() throws Exception {
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
FileFormat solFile = null;
try {
solFile = fileFormat.createInstance(fileName, FileFormat.READ);
solFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group solutionGroup = null;
for (Object member : rootGroup.getMemberList()) {
String memberName = ((HObject) member).getName();
if (member instanceof Group) {
MBSDataGroup group = MBSDataGroup.valueOf(memberName);
if (group == MBSDataGroup.Solution) {
solutionGroup = (Group) member;
break;
}
}
}
if (solutionGroup == null) {
throw new Exception("Group " + MBSDataGroup.Solution + " not found");
}
// find any timeGroup
Group timeGroup = null;
for (Object member : solutionGroup.getMemberList()) {
String memberName = ((HObject) member).getName();
if (member instanceof Group && memberName.startsWith("time")) {
timeGroup = (Group) member;
break;
}
}
if (timeGroup == null) {
throw new Exception("No time group found");
}
// find all the datasets in that time group
for (Object member : timeGroup.getMemberList()) {
if (member instanceof Dataset) {
List<Attribute> solAttrList = ((Dataset) member).getMetadata();
int size = 0;
String varName = null;
VariableType varType = null;
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
Object attrValue = attr.getValue();
if (attrName.equals(MSBDataAttribute.name.name())) {
varName = ((String[]) attrValue)[0];
} else if (attrName.equals(MSBDataAttribute.size.name())) {
size = ((int[]) attrValue)[0];
} else if (attrName.equals(MSBDataAttribute.type.name())) {
String vt = ((String[]) attrValue)[0];
if (vt.equals(MSBDataAttributeValue.Point.name())) {
varType = VariableType.POINT_VARIABLE;
} else if (vt.equals(MSBDataAttributeValue.Volume.name())) {
varType = VariableType.VOLUME;
} else if (vt.equals(MSBDataAttributeValue.PointSubDomain.name())) {
// Position for PointSubdomain
}
}
}
if (varType == VariableType.VOLUME) {
// only display volume
dataBlockList.addElement(DataBlock.createDataBlock(varName, varType.getType(), size, 0));
}
if (varType == VariableType.POINT_VARIABLE) {
// only display volume
dataBlockList.addElement(DataBlock.createDataBlock(varName, varType.getType(), size, 0));
}
}
}
} finally {
if (solFile != null) {
try {
solFile.close();
} catch (Exception e) {
// ignore
}
}
}
}
use of ncsa.hdf.object.HObject in project vcell by virtualcell.
the class H5FileStructure method printGroup.
/**
* Recursively print a group and its members.
*
* @throws Exception
*/
private static void printGroup(Group g, String indent) throws Exception {
if (g == null)
return;
java.util.List members = g.getMemberList();
int n = members.size();
indent += " ";
HObject obj = null;
for (int i = 0; i < n; i++) {
obj = (HObject) members.get(i);
System.out.println(indent + obj);
if (obj instanceof Group) {
printGroup((Group) obj, indent);
}
Dataset ds = BeanUtils.downcast(Dataset.class, obj);
if (ds != null && ds.getName().equals("elements")) {
// if (ds != null && ds.getName().equals("boundaries")) {
VH5Dataset vds = new VH5Dataset(ds);
vds.info();
vds.meta();
}
}
}
Aggregations