public class H4Vdata extends CompoundDS
A vdata is like a table that consists of a collection of records whose values are stored in fixed-length fields. All records have the same structure and all values in each field have the same data type. Vdatas are uniquely identified by a name, a class, and a series of individual field names.
How to Select a Subset
Dataset defines APIs for reading, writing and subsetting a dataset. No function is defined to select a subset of a data array. The selection is done in an implicit way. Function calls to dimension information such as getSelectedDims() return an array of dimension values, which is a reference to the array in the dataset object. Changes of the array outside the dataset object directly change the values of the array in the dataset object. It is like pointers in C.
The following is an example of how to make a subset. In the example, the dataset
is a 4-dimension with size of [200][100][50][10], i.e.
dims[0]=200; dims[1]=100; dims[2]=50; dims[3]=10;
We want to select every other data point in dims[1] and dims[2]
int rank = dataset.getRank(); // number of dimensions of the dataset long[] dims = dataset.getDims(); // the dimension sizes of the dataset long[] selected = dataset.getSelectedDims(); // the selected size of the dataet long[] start = dataset.getStartDims(); // the offset of the selection long[] stride = dataset.getStride(); // the stride of the dataset int[] selectedIndex = dataset.getSelectedIndex(); // the selected dimensions for display // select dim1 and dim2 as 2D data for display, and slice through dim0 selectedIndex[0] = 1; selectedIndex[1] = 2; selectedIndex[1] = 0; // reset the selection arrays for (int i=0; i<rank; i++) { start[i] = 0; selected[i] = 1; stride[i] = 1; } // set stride to 2 on dim1 and dim2 so that every other data point is selected. stride[1] = 2; stride[2] = 2; // set the selection size of dim1 and dim2 selected[1] = dims[1]/stride[1]; selected[2] = dims[1]/stride[2]; // when dataset.read() is called, the selection above will be used since // the dimension arrays is passed by reference. Changes of these arrays // outside the dataset object directly change the values of these array // in the dataset object.
isMemberSelected, memberDims, memberNames, memberOrders, memberTypes, numberOfMembers, separator
chunkSize, compression, compression_gzip_txt, convertByteToString, convertedBuf, data, datatype, dimNames, dims, enumConverted, filters, isDataLoaded, maxDims, nPoints, originalBuf, rank, selectedDims, selectedIndex, selectedStride, startDims, storage, storage_layout
fileFormat, linkTargetObjName, oid
Constructor and Description |
---|
H4Vdata(FileFormat theFile,
String name,
String path) |
H4Vdata(FileFormat theFile,
String name,
String path,
long[] oid)
Creates an H4Vdata object with specific name and path.
|
Modifier and Type | Method and Description |
---|---|
void |
close(int vsid)
Closes access to the object.
|
Dataset |
copy(Group pgroup,
String name,
long[] dims,
Object data)
Creates a new dataset and writes the data buffer to the new dataset.
|
Datatype |
getDatatype()
Returns the datatype object of the dataset.
|
int |
getFieldCount()
Returns the number of fields.
|
int[] |
getFieldOrders()
Returns the orders of fields
|
List |
getMetadata()
Retrieves the metadata such as attributes from file.
|
List |
getMetadata(int... attrPropList) |
int |
getRecordCount()
Returns the number of records.
|
boolean |
hasAttribute()
Check if the object has any attributes attached.
|
void |
init()
Initializes the H4Vdata such as dimension sizes of this dataset.
|
int |
open()
Opens an existing object such as a dataset or group for access.
|
Object |
read()
Reads the data from file.
|
byte[] |
readBytes()
Reads the raw data of the dataset from file to a byte array.
|
void |
removeMetadata(Object info)
Deletes an existing metadata from this data object.
|
void |
updateMetadata(Object info)
Updates an existing metadata from this data object.
|
void |
write(Object buf)
Writes a memory buffer to the dataset in file.
|
void |
writeMetadata(Object info)
Writes a specific metadata (such as attribute) into file.
|
getMemberCount, getMemberDims, getMemberNames, getMemberOrders, getMemberTypes, getSelectedMemberCount, getSelectedMemberOrders, getSelectedMemberTypes, isMemberSelected, selectMember, setMemberSelection
byteToString, clear, clearData, convertFromUnsignedC, convertFromUnsignedC, convertToUnsignedC, convertToUnsignedC, getChunkSize, getCompression, getConvertByteToString, getData, getDimNames, getDims, getFilters, getHeight, getMaxDims, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getSize, getStartDims, getStorage, getStorageLayout, getStride, getWidth, isEnumConverted, isString, setConvertByteToString, setData, setEnumConverted, stringToByte, write
debug, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, setLinkTargetObjName, setName, setPath, toString
public H4Vdata(FileFormat theFile, String name, String path)
public H4Vdata(FileFormat theFile, String name, String path, long[] oid)
theFile
- the HDF file.name
- the name of this H4Vdata.path
- the full path of this H4Vdata.oid
- the unique identifier of this data object.public boolean hasAttribute()
DataFormat
public Datatype getDatatype()
Dataset
getDatatype
in class Dataset
public byte[] readBytes() throws hdf.hdflib.HDFException
Dataset
readBytes() reads raw data to an array of bytes instead of array of its datatype. For example, for a one-dimension 32-bit integer dataset of size 5, readBytes() returns a byte array of size 20 instead of an int array of 5.
readBytes() can be used to copy data from one dataset to another efficiently because the raw data is not converted to its native type, it saves memory space and CPU time.
public Object read() throws hdf.hdflib.HDFException
Dataset
read() reads the data from file to a memory buffer and returns the memory buffer. The dataset object does not hold the memory buffer. To store the memory buffer in the dataset object, one must call getData().
By default, the whole dataset is read into memory. Users can also select a subset to read. Subsetting is done in an implicit way.
How to Select a Subset
A selection is specified by three arrays: start, stride and count.
The following example shows how to make a subset. In the example, the
dataset is a 4-dimensional array of [200][100][50][10], i.e. dims[0]=200;
dims[1]=100; dims[2]=50; dims[3]=10;
We want to select every other data point in dims[1] and dims[2]
int rank = dataset.getRank(); // number of dimensions of the dataset long[] dims = dataset.getDims(); // the dimension sizes of the dataset long[] selected = dataset.getSelectedDims(); // the selected size of the dataset long[] start = dataset.getStartDims(); // the offset of the selection long[] stride = dataset.getStride(); // the stride of the dataset int[] selectedIndex = dataset.getSelectedIndex(); // the selected dimensions for display // select dim1 and dim2 as 2D data for display, and slice through dim0 selectedIndex[0] = 1; selectedIndex[1] = 2; selectedIndex[1] = 0; // reset the selection arrays for (int i = 0; i < rank; i++) { start[i] = 0; selected[i] = 1; stride[i] = 1; } // set stride to 2 on dim1 and dim2 so that every other data point is // selected. stride[1] = 2; stride[2] = 2; // set the selection size of dim1 and dim2 selected[1] = dims[1] / stride[1]; selected[2] = dims[1] / stride[2]; // when dataset.getData() is called, the selection above will be used since // the dimension arrays are passed by reference. Changes of these arrays // outside the dataset object directly change the values of these array // in the dataset object.
For ScalarDS, the memory data buffer is a one-dimensional array of byte, short, int, float, double or String type based on the datatype of the dataset.
For CompoundDS, the memory data object is an java.util.List object. Each element of the list is a data array that corresponds to a compound field.
For example, if compound dataset "comp" has the following nested structure, and member datatypes
comp --> m01 (int) comp --> m02 (float) comp --> nest1 --> m11 (char) comp --> nest1 --> m12 (String) comp --> nest1 --> nest2 --> m21 (long) comp --> nest1 --> nest2 --> m22 (double)getData() returns a list of six arrays: {int[], float[], char[], String[], long[] and double[]}.
read
in class Dataset
hdf.hdflib.HDFException
Dataset.getData()
public void write(Object buf) throws hdf.hdflib.HDFException
Dataset
public List getMetadata() throws hdf.hdflib.HDFException
DataFormat
Metadata such as attributes are stored in a List.
hdf.hdflib.HDFException
public void writeMetadata(Object info) throws Exception
DataFormat
info
- the metadata to write.Exception
- if the metadata can not be writtenpublic void removeMetadata(Object info) throws hdf.hdflib.HDFException
DataFormat
info
- the metadata to delete.hdf.hdflib.HDFException
public void updateMetadata(Object info) throws Exception
DataFormat
info
- the metadata to update.Exception
- if the metadata can not be updatedpublic int open()
HObject
open
in class HObject
HObject.close(int)
public void close(int vsid)
HObject
Sub-classes must implement this interface because different data objects have their own ways of how the data resources are closed.
For example, H5Group.close() calls the hdf.hdf5lib.H5.H5Gclose() method and closes the group resource specified by the group id.
public void init()
public int getRecordCount()
public int getFieldCount()
public int[] getFieldOrders()
public List getMetadata(int... attrPropList) throws Exception
Exception
public Dataset copy(Group pgroup, String name, long[] dims, Object data) throws Exception
Dataset
This function allows applications to create a new dataset for a given data buffer. For example, users can select a specific interesting part from a large image and create a new image with the selection.
The new dataset retains the datatype and dataset creation properties of this dataset.
copy
in class CompoundDS
pgroup
- the group which the dataset is copied to.name
- the name of the new dataset.dims
- the dimension sizes of the the new dataset.data
- the data values of the subset to be copied.Exception
- if dataset can not be copiedCopyright © 2017. All Rights Reserved.