420 likes | 792 Views
WRF Post-Processing. Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD). Outline. NetCDF data NCL General information How is it used in WRF post-processing? How to run it? WRF-to-Vis5D. netCDF Data. netCDF Data.
E N D
WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)
Outline • NetCDF data • NCL • General information • How is it used in WRF post-processing? • How to run it? • WRF-to-Vis5D
netCDF Data • netCDF is one of the data formats chosen for WRF I/O, and is currently supported. • What is netCDF? “A library for storing and retrieving scientific data in self-describing, platform-independent files; enhanced by various utilities,…” (http://www.unidata.ucar.edu/) • Documentation available at above site.
netCDF Data (cont) • What are the advantages of using netCDF? • Platform-independent (no big_endian, little_endian) – though it may be with some caveat.. • Many software may already exist which can be used to process netCDF data.
netCDF Data (cont) • netCDF utilities available: • ncdump reads a netCDF dataset and prints a textual representation of the information in the dataset e.g. ncdump –h file -- print header (inc. variables in the file) ncdump –v variable-name file-- print values of the var • ncgen reads a textual representation of a netCDF dataset and generates the corresponding binary netCDF file or a C or FORTRAN program to create the netCDF dataset
netCDF Data (cont) • Other netCDF operators are available from http://nco.sourceforge.net/, which can be used to manipulate data, such as performing grid point averaging, file differencing, and file ‘appending’.
netCDF Data (cont) • In WRF system, simple utilities also available. See module_wrf_to_v5d_util.F in wrf2vis5d.tar file.
netCDF Data (cont) • Simple calls to access the data. For example, call get_dims_cdf( file_for_time(1), 'T', & dims, ndims, debug ) > get dimensions of field T in an array dims call get_gl_att_real_cdf( file_for_time(1), & 'CEN_LON', cen_lon, debug ) > get attributes from a netCDF file call get_var_2d_real_cdf( file_for_time(1), & 'XLAT', xlat, dims(1), dims(2), 1, debug) > get the 2D field XLAT (similar call for a 3D field)
What is NCL? • NCL stands for NCAR Command Language • NCL is an interpreted programming language • Array based algebraic operators • Support netCDF data • Wide variety of graphics capabilities: • Maps, Contours, XY, Vectors, Streamlines, labelbars, text, tickmarks as well as line, marker and polygon primatives • Output to X, NCGM, PostScript
What is NCL? • NCL is available on most UNIX platforms • NCL can run in batch or interactive mode • Interactive mode has command history and command line editing • Many useful functions and procedures • Code integration tool (ability to import FORTRAN) • It is free!
Downloading NCL • Go to: • http://ngwww.ucar.edu/ncl/download • Read and agree to GPL license • Fill out short registration form • Download binaries • Precompiled versions exist for: • IBM RS6000, DEC Alpha, Sun Solaris, RedHat Linux, SGI IRIX, Alpha running RedHat Linux, and Mac running OSX
Installing NCL • Uncompress tar file in installation directory: • cd /usr/local • gunzip ncl-4.2.0.a024_OSF5.1_alpha.tar.gz • Untar: • tar –xvf ncl-4.2.0.a024_OSF5.1_alpha.tar • Set NCARG_ROOT environment variable: • setenv NCARG_ROOT /usr/local/ • set path = ( /usr/local/bin $PATH)
Important resources forusing and learning NCL • Main NCL home page: • http://ngwww.ucar.edu/ncl • Contains links to documentation, examples, FAQ, ncl-talk email list, and update information
Reference Documentation • Main reference documentation • http://ngwww.ucar.edu/ngdoc/ng/ref/ncl/Overview.html • All syntax and statements defined • Links to all procedures and functions • Basic overview of graphics • Usage tips • Information on importing FORTRAN • Information on supported data formats • Function and Procedure Reference • http://ngwww.ucar.edu/ngdoc/ng/ref/ncl/NclFuncsAndProcs.html
Getting Started Using NCL (GSUN) • Getting Started Using NCL (GSUN) • http://ngwww.ucar.edu/ngdoc/ng/ug/ncl/gsun/ • Intended for users with little or no NCL experience • Some programming language knowledge is assumed • Learning by example concept • Starts with basics and builds from there • Provides a set of simple functions written in NCL to be used by new users instead of NCL’s object oriented Graphics interface • The “Beyond the Basics” section covers incorporating FORTRAN into NCL
Additional resources for using and learning NCL • NCL users email list • http://ngwww.ucar.edu/ncl-talk/ • Email list devoted to NCL discussion • Read by NCL developers and support staff • Examples page • http://ngwww.ucar.edu/ncl/examples.html • CCSM NCL page for additional examples • http://www.cgd.ucar.edu/csm/support
Incorporating FORTRAN codes • Create FORTRAN stub text file or add comments to existing FORTRAN codes C NCLFORTSTART FUNCTION ARCLN(NUMPNT, POINTX, POINTY) DIMENSION POINTX(NUMPNT), POINTY(NUMPNT) C NCLEND • Call wrapit77 wrapit77 < wrapper_input >! wrapper_W.c
Incorporating FORTRAN codes • Compile FORTRAN and C wrapper to create .o files • Link object files to create shared object Example: nhlcc -c fcode_W.c nhlf77 -c fcode.f ld -shared -o fcode.so fcode_W.o fcode.o
NCL for WRF Model Output • The NCL scripts for plotting WRF model output are our first attempt at producing plots for use in our development efforts. • They can do vertical interpolation (so one can plot data on pressure levels), skew-T, and vertical cross-sections. • They currently plot model output variables plus a few diagnostic variables, such as SLP, dew point temperature, and rotate model wind to earth coordinate.
Downloading • From wrf-model.org web site: http://www.mmm.ucar.edu/wrf/users/download.html • tar file: wrf_ncl.tar • After untar, one finds directory WRF_NCL/README_FIRST README_NCL eh/ em/
WRF_NCL/em/ directory make_ncl_fortran make_ncl_fortran.alpha make_ncl_fortran.rhlinux wrf_user_fortran_util_0.f wrf_user_fortran_util_0.o wrf_user_fortran_util_0.so wrf_user_fortran_util_0_W.c wrf_user_fortran_util_0_W.o wrf_plot.ncl wrf_user_mass.ncl skewt_func.ncl gsn_code.ncl wrf_em_b_wave.ncl wrf_em_hill2d.ncl wrf_em_qss.ncl wrf_em_squall_2d_x.ncl wrf_em_squall_2d_y.ncl wrf_em_sfc.ncl wrf_em_slp.ncl wrf_em_qv.ncl wrf_em_the.ncl wrf_em_real.ncl Scripts to build fortran shared library Created by fortran build NCL functions and routines used by the plotting scripts Plotting scripts
How to generate shared object file? • Two makefiles exist to create shared object file from Fortran code: make_ncl_fortran.alpha make_ncl_fortran.linux • Type make_ncl_fortran.alpha wrf_user_fortran_util_0 -> creates wrf_user_fortran_util_0.so • For other machines, edit one of the make files
How to run NCL? • Type the following to run ncl < wrf_em_real.ncl • Depending on output option, one can run NCL interactively or in ‘batch’ mode. • There are corresponding NCL scripts for height model. cd WRF_NCL/eh/
Files containing NCL functions and routines open netcdf file output options Example WRF NCL Plotting Script ; ; script to produce standard plots for a wrf real-data run ; load "wrf_plot.ncl" load "wrf_user.ncl" load "gsn_code.ncl" load "skewt_func.ncl" a = addfile("wrfout_01_000000.nc","r") ;wks = wrf_open_X11() ; output to screen wks = wrf_open_ncgm("wrf_plots") ; output to ncgm ;wks = wrf_open_PS("wrf_plots") ; output to postscript times = wrf_user_list_times(a) ; get times in the file pressure_levels = (/ 850., 700., 500., 300./) ; pressure levels to plot ntimes = dimsizes(times) ; number of times in the file nlevels = dimsizes(pressure_levels) ; number of pressure levels
Loop through all times in the output file Example WRF NCL Plotting Script (cont.) do it = 0, ntimes-1 time = it print(times(it)) if (it.eq.0) then time_save = times(it) end if hours = it*6. ; start with surface pressure plot slvl = wrf_user_getvar(a,"slvl",time) ; psl wrf_user_filter2d(slvl, 3) ; filter the fields tc = wrf_user_getvar(a,"tc",time) tc = 1.8*tc+32. u = wrf_user_getvar(a,"ua",time) ; ua is u averaged to mass points v = wrf_user_getvar(a,"va",time) ; va is v averaged to mass points u = u*1.94386 v = v*1.94386 tc_plane = tc(0,:,:) u_plane = u(0,:,:) v_plane = v(0,:,:) Function (wrf_user_getvar) that reads data from the WRF output file and computes appropriate diagnostic fields (if necessary)
Options for plots. Logical variable is “True” if options are present, options are attributes of the logical variable Create map background, label map Example WRF NCL Plotting Script (cont.) opts_tc = True opts_tc@MainTitle = "Surface T (F, color) SLP (mb) and winds (kts)" ; and many more options... opts_psl = True ; and many more options... opts_vct = True opts_vct@NumVectors = 47 opts_vct@WindBarbsOn = True opts_vct@NoTitles = True opts_vct@vcWindBarbColor = "black" opts_vct@vcRefAnnoOn = False opts_mp = True ; and many more options... map = wrf_new_map(wks,a,opts_mp) opts_map = True opts_map@LabelFont = "HELVETICA-BOLD" opts_map@LabelFontHeight = .01 wrf_maplabel(wks,map,opts_map)
Create plots (contour fill/line and vector) Combine individual plots into single picture (overlay or merge) Send picture to output device Clear for the next picture Example WRF NCL Plotting Script (cont.) contour_tc = wrf__fill_contour(wks,tc_plane,opts_tc) contour_psl = wrf_new_line_contour(wks,slvl(:,:),opts_psl) vector = wrf_new_vector(wks,u_plane, v_plane,opts_vct) wrf_mapoverlay(map,contour_tc) wrf_mapoverlay(map,contour_psl) wrf_mapoverlay(map,vector) draw(map) frame(wks)
Example WRF NCL Plotting Script (cont.) ; preparing for 3-D plots p = wrf_user_getvar(a, "p",time) ; pressure is our vertical coordinate z = wrf_user_getvar(a, "Z",time) ; grid point height rh = wrf_user_getvar(a,"rh",time) w = wrf_user_getvar(a,"wa",time) w = 100.*w tc = (tc-32.)*.55555 do level = 0,nlevels-1 pressure = pressure_levels(level) z_plane = wrf_user_intrp3d( z,p,ter,"h",pressure,0.) tc_plane = wrf_user_intrp3d(tc,p,ter,"h",pressure,0.) u_plane = wrf_user_intrp3d( u,p,ter,"h",pressure,0.) v_plane = wrf_user_intrp3d( v,p,ter,"h",pressure,0.) rh_plane = wrf_user_intrp3d( rh,p,ter,"h",pressure,0.) w_plane = wrf_user_intrp3d( w,p,ter,"h",pressure,0.) ; lots of plotting... end do Loop over desired pressure surface for plots Vertical interp to desired surface
Example WRF NCL Plotting Script (cont.) do ip = 1, 2 dimsrh = dimsizes(rh) plane = new(2,float) plane = (/ dimsrh(2)/2, dimsrh(1)/2 /) if(ip .eq. 1) angle = 90. else angle = 0. end if rh_plane = wrf_user_intrp3d(rh,z,ter,"v",plane,angle) tc_plane = wrf_user_intrp3d(tc,z,ter,"v",plane,angle) ; lots of plotting... end do Point in model ‘gridpoint’ space Angle of plane passing through ‘gridpoint’ Interpolation to vertical cross section
Example WRF NCL Plotting Script (cont.) Skew-T plots First get necessary variables qv = wrf_user_getvar(a,"QVAPOR",time) td = wrf_user_getvar(a,"td",time) u = wrf_user_getvar(a,"umet",time) v = wrf_user_getvar(a,"vmet",time) u = u*1.94386 v = v*1.94386 locr = wrf_user_find_ij_lat_long(a, 39.77, 104.87 ) loc = floattointeger(locr) loc_str = "Skew-T at Denver valid at " + times(it) skewt_bkgd = skewT_BackGround (wks, skewtOpts) draw (skewt_bkgd) skewT_data = skewT_PlotData(wks, skewt_bkgd, p(:,loc(0), loc(1)), \ tc(:,loc(0), loc(1)), \ td(:,loc(0), loc(1)), \ z(:,loc(0), loc(1)), \ -u(:,loc(0), loc(1)), \ -v(:,loc(0), loc(1)), \ dataOpts ) frame(wks) end do end do Find nearest gridpoint Options needed (skewOpts) not shown here
Sample plots • http://rain.mmm.ucar.edu/mm5/pages/wrf.html
WRF-to-VIS5D Wei Wang NCAR/MMM
What does it do? • Convert WRF model output data in netCDF to vis5D format. • vis5D is a three-dimensional visualization software • vis5D is free and can be downloaded from http://www.ssec.wisc.edu/~billh/vis5d.html
Downloading • From wrf-model.org web site: http://www.mmm.ucar.edu/wrf/users/download.html • tar file: wrf2vis5d.tar • After untar, one finds directory WRF2VIS5D/README eh/ em/
WRF2VIS5D/em directory The following files exist in the directory: Makefile README module_wrf_to_v5d_util.F module_wrf_to_v5d_netcdf.F v5df.h wrf_to_v5d.F wrf_v5d_input
How to compile and run? • Type the following to compile: make wrf_to_v5d • Edit command line input file: wrf_v5d_input • Type the following to run: wrf_to_v5d wrf_v5f_input vis5d-filename
File wrf_v5d_input -1 ! number of times to put in vis5d file, negative means ignore the times 2000-01-24_18:00:00 U ! variable list for vis5d file, indent one space to skip V ! first five in list are special variables (diagnosed) W THETA TK TC QVAPOR QCLOUD QRAIN RAINC TSK end_of_variable_list Space at the beginning: Not processed
File wrf_v5d_input (cont.) wrfout_01_000000 ! WRF output file name end_of_file_list -1 ! specify v5d vertical grid 0=cartesian, -1=interp to z from lowest h, >1 list levels (z) desired in vis5d file 1 1. 2 2. 3 3. 4 4. 5 5. 6 6. 7 7. 8 8. 9 9. 10 10.