NCL learning

Post processing WRF is a big task, especially when different tasks come in different times. Most of the time I can find pretty simple (and beautiful) solutions in NCL, so I decided to learn more about it. I will add more to this post when I get new codes that are useful.

NCL means NCAR Command Language, and here is the official website. It is designed to handle the climate data, so WRF is kind of natively supported. It has a package called “WRFUserARW.ncl”, which is super helpful in processing WRF results.

NCL has 3 main references, and they are great tools to start with. Here I mainly handling NetCDF files, and I am only putting some useful quick notes (or short code piece) in case I need them.

1. NetCDF variable handle

pw = wrf_user_getvar(a, "pw", -1) # Here the var is derived from a WRF output file
pw!0 = "Time" # define the dimension name. Otherwise it is "ncl1" by default
pw!1 = "south_north"
pw!2 = "west_east"
pw@units = "kg/m2 (i.e. mm)" # define the var attribute
printVarSummary(pw) # to check the basic info of the variable
plot = gsn_contour(pw(0,:,:,:)) # make some simple plot

2. NetCDF file handle

ncdf = addfile("test_ncl.nc","c") # get a filename
fAtt = True
fAtt@title = "Precipitation" # file name, displayed when opened in ncview
fAtt@creation_date = systemfunc("date") # time stamp
fileattdef(ncdf, fAtt) # put the above file attribute to the file

3. Calculate vars using built-in functions

 

 

 

References

[1] NCL official website: https://www.ncl.ucar.edu/index.shtml

[2] NCL documentations: https://www.ncl.ucar.edu/Document/index.shtml. This is the hub for tutorials, references and other useful materials.