Top Banner
WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)
41

WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Dec 26, 2015

Download

Documents

Beverly Willis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

WRF Post-Processing

Wei Wang and Bill SkamarockNCAR/MMM

Ethan Alpert (NCAR/SCD)

Page 2: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Outline

NetCDF dataNCL

General information How is it used in WRF post-processing? How to run it?

WRF-to-Vis5D

Page 3: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

netCDF Data

Page 4: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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.

Page 5: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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.

Page 6: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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

Page 7: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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’.

Page 8: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

netCDF Data (cont)

In WRF system, simple utilities also available. See module_wrf_to_v5d_util.F in wrf2vis5d.tar file.

Page 9: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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)

Page 10: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

NCL in WRF

Page 11: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

What is NCL?

NCL stands for NCAR Command Language

NCL is an interpreted programming languageArray based algebraic operatorsSupport netCDF dataWide 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

Page 12: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

What is NCL?

NCL is available on most UNIX platformsNCL can run in batch or interactive mode

Interactive mode has command history and command line editing

Many useful functions and proceduresCode integration tool (ability to import FORTRAN)It is free!

Page 13: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Downloading NCL

Go to:http://ngwww.ucar.edu/ncl/download

Read and agree to GPL licenseFill out short registration formDownload binaries

Precompiled versions exist for:• IBM RS6000, DEC Alpha, Sun Solaris, RedHat Linux, SGI

IRIX, Alpha running RedHat Linux, and Mac running OSX

Page 14: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Installing NCL

Uncompress tar file in installation directory:cd /usr/localgunzip 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)

Page 15: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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

Page 16: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Reference Documentation

Main reference documentationhttp://ngwww.ucar.edu/ngdoc/ng/ref/ncl/Overview.htmlAll syntax and statements definedLinks to all procedures and functionsBasic overview of graphicsUsage tipsInformation on importing FORTRANInformation on supported data formats

Function and Procedure Referencehttp://ngwww.ucar.edu/ngdoc/ng/ref/ncl/NclFuncsAndProcs.html

Page 17: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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 experienceSome programming language knowledge is assumedLearning by example conceptStarts with basics and builds from thereProvides a set of simple functions written in NCL to be used by new users instead of NCL’s object oriented Graphics interfaceThe “Beyond the Basics” section covers incorporating FORTRAN into NCL

Page 18: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Additional resources for using and learning NCL

NCL users email listhttp://ngwww.ucar.edu/ncl-talk/Email list devoted to NCL discussionRead by NCL developers and support staff

Examples pagehttp://ngwww.ucar.edu/ncl/examples.html

CCSM NCL page for additional exampleshttp://www.cgd.ucar.edu/csm/support

Page 19: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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

Page 20: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Incorporating FORTRAN codes

Compile FORTRAN and C wrapper to create .o filesLink object files to create shared objectExample:

nhlcc -c fcode_W.cnhlf77 -c fcode.fld -shared -o fcode.so fcode_W.o fcode.o

Page 21: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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.

Page 22: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Downloading

From wrf-model.org web site: http://www.mmm.ucar.edu/wrf/users/download.html

tar file: wrf_ncl.tarAfter untar, one finds directory

WRF_NCL/README_FIRST README_NCL eh/ em/

Page 23: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

WRF_NCL/em/ directorymake_ncl_fortranmake_ncl_fortran.alphamake_ncl_fortran.rhlinux

wrf_user_fortran_util_0.fwrf_user_fortran_util_0.owrf_user_fortran_util_0.sowrf_user_fortran_util_0_W.cwrf_user_fortran_util_0_W.o

wrf_plot.nclwrf_user_mass.nclskewt_func.nclgsn_code.ncl

wrf_em_b_wave.nclwrf_em_hill2d.nclwrf_em_qss.nclwrf_em_squall_2d_x.nclwrf_em_squall_2d_y.nclwrf_em_sfc.nclwrf_em_slp.nclwrf_em_qv.nclwrf_em_the.nclwrf_em_real.ncl

Scripts to build fortran shared library

Created by fortran build

NCL functions and routines used by the plotting scripts

Plotting scripts

Page 24: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

How to generate shared object file?

Two makefiles exist to create shared object file from Fortran code:make_ncl_fortran.alphamake_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

Page 25: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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/

Page 26: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

;; 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 screenwks = 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 filepressure_levels = (/ 850., 700., 500., 300./) ; pressure levels to plotntimes = dimsizes(times) ; number of times in the filenlevels = dimsizes(pressure_levels) ; number of pressure levels

Example WRF NCL Plotting Script

Files containingNCL functions and routines

open netcdf file

outputoptions

Page 27: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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)

Loop through all times in the output file

Page 28: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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)

Options for plots. Logical variableis “True” if options are present, optionsare attributes of the logical variable

Create map background,label map

Page 29: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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)

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

Page 30: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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

Page 31: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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

Page 32: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Example WRF NCL Plotting Script (cont.) 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 doend do

Skew-T plotsFirst get necessary variables

Find nearest gridpoint

Options needed (skewOpts)not shown here

Page 33: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Sample plots

http://rain.mmm.ucar.edu/mm5/pages/wrf.html

Page 34: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

WRF-to-VIS5D

Wei WangNCAR/MMM

Page 35: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

What does it do?

Convert WRF model output data in netCDF to vis5D format.vis5D is a three-dimensional visualization softwarevis5D is free and can be downloaded from

http://www.ssec.wisc.edu/~billh/vis5d.html

Page 36: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

Downloading

From wrf-model.org web site: http://www.mmm.ucar.edu/wrf/users/download.html

tar file: wrf2vis5d.tarAfter untar, one finds directory

WRF2VIS5D/README eh/ em/

Page 37: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

WRF2VIS5D/em directory

The following files exist in the directory:

MakefileREADMEmodule_wrf_to_v5d_util.Fmodule_wrf_to_v5d_netcdf.Fv5df.hwrf_to_v5d.Fwrf_v5d_input

Page 38: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

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

Page 39: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

File wrf_v5d_input-1 ! number of times to put in vis5d file, negative means ignore the times2000-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 TKTC QVAPORQCLOUDQRAINRAINCTSKend_of_variable_list

Space at the beginning: Not processed

Page 40: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

File wrf_v5d_input (cont.)

wrfout_01_000000 ! WRF output file nameend_of_file_list-1 ! specify v5d vertical grid 0=cartesian, -1=interp to z

from lowest h, >1 list levels (z) desired in vis5d file1 1.2 2.3 3.4 4.5 5.6 6.7 7.8 8.9 9.10 10.

Page 41: WRF Post-Processing Wei Wang and Bill Skamarock NCAR/MMM Ethan Alpert (NCAR/SCD)

The end