Mathematica HDF5 和复合数组

发布于 2024-10-08 11:52:33 字数 206 浏览 5 评论 0原文

有人在 Mathematica 中有解决方法来读取 HDF5 复合数组吗?我在表中有一个简单的 2D 复合类型(int/float),但它目前被忽略。

HDF5 类型的示例可能是:

DATATYPE H5T_COMPOUND {
    H5T_IEEE_F32LE "X";
    H5T_IEEE_F32LE "Y";
}

Does anybody have a workaround in Mathematica for reading HDF5 compound arrays? I have a simple 2D compound type (int/float) in a table but it is currently ignored.

An example HDF5 type might be:

DATATYPE H5T_COMPOUND {
    H5T_IEEE_F32LE "X";
    H5T_IEEE_F32LE "Y";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我不吻晚风 2024-10-15 11:52:33

有一个包,显然是由 Scot Martin 此处 创建的。

据我所知,它实现了许多 HDF5 功能,包括复合类型。

以下是包中 11 HDF5HighLevel Examples.nb 的简短片段:

With[
 {
  file = FileNameJoin[{Directory[], subfolderWithExamples, "h5ex_t_cmpd.h5"}],
  dataSet = "DS1"
  },
 CompoundDataType`Information[file, dataSet]
 ]
(*
{"DataSpaceDimensions" -> {4}, 
 "MemberDataTypeClass" -> {0, -3, 1, 1},  
 "MemberMemorySize" -> {8, 8, 8, 8}, 
 "MemberName" -> {"Serial number"  , "Location", 
                  "Temperature (F)", "Pressure (inHg)"},  
 "MemberOffset" -> {0, 8, 20, 28}, 
 "MemberSize" -> {8, 8, 8, 8}, 
 "MemoryDataTypeSize" -> 32, 
 "NumberOfMembers" -> 4}
*)

HTH!

There is a package, apparently created by Scot Martin here.

As far as I can see, it implements a lot of the HDF5 functionality, including Compound Types.

Here is a brief snippet from 11 HDF5HighLevel Examples.nb in the package:

With[
 {
  file = FileNameJoin[{Directory[], subfolderWithExamples, "h5ex_t_cmpd.h5"}],
  dataSet = "DS1"
  },
 CompoundDataType`Information[file, dataSet]
 ]
(*
{"DataSpaceDimensions" -> {4}, 
 "MemberDataTypeClass" -> {0, -3, 1, 1},  
 "MemberMemorySize" -> {8, 8, 8, 8}, 
 "MemberName" -> {"Serial number"  , "Location", 
                  "Temperature (F)", "Pressure (inHg)"},  
 "MemberOffset" -> {0, 8, 20, 28}, 
 "MemberSize" -> {8, 8, 8, 8}, 
 "MemoryDataTypeSize" -> 32, 
 "NumberOfMembers" -> 4}
*)

HTH!

记忆消瘦 2024-10-15 11:52:33

似乎版本 8 仍然忽略复合数据类型。但是,从第 8 版开始,另一种方法可能是创建一个 导入转换器可以加载复合数据类型。这可能意味着您将不得不重新实现 HDF5 导入器,但我还没有尝试过。我仍在使用 7,但我长期以来一直想要这种类型的功能。

It appears that version 8 still ignores compound data types. However, as of v. 8, an alternative may be to create an Import Converter that can load in compound data types. This may mean you will have to implement the HDF5 importer all over again, but I haven't tried it. I am still using 7, but I've wanted this type of functionality for a long time.

谎言月老 2024-10-15 11:52:33

我创建了 h5dumpImport,这是一个开源 Mathematica 包,它提供了一种独立于平台的方式来导入具有复合数据类型的 HDF5 (.h5) 文件数据集,同时隐藏了大部分 HDF5 实现用户。包含文档、示例和单元测试的包位于此处

目前,h5dumpImport 包不直接导入 HDF5 (.h5) 文件格式。 h5dumpImport 包导入由 h5dump 命令行工具生成的数据集的 ASCII 转储。

HDF5 软件的源代码和预构建的二进制发行版(包括 h5dump 命令行工具)可以在 HDF Group 的 网站

基本示例

Needs["h5dumpImport`"]
datasets = Import["testData.h5", {"Datasets"}];
dumpFile = h5dump["/usr/bin/h5dump", "testData.h5", datasets[[1]]];
dumpImport = h5dumpImportNew[h5dumpImport[], dumpFile];
dumpImport.h5dumpImportData[All]
dumpImport.h5dumpImportClose[];

结果:

{{1, 11, 111, 1111, 11111, 111111, 1111111, 1.1, 11.11, "one"},
 {2, 22, 222, 2222, 22222, 222222, 2222222, 2.2, 22.22, "two"},
 {3, 33, 333, 3333, 33333, 333333, 3333333, 3.3, 33.33, "three"}}

详细的安装说明、使用信息以及文档、示例和单元测试可以在此处找到。

I have created h5dumpImport, an open source Mathematica Package that provides a platform independent way to import HDF5 (.h5) file's datasets with compound datatypes while hiding much of the HDF5 implementation from the user. The package with documentation, examples, and unit test is located here.

Currently, the h5dumpImport package does not directly import the HDF5 (.h5) file format. The h5dumpImport package imports an ASCII dump of a dataset generated by the h5dump command line tool.

Source code and pre-built binary distributions of the HDF5 Software which includes the h5dump command line tool can be found at the The HDF Group's website.

Basic Example

Needs["h5dumpImport`"]
datasets = Import["testData.h5", {"Datasets"}];
dumpFile = h5dump["/usr/bin/h5dump", "testData.h5", datasets[[1]]];
dumpImport = h5dumpImportNew[h5dumpImport[], dumpFile];
dumpImport.h5dumpImportData[All]
dumpImport.h5dumpImportClose[];

Results:

{{1, 11, 111, 1111, 11111, 111111, 1111111, 1.1, 11.11, "one"},
 {2, 22, 222, 2222, 22222, 222222, 2222222, 2.2, 22.22, "two"},
 {3, 33, 333, 3333, 33333, 333333, 3333333, 3.3, 33.33, "three"}}

Detailed installation instructions, usage information, and documentation, examples, and unit tests can be found here.

拥抱影子 2024-10-15 11:52:33

从版本 11.1 开始,HDF5 文件的导入可以处理复合类型(甚至嵌套),并将它们转换为关联。

示例文件 ExampleData/sample2.h5 包含名为 /Compound 的数据集,其中包含 2x2 复合元素矩阵。您可以像这样导入数据:

In[3]:= Import["ExampleData/sample2.h5", "/Compound"]

Out[3]= {
  {
    <|
      "Country" -> "Botswana", 
      "Military" -> {5.3, 4.5}, 
      "Elevation" -> <|"Max" -> 4892, "Min" -> 513, "Highest point" -> "Otse Hill"|>
    |>,
    <|
      "Country" -> "Chile", 
      "Military" -> {8.8, 3.7}, 
      "Elevation" -> <|"Max" -> 6893, "Min" -> 0, "Highest point" -> "Ojos del Salado"|>
    |>
  }, {
    <|
      "Country" -> "France", 
      "Military" -> {5.3, 3.3}, 
      "Elevation" -> <|"Max" -> 4810, "Min" -> -10, "Highest point" -> "Mont Blanc"|>
    |>, 
    <|
      "Country" -> "Laos", 
      "Military" -> {18.9, 4.3}, 
      "Elevation" -> <|"Max" -> 2817, "Min" -> 70, "Highest point" -> "Phou Bia"
    |>
  |>
}}

要了解有关特定数据集的复合数据类型的更多信息,您可以检查 DataFormat 元素:

In[2]:= Import["ExampleData/sample2.h5", {"DataFormat", "/Compound"}]

Out[2]= <|
  "Class" -> "Compound", 
  "Structure" -> <|
    "Country" -> "String", 
    "Military" -> <|"Class" -> "Array", "Dimensions" -> {2}, "DataFormat" -> "Real64"|>, 
    "Elevation" -> <|
      "Class" -> "Compound", 
      "Structure" -> <|"Max" -> "Integer16", "Min" -> "Integer16", "Highest point" -> "String"|>
    |>
  |>
|>

Starting from version 11.1 Import of HDF5 files can handle compound types (even nested) and they are translated to Associations.

A sample file ExampleData/sample2.h5 contains a dataset named /Compound with a 2x2 matrix of compound elements. You can import the data like this:

In[3]:= Import["ExampleData/sample2.h5", "/Compound"]

Out[3]= {
  {
    <|
      "Country" -> "Botswana", 
      "Military" -> {5.3, 4.5}, 
      "Elevation" -> <|"Max" -> 4892, "Min" -> 513, "Highest point" -> "Otse Hill"|>
    |>,
    <|
      "Country" -> "Chile", 
      "Military" -> {8.8, 3.7}, 
      "Elevation" -> <|"Max" -> 6893, "Min" -> 0, "Highest point" -> "Ojos del Salado"|>
    |>
  }, {
    <|
      "Country" -> "France", 
      "Military" -> {5.3, 3.3}, 
      "Elevation" -> <|"Max" -> 4810, "Min" -> -10, "Highest point" -> "Mont Blanc"|>
    |>, 
    <|
      "Country" -> "Laos", 
      "Military" -> {18.9, 4.3}, 
      "Elevation" -> <|"Max" -> 2817, "Min" -> 70, "Highest point" -> "Phou Bia"
    |>
  |>
}}

To learn more about the compound datatype for specific dataset, you may examine the DataFormat element:

In[2]:= Import["ExampleData/sample2.h5", {"DataFormat", "/Compound"}]

Out[2]= <|
  "Class" -> "Compound", 
  "Structure" -> <|
    "Country" -> "String", 
    "Military" -> <|"Class" -> "Array", "Dimensions" -> {2}, "DataFormat" -> "Real64"|>, 
    "Elevation" -> <|
      "Class" -> "Compound", 
      "Structure" -> <|"Max" -> "Integer16", "Min" -> "Integer16", "Highest point" -> "String"|>
    |>
  |>
|>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文