Search in sources :

Example 11 with FileFormat

use of ncsa.hdf.object.FileFormat 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 12 with FileFormat

use of ncsa.hdf.object.FileFormat 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 13 with FileFormat

use of ncsa.hdf.object.FileFormat in project vcell by virtualcell.

the class SimDataReader method getNextDataAtCurrentTimeChombo.

private void getNextDataAtCurrentTimeChombo(double[][] returnValues) throws Exception {
    if (zipFilenNames == null || zipFilenNames[masterTimeIndex] == null) {
        return;
    }
    if (currentZipFile == null || !currentZipFileName.equals(zipFilenNames[masterTimeIndex])) {
        close();
        currentZipFile = new ZipFile(zipFilenNames[masterTimeIndex]);
        currentZipFileName = zipFilenNames[masterTimeIndex];
    }
    File tempFile = null;
    FileFormat solFile = null;
    try {
        tempFile = DataSet.createTempHdf5File(currentZipFile, simDataFileNames[masterTimeIndex]);
        FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
        solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
        solFile.open();
        for (int k = 0; k < varNames.length; ++k) {
            try {
                boolean bExtrapolatedValue = false;
                String varName = varNames[k];
                if (varName.endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                    bExtrapolatedValue = true;
                    varName = varName.substring(0, varName.lastIndexOf(InsideVariable.INSIDE_VARIABLE_SUFFIX));
                } else if (varName.endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    bExtrapolatedValue = true;
                    varName = varName.substring(0, varName.lastIndexOf(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX));
                }
                double[] sol = null;
                if (bExtrapolatedValue) {
                    sol = DataSet.readChomboExtrapolatedValues(varName, solFile);
                } else {
                    String varPath = Hdf5Utils.getVarSolutionPath(varNames[k]);
                    HObject solObj = FileFormat.findObject(solFile, varPath);
                    if (solObj instanceof Dataset) {
                        Dataset dataset = (Dataset) solObj;
                        sol = (double[]) dataset.read();
                    }
                }
                if (sol != null) {
                    for (int l = 0; l < varIndexes[k].length; ++l) {
                        int idx = varIndexes[k][l];
                        double val = sol[idx];
                        returnValues[k][l] = val;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace(System.out);
                throw new DataAccessException(e.getMessage(), e);
            }
        }
    } finally {
        try {
            if (solFile != null) {
                solFile.close();
            }
            if (tempFile != null) {
                if (!tempFile.delete()) {
                    System.err.println("couldn't delete temp file " + tempFile.getAbsolutePath());
                }
            }
        } catch (Exception e) {
        // ignore
        }
    }
    ++masterTimeIndex;
    if (masterTimeIndex >= times.length) {
        close();
    }
}
Also used : HObject(ncsa.hdf.object.HObject) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) Dataset(ncsa.hdf.object.Dataset) FileFormat(ncsa.hdf.object.FileFormat) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DataAccessException(org.vcell.util.DataAccessException)

Example 14 with FileFormat

use of ncsa.hdf.object.FileFormat in project vcell by virtualcell.

the class SimulationDataSpatialHdf5 method retrieveSimDataSet.

public SimDataSet retrieveSimDataSet(double time, String varName) throws Exception {
    File tempFile = getTempSimHdf5File(time);
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    FileFormat solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
    solFile.open();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
    Group rootGroup = (Group) rootNode.getUserObject();
    Group solGroup = (Group) rootGroup.getMemberList().get(0);
    SimDataSet simDataSet = new SimDataSet();
    List<HObject> memberList = solGroup.getMemberList();
    for (HObject member : memberList) {
        if (!(member instanceof Dataset)) {
            continue;
        }
        Dataset dataset = (Dataset) member;
        String dsname = dataset.getName();
        if (!dsname.equals(varName)) {
            continue;
        }
        simDataSet.solValues = (double[]) dataset.read();
        List<Attribute> attrList = dataset.getMetadata();
        for (Attribute attr : attrList) {
            String attrName = attr.getName();
            Object val = attr.getValue();
            double dval = 0;
            if (val instanceof double[]) {
                dval = ((double[]) val)[0];
            }
            if (attrName.equals(SOLUTION_DATASET_ATTR_MAX_ERROR)) {
                simDataSet.maxError = dval;
            } else if (attrName.equals(SOLUTION_DATASET_ATTR_MEAN)) {
                simDataSet.mean = dval;
            } else if (attrName.equals(SOLUTION_DATASET_ATTR_RELATIVE_L2ERROR)) {
                simDataSet.l2Error = dval;
            } else if (attrName.equals(SOLUTION_DATASET_ATTR_SUM_VOLFRAC)) {
                simDataSet.sumVolFrac = dval;
            }
        }
        break;
    }
    return simDataSet;
}
Also used : Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Attribute(ncsa.hdf.object.Attribute) Dataset(ncsa.hdf.object.Dataset) FileFormat(ncsa.hdf.object.FileFormat) HObject(ncsa.hdf.object.HObject) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 15 with FileFormat

use of ncsa.hdf.object.FileFormat in project vcell by virtualcell.

the class SimulationDataSpatialHdf5 method readMeshFile.

public static ChomboMesh readMeshFile(File chomboMeshFile) throws Exception {
    // if (chomboMesh != null)
    // {
    // return;
    // }
    ChomboMesh chomboMesh = new ChomboMesh();
    // File mfile = new File(userDirectory, getMeshFileName());
    if (H5.H5open() < 0) {
        throw new Exception("H5.H5open() failed");
    }
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    if (fileFormat == null) {
        throw new Exception("FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5) failed, returned null.");
    }
    FileFormat meshFile = fileFormat.createInstance(chomboMeshFile.getAbsolutePath(), FileFormat.READ);
    meshFile.open();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
    Group rootGroup = (Group) rootNode.getUserObject();
    Group meshGroup = (Group) rootGroup.getMemberList().get(0);
    List<Attribute> meshAttrList = meshGroup.getMetadata();
    for (Attribute attr : meshAttrList) {
        String attrName = attr.getName();
        Object value = attr.getValue();
        if (attrName.equals(MESH_ATTR_DIMENSION)) {
            chomboMesh.dimension = ((int[]) value)[0];
        } else {
            String[] valueStrArray = (String[]) value;
            String value0 = valueStrArray[0];
            StringTokenizer st = new StringTokenizer(value0, "{,} ");
            List<Double> valueList = new ArrayList<Double>();
            while (st.hasMoreTokens()) {
                String token = st.nextToken();
                valueList.add(Double.parseDouble(token));
            }
            if (attrName.equals(MESH_ATTR_DX)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.dx[i] = valueList.get(i);
                }
            } else if (attrName.equals(MESH_ATTR_EXTENT)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.extent[i] = valueList.get(i);
                }
            } else if (attrName.equals(MESH_ATTR_NX)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.nx[i] = valueList.get(i).intValue();
                }
            } else if (attrName.equals(MESH_ATTR_ORIGIN)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.origin[i] = valueList.get(i);
                }
            }
        }
    }
    List<HObject> memberList = meshGroup.getMemberList();
    for (HObject member : memberList) {
        if (member instanceof Dataset) {
            Dataset dataset = (Dataset) member;
            Vector vectValues = (Vector) dataset.read();
            String name = dataset.getName();
            if (name.equals(BOXES_DATASET)) {
            // not needed right now
            } else if (name.equals(METRICS_DATASET)) {
                H5CompoundDS compoundDataSet = (H5CompoundDS) dataset;
                chomboMesh.metricsColumnNames = compoundDataSet.getMemberNames();
                int c = -1;
                int[] index = (int[]) vectValues.get(++c);
                int[] i = (int[]) vectValues.get(++c);
                int[] j = (int[]) vectValues.get(++c);
                int[] k = null;
                if (chomboMesh.dimension == 3) {
                    k = (int[]) vectValues.get(++c);
                }
                double[] x = (double[]) vectValues.get(++c);
                double[] y = (double[]) vectValues.get(++c);
                double[] z = null;
                if (chomboMesh.dimension == 3) {
                    z = (double[]) vectValues.get(++c);
                }
                double[] normalx = (double[]) vectValues.get(++c);
                double[] normaly = (double[]) vectValues.get(++c);
                double[] normalz = null;
                if (chomboMesh.dimension == 3) {
                    normalz = (double[]) vectValues.get(++c);
                }
                double[] volFrac = (double[]) vectValues.get(++c);
                double[] areaFrac = (double[]) vectValues.get(++c);
                for (int n = 0; n < index.length; ++n) {
                    ChomboMeshMetricsEntry entry = new ChomboMeshMetricsEntry(index[n], i[n], j[n], k == null ? 0 : k[n], x[n], y[n], z == null ? 0 : z[n], normalx[n], normaly[n], normalz == null ? 0 : normalz[n], volFrac[n], areaFrac[n]);
                    chomboMesh.metrics.add(entry);
                }
            } else if (name.equals(SURFACE_DATASET)) {
            // not needed right now
            } else if (name.equals(SLICE_VIEW_DATASET)) {
            // not needed right now
            }
        }
    }
    return chomboMesh;
}
Also used : Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Attribute(ncsa.hdf.object.Attribute) Dataset(ncsa.hdf.object.Dataset) ArrayList(java.util.ArrayList) FileFormat(ncsa.hdf.object.FileFormat) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) StringTokenizer(java.util.StringTokenizer) HObject(ncsa.hdf.object.HObject) H5CompoundDS(ncsa.hdf.object.h5.H5CompoundDS) Vector(java.util.Vector)

Aggregations

FileFormat (ncsa.hdf.object.FileFormat)18 Group (ncsa.hdf.object.Group)13 IOException (java.io.IOException)11 Dataset (ncsa.hdf.object.Dataset)11 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)10 HObject (ncsa.hdf.object.HObject)10 File (java.io.File)8 FileNotFoundException (java.io.FileNotFoundException)8 Attribute (ncsa.hdf.object.Attribute)8 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)7 MBSDataGroup (cbit.vcell.solvers.CartesianMeshMovingBoundary.MBSDataGroup)3 MSBDataAttribute (cbit.vcell.solvers.CartesianMeshMovingBoundary.MSBDataAttribute)3 DataAccessException (org.vcell.util.DataAccessException)3 VariableType (cbit.vcell.math.VariableType)2 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2 Vector (java.util.Vector)2 Extent (org.vcell.util.Extent)2 ISize (org.vcell.util.ISize)2 Origin (org.vcell.util.Origin)2