MATLAB provides APIs for accessing HDF5 data including HDF-EOS5. To use these APIs, user must be familiar with the HDF5 library APIs. This page presents a few examples on how to read and visualize HDF-EOS5 data via MATLAB.
HDF-EOS5 grid data is special in that it does not have to store longitude and latitude values. Instead of storing those values, HDF-EOS5 grid may keep only several parameters that can generate the entire longitude and latitude values. This can save some disk space, but this also makes it difficult to retrieve those values unless HDF-EOS5 API is used.
The degree of difficulty of obtaining longitude and latitude values depends on the projection method used in HDF-EOS5 grid. The simplest projection is the geographic projection. We will cover this case using a real OMI level 3 Ozone data file from GES DISC. You can download the file here.
To access a data field in a grid data, the HDF-EOS5 file should be opened
using H5F.open
, first.
Using the descriptor returned by that API, the grid should be opened.
In this example, we will access a grid dataset called ColumnAmountO3
in an HDF-EOS5 file named
OMI-Aura_L3-OMTO3e_2017m0105_v003-2017m0203t091906.he5.
H5D.open
is the function which MATLAB provides to read data
from an HDF-EOS5 grid file.
Then, dimensions, datasets, and attributes in this grid can be accessed.
H5D.read
.
Note that data_id
, is the descriptor returned by
H5D.open
.
data
is the buffer where the data is stored.
Unlike using C APIs, users do not need to allocate memory for this buffer;
memory will be automatically allocated.
Also, users do not need to specify the type of data
because MATLAB is a dynamically typed language.
After finishing reading all fields, one needs to close the grid using
H5D.close
.
Similarly, if accessing the grid file is done, one needs to close the file
using H5F.close
.
data_id
is what H5D.open
returned,
and file_id
is what H5F.open
returned.
A few more steps are required to visualize the data field we just read. To generate a more meaningful plot, the data field needs to be associated with coordinates. Users need to provide longitude and latitude values. Note that the following explanation only applies to the geographic projection.
The geographic projection, which is used by OMI Column Amount O3 grid, maps meridians to equally spaced vertical straight lines, and circles of latitude to evenly spread horizontal straight lines [1] . This implies that we can precisely interpolate all longitude and latitude values if we know the followings:
We need to retrieve those four types of information. We will use HDFView to get the values for all the required variables. Using HDFView, you can open StructMetadata.0 string dataset under HDFEOS INFORMATION group. The string data contains XDim, YDim, UpperLeftPointMtrs, LowerRightMtrs, PixelRegistration, and GridOrigin information.
The usage of the above values for calculating latitude and longitude values can be seen in Figure 5.
Finally, one can use the contour
function to draw a plot
using data
, lon
and lat
calculated above.
Since Many options are provided for using the surfm
function,
users may need to refer to
MATLAB's detailed document for more information about this function.