Search in sources :

Example 11 with HObject

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());
        }
    }
}
Also used : Attribute(ncsa.hdf.object.Attribute) ArrayList(java.util.ArrayList) List(java.util.List) HObject(ncsa.hdf.object.HObject)

Example 12 with HObject

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);
    }
}
Also used : Origin(org.vcell.util.Origin) Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) Extent(org.vcell.util.Extent) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) Dataset(ncsa.hdf.object.Dataset) ArrayList(java.util.ArrayList) H5ScalarDS(ncsa.hdf.object.h5.H5ScalarDS) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CacheException(org.vcell.util.CacheException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileNotFoundException(java.io.FileNotFoundException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) Datatype(ncsa.hdf.object.Datatype) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with HObject

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
        }
    }
}
Also used : MBSDataGroup(cbit.vcell.solvers.CartesianMeshMovingBoundary.MBSDataGroup) Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MSBDataAttribute(cbit.vcell.solvers.CartesianMeshMovingBoundary.MSBDataAttribute) Attribute(ncsa.hdf.object.Attribute) Dataset(ncsa.hdf.object.Dataset) FileFormat(ncsa.hdf.object.FileFormat) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HObject(ncsa.hdf.object.HObject) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 14 with HObject

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
            }
        }
    }
}
Also used : MBSDataGroup(cbit.vcell.solvers.CartesianMeshMovingBoundary.MBSDataGroup) Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VariableType(cbit.vcell.math.VariableType) MSBDataAttribute(cbit.vcell.solvers.CartesianMeshMovingBoundary.MSBDataAttribute) Attribute(ncsa.hdf.object.Attribute) Dataset(ncsa.hdf.object.Dataset) FileFormat(ncsa.hdf.object.FileFormat) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HObject(ncsa.hdf.object.HObject) MBSDataGroup(cbit.vcell.solvers.CartesianMeshMovingBoundary.MBSDataGroup)

Example 15 with HObject

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();
        }
    }
}
Also used : HObject(ncsa.hdf.object.HObject) Group(ncsa.hdf.object.Group) Dataset(ncsa.hdf.object.Dataset)

Aggregations

HObject (ncsa.hdf.object.HObject)18 Dataset (ncsa.hdf.object.Dataset)13 Group (ncsa.hdf.object.Group)13 FileFormat (ncsa.hdf.object.FileFormat)11 IOException (java.io.IOException)10 Attribute (ncsa.hdf.object.Attribute)10 File (java.io.File)7 FileNotFoundException (java.io.FileNotFoundException)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)5 ArrayList (java.util.ArrayList)4 H5ScalarDS (ncsa.hdf.object.h5.H5ScalarDS)4 DataAccessException (org.vcell.util.DataAccessException)4 MBSDataGroup (cbit.vcell.solvers.CartesianMeshMovingBoundary.MBSDataGroup)3 MSBDataAttribute (cbit.vcell.solvers.CartesianMeshMovingBoundary.MSBDataAttribute)3 Vector (java.util.Vector)3 H5CompoundDS (ncsa.hdf.object.h5.H5CompoundDS)3 ExpressionException (cbit.vcell.parser.ExpressionException)2 ODESimData (cbit.vcell.solver.ode.ODESimData)2 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)2