Search in sources :

Example 1 with H5CompoundDS

use of ncsa.hdf.object.h5.H5CompoundDS 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;
}
Also used : Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) Attribute(ncsa.hdf.object.Attribute) HDF5Exception(ncsa.hdf.hdf5lib.exceptions.HDF5Exception) DataFormat(ncsa.hdf.object.DataFormat) HObject(ncsa.hdf.object.HObject) H5CompoundDS(ncsa.hdf.object.h5.H5CompoundDS)

Example 2 with H5CompoundDS

use of ncsa.hdf.object.h5.H5CompoundDS in project vcell by virtualcell.

the class Hdf5Reader method getDataTable.

public static Hdf5Reader.DataColumn[] getDataTable(Group group, String name) throws Exception {
    List<HObject> memberList = group.getMemberList();
    for (HObject member : memberList) {
        if (member.getName().equals(name)) {
            if (member instanceof H5CompoundDS) {
                H5CompoundDS compoundDataSet = (H5CompoundDS) member;
                Vector columnValueArrays = (Vector) compoundDataSet.read();
                String[] columnNames = compoundDataSet.getMemberNames();
                ArrayList<Hdf5Reader.DataColumn> dataColumns = new ArrayList<Hdf5Reader.DataColumn>();
                for (int c = 0; c < columnNames.length; c++) {
                    Object column = columnValueArrays.get(c);
                    if (column instanceof int[]) {
                        dataColumns.add(new Hdf5Reader.IntColumn(columnNames[c], (int[]) columnValueArrays.get(c)));
                    } else if (column instanceof double[]) {
                        dataColumns.add(new Hdf5Reader.DoubleColumn(columnNames[c], (double[]) columnValueArrays.get(c)));
                    } else {
                        throw new RuntimeException("unexpected type '" + column.getClass().getName() + "' for group member '" + name + "'");
                    }
                }
                return dataColumns.toArray(new Hdf5Reader.DataColumn[0]);
            } else if (member instanceof H5ScalarDS) {
                H5ScalarDS compoundDataSet = (H5ScalarDS) member;
                Object column = compoundDataSet.read();
                if (column instanceof int[]) {
                    return new Hdf5Reader.DataColumn[] { new Hdf5Reader.IntColumn("col", (int[]) column) };
                } else if (column instanceof double[]) {
                    return new Hdf5Reader.DataColumn[] { new Hdf5Reader.DoubleColumn("col", (double[]) column) };
                } else if (column instanceof long[]) {
                    return new Hdf5Reader.DataColumn[] { new Hdf5Reader.LongColumn("col", (long[]) column) };
                } else {
                    throw new RuntimeException("unexpected type '" + column.getClass().getName() + "' for group member '" + name + "'");
                }
            } else {
                throw new RuntimeException("expecting type H5CompoundDS for group member '" + name + "', found type " + member.getClass().getName());
            }
        }
    }
    throw new RuntimeException("group member '" + name + "' not found");
}
Also used : HObject(ncsa.hdf.object.HObject) ArrayList(java.util.ArrayList) H5ScalarDS(ncsa.hdf.object.h5.H5ScalarDS) HObject(ncsa.hdf.object.HObject) H5CompoundDS(ncsa.hdf.object.h5.H5CompoundDS) Vector(java.util.Vector)

Example 3 with H5CompoundDS

use of ncsa.hdf.object.h5.H5CompoundDS in project vcell by virtualcell.

the class VH5Dataset method info.

public void info() {
    try {
        System.out.println(dataset.getName());
        System.out.println(dataset.getFullName());
        H5ScalarDS sds = BeanUtils.downcast(H5ScalarDS.class, dataset);
        if (sds != null) {
            info(sds);
        }
        H5CompoundDS cds = BeanUtils.downcast(H5CompoundDS.class, dataset);
        int rank = dataset.getRank();
        long[] d = dataset.getDims();
        long[] s = dataset.getSelectedDims();
        for (int i = 0; i < rank; i++) {
            s[i] = d[i];
        }
        if (cds != null) {
            info(cds);
        } else {
            Object obj = dataset.read();
            analyze(obj);
        }
        String[] names = dataset.getDimNames();
        if (names == null) {
            names = new String[rank];
        }
        long[] dims = dataset.getMaxDims();
        for (int i = 0; i < rank; i++) {
            System.out.println("n " + StringUtils.defaultString(names[i]) + " has " + dims[i]);
        }
        System.out.println("current dims " + Arrays.toString(dataset.getDims()));
        System.out.println("chunk size " + Arrays.toString(dataset.getChunkSize()));
        System.out.println("selected " + Arrays.toString(dataset.getSelectedDims()));
        System.out.println("start " + Arrays.toString(dataset.getStartDims()));
        System.out.println("stride " + Arrays.toString(dataset.getStride()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : H5ScalarDS(ncsa.hdf.object.h5.H5ScalarDS) H5CompoundDS(ncsa.hdf.object.h5.H5CompoundDS)

Example 4 with H5CompoundDS

use of ncsa.hdf.object.h5.H5CompoundDS in project vcell by virtualcell.

the class VH5Dataset method info.

public void info(H5CompoundDS ds) throws Exception {
    Datatype dt = ds.getDatatype();
    String[] mn = ds.getMemberNames();
    System.out.println(ArrayUtils.toString(mn));
    System.out.println(dt.getFullName());
    System.out.println(dt.getDatatypeDescription());
    Object obj = ds.read();
    Collection<?> coll = BeanUtils.downcast(Collection.class, obj);
    VCAssert.assertTrue(coll.size() == mn.length, "collection matches names");
    int i = 0;
    for (Object o : coll) {
        System.out.println(mn[i++] + " ");
        analyze(o);
    }
}
Also used : H5Datatype(ncsa.hdf.object.h5.H5Datatype) Datatype(ncsa.hdf.object.Datatype)

Example 5 with H5CompoundDS

use of ncsa.hdf.object.h5.H5CompoundDS 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

H5CompoundDS (ncsa.hdf.object.h5.H5CompoundDS)4 HObject (ncsa.hdf.object.HObject)3 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 Attribute (ncsa.hdf.object.Attribute)2 Group (ncsa.hdf.object.Group)2 H5ScalarDS (ncsa.hdf.object.h5.H5ScalarDS)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringTokenizer (java.util.StringTokenizer)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 HDF5Exception (ncsa.hdf.hdf5lib.exceptions.HDF5Exception)1 DataFormat (ncsa.hdf.object.DataFormat)1 Dataset (ncsa.hdf.object.Dataset)1 Datatype (ncsa.hdf.object.Datatype)1 FileFormat (ncsa.hdf.object.FileFormat)1 H5Datatype (ncsa.hdf.object.h5.H5Datatype)1 DataAccessException (org.vcell.util.DataAccessException)1