How to Visualize HDF-EOS data Using MATLAB via OPeNDAP

MATLABexternal is a general-purpose high-level language and user interface for matrix mathematics. Using the OPeNDAP Structs Command Line Toolexternal the user can can visualize a remote HDF-EOS file in MATLAB through an OPeNDAPexternal command-line interface to the Network Data Access Protocol. In this example, we assume that the user has both MATLAB software and the OPeNDAP Structs Command Line Tool (also known as 'loaddap') library installed on your system. MATLAB is commercial software that requires purchase of a license. The user can download versions of the OPeNDAP Structs Command Line Tool for Windows, MacOS-X and Linux from this link for free.

Installing the MATLAB OPeNDAP Structs Command Line Tool

The Windows loaddap binary distribution contains all the additional libraries you need. loaddap for MacOS-X and Linux require libdap and possibly libxml2 packages.

Starting MATLAB

The first step is to add the MATLAB OPeNDAP Structs Command Line Tool installation location to the path for dynamically-loaded shared libraries. In Linux:

Figure 1 Add the MATLAB OPeNDAP loaddap location to LD_LIBRARY_PATH
csh>> setenv LD_LIBRARY_PATH /usr/local/matlab-opendap:$LD_LIBRARY_PATH
# or
sh$ export set LD_LIBRARY_PATH=/usr/local/matlab-opendap:$LD_LIBRARY_PATH

Once in the running MATLAB session, add the path to the OPeNDAP Structs Command Line Tool installation bin directory, where it is installed on your local system.

Figure 2 Add the path to the OPeNDAP Structs Command Line Tool in MATLAB
clear

addpath /usr/local/matlab-opendap/dapbin/bin

Load the HDF data file into MATLAB using the loaddap command. For this example, we are using a GESDISC AIRS Swath HDF file. The user can examine the HDF file's attributes using the OPeNDAP web services interface at the following URL: https://eosdap.hdfgroup.org:8080/opendap/data/NASAFILES/hdf4/AIRS.2002.12.31.001.L2.CC_H.v5.0.14.0.G07282131425.hdf.das.

loaddap reports that it creates the following structures in matlab:

Figure 4 MATLAB loaddap output
...
matrix radiances (45 x 30 x 2378) with 3210300 elements.
...
matrix Latitude (45 x 30) with 1350 elements.
matrix Longitude (45 x 30) with 1350 elements.
...
The structure element name must be known in advance to access the structure element in MATLAB. The structure element name is the same as the HDF file attribute name. The file attributes are returned as a MATLAB structure by the "-A" option to loaddap.

The HDF file attribute names can be obtained via the OPeNDAP web services interface at the previous URL, or they can be found by examining the structures in MATLAB using the datatipinfo command.

Figure 6 Structure element names in MATLAB
>> datatipinfo(radiances);

radiances: 30x2378x45 double

>> datatipinfo(attrs.radiances);
:
coordinates: 'Latitude Longitude nominal_freq'
long_name: 'radiances'
ml__FillValue: -9999
DODS_ML_Size: [3x1 double]
DODS_ML_Real_Name: 'radiances'
Data field structures radiances, Latitude and Longitude are already of type double. We will now extract 2-D data at level 568 of radiances:
Figure 7 Subset 2D from 3D MATLAB structure
data=squeeze(radiances(:,568,:));
For generating the contour plot, Lat, Long and radiances must have the same dimensions -- the radiances matrix is transposed. Replacing the fill value with IEEE NaN excludes these data values from computation. We obtain the fill value from the data field's attributes.
Figure 9 Replacing the fill value with NaN
dataTranspose(dataTranspose==attrs.radiances.ml__FillValue) = NaN;

Now we are ready to plot the dataset defined above.

Figure 10 Display data from the URL
pole=[-90 0 0];
latlim=[floor(min(min(Latitude))),ceil(max(max(Latitude)))];
lonlim=[floor(min(min(Longitude))),ceil(max(max(Longitude)))];
min_data=floor(min(min(dataTranspose)));
max_data=ceil(max(max(dataTranspose)));

figure('Name','AIRS.2002.12.31.001.L2.CC_H.v5.0.14.0.G07282131425_radiances_channel567')
axesm('MapProjection','stereo','MapLatLimit',latlim,'MapLonLimit',lonlim, ...
'Origin',pole,'Frame','on','Grid','on', ...
'MeridianLabel','on','ParallelLabel','on')

coast = load('coast.mat');
The MATLAB surfacem function is faster than contourfm, but produces a less desirable graph in this example.
Figure 11 MATLAB call to Contourfm
contourfm(Latitude,Longitude,dataTranspose,'LineStyle','none');
The remaining code draws the plot axes, geographical coastlines, color bar and title.
Figure 12 Draw grids and maps
colormap('Jet');
caxis([min_data max_data]);
colorbar('YTick', min_data:4:max_data);

plotm(coast.lat,coast.long,'k')

title({'AIRS.2002.12.31.001.L2.CC\_H.v5.0.14.0.G07282131425';'Radiances at channel=567'} ,'FontSize',16,'FontWeight','bold');

Please see the complete code for this example here.

References

Edward T. Olsen, ed., AIRS/AMSU/HSB Version 5 Data Release User Guideexternal, Goddard Space Flight Center, NASA


Last modified: 11/11/2020
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by Subcontract number 4400528183 under Raytheon Contract number NNG15HZ39C, funded by NASA / Maintained by The HDF Group