private void GetGroupDatasetNames(string groupName) { H5GroupId h5GroupId = H5G.open(_h5FileId, groupName); try { long dscount = H5G.getNumObjects(h5GroupId); for (int i = 0; i < dscount; i++) { string objname = H5G.getObjectNameByIndex(h5GroupId, (ulong)i); ObjectInfo objInfo = H5G.getObjectInfo(h5GroupId, objname, false); switch (objInfo.objectType) { case H5GType.DATASET: if (objInfo.objectType == H5GType.DATASET) { if (groupName == "/") { _datasetNames.Add(objname); } else { _datasetNames.Add(groupName + objname); } } break; case H5GType.GROUP: if (groupName == "/") { GetGroupDatasetNames(objname + "/"); } else { GetGroupDatasetNames(groupName + objname + "/"); } break; case H5GType.LINK: break; case H5GType.TYPE: break; default: break; } } } finally { if (h5GroupId != null) { H5G.close(h5GroupId); } } }
private void createHD5GroupObject(H5GroupId id, String name, ref HDF5GroupObject hdf5Obj) { hdf5Obj.GroupID = id; hdf5Obj.GroupName = name; long num = H5G.getNumObjects(hdf5Obj.GroupID); // the items under the group for (ulong i = 0; i < (ulong)num; i++) { String objName = H5G.getObjectNameByIndex(hdf5Obj.GroupID, i); // get the link info. //linfo = H5L.getInfo(groupID, objName); ObjectInfo objInfo = H5G.getObjectInfo(hdf5Obj.GroupID, objName, true); if (objInfo.objectType == H5GType.GROUP) { String pathName = "/" + name + "/" + objName; if (name.CompareTo("/") == 0) { pathName = "/" + objName; } H5GroupId groupID = null; try { groupID = H5G.open(hdf5Obj.GroupID, pathName); HDF5GroupObject subObj = new HDF5GroupObject(); subObj.ShortName = objName; createHD5GroupObject(groupID, pathName, ref subObj); hdf5Obj.SubGroups.Add(subObj); } catch (Exception e) { Console.WriteLine(e.Message); if (groupID != null) { H5G.close(groupID); } } } else if (objInfo.objectType == H5GType.DATASET) { String pathName = "/" + name + "/" + objName; HD5DataSetObject dataObject = new HD5DataSetObject(); dataObject.ShortName = objName; createHD5DataObject(hdf5Obj.GroupID, pathName, ref dataObject); hdf5Obj.Datasets.Add(dataObject); } } }
/// <summary> /// 得到所有数据集合名,未对异常进行处理 /// </summary> private void getDatasetNames() { H5GroupId groupId = H5G.open(_fileId, "/"); long dscount = H5G.getNumObjects(groupId); for (int ii = 0; ii < dscount; ++ii) { String v = H5G.getObjectNameByIndex(groupId, (ulong)ii); _datasetNames.Add(v); } if (groupId != null) { H5G.close(groupId); } }
private bool getOMXMatrixTables() { // get info about the tables this.dataGroup = H5G.open(fileId, dataGroupName); this.NumMatrix = (int)H5G.getNumObjects(this.dataGroup); this.MatrixNames = new List <string>(); for (int i = 0; i < NumMatrix; i++) { string matName = H5G.getObjectNameByIndex(this.dataGroup, (ulong)i); MatrixNames.Add(matName); H5DataSetId matId = H5D.open(dataGroup, matName); tables.Add(matName, matId); } return(true); }
private bool getOMXIndexMaps() { this.luGroup = H5G.open(fileId, luGroupName); this.NumIndexMap = (int)H5G.getNumObjects(this.luGroup); this.IndexMapNames = new List <string>(); for (int i = 0; i < NumIndexMap; i++) { string imName = H5G.getObjectNameByIndex(this.luGroup, (ulong)i); IndexMapNames.Add(imName); H5DataSetId imId = H5D.open(luGroup, imName); indexMaps.Add(imName, imId); } return(true); }
public static List <string> GetChildGroupNames(H5GroupId _groupId) { List <string> names = new List <string>(); ulong count = (ulong)H5G.getNumObjects(_groupId);; for (ulong i = 0; i < count; i++) { string name = H5G.getObjectNameByIndex(_groupId, i); ObjectInfo info = H5G.getObjectInfo(_groupId, name, false); if (info.objectType == H5GType.GROUP) { names.Add(name); } } return(names); }
public SkimMatrix Read(string fileNameAndGroupAndDataTable, int field, float scale) { //mb merged these changes to local develop before pushing #210 //hdf5 filename contain "filename/group/skim" //get the index of group int hdf5GroupEnd = fileNameAndGroupAndDataTable.LastIndexOf("/"); string fileNameAndGroup = hdf5GroupEnd > 0 ? fileNameAndGroupAndDataTable.Substring(0, hdf5GroupEnd) : fileNameAndGroupAndDataTable; //get the index of filename int hdf5NameEnd = hdf5GroupEnd > 0 ? fileNameAndGroup.LastIndexOf("/") : -1; string groupName = fileNameAndGroup.Substring(hdf5NameEnd + 1); //get the omx/hdf5 filename string HDFName = fileNameAndGroup.Substring(0, hdf5NameEnd); string groupAndDataTable = fileNameAndGroupAndDataTable.Substring(hdf5NameEnd); string hdfFile = Path.Combine(_path, HDFName); FileInfo file = new FileInfo(hdfFile); if (!file.Exists) { throw new FileNotFoundException(string.Format("The skim file {0} could not be found.", file.FullName)); } H5FileId dataFile = H5F.open(hdfFile, H5F.OpenMode.ACC_RDONLY); H5DataSetId dataSet = H5D.open(dataFile, groupAndDataTable); H5DataSpaceId space = H5D.getSpace(dataSet); long[] size2 = H5S.getSimpleExtentDims(space); long nRows = size2[0]; long nCols = size2[1]; Debug.Assert(nRows == nCols); long numZones = _mapping.Count(); int[] lookupMap = null; string lookupMapName = null; string lookupGroupName = "lookup"; H5GroupId luGroup = H5G.open(dataFile, lookupGroupName); if (H5G.getNumObjects(luGroup) == 1L) { lookupMapName = H5G.getObjectNameByIndex(luGroup, 0); H5DataSetId lookupDataSet = H5D.open(dataFile, string.Concat(lookupGroupName, "/", lookupMapName)); H5DataTypeId lookupMapType = H5D.getType(lookupDataSet); H5DataSpaceId lookupMapSpace = H5D.getSpace(lookupDataSet); long lookupMapSize = H5S.getSimpleExtentDims(lookupMapSpace)[0]; lookupMap = new int[lookupMapSize]; H5Array <int> lookupWrapArray = new H5Array <int>(lookupMap); H5D.read(lookupDataSet, lookupMapType, lookupWrapArray); } if (lookupMap != null) { if (lookupMap.Length != nRows) { Global.PrintFile.WriteLine(string.Format("DATA WARNING: skim file: {0} has a lookup map named {1} but its length ({2}) is different than the matrix size ({3}) in group table {4}", hdfFile, lookupMapName, lookupMap.Length, nRows, groupAndDataTable)); lookupMap = null; } } // if the count in the hdf5 file is larger than the number of // tazs in the mapping, ignore the values over the total number //of tazs in the mapping because these are not valid zones. _matrix = new ushort[numZones][]; for (int i = 0; i < numZones; i++) { _matrix[i] = new ushort[numZones]; } //OMX is a square matrix of doubles //In addition to the data folder for matrices, an OMX file has a lookup folder //with a zone mapping vector. However, this is ignored since DaySim also has one. //Therefore, it is assumed the OMX matrix does not skip rows/cols and every row/col //corresponds to an actual zone in the DaySim zone mapping file by index double[,] dataArray = new double[nRows, nCols]; H5Array <double> wrapArray = new H5Array <double>(dataArray); H5DataTypeId tid1 = H5D.getType(dataSet); H5D.read(dataSet, tid1, wrapArray); long numSuccessfuLookups = 0; for (int row = 0; row < nRows; row++) { int mappingKey = (lookupMap == null) ? (row + 1) : lookupMap[row]; if (_mapping.TryGetValue(mappingKey, out int mappedRow)) { for (int col = 0; col < nCols; col++) { mappingKey = (lookupMap == null) ? (col + 1) : lookupMap[col]; if (_mapping.TryGetValue(mappingKey, out int mappedCol)) { double value = dataArray[row, col] * scale; ++numSuccessfuLookups; if (value > 0) { if (value > ushort.MaxValue - 1) { value = ushort.MaxValue - 1; } _matrix[mappedRow][mappedCol] = (ushort)value; //bug #208 deferred but this will eventually changed be Convert.ToUInt16 to avoid 0.57*100=56 bug } } } //for col } } //for row Global.PrintFile.WriteLine(string.Format("Loaded skim file: {0} dataset: {1}, scale={6} with input matrix size={2} and DaySim matrix size={3} zones. Percentage successful mappings {4}. {5}", hdfFile, groupAndDataTable, nRows, numZones, (numSuccessfuLookups / (nRows * nCols)) * 100.0, lookupMap != null ? string.Format("Using lookupMap {0}.", lookupMapName) : "No lookupMap.", scale), true); SkimMatrix skimMatrix = new SkimMatrix(_matrix); return(skimMatrix); }