use of ncsa.hdf.object.Datatype in project vcell by virtualcell.
the class VH5Dataset method info.
public static void info(H5ScalarDS ds) throws Exception {
Datatype dt = ds.getDatatype();
System.out.println(dt.getFullName());
System.out.println(dt.getDatatypeDescription());
int n = dt.toNative();
Datatype nt = new H5Datatype(n);
// dt = dt.getBasetype();
System.out.println(nt.getFullName());
System.out.println(nt.getDatatypeDescription());
System.out.println(H5Client.parseMeta(dt));
// ds.init();
// int did = ds.open();
// ds.read();
//
// int cdt = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND,128);
// int vtype = H5.H5Tvlen_create(cdt);
// int ndims = ds.getRank();
// long dims[] = new long[ndims];
// long maxdims[] = new long[ndims];
// int space = H5.H5Dget_space(did);
// H5.H5Sget_simple_extent_dims(space, dims,maxdims);
// System.out.println(StringUtils.join(dims));
// long bsize = H5.H5Dvlen_get_buf_size_long(did,vtype,space);
//
// double bdata[][] = new double[2][(int)dims[0]];
// int status = H5.H5Dread(did,vtype,HDF5Constants.H5S_ALL,HDF5Constants.H5S_ALL,HDF5Constants.H5P_DEFAULT,bdata);
// System.out.println(status);
}
use of ncsa.hdf.object.Datatype in project vcell by virtualcell.
the class H5FileStructure method createFile.
/**
* create the file and add groups and dataset into the file, which is the
* same as javaExample.H5DatasetCreate
*
* @see javaExample.HDF5DatasetCreate
* @throws Exception
*/
private static void createFile() throws Exception {
// retrieve an instance of H5File
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
if (fileFormat == null) {
System.err.println("Cannot find HDF5 FileFormat.");
return;
}
// create a new file with a given file name.
H5File testFile = (H5File) fileFormat.createFile(fname, FileFormat.FILE_CREATE_DELETE);
if (testFile == null) {
System.err.println("Failed to create file:" + fname);
return;
}
// open the file and retrieve the root group
testFile.open();
Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) testFile.getRootNode()).getUserObject();
// create groups at the root
Group g1 = testFile.createGroup("integer arrays", root);
Group g2 = testFile.createGroup("float arrays", root);
// create 2D 32-bit (4 bytes) integer dataset of 20 by 10
Datatype dtype = testFile.createDatatype(Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, Datatype.NATIVE);
Dataset dataset = testFile.createScalarDS("2D 32-bit integer 20x10", g1, dtype, dims2D, null, null, 0, null);
// create 3D 8-bit (1 byte) unsigned integer dataset of 20 by 10 by 5
dtype = testFile.createDatatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, Datatype.SIGN_NONE);
dataset = testFile.createScalarDS("3D 8-bit unsigned integer 20x10x5", g1, dtype, dims3D, null, null, 0, null);
// create 2D 64-bit (8 bytes) double dataset of 20 by 10
dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, -1);
dataset = testFile.createScalarDS("2D 64-bit double 20x10", g2, dtype, dims2D, null, null, 0, null);
// create 3D 32-bit (4 bytes) float dataset of 20 by 10 by 5
dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 4, Datatype.NATIVE, -1);
dataset = testFile.createScalarDS("3D 32-bit float 20x10x5", g2, dtype, dims3D, null, null, 0, null);
// close file resource
testFile.close();
}
use of ncsa.hdf.object.Datatype 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);
}
}
use of ncsa.hdf.object.Datatype 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);
}
}
Aggregations