HDF5-CSharp
1.19.0
dotnet add package HDF5-CSharp --version 1.19.0
NuGet\Install-Package HDF5-CSharp -Version 1.19.0
<PackageReference Include="HDF5-CSharp" Version="1.19.0" />
paket add HDF5-CSharp --version 1.19.0
#r "nuget: HDF5-CSharp, 1.19.0"
// Install HDF5-CSharp as a Cake Addin #addin nuget:?package=HDF5-CSharp&version=1.19.0 // Install HDF5-CSharp as a Cake Tool #tool nuget:?package=HDF5-CSharp&version=1.19.0
HDF5-CSharp helps in reading and writing hdf5 files for .net environments
Usage
write an object to an HDF5 file
In the example below an object is created with some arrays and other variables The object is written to a file and than read back in a new object.
private class TestClassWithArray
{
public double[] TestDoubles { get; set; }
public string[] TestStrings { get; set; }
public int TestInteger { get; set; }
public double TestDouble { get; set; }
public bool TestBoolean { get; set; }
public string TestString { get; set; }
}
var testClass = new TestClassWithArray() {
TestInteger = 2,
TestDouble = 1.1,
TestBoolean = true,
TestString = "test string",
TestDoubles = new double[] { 1.1, 1.2, -1.1, -1.2 },
TestStrings = new string[] { "one", "two", "three", "four" }
};
int fileId = Hdf5.CreateFile("testFile.H5");
Hdf5.WriteObject(fileId, testClass, "testObject");
TestClassWithArray readObject = new TestClassWithArray();
readObject = Hdf5.ReadObject(fileId, readObject, "testObject");
Hdf5.CloseFile(fileId);
Write a dataset and append new data to it
/// <summary>
/// create a matrix and fill it with numbers
/// </summary>
/// <param name="offset"></param>
/// <returns>the matrix </returns>
private static double[,]createDataset(int offset = 0)
{
var dset = new double[10, 5];
for (var i = 0; i < 10; i++)
for (var j = 0; j < 5; j++)
{
double x = i + j * 5 + offset;
dset[i, j] = (j == 0) ? x : x / 10;
}
return dset;
}
// create a list of matrices
dsets = new List<double[,]> {
createDataset(),
createDataset(10),
createDataset(20) };
string filename = Path.Combine(folder, "testChunks.H5");
int fileId = Hdf5.CreateFile(filename);
// create a dataset and append two more datasets to it
using (var chunkedDset = new ChunkedDataset<double>("/test", fileId, dsets.First()))
{
foreach (var ds in dsets.Skip(1))
chunkedDset.AppendDataset(ds);
}
// read rows 9 to 22 of the dataset
ulong begIndex = 8;
ulong endIndex = 21;
var dset = Hdf5.ReadDataset<double>(fileId, "/test", begIndex, endIndex);
Hdf5.CloseFile(fileId);
for more example see unit test project
Reading H5 File:
you can use the following two method to read the structure of an existing file:
string fileName = @"FileStructure.h5";
var tree =Hdf5.ReadTreeFileStructure(fileName);
var flat = Hdf5.ReadFlatFileStructure(fileName);
Additional settings
- Hdf5EntryNameAttribute: control the name of the field/property in the h5 file:
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public sealed class Hdf5EntryNameAttribute : Attribute
{
public string Name { get; }
public Hdf5EntryNameAttribute(string name)
{
Name = name;
}
}
example:
private class TestClass : IEquatable<TestClass>
{
public int TestInteger { get; set; }
public double TestDouble { get; set; }
public bool TestBoolean { get; set; }
public string TestString { get; set; }
[Hdf5EntryNameAttribute("Test_time")]
public DateTime TestTime { get; set; }
}
- Time and fields names in H5 file:
public class Settings
{
public DateTimeType DateTimeType { get; set; }
public bool LowerCaseNaming { get; set; }
}
public enum DateTimeType
{
Ticks,
UnixTimeSeconds,
UnixTimeMilliseconds
}
usage:
[ClassInitialize()]
public static void ClassInitialize(TestContext context)
{
Hdf5.Hdf5Settings.LowerCaseNaming = true;
Hdf5.Hdf5Settings.DateTimeType = DateTimeType.UnixTimeMilliseconds;
}
- Logging: use can set logging callback via: Hdf5Utils.LogError, Hdf5Utils.LogInfo, etc
public static class Hdf5Utils
{
public static Action<string> LogError;
public static Action<string> LogInfo;
public static Action<string> LogDebug;
public static Action<string> LogCritical;
}
in order to log errors use this code snippet:
Hdf5.Hdf5Settings.EnableErrorReporting(true);
Hdf5Utils.LogWarning = (string s) => {...}
Hdf5Utils.LogCritical = (string s) => {...}
Hdf5Utils.LogError = (string s) => {...}
History
V1.17.0 (25.03.2023):
- Update Breaking Change inside Dependecy PureHDF (previously HDF5.NET)
V1.16.3 (25.01.2023):
- Update Dependecy PureHDF (previously HDF5.NET)
V1.16.2 (18.11.2022):
- File close problem #249
- Hdf5.WriteCompounds is missing the write attributes fix (move write to created compound name and not group id) #248
V1.16.1 (12.11.2022):
- Hdf5.WriteCompounds is missing the write attributes fix #248
V1.16.0 (11.09.2022):
- Add net 7 target framework.
V1.15.4.1 (03.08.2022):
- Replace net.6.0-windows target with net6.0.
V1.15.3 (23.07.2022):
- https://github.com/LiorBanai/HDF5-CSharp/issues/224: Memory increased #224
V1.15.2 (14.07.2022):
- https://github.com/LiorBanai/HDF5-CSharp/issues/213: [NET5+] Add support for newly added primitive types #213
- https://github.com/LiorBanai/HDF5-CSharp/issues/216: Nullable support for "ReadObject" #216 (additional changes)
V1.15.1:
- https://github.com/LiorBanai/HDF5-CSharp/issues/219: Add Support for Reference Nullable Types #219
V1.15.0:
- https://github.com/LiorBanai/HDF5-CSharp/issues/216: Nullable support for "ReadObject" #216
V1.14.3:
- https://github.com/LiorBanai/HDF5-CSharp/issues/215: [BUG] Compound struct - missing memory release #215
V1.14.2:
- https://github.com/LiorBanai/HDF5-CSharp/issues/214: [BUG] OpenAttributeIfExists Tries to open dataset instead of attribute #214
- https://github.com/LiorBanai/HDF5-CSharp/issues/212: [IMPROVEMENT] Add Throw if not exists boolean flag or Mandatory Attribute? #212
V1.14.1:
- https://github.com/LiorBanai/HDF5-CSharp/issues/211: [IMPROVEMENT] don't try to open group if it does not exist #211
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- HDF.PInvoke.1.10 (>= 1.10.612)
- PureHDF (>= 1.0.0-beta.2)
- System.Memory (>= 4.5.5)
- System.Resources.Extensions (>= 7.0.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
.NETStandard 2.1
- HDF.PInvoke.1.10 (>= 1.10.612)
- PureHDF (>= 1.0.0-beta.2)
- System.Resources.Extensions (>= 7.0.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
net6.0
- HDF.PInvoke.1.10 (>= 1.10.612)
- PureHDF (>= 1.0.0-beta.2)
- System.Resources.Extensions (>= 7.0.0)
-
net7.0
- HDF.PInvoke.1.10 (>= 1.10.612)
- PureHDF (>= 1.0.0-beta.2)
- System.Resources.Extensions (>= 7.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on HDF5-CSharp:
Package | Downloads |
---|---|
TensorFlow.Keras
Keras for .NET Keras is an API designed for human beings, not machines. Keras follows best practices for reducing cognitive load: it offers consistent & simple APIs, it minimizes the number of user actions required for common use cases, and it provides clear & actionable error messages. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on HDF5-CSharp:
Repository | Stars |
---|---|
SciSharp/TensorFlow.NET
.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
|
Version | Downloads | Last updated |
---|---|---|
1.19.0 | 58,274 | 9/28/2023 |
1.18.0 | 20,442 | 8/22/2023 |
1.17.0 | 44,808 | 3/25/2023 |
1.16.3 | 29,038 | 1/25/2023 |
1.16.2 | 5,804 | 11/18/2022 |
1.16.1 | 578 | 11/12/2022 |
1.16.0 | 141 | 11/9/2022 |
1.15.4.1 | 6,032 | 8/3/2022 |
1.15.4 | 136 | 8/3/2022 |
1.15.3 | 452 | 7/23/2022 |
1.15.2 | 1,145 | 7/14/2022 |
1.15.1 | 215 | 7/13/2022 |
1.15.0 | 141 | 7/13/2022 |
1.14.3 | 287 | 7/10/2022 |
1.14.2 | 247 | 7/5/2022 |
1.14.1 | 156 | 7/5/2022 |
1.14.0 | 205 | 7/1/2022 |
1.13.5.8-RC | 108 | 6/30/2022 |
1.13.5.7-RC | 106 | 6/29/2022 |
1.13.5.6-RC | 109 | 6/29/2022 |
1.13.5.5-RC | 105 | 6/29/2022 |
1.13.5.4-RC | 113 | 6/28/2022 |
1.13.5.3-RC | 125 | 6/25/2022 |
1.13.5.2-RC | 134 | 6/21/2022 |
1.13.5.1-RC | 131 | 6/21/2022 |
1.13.5-RC | 122 | 6/21/2022 |
1.13.4 | 1,249 | 6/13/2022 |
1.13.3 | 476 | 6/13/2022 |
1.13.2 | 967 | 5/18/2022 |
1.13.1 | 513 | 5/11/2022 |
1.13.0 | 772 | 4/25/2022 |
1.13.0-rc | 224 | 3/22/2022 |
1.12.9-rc | 178 | 3/16/2022 |
1.12.8 | 890 | 3/13/2022 |
1.12.7 | 2,242 | 3/1/2022 |
1.12.6 | 478 | 2/26/2022 |
1.12.5 | 17,228 | 12/21/2021 |
1.12.4 | 3,204 | 7/15/2021 |
1.12.3 | 2,244 | 3/22/2021 |
1.12.2 | 395 | 3/20/2021 |
1.12.0 | 557 | 2/27/2021 |
1.11.2 | 1,283 | 2/2/2021 |
1.11.1 | 735 | 11/13/2020 |
1.11.0 | 1,006 | 10/18/2020 |
1.10.610.10 | 632 | 8/18/2020 |
1.10.610.9 | 648 | 5/23/2020 |
1.10.610.8 | 656 | 4/26/2020 |
1.10.610.7 | 495 | 4/24/2020 |
1.10.610.6 | 516 | 4/16/2020 |
1.10.610.5 | 518 | 4/16/2020 |
1.10.610.4 | 523 | 4/14/2020 |
1.10.610.3 | 533 | 4/8/2020 |
1.10.610.2 | 559 | 4/8/2020 |
1.10.610.1 | 581 | 3/30/2020 |