Class H5Dataset

java.lang.Object
nz.org.riskscape.hdf5.H5Object
nz.org.riskscape.hdf5.H5Dataset
All Implemented Interfaces:
AutoCloseable

public class H5Dataset extends H5Object

Supports reading a one-dimensional dataset from an h5 file. Datasets should be created via the H5File or H5Group classes.

  • Method Details

    • openCursor

      public H5DatasetCursor openCursor(int bufferSize)
      Parameters:
      bufferSize - the size of the memory buffer that elements are read into
      Returns:
      a new cursor/iterator over this data. There is as yet no support for reading from chunks stored in different data spaces
    • openCursor

      public H5DatasetCursor openCursor()
    • newDataSpace

      public H5DataSpace newDataSpace()
      Returns:
      a new dataspace that can be used to select elements from the dataset independently from the default dataspace that comes from getDataSpace(). Be aware that you'll need to close this dataspace when you're finished with it, otherwise you'll end up with resource leaks.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class H5Object
    • getElementsAsDouble

      public double[] getElementsAsDouble()
      Returns:
      the dataset elements as an array of doubles Warning: this will only work for datasets small enough to fit in an array
    • numElements

      public long numElements()
      Returns:
      the total number of elements in the dataset, as per H5DataSpace.numElements()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • readVlenElements

      public byte[][] readVlenElements(H5DataSpace memspace, H5DataSpace filespace, int numElements)

      Read n variable length (vlen) elements and return them as a 2d array of bytes, where the 1st dimension contains the bytes of each element. You can then pass each byte array to a vlen type's member type to deserialize the bytes in to the java representation of the data.

      This is done as a special case because H5 vlen types are stored "off to the side" and the data is not kept in the same contiguous block as a non vlen type. This makes reading the data in to java difficult/impossible, and in fact required patching of the h5 library's jni bindings to even make possible in this way.

      Parameters:
      memspace - a dataspace that data is being read in to. This must be big enough to hold numElements
      filespace - the dataspace that data is being read from. Its selection must yield the same number of elements as numElements, i.e. by calling H5DataSpace.selectElements(long[], long[])
      numElements - the number of elements to select. Must agree with the sizes of memspace and filespace
      Returns:
      an array of byte arrays you can read the elements from
    • getDataType

      public H5Type getDataType()
    • getDataSpace

      public H5DataSpace getDataSpace()
    • getDatasetName

      public String getDatasetName()