Introduction to HDF5 files
Hierarchical Data Format Version 5 (HDF5) is a general-purpose machine-independent standard developed by the National Center for Supercomputing Applications (NCSA) for storing scientific data in files. HDF5 is widely used in engineering and science fields, which require a standard data storage method in order to share data.
View he5 data file information
h5disp - 查看 HDF5 文件的内容
h5info - 创建包含定义 HDF5 文件的所有元数据的结构体
h5read - 从 HDF5 文件中的变量读取数据
h5readatt - 从与 HDF5 文件中的变量或文件本身相关联的属性(全局属性)读取数据。
Take OMI ozone data as an example
Determine the content of HDF5 files. HDF5 files can contain data and metadata, called attributes. In HDF5 files, the directories in the hierarchy are called groups. Groups can contain other groups, data sets, attributes, links, and data types. A data set is a collection of data, such as a multi-dimensional numerical array or string. An attribute is any data associated with another entity (such as a data set). The data type is the description of the data in the data set or attribute. The data type describes how to interpret the data in the data set.
Use the h5disp function to quickly view the contents of the HDF5 file.
h5disp
h5disp('C:\Users\Administrator\Desktop\OMI-Aura_L3-OMTO3e_2004m1001_v003-2012m0409t101417.he5')
Output
HDF5 OMI-Aura_L3-OMTO3e_2004m1001_v003-2012m0409t101417.he5
Group '/'
Group '/HDFEOS'
Group '/HDFEOS/ADDITIONAL'
Group '/HDFEOS/ADDITIONAL/FILE_ATTRIBUTES'
Attributes:
'OrbitNumber': 1117 1118 1119 1120 1121 1122 1123 1124 1125 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
'OrbitPeriod': 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000 5933.000000 5932.000000
'InstrumentName': 'OMI'
'ProcessLevel': '3e'
'GranuleMonth': 10
'GranuleDay': 1
'GranuleYear': 2004
'GranuleDayOfYear': 275
'TAI93At0zOfGranule': 370742405.000000
'PGEVersion': '"1.0.5.1"'
'StartUTC': '2004-09-30T12:15:00.000000Z'
'EndUTC': '2004-10-02T11:45:00.000000Z'
'Period': 'Daily'
Group '/HDFEOS/GRIDS'
Group '/HDFEOS/GRIDS/OMI Column Amount O3'
Attributes:
'GCTPProjectionCode': 0
'Projection': 'Geographic'
'GridOrigin': 'Center'
'GridSpacing': '(0.25,0.25)'
'GridSpacingUnit': 'deg'
'GridSpan': '(-180,180,-90,90)'
'GridSpanUnit': 'deg'
'NumberOfLongitudesInGrid': 1440
'NumberOfLatitudesInGrid': 720
Group '/HDFEOS/GRIDS/OMI Column Amount O3/Data Fields'
Dataset 'ColumnAmountO3'
Size: 1440x720
MaxSize: 1440x720
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: 180x180
Filters: deflate(5)
FillValue: -1267650600228229401496703205376.000000
Attributes:
'_FillValue': -1267650600228229401496703205376.000000
'Units': 'DU'
'Title': 'Best Total Ozone Solution'
'UniqueFieldDefinition': 'TOMS-OMI-Shared'
'ScaleFactor': 1.000000
'Offset': 0.000000
'ValidRange': 50.000000 700.000000
'MissingValue': -1267650600228229401496703205376.000000
Dataset 'RadiativeCloudFraction'
Size: 1440x720
MaxSize: 1440x720
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: 180x180
Filters: deflate(5)
FillValue: -1267650600228229401496703205376.000000
Attributes:
'_FillValue': -1267650600228229401496703205376.000000
'Units': 'NoUnits'
'Title': 'Radiative Cloud Fraction = fc*Ic331/Im331'
'UniqueFieldDefinition': 'TOMS-OMI-Shared'
'ScaleFactor': 1.000000
'Offset': 0.000000
'ValidRange': 0.000000 1.000000
'MissingValue': -1267650600228229401496703205376.000000
Dataset 'SolarZenithAngle'
Size: 1440x720
MaxSize: 1440x720
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: 180x180
Filters: deflate(5)
FillValue: -1267650600228229401496703205376.000000
Attributes:
'_FillValue': -1267650600228229401496703205376.000000
'Units': 'deg'
'Title': 'Solar Zenith Angle'
'UniqueFieldDefinition': 'TOMS-Aura-Shared'
'ScaleFactor': 1.000000
'Offset': 0.000000
'ValidRange': 0.000000 180.000000
'MissingValue': -1267650600228229401496703205376.000000
Dataset 'ViewingZenithAngle'
Size: 1440x720
MaxSize: 1440x720
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: 180x180
Filters: deflate(5)
FillValue: -1267650600228229401496703205376.000000
Attributes:
'_FillValue': -1267650600228229401496703205376.000000
'Units': 'deg'
'Title': 'Viewing Zenith Angle'
'UniqueFieldDefinition': 'TOMS-OMI-Shared'
'ScaleFactor': 1.000000
'Offset': 0.000000
'ValidRange': 0.000000 70.000000
'MissingValue': -1267650600228229401496703205376.000000
Group '/HDFEOS INFORMATION'
Attributes:
'HDFEOSVersion': 'HDFEOS_5.1.11'
Dataset 'StructMetadata.0'
Size: scalar
Datatype: H5T_STRING
String Length: 32000
Padding: H5T_STR_NULLTERM
Character Set: H5T_CSET_ASCII
Character Type: H5T_C_S1
ChunkSize: []
Filters: none
FillValue: ' '
To explore the hierarchical organization of HDF5 files, use the h5info function. h5info returns a structure containing various information about the HDF5 file, including the file name.
h5info
info = h5info('C:\Users\Administrator\Desktop\OMI-Aura_L3-OMTO3e_2004m1001_v003-2012m0409t101417.he5')
info =
包含以下字段的 struct:
Filename: 'C:\Users\Administrator\Desktop\OMI-Aura_L3-OMTO3e_2004m1001_v003-2012m0409t101417.he5'
Name: '/'
Groups: [2×1 struct]
Datasets: []
Datatypes: []
Links: []
Attributes: []
You can see that the file contains 2 groups. The Datasets, Datatypes, Attributes, and Links fields are all empty, indicating that the root group does not contain any data sets, data types, or links. To learn more about the contents of the sample HDF5 file, check a structure in Groups.
g1 = info.Groups(1)
g2 = info.Groups(2)
g1 =
包含以下字段的 struct:
Name: '/HDFEOS'
Groups: [2×1 struct]
Datasets: []
Datatypes: []
Links: []
Attributes: []
g2 =
包含以下字段的 struct:
Name: '/HDFEOS INFORMATION'
Groups: []
Datasets: [1×1 struct]
Datatypes: []
Links: []
Attributes: [1×1 struct]
You can see that there are two more groups under the group HDFEOS.
h5read
The previous section introduced the view of the data structure from the he5 file, and the next section will be the content, which is to read the required data.
The data structure can be seen in detail from the h5disp function.
The ozone group in the data read here is'/HDFEOS/GRIDS/OMI Column Amount O3/Data Fields', this group contains four data sets (can be viewed by h5disp):
Dataset'ColumnAmountO3'
Dataset ‘RadiativeCloudFraction’
Dataset ‘SolarZenithAngle’
Dataset'ViewingZenithAngle'
reads the ozone data in it
data = h5read('C:\Users\Administrator\Desktop\OMI-Aura_L3-OMTO3e_2004m1001_v003-2012m0409t101417.he5','/HDFEOS/GRIDS/OMI Column Amount O3/Data Fields/ColumnAmountO3');
Read other fields as shown above.
Official reference
https://ww2.mathworks.cn/help/matlab/import_export/importing-hierarchical-data-format-hdf5-files.html#bsxixpv-2
https://ww2.mathworks.cn/help/matlab/ref/h5read.html