Search in sources :

Example 6 with H5ScalarDS

use of ncsa.hdf.object.h5.H5ScalarDS 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);
    }
}
Also used : Origin(org.vcell.util.Origin) Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) Extent(org.vcell.util.Extent) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) Dataset(ncsa.hdf.object.Dataset) ArrayList(java.util.ArrayList) H5ScalarDS(ncsa.hdf.object.h5.H5ScalarDS) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CacheException(org.vcell.util.CacheException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileNotFoundException(java.io.FileNotFoundException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) Datatype(ncsa.hdf.object.Datatype) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

H5ScalarDS (ncsa.hdf.object.h5.H5ScalarDS)5 ArrayList (java.util.ArrayList)2 Datatype (ncsa.hdf.object.Datatype)2 HObject (ncsa.hdf.object.HObject)2 H5CompoundDS (ncsa.hdf.object.h5.H5CompoundDS)2 MathException (cbit.vcell.math.MathException)1 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 XmlParseException (cbit.vcell.xml.XmlParseException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Vector (java.util.Vector)1 Dataset (ncsa.hdf.object.Dataset)1 Group (ncsa.hdf.object.Group)1 H5Datatype (ncsa.hdf.object.h5.H5Datatype)1 CacheException (org.vcell.util.CacheException)1 DataAccessException (org.vcell.util.DataAccessException)1