% % This example code illustrates how to access and visualize OMI L3 file % in MATLAB. % % If you have any questions, suggestions, comments on this example, please % use the HDF-EOS Forum (http://hdfeos.org/forums). % % If you would like to see an example of any other NASA HDF/HDF-EOS data % product that is not listed in the HDF-EOS Comprehensive Examples page % (http://hdfeos.org/zoo), feel free to contact us at eoshelp@hdfgroup.org % or post it at the HDF-EOS Forum (http://hdfeos.org/forums). % % Usage:save this script and run (without .m at the end) % % $matlab -nosplash -nodesktop -r OMI_Aura_L3_OMTO3e_2017m0105_v003_2017m0203t091906_he5 % % Tested under: MATLAB R2017a % Last updated: 2017-3-29 clear % Open the HDF5 File. FILE_NAME = 'OMI-Aura_L3-OMTO3e_2017m0105_v003-2017m0203t091906.he5'; file_id = H5F.open (FILE_NAME, 'H5F_ACC_RDONLY', 'H5P_DEFAULT'); % Open the dataset. DATAFIELD_NAME = '/HDFEOS/GRIDS/OMI Column Amount O3/Data Fields/ColumnAmountO3'; data_id = H5D.open (file_id, DATAFIELD_NAME); % Get dataspace. data_space = H5D.get_space (data_id); [data_numdims data_dims data_maxdims]= H5S.get_simple_extent_dims (data_space); data_dims=fliplr(data_dims'); % Read the dataset. data=H5D.read (data_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT'); % Transpose the data to match the map projection. data=data'; % Release resources. H5S.close (data_space) % Read the units. ATTRIBUTE = 'Units'; attr_id = H5A.open_name (data_id, ATTRIBUTE); units = H5A.read(attr_id, 'H5ML_DEFAULT'); % Read the fill value. ATTRIBUTE = '_FillValue'; attr_id = H5A.open_name (data_id, ATTRIBUTE); fillvalue=H5A.read (attr_id, 'H5T_NATIVE_DOUBLE'); % Read the missing value. ATTRIBUTE = 'MissingValue'; attr_id = H5A.open_name (data_id, ATTRIBUTE); missingvalue=H5A.read (attr_id, 'H5T_NATIVE_DOUBLE'); % Read title attribute. ATTRIBUTE = 'Title'; attr_id = H5A.open_name (data_id, ATTRIBUTE); long_name=H5A.read (attr_id, 'H5ML_DEFAULT'); % Close and release resources. H5A.close (attr_id) H5D.close (data_id); H5F.close (file_id); % Since the datafile doesn't provide lat and lon, % we need to calculate lat and lon data using Geo projection. offsetY = 0.5; offsetX = 0.5; scaleX = 360/data_dims(2); scaleY = 180/data_dims(1); for i = 0:(data_dims(2)-1) lon_value(i+1) = (i+offsetX)*(scaleX) + (-180); end for j = 0:(data_dims(1)-1) lat_value(j+1) = (j+offsetY)*(scaleY) - 90; end % Convert the data to double type for plot. lon=double(lon_value); lat=double(lat_value); % Replace the fill value with NaN. data(data==fillvalue) = NaN; % Replace the missing value with NaN. data(data==missingvalue) = NaN; % Plot the data using surfm and axesm. f = figure('Name', FILE_NAME, 'visible', 'off'); if isempty(ver('map')) warning('Mapping Toolbox not present.') pcolor(lon,lat,data); shading flat; else latlim=[floor(min(min(lat))),ceil(max(max(lat)))]; lonlim=[floor(min(min(lon))),ceil(max(max(lon)))]; axesm('MapProjection','eqdcylin','MapLatLimit', ... latlim,'MapLonLimit',lonlim,'Frame','on','Grid','on', ... 'MeridianLabel','on','ParallelLabel','on', ... 'MLabelParallel','south'); surfm(lat,lon,data); coast = load('coast.mat'); plotm(coast.lat,coast.long,'k') end % Change the value if you want to have more than 10 tick marks. ntickmarks = 10; min_data=floor(min(min(data))); max_data=ceil(max(max(data))); granule = (max_data - min_data) / ntickmarks; colormap('Jet'); caxis([min_data max_data]); h = colorbar('YTick', min_data:granule:max_data); % An HDF5 string attribute is an array of characters. % Without the following conversion, the characters in unit will appear % in a veritcal direction. unit = sprintf('%s', units); name = sprintf('%s', long_name); set(get(h, 'title'), 'string', unit, 'FontSize',16,'FontWeight', ... 'bold'); plotm(coast.lat,coast.long,'k') title({FILE_NAME; name}, ... 'Interpreter', 'None', 'FontSize',10,'FontWeight','bold'); saveas(f, [FILE_NAME '.m.png']); exit;