; This example code illustrates how to access and visualize GESDISC ; OMI Swath file in IDL and save the plot as Goolge Earth KMZ. ; ; 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). ; ; Tested under: IDL 8.2.3 ; Last Updated: 2013-10-30 ; Open file. file_name='OMI-Aura_L2-OMNO2_2008m0720t2016-o21357_v003-2008m0721t101450.he5' file_id=H5F_OPEN(file_name) datafield_name='/HDFEOS/SWATHS/ColumnAmountNO2/Data Fields/CloudFraction' data_id=H5D_OPEN(file_id,datafield_name) dataspace_id=H5D_GET_SPACE(data_id) Dims=H5S_GET_SIMPLE_EXTENT_DIMS(dataspace_id) Dims=float(Dims) data=H5D_READ(data_id) ; Read lat/lon Lat_NAME='/HDFEOS/SWATHS/ColumnAmountNO2/Geolocation Fields/Latitude' lat_id=H5D_OPEN(file_id,Lat_NAME) lat=H5D_READ(lat_id) Lon_NAME='/HDFEOS/SWATHS/ColumnAmountNO2/Geolocation Fields/Longitude' lon_id=H5D_OPEN(file_id,Lon_NAME) lon=H5D_READ(lon_id) ; Retrieve units, missing value, scale_factor and offset units_id=H5A_OPEN_NAME(data_id, 'Units') units=H5A_READ(units_id) slope_id=H5A_OPEN_NAME(data_id, 'ScaleFactor') slope=H5A_READ(slope_id) intercept_id=H5A_OPEN_NAME(data_id, 'Offset') intercept=H5A_READ(intercept_id) missingvalue_id=H5A_OPEN_NAME(data_id,'MissingValue') missingvalue=H5A_READ(missingvalue_id) ; Convert data type dataf=float(data) missingvaluef=float(missingvalue(0)) H5A_Close, missingvalue_id H5D_Close, data_id ; data transformation dataf=(slope(0))*(dataf-intercept(0)) missingvaluef=(slope(0))*(missingvaluef-intercept(0)) ; Process missing value, convert dataf that are equal to missingvaluef to NaN idx=where(dataf eq missingvaluef(0), cnt) if cnt gt 0 then dataf[idx] = !Values.F_NAN ; Get max and min value of data for color bar. datamin = MIN(dataf, /NAN) datamax = MAX(dataf, /NAN) ; Prepare field name title using long name attribute. field = 'CloudFraction' units = 'none' ; Use Z-buffer to eliminate the X-Windows device dependency. SET_PLOT, 'Z' ; Start generating the plot. levels = 254 ; Set the window size big to get a better resolution. ; The aspect ratio should match 2:1 to geo-reference the global map [1]. DEVICE, SET_RESOLUTION=[1440, 720], SET_PIXEL_DEPTH=24, DECOMPOSED=0 LOADCT, 33, NCOLORS=levels, BOTTOM=1 ; Use the entire window by setting margins 0 without any border. ; Turn off grid / continents also because Google Earth can provide them. ; MAP_SET, /GRID, /CONTINENTS, ... MAP_SET, XMARGIN=0, YMARGIN=0, /NOBORDER CONTOUR, dataf, lon, lat, /OVERPLOT, /CELL_FILL, C_Colors=Indgen(levels)+3, Background=1, NLEVELS=levels, Color=Black ; Write a JPG image first. im = TVRD(0,0,1440,720,TRUE=1) jpg = file_name + '.jpg' WRITE_JPEG, jpg, im, QUALITY=100, TRUE=1 ; Create the image graphic that can create KML. ; GRID_UNITS 2 means "degrees". ; Setting GRID_LATITUDE=0, GRID_LONGITUDE=0 will turn off drawing ; grids. Please remove them if you want to verify IDL's grid lines against ; Goolge Earth's grid lines. arctic = IMAGE(jpg, $ GRID_UNITS=2, $ LIMIT=[90, -180, -90, 180], IMAGE_LOCATION=[-180,-90], $ IMAGE_DIMENSIONS=[360,180], MAP_PROJECTION='Geographic', $ GRID_LATITUDE=0, GRID_LONGITUDE=0, $ /CURRENT, BACKGROUND_color=[0,0,0], NAME=file_name) ; Save the IMAGE graphic as a KML file, which will produce an overlay ; PNG file. kml = file_name + '.kml' arctic.SAVE, kml ; Make the overlay PNG file background transparent. overlay = '_' + file_name + '_image0.PNG' arctic.SAVE, overlay, TRANSPARENT=[0,0,0], BORDER=0 ; Make a compressed KMZ file using zip. ; FILE_ZIP command is available in IDL 8.2.3 [2]. ; Older versions of IDL may not work. kmz = file_name + '.idl.kmz' FILE_ZIP, [kml, overlay], kmz exit ; Reference ; ; [1] http://www.exelisvis.com/docs/SaveKML.html ; [2] http://www.exelisvis.com/docs/FILE_ZIP.html