/// <summary> /// Read a 1x1 degree square from the HDF5 file, preferentially using data from the high-resolution dataset if it exists, and filling /// in any holes in the high-res data from the corresponding area of the low-resolution dataset /// </summary> /// <param name="highResGroup">Group ID of the high resolution group</param> /// <param name="highResolution">Resolution of the high resolution group, in minutes per sample</param> /// <param name="lowResGroup">Group ID of the low resolution group</param> /// <param name="lowResolution">Resolution of the low resolution group, in minutes per sample</param> /// <param name="desiredResolution">Desired resolution of the output data, in minutes per sample</param> /// <param name="latitude">Latitude of the south-west corner of the 1x1 degree square to be extracted from the HDF5 file</param> /// <param name="longitude">Longitude of the south-west corner of the 1x1 degree square to be extracted from the HDF5 file</param> /// <returns></returns> static IEnumerable<SedimentSample> ReadDataset(H5FileOrGroupId highResGroup, double highResolution, H5FileOrGroupId lowResGroup, double lowResolution, double desiredResolution, int latitude, int longitude) { short[,] result = null; double resolutionStep; double sampleStepSize; if (highResGroup != null) result = ReadDataset(highResGroup, latitude, longitude); if (result != null) { resolutionStep = highResolution / 60; sampleStepSize = desiredResolution / highResolution; } else { if (lowResGroup != null) result = ReadDataset(lowResGroup, latitude, longitude); //if (result == null) throw new KeyNotFoundException(string.Format("Unable to locate sediment data for lat: {0}, lon: {1}", latitude, longitude)); if (result == null) return null; resolutionStep = lowResolution / 60.0; sampleStepSize = desiredResolution / lowResolution; } var sedimentList = new HashedArrayList<SedimentSample>(); for (var i = 0.0; i < result.GetLength(0); i += sampleStepSize) for (var j = 0.0; j < result.GetLength(1); j += sampleStepSize) if (result[(int)i, (int)j] > 0) sedimentList.Add(new SedimentSample(latitude + (i * resolutionStep), longitude + (j * resolutionStep), new SedimentSampleBase { SampleValue = result[(int)i, (int)j] })); return sedimentList; }
protected override void WriteEpochGroupStart(string label, string source, string[] keywords, IDictionary <string, object> properties, Guid identifier, DateTimeOffset startTime, double timeZoneOffset) { H5FileOrGroupId parent = CurrentEpochGroupID == null ? (H5FileOrGroupId)fileId : CurrentEpochGroupID.SubGroupsId; var epochGroup = H5G.create((H5LocId)parent, label + "-" + identifier); var subGroups = H5G.create((H5LocId)epochGroup, "epochGroups"); var epochs = H5G.create((H5LocId)epochGroup, "epochs"); WriteAttribute(epochGroup, "label", label); WriteAttribute(epochGroup, "source", string.IsNullOrEmpty(source) ? "<none>" : source); WriteDictionary(epochGroup, "properties", properties); WriteAttribute(epochGroup, "symphony.uuid", identifier.ToString()); WriteKeywords(epochGroup, new HashSet <string>(keywords)); WriteAttribute(epochGroup, startTimeUtcName, startTime.Ticks); WriteAttribute(epochGroup, startTimeOffsetName, timeZoneOffset); //H5G.close(subGroups); //H5G.close(epochs); EpochGroupsIDs.Push(new EpochGroupIDs(epochGroup, subGroups, epochs)); }
public static void GetDataSet <T> (H5FileOrGroupId groupOrFileId, string name, out T[,,,] array, int width, int height, int depth, int number) { if (groupOrFileId is null) { throw new ArgumentNullException(nameof(groupOrFileId)); } if (name is null) { throw new ArgumentNullException(nameof(name)); } H5DataSetId h5DataSetId = H5D.open(groupOrFileId, name); H5DataTypeId h5DataTypeId = H5D.getType(h5DataSetId); array = new T[height, width, depth, number]; H5D.read(h5DataSetId, h5DataTypeId, new H5Array <T> (array)); H5T.close(h5DataTypeId); H5D.close(h5DataSetId); }
public static void GetDataSet <T> (H5FileOrGroupId groupOrFileId, string name, out T[] array, int length) { if (groupOrFileId is null) { throw new ArgumentNullException(nameof(groupOrFileId)); } if (name is null) { throw new ArgumentNullException(nameof(name)); } array = new T[length]; H5DataSetId h5DataSetId = H5D.open(groupOrFileId, name); H5DataTypeId h5DataTypeId = H5D.getType(h5DataSetId); H5D.read(h5DataSetId, h5DataTypeId, new H5Array <T> (array)); H5T.close(h5DataTypeId); H5D.close(h5DataSetId); }
static short[,] ReadDataset(H5FileOrGroupId groupId, int latitude, int longitude) { if (groupId == null) return null; try { var data = H5D.open(groupId, string.Format("{0}_{1}", latitude, longitude)); var sid = H5D.getSpace(data); var dims = H5S.getSimpleExtentDims(sid); var readBuf = new short[dims[0], dims[1]]; H5D.read(data, H5T.copy(H5T.H5Type.NATIVE_SHORT), new H5Array<short>(readBuf)); H5D.close(data); return readBuf; } catch (HDFException) { return null; } }
static short[,] ReadDataset(H5FileOrGroupId groupId, double nativeResolution, double desiredResolution, int latitude, int longitude) { var decimationStepSize = desiredResolution / nativeResolution; var rawData = ReadDataset(groupId, latitude, longitude); if (rawData == null) return null; var resampledData = new short[(int)((rawData.GetLength(0) - 1) / decimationStepSize), (int)((rawData.GetLength(1) - 1) / decimationStepSize)]; for (var i = 0; i < resampledData.GetLength(0); i++) for (var j = 0; j < resampledData.GetLength(1); j++) resampledData[i, j] = rawData[(int)(i * decimationStepSize), (int)(j * decimationStepSize)]; return resampledData; }
/// <summary> /// Read a 1x1 degree square from the HDF5 file, preferentially using data from the high-resolution dataset if it exists, and filling /// in any holes in the high-res data from the corresponding area of the low-resolution dataset /// </summary> /// <param name="highResGroup">Group ID of the high resolution group</param> /// <param name="highResolution">Resolution of the high resolution group, in minutes per sample</param> /// <param name="lowResGroup">Group ID of the low resolution group</param> /// <param name="lowResolution">Resolution of the low resolution group, in minutes per sample</param> /// <param name="desiredResolution">Desired resolution of the output data, in minutes per sample</param> /// <param name="latitude">Latitude of the south-west corner of the 1x1 degree square to be extracted from the HDF5 file</param> /// <param name="longitude">Longitude of the south-west corner of the 1x1 degree square to be extracted from the HDF5 file</param> /// <returns></returns> static IEnumerable<SedimentSample> ReadDatasetHierarchical(H5FileOrGroupId highResGroup, double highResolution, H5FileOrGroupId lowResGroup, double lowResolution, double desiredResolution, int latitude, int longitude) { short[,] highResData = null; short[,] lowResData = null; if (highResGroup != null) highResData = ReadDataset(highResGroup, highResolution, desiredResolution, latitude, longitude); if (lowResGroup != null) lowResData = ReadDataset(lowResGroup, lowResolution, desiredResolution, latitude, longitude); if (highResData == null && lowResData == null) throw new KeyNotFoundException(string.Format("Unable to locate sediment data for lat: {0}, lon: {1}", latitude, longitude)); var resolutionStepSize = desiredResolution / 60; var resolutionStepCount = (int)(1.0 / resolutionStepSize); if (highResData != null && (highResData.GetLength(0) != resolutionStepCount || highResData.GetLength(1) != resolutionStepCount)) throw new IndexOutOfRangeException("High resolution dataset is not the correct size"); if (lowResData != null && (lowResData.GetLength(0) != resolutionStepCount || lowResData.GetLength(1) != resolutionStepCount)) throw new IndexOutOfRangeException("Low resolution dataset is not the correct size"); Func<int, int, short> highResDataFunc = (i, j) => highResData[i, j] == NoData ? (short)0 : highResData[i, j]; Func<int, int, short> lowResDataFunc = (i, j) => lowResData[i, j] == NoData ? (short)0 : lowResData[i, j]; Func<int, int, short> dataFunc; if (highResData != null && lowResData != null) dataFunc = (i, j) => highResDataFunc(i, j) == 0 ? lowResDataFunc(i, j) : highResDataFunc(i, j); else if (highResData != null) dataFunc = highResDataFunc; else dataFunc = lowResDataFunc; return BuildSedimentSampleList(desiredResolution, latitude, longitude, dataFunc); }
internal HDF5Dataset(H5FileOrGroupId _parentObjectId, string _name) { m_ParentObjectID = _parentObjectId; m_DatasetId = H5D.open(_parentObjectId, _name); }