Usage of NCL to Access remote HDF-EOS5 MLS Files

1. Introduction

In this document we describe how to use NCL[1] to visualize a remote HDF-EOS5 MLS files. For the general usages of NCL, please refer to the NCL user's guides[2], or websites.

2. Sample MLS File

The sample MLS file name is MLS-Aura_L2GP-CO_v02-23-c02_2008d277.he5. You can download it from here.

3. How to Open and Read OPeNDAP data wtih NCL

The following code shows a typical way to use NCL to open and read a variable through OPeNDAP. This code needs to be typed at the prompt that NCL shows.

Figure 1 A typical NCL code to read and plot OPeNDAP data
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin
url = "http://eosdap.hdfgroup.uiuc.edu:8080/opendap/data/NASAFILES/hdf5/"
fName = "MLS-Aura_L2GP-CO_v02-23-c02_2008d277.he5"
if ( isfilepresent(url+fName) ) then
f = addfile ( url + fName, "r")
vNames = getfilevarnames(f)
end if
; Uncomment this to check if the remote file is opened successfully.
; print(f)
;
; Uncomment this to locate the L2gpValue.
; print(vNames)
;
In the above code, the url points to the remote MLS file being served by OPeNDAP. Use print command to check if the url file is opened successfully and to see what variables are available inside the file.

4. Setting up key MLS Variables

The next code snippet shows a typical way to handle MLS variables. MLS file holds the key data under L2gpValue and related geo-location information under Latitude, Longitude and Pressure variable. You need to adjust the numeric variable index inside the parentheses to match the right variables.

Figure 2 Handle MLS specific variables
; From the above, we know that the 12th variable is L2gpValue.
T = f->$vNames(12)$
; Re-scale the values.
T = T*1e7
T@units= T@units + "*1e7"
lat = f->$vNames(8)$
lon = f->$vNames(5)$
; The below mapping assumes that the OPeNDAP hdf5_handler maps nTimes to time
; and Pressure to lev variable.
; Otherwise, you need to use numeric index.
lev = f->lev
time = f->time
ntime = dimsizes(time)

; This is useful to set manual contour levels. See "ManualLevels" below.
printVarSummary(T)
In the above code, we re-scaled the L2gpValue va since they are too small. You need to adjust the scale factor depending on the MLS product.

5. Visualizing MLS Data

The final code snippet is almost identical to the official NCL MLS example code in NCL HDF Application Page.

Figure 3 MLS Data Visualization
; This is useful to set manual contour levels. See "ManualLevels" below.
printVarSummary(T)
; The rest of the code is almost identical to hdf5eos_3.ncl
printMinMax(T, True)
print("==============")

; time units: NCL does not *yet* have a function analogous
; to ut_calendar for TAI93 (International Atomic Time).
; Create an "elapsed time" variable.

telapse = (time - time(0))/60
telapse@long_name = "Elapsed Time (minutes)"
telapse@units = "minutes since "+time(0)

;************************************************
; plot
;************************************************
pltType= "ps"
pltName= fName+".L2gpValue.ncl"

wks = gsn_open_wks (pltType,pltName); open workstation
gsn_define_colormap(wks,"amwg") ; choose colormap
dumb= NhlNewColor(wks,0.7,0.7,0.7); add gray to colormap

res = True
res@gsnMaximize= True ; make ps/eps/pdf
res@gsnSpreadColors= True
res@gsnSpreadColorEnd= -2 ; do not use gray for contours
;res@gsnPaperOrientation= "portrait" ; force portrait

res@tiMainString = fName

res@cnFillOn = True
res@cnLinesOn= False
res@cnLineLabelsOn = False
res@cnFillMode = "RasterFill" ; faster
res@cnRasterSmoothingOn= True

res@lbLabelAutoStride= True
res@lbOrientation= "Vertical"

; Change these values based on min/max values of L2gpValue dataset.
res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
res@cnMinLevelValF = -6. ; set min contour level
res@cnMaxLevelValF = 6. ; set max contour level
res@cnLevelSpacingF=1. ; set contour spacing

res@trYReverse = True ; reverse y-axis
T&lev= lev; assign "pressure" coordinates
T&time = telapse; assign temporal coordinates

res@gsnYAxisIrregular2Linear = True
res@tmYLFormat = "f"; force minimal precision
res@tiYAxisString= "Pressure (hPa)"

res@gsnLeftString= T@title

plot= gsn_csm_contour (wks,T(lev|:,time|:) , res)

;***************************************
; create trajectory plot
;***************************************

mpres= True; Plot options desired.
mpres@gsnFrame = False ; Don't advance the frame
mpres@gsnMaximize= True
mpres@mpLandFillColor= "gray70"; color of land
;mpres@gsnPaperOrientation= "portrait"; force portrait
plot = gsn_csm_map_ce(wks,mpres) ; Draw map

gsres= True; "Graphic Style" resources
gsres@gsMarkerSizeF= 10.0; Marker size
gsres@gsMarkerThicknessF = 1.0 ; Marker thickness
gsres@gsMarkerColor= "Blue"; Marker color
gsres@gsMarkerIndex= 1 ; Marker style

mpres@tiMainString = fName

gsn_polymarker(wks,plot,lon,lat,gsres) ; plot trajectory
frame(wks)

end
In the above code, we adjusted the res@cnMinLevelValF and res@cnMaxLevelValF to get a nice graph since the values in that range are the most meaningful values based on the pressure level.

See the complete code here. Run the code as follows:

Then, it will create a MLS-Aura_L2GP-CO_v02-23-c02_2008d277.he5.L2gpValue.ncl.ps file as a result. The PostScript file will have two images like Figure 5 and Figure 6.

6. References


Last modified: 08/09/2011
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by NASA Cooperative Agreement Grant Number NNX08AO77A / Maintained by The HDF Group