WRF学习之 ch3 WPS(三)WPS并行,检查WPS输出,WPS工具,输出到中间文件,运行WRF所需要的气象场,使用MPAS输出作为WRF初边界条件

时间:2024-03-10 22:27:41

参考自 WRF用户手册http://www2.mmm.ucar.edu/wrf/users/docs/user_guide_V4/WRFUsersGuide.pdf第三章
3. The WRF Preprocessing System (WPS)

  • Introduction ................................................................................. 3-1
  • Function of Each WPS Program ................................................. 3-2
  • Installing the WPS ...................................................................... 3-5
  • Running the WPS ....................................................................... 3-8
  • Creating Nested Domains with the WPS .................................. 3-20
  • Selecting Between USGS and MODIS-based Land Use Data .......................................................................... 3-22
  • Selecting Static Data for the Gravity Wave Drag Scheme ........ 3-23
  • Using Multiple Meteorological Data Sources ............................ 3-23
  • Using Non-isobaric Meteorological Datasets .............................3-26
  • Alternative Initialization of Lake SSTs ............................. 3-27
  • Parallelism in the WPS ............................................................. 3-28
  • Checking WPS Output .............................................................. 3-29
  • WPS Utility Programs ............................................................... 3-30
  • Writing Meteorological Data to the Intermediate Format ........... 3-34
  • Required Meteorological Fields for Running WRF.....................3-36
  • Using MPAS Output for WRF Initial and Boundary Conditions..3-37
  • Creating and Editing Vtables .................................................... 3-39
  • Writing Static Data to the Geogrid Binary Format ..................... 3-41
  • Creating an Urban Fraction Field from NLCD Data .................. 3-44
  • Description of Namelist Variables ............................................. 3-46
  • Description of GEOGRID.TBL Options ..................................... 3-52
  • Description of index Options ..................................................... 3-55
  • Description of METGRID.TBL Options ..................................... 3-58
  • Available Interpolation Options in Geogrid and Metgrid ............ 3-61
  • Land Use and Soil Categories in the Static Data ...................... 3-64
  • WPS Output Fields ................................................................... 3-66

WPS中的并行

如果WPS要处理的区域太大,无法容纳在单个CPU的内存中,那么可以在分布式内存配置中运行geogrid和metgrid程序。为了编译geogrid和metgrid以执行分布式内存,用户必须在计算机上安装MPI库,并且必须使用“DM parallel”配置选项编译WPS。编译成功后,geogrid和metgrid程序可以使用mpirun或mpiexec命令运行,也可以通过批处理队列系统运行,具体取决于机器。

如前所述,ungrib程序不适用于并行化,而且,ungrib处理的内存需求独立于geogrid和metgrid的内存需求;因此,不管配置期间是否采用“DM parallel”配置选项,ungrib总是为单个处理器编译并在单个CPU上运行。

每个标准WRF I/O API格式(NetCDF、GRIB1、binary)都有一个对应的并行格式,其编号是通过将标准格式的io_form 值(即io_form_geogrid和io_form_metgrid的值)加100来给出的。不必使用并行io_form,但当使用并行io_form形式时,每个CPU都会将其输入/输出读/写到一个单独的文件中,该文件的名称就是是“串行执行期间使用的名称”+“四位的处理器ID”。例如,在io_form_geogrid=102的四个处理器上运行geogrid将为粗网格创建名为geo_em.d01.nc.0000、geo_em.d01.nc.0001、geo_em.d01.nc.0002和geo_em.d01.nc.0003的输出文件。

在分布式内存执行期间,模型域被分解为矩形块(patches),每个处理器处理单个块。当从WRF I/O API格式读/写时,每个处理器只读/写各自对应的块。因此,如果geogrid的输出选择的是并行io形式,那么运行metgrid时也必须选择相同数量的处理器。类似地,如果为metgrid输出文件选择了并行io形式,则运行real程序时必须使用相同数量的处理器。当然,当在多个处理器上运行时,仍然可以使用标准的io_form,在这种情况下,模型域的所有数据都将在 输入/输出 时 分发/收集。最后,当在多个处理器上运行geogrid或metgrid时,每个处理器都将编写自己的日志文件,日志文件名将附加与用于I/o API文件的相同的四位处理器ID号。

检查WPS输出

在运行WPS时,检查程序生成的输出可能会有所帮助。例如,在确定嵌套的位置时,查看插值的静态地理数据和纬度/经度变量可能会有所帮助。另一个例子是,在将新的数据源(静态数据或气象数据)导入WPS时,检查生成的插值场通常是有帮助的,以便对geogrid或metgrid使用的插值方法进行调整。

如果把geogrid和metgrid I/O 格式设置成NetCDF格式,就可以使用各种读取NetCDF数据的可视化工具来检查geogrid处理的区域文件或metgrid生成的水平插值气象场。为了将geogrid和metgrid的文件格式设置为NetCDF,用户应将WPS namelist文件中的 io_form_geogrid 和io_form_metgrid设置成2(注意:2是这些选项的默认设置):

&share
 io_form_geogrid = 2,
/

&metgrid
 io_form_metgrid = 2,
/

在这些可用的工具中,ncdump、ncview和新的RIP4程序可能会引起兴趣。ncdump程序是一个与NetCDF库一起分发的实用小工具,它能输出NetCDF文件中的变量和属性。这对于检查geogrid区域文件中的网格参数(例如,东西向维度、南北向维度或域中心点)尤其有用。ncview程序提供了一种交互式方式来查看NetCDF文件中的变量。此外,希望生成适合出版的图的用户可能会对新版的RIP4程序的感兴趣。新版的RIP4能够绘制水平等高线,地图背景,并在同一个绘图叠加多个变量。

ungrib程序的输出文件总是以简单的二进制格式(‘WPS’、‘SI’或‘MM5’)编写的,因此无法使用查看NetCDF文件的软件查看。但是,随WPS源代码一起,提供了基于NCAR图形的实用程序plotfmt。这个实用程序可以绘制的等高线图。如果正确安装了NCAR图形库,则在编译WPS时,plotfmt程序将与其他实用程序一起自动编译。(注意:plotfmt和plotgrids程序在WRF4.2.1中不是自动编译的,需要执行./compile plotfmt 和./compile plotgrids命令手动编译)

WPS 实用程序

除了三个主要的WPS程序geogrid、ungrib和metgrid之外,还有许多WPS附带的实用程序,它们被编译在util目录中。这些实用程序可用于检查数据文件、可视化嵌套域的位置、计算气压场和计算平均表面温度场。

A. avg_tsfc.exe

avg_tsfc.exe文件程序以中间格式计算给定输入文件的日平均表面温度。基于namelist.wps文件中“share”部分中指定的日期范围,并考虑中间文件之间的间隔,avg_tsfc.exe文件将使用尽可能多的完整天数的数据来计算平均值,从namelist中指定的开始日期开始。如如果一天的数据不完整,则不会写入输出文件,一旦确定,程序将立即停止。类似地,对于不能作为完整24小时周期的一部分使用的日期的任何中间文件都将被忽略;例如,如果在6小时间隔内有5个中间文件可用,则最后一个文件将被忽略。计算出的平均值变量使用与输入文件相同的中间格式版本写入名为TAVGSFC的新文件。然后,metgrid可以通过在namelist中的“metgrid” 部分中将constants_name变量设定成“TAVGSFC”来获取每日平均表面温度场。

B. mod_levs.exe

mod_levs.exe程序用于从中间格式文件中删除数据的层次。在namelist.wps文件中有一个新的变量,用来说明哪些层次需要保留。

&mod_levs
 press_pa = 201300 , 200100 , 100000 ,
             95000 ,  90000 ,
             85000 ,  80000 ,
             75000 ,  70000 ,
             65000 ,  60000 ,
             55000 ,  50000 ,
             45000 ,  40000 ,
             35000 ,  30000 ,
             25000 ,  20000 ,
             15000 ,  10000 ,
              5000 ,   1000
/

在&mod_levs namelist记录中,变量press_pa用于指定要保留的层次列表;指定的层次应与中间格式文件中xlvl的值匹配(有关中间文件场的更多信息,请参阅WPS中间格式的说明)。mod_levs程序采用两个命令行参数作为输入。第一个参数是要操作的中间文件的名称,第二个参数是要写入的输出文件的名称。

例如,当一个数据集将用于模式的初始条件,而另一个数据集将用于侧边界条件时,从气象数据集中移除指定层次之外的数据是十分有用的。
这个可以通过在(metgrid程序第一次插值的时间段)提供初始状态数据集,在其它所有时刻的边界状态的数据来完成。
例如,当一组数据集用于模型初始条件,而另一组数据集用于侧边界条件时。这可以通过在第一个时间段内提供由metgrid插值的初始条件数据集,以及所有其他时间的边界条件数据集来实现。如果两个数据集有相同数量的垂直层次,那么不需要做任何工作;然而,当这两个数据集有不同数量的层次,这将是必要的,至少,从具有m层的数据集中删除(m-n)的层次,其中m>n(m和n的是两个数据集的层次)。上述做法的原因(在所有文件中有相同数量的垂直层次的必要性)是因为real.exe程序的局限性,它需要一个恒定数量的垂直层次来插值。

mod_levs实用程序是解决容纳两个或更多具有不同垂直级别数的数据集的问题的一种临时解决方案。如果用户选择使用mod_levs,应该注意的是,虽然在数据集之间的垂直层次的位置不需要匹配,所有数据集应该有一个地面层的数据,并且,当运行real.exe和wrf.exe时,p_top的值必须位于在数据集最低的顶层以下。

C. calc_ecmwf_p.exe

在垂直插值气象场的过程中,real程序要求三维气压和位势高度场与其他大气场在同一层次上。calc_ecmwf_p.exe实用程序可用于创建这些场,以便与ECMWF-sigma层次数据集一起使用。给定地面气压场(或地面压力场的对数)和系数a和B的列表,calc_ecmwf_p.exe就可以计算网格点(i,j)在ECMWF-sigma层的第k层处的压力:Pijk = Ak + Bk*Psfcij。计算气压中使用的系数可以从一个合适的表中复制,该表适用于以下链接之一的数据集中的sigma层次数:

http://www.ecmwf.int/en/forecasts/documentation-and-support/16-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/19-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/31-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/40-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/50-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/60-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/62-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/91-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/137-model-levels

此表应以纯文本形式写入当前工作目录中的文件ecmwf_coeffs;例如,对于16层sigma层次,文件ecmwf_coeffs将包含以下内容:

    0         0.000000      0.000000000
    1      5000.000000      0.000000000
    2      9890.519531      0.001720764
    3     14166.304688      0.013197623
    4     17346.066406      0.042217135
    5     19121.152344      0.093761623
    6     19371.250000      0.169571340
    7     18164.472656      0.268015683
    8     15742.183594      0.384274483
    9     12488.050781      0.510830879
   10      8881.824219      0.638268471
   11      5437.539063      0.756384850
   12      2626.257813      0.855612755
   13       783.296631      0.928746223
   14         0.000000      0.972985268
   15         0.000000      0.992281914
   16         0.000000      1.000000000

此外,如果有土壤高度(或土壤位势)、三维温度场和三维比湿场这些变量,calc_ecmwf_p.exe将计算三维位势高度场,这是在real程序中获得精确垂直插值所需的。

给定ungrib生成的一组中间文件和ecmwf_coeffs文件,calc_ecmwf_p循环遍历namelist.wps中的所有时间段。并且每次生成一个额外的中间文件PRES:YYYY-MM-DD_HH,其中包含每个完整sigma层次的气压和位势高度数据,以及三维相对湿度场。应该将这个中间文件以及ungrib生成的中间数据指定给metgrid,方法是将“PRES”添加到fg_name namelist变量中的前缀列表中。

D. height_ukmo.exe

real程序需要三维气压和位势高度场来垂直插值metgrid程序的输出;然而,来自UKMO统一模型的数据集包含一个三维气压场,但不包含一个位势高度场。因此,可以使用height_ukmo.exe程序计算UKMO Unified Model数据集的位势高度场。height_ukmo.exe程序不需要命令行参数,但读取namelist 中的&metgrid记录以获得ungrib.exe创建的中间文件的前缀;由namelist 中的&metgrid记录的fg_name变量的第一个前缀表示的中间文件预计将包含一个SOILHGT变量,hight_ukmo.exe程序在辅助表的帮助下从该变量计算三维位势高度变量。计算的高度变量被写入一个新的中间文件,该文件的前缀为HGT,然后应该在运行metgrid.exe之前将前缀\' HGT \'添加到namelist中的&metgrid部分中的fg_name变量中。包含辅助表的文件的名称目前硬连接在height_ukmo.exe程序的源代码中,用户负责将WPS/util/src/height_ukmo.F中的文件名更改为与ungrib.exe处理的GRIB数据具有相同层次数目的表名;WPS/util目录中提供了38、50和70层的数据表,文件名分别为vertical_grid_38_20m_G3.txt,vertical_grid_50_20m_63km.txt,和vertical_grid_70_20m_80km.txt。

E. plotgrids.ncl

plotgrids.ncl程序是一个基于NCAR图形的实用程序,其目的是绘制namelist.wps文件中定义的所有嵌套的位置。程序对namelist.wps文件进行操作,因此,可以在不运行任何三个WPS主程序的情况下运行。成功完成后,plotgrids将生成一个选定格式的图形文件(有关对输出格式的更改,请参见plotgrids.ncl脚本),绘制粗网格域占整个绘图框,在网格上绘制带有政治边界的地图轮廓,任何嵌套域都被绘制为矩形,勾勒出每个嵌套的范围。这个实用程序可能非常有用,特别是在域的初始设置期间,此时用户可以通过迭代“编辑namelist.wps文件调整嵌套的位置,运行plotgrid.ncl”,从而确定对巢位置的一组调整。要运行这个程序,只需在命令行中WPS/目录中键入\'ncl util/plotgrids.ncl\'。目前,此实用程序不适用于使用经纬度投影的ARW 网格(例如,当map_proj = \'lat-on\')。

F. g1print.exe

g1print.exe程序的输入参数是GRIB Edition 1文件的名称,程序打印出文件中数据的变量、层次和日期的列表。

G. g2print.exe

类似于类似于g1print.exe, g2print.exe程序将GRIB Edition 2文件的名称作为它唯一的命令行参数。程序打印出文件中数据的字段、级别和日期的列表。, g2print.exe程序将GRIB Edition 2文件的名称作为它唯一的命令行参数。程序打印出文件中数据的字段、级别和日期的列表。

H. rd_intermediate.exe

在命令行中给定一个单一中间格式文件的名称,rd_intermediate.exe程序将打印关于文件中包含的字段的信息。

将气象数据写入中间格式

ungrib程序的作用是将GRIB数据集解码为metgrid能够理解的简单中间格式。如果气象数据不能使用GRIB第1版或GRIB第2版格式,用户有责任将其写入中间文件格式。幸运的是,中间格式相对简单,由一系列未格式化的Fortran写入组成。需要注意的是,这些未格式化的写操作使用大端字节顺序,这通常可以用编译器标记来指定。下面,我们描述WPS中间格式;对SI或MM5中间格式感兴趣的用户可以先熟悉WPS格式,WPS格式非常类似,然后再研究读写所有这三种中间格式的Fortran子例程(metgrid/src/read_met_module.F和metgrid/src/write_met_module.F)。

The role of the ungrib program is to decode GRIB data sets into a simple intermediate format that is understood by metgrid. If meteorological data are not available in GRIB Edition 1 or GRIB Edition 2 formats, the user is responsible for writing such data into the intermediate file format. Fortunately, the intermediate format is relatively simple, consisting of a sequence of unformatted Fortran writes. It is important to note that these unformatted writes use big-endian byte order, which can typically be specified with compiler flags. Below, we describe the WPS intermediate format; users interested in the SI or MM5 intermediate formats can first gain familiarity with the WPS format, which is very similar, and later examine the Fortran subroutines that read and write all three intermediate formats (metgrid/src/read_met_module.F and metgrid/src/write_met_module.F, respectively).

当将数据写入WPS中间格式时,二维字段被写入为实数的矩形数组。三维数组必须在垂直维度上划分为二维数组,二维数组是独立写入的。还应该注意的是,对于全局数据集,必须使用高斯投影或圆柱等距投影,对于区域数据集,可以使用墨卡托投影、兰伯特正形投影、极立体投影或圆柱等距投影。用于以WPS中间格式写入单个二维数组的写入序列如下(注意,并不是下面声明的所有变量都用于数据的给定投影)。

When writing data to the WPS intermediate format, 2-dimensional fields are written as a rectangular array of real values. 3-dimensional arrays must be split across the vertical dimension into 2-dimensional arrays, which are written independently. It should also be noted that, for global data sets, either a Gaussian or cylindrical equidistant projection must be used, and for regional data sets, either a Mercator, Lambert conformal, polar stereographic, or cylindrical equidistant may be used. The sequence of writes used to write a single 2-dimensional array in the WPS intermediate format is as follows (note that not all of the variables declared below are used for a given projection of the data).


integer :: version             ! Format version (must =5 for WPS format)
integer :: nx, ny              ! x- and y-dimensions of 2-d array
integer :: iproj               ! Code for projection of data in array:
                               !       0 = cylindrical equidistant
                               !       1 = Mercator
                               !       3 = Lambert conformal conic
                               !       4 = Gaussian (global only!)
                               !       5 = Polar stereographic
real :: nlats                  ! Number of latitudes north of equator
                               !       (for Gaussian grids)
real :: xfcst                  ! Forecast hour of data
real :: xlvl                   ! Vertical level of data in 2-d array
real :: startlat, startlon     ! Lat/lon of point in array indicated by
                               !       startloc string
real :: deltalat, deltalon     ! Grid spacing, degrees
real :: dx, dy                 ! Grid spacing, km
real :: xlonc                  ! Standard longitude of projection
real :: truelat1, truelat2     ! True latitudes of projection
real :: earth_radius           ! Earth radius, km
real, dimension(nx,ny) :: slab ! The 2-d array holding the data
logical :: is_wind_grid_rel    ! Flag indicating whether winds are                                         
                               !       relative to source grid (TRUE) or
                               !       relative to earth (FALSE)
character (len=8)  :: startloc ! Which point in array is given by
                               !       startlat/startlon; set either                                       
                               !       to \'SWCORNER\' or \'CENTER  \'
character (len=9)  :: field    ! Name of the field
character (len=24) :: hdate    ! Valid date for data YYYY:MM:DD_HH:00:00
character (len=25) :: units    ! Units of data
character (len=32) :: map_source  !  Source model / originating center
character (len=46) :: desc     ! Short description of data
 
   
!  1) WRITE FORMAT VERSION
write(unit=ounit) version
 
!  2) WRITE METADATA
! Cylindrical equidistant
if (iproj == 0) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, &
                        deltalat, deltalon, earth_radius
 
! Mercator
else if (iproj == 1) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, dx, dy, &
                        truelat1, earth_radius
 
! Lambert conformal
else if (iproj == 3) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, dx, dy, &
                        xlonc, truelat1, truelat2, earth_radius
 
! Gaussian
else if (iproj == 4) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, &
                               nlats, deltalon, earth_radius
 
! Polar stereographic
else if (iproj == 5) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, dx, dy, &
                        xlonc, truelat1, earth_radius
    
end if
 
!  3) WRITE WIND ROTATION FLAG
write(unit=ounit) is_wind_grid_rel
 
!  4) WRITE 2-D ARRAY OF DATA
write(unit=ounit) slab

运行WRF所需的气象场

为了成功初始化WRF模拟real.exe文件预处理器要求在系统输出中至少有一组气象和地表场metgrid.exe程序。因此,这些必填字段必须在由处理的中间文件中可用metgrid.exe. 下表中描述了一组必填字段。
In order to successfully initialize a WRF simulation, the real.exe pre-processor requires a minimum set of meteorological and land-surface fields to be present in the output from the metgrid.exe program. Accordingly, these required fields must be available in the intermediate files processed by metgrid.exe. The set of required fields is described in the table, below.

Field name in intermediate file

Units

Description

Notes

TT

K

3-d air temperature

 

RH

%

3-d relative humidity

Not needed if SPECHUMD is available

SPECHUMD

kg kg-1

3-d specific humidity

Not needed if RH is available

UU

m s-1

3-d wind u-component

 

VV

m s-1

3-d wind v-component

 

GHT

m

3-d geopotential height

 

PRESSURE

Pa

3-d pressure

Only needed for non-isobaric datasets

PSFC

Pa

Surface pressure

 

PMSL

Pa

Mean sea-level pressure

 

SKINTEMP

K

Skin temperature

 

SOILHGT

m

Soil height

 

TT

K

2-meter air temperature

 

RH

%

2-meter relative humidity

Not needed if SPECHUMD is available

SPECHUMD

kg kg-1

2-meter specific humidity

Not needed if RH is available

UU

m s-1

10-meter wind u-component

 

VV

m s-1

10-meter wind v-component

 

LANDSEA

fraction

Land-sea mask (0=water, 1=land)

 

SMtttbbb

m3 m-3

Soil moisture

\'ttt\' is the layer top depth in cm, and \'bbb\' is the layer bottom depth in cm

STtttbbb

K

Soil temperature

SOILMmmm

kg m-3

Soil moisture

\'mmm\' is the level depth in cm, not needed if SMtttbbb available

SOILTmmm

K

Soil temperature

Using MPAS Output for WRF Initial and Lateral Boundary Conditions 使用MPAS输出作为WRF初始和侧边界条件

从WPS的v3.9版本开始,metgrid.exe程序能够读取来自跨尺度预测模型(MPAS;https://mpas-dev.github.io/);然后metgrid.exe程序可以水平地将MPAS字段直接插入到geogrid.exe程序定义的任何域,以产生WRF real.exe程序可用的输出文件,其方式与从中间文件插入metgrid输出完全相同。这样,MPAS的输出可以用来为WRF提供初始和横向边界条件。

Beginning with the v3.9 release of the WPS, the metgrid.exe program is capable of reading native, unstructured mesh output in netCDF format from the Model for Prediction Across Scales (MPAS; https://mpas-dev.github.io/); the metgrid.exe program can then horizontally interpolate the MPAS fields directly to any domain defined by the geogrid.exe program to produce output files that are usable by the WRF real.exe program in exatly the same way as metgrid output interpolated from intermediate files. In this way, output from MPAS may be used to provide initial and lateral boundary conditions for WRF.

当运行MPAS模拟时,输出流必须设置为包含初始化WRF模拟所需的最小字段集。对于MPAS v5,下面的输出流应该足够了。x和以后的代码。
When running an MPAS simulation, an output stream must be set up to contain the minimum set of fields necessary to initialize a WRF simulation. The following output stream should be sufficient with the MPAS v5.x and later code.

<stream name="wrf_ic_bc"
        type="output"
        filename_template="MPAS.$Y-$M-$D_$h.nc"
        output_interval="3:00:00" > 

 <var name="xtime"/>
 <var_array name="scalars"/>
 <var name="pressure"/>
 <var name="zgrid"/>
 <var name="theta"/>
 <var name="uReconstructZonal"/>
 <var name="uReconstructMeridional"/>
 <var name="u10"/>
 <var name="v10"/>
 <var name="q2"/>
 <var name="t2m"/>
 <var name="skintemp"/>
 <var name="surface_pressure"/>
 <var name="mslp"/>
 <var name="tslb"/>
 <var name="smois"/> 

</stream>

After having run MPAS with a suitable output stream defined, a set of netCDF files containing fields on the native MPAS mesh will have been produced. Because these files do not contain fields describing the locations, geometry, and connectivity of the MPAS grid cells, this information must be provided to the metgrid program with a “static” file from the MPAS simulation. Therefore, it is necessary to specify MPAS netCDF files (prefixed with ‘mpas:’) in the &metgrid namelist record with both the constants_name and fg_name variables, e.g.,

&metgrid
 constants_name = ‘mpas:static.nc’
 fg_name = ‘mpas:MPAS’
/

In the above example, the metgrid.exe program would first read the MPAS ‘static.nc’ file to read mesh information and compute remapping weights from the MPAS mesh to the WRF domain defined by the geogrid.exe program, then all time periods of the MPAS files with a prefix of ‘MPAS’ (and a suffix of YYYY-MM-DD_HH.nc) would be processed. The real.exe program can then be run as usual.

Data from intermediate files created by the ungrib.exe program can be combined with MPAS data by the metgrid program. This may be useful, e.g., to use SST, sea ice, or land-surface fields from another source. An example of combining MPAS data with ERA-Interim intermediate files with soil data (with the prefix ‘ERAI_SOIL’) is shown below.

&metgrid
  constants_name = ‘mpas:static.nc’
  fg_name = ‘mpas:MPAS’, ‘ERAI_SOIL’
/

Because the MPAS ‘zgrid’ field does not change in time, it can be omitted from the MPAS periodic output stream; in this case, however, the ‘zgrid’ field must be placed in its own netCDF file that must also define the dimension ‘Time’ as a netCDF unlimited dimension. Then, this file (say, ‘zgrid.nc’) can be supplied to the metgrid program using the constants_name namelist variable, e.g.,

&metgrid
 constants_name = ‘mpas:static.nc’, ‘mpas:zgrid.nc’
 fg_name = ‘mpas:MPAS’
/

Placing the ‘zgrid’ field in its own file can save considerable space when long MPAS simulations are run, or when the output stream to be used as WRF initial and boundary conditions is written out at high temporal frequency. The python script, below, may serve as an example of how to extract the ‘zgrid’ field to its own netCDF file.

from netCDF4 import Dataset

fin = Dataset(\'init.nc\')
fout = Dataset(\'zgrid.nc\',\'w\',format=\'NETCDF3_64BIT\')
 
nCells = fin.dimensions[\'nCells\'].size
nVertLevelsP1 = fin.dimensions[\'nVertLevelsP1\'].size
 
fout.createDimension(dimname=\'Time\',size=None)
fout.createDimension(dimname=\'nCells\',size=nCells)
fout.createDimension(dimname=\'nVertLevelsP1\',size=nVertLevelsP1)
fout.createVariable(varname=\'zgrid\',datatype=\'f\',dimensions=(\'nCells\', \'nVertLevelsP1\'))
fout.variables[\'zgrid\'][:] = fin.variables[\'zgrid\'][:]
fout.close()
fin.close()

It is worth noting that the use of native MPAS output with metgrid.exe has not been thoroughly tested for parallel (i.e., “dmpar”) builds of the WPS; as of the WPS v4.0 release, it is therefore recommended to run metgrid.exe in serial when processing MPAS datasets.

Also, in cases of large MPAS meshes, it may be necessary to increase the value of two constants in the metgrid code that are used to statically allocate several datastructures used in the computation of remapping weights from the MPAS mesh to the WRF domain. These two constants, shown below, are located in the WPS/src/metgrid/remapper.F file.

! should be at least (earth circumference / minimum grid distance)
integer, parameter :: max_queue_length    = 2700
 
! should be at least (nCells/32)
integer, parameter :: max_dictionary_size = 82000  

After changing the value of these constants, metgrid must be recompiled.

------------恢复内容开始------------
参考自 WRF用户手册http://www2.mmm.ucar.edu/wrf/users/docs/user_guide_V4/WRFUsersGuide.pdf第三章
3. The WRF Preprocessing System (WPS)

  • Introduction ................................................................................. 3-1
  • Function of Each WPS Program ................................................. 3-2
  • Installing the WPS ...................................................................... 3-5
  • Running the WPS ....................................................................... 3-8
  • Creating Nested Domains with the WPS .................................. 3-20
  • Selecting Between USGS and MODIS-based Land Use Data .......................................................................... 3-22
  • Selecting Static Data for the Gravity Wave Drag Scheme ........ 3-23
  • Using Multiple Meteorological Data Sources ............................ 3-23
  • Using Non-isobaric Meteorological Datasets .............................3-26
  • Alternative Initialization of Lake SSTs ............................. 3-27
  • Parallelism in the WPS ............................................................. 3-28
  • Checking WPS Output .............................................................. 3-29
  • WPS Utility Programs ............................................................... 3-30
  • Writing Meteorological Data to the Intermediate Format ........... 3-34
  • Required Meteorological Fields for Running WRF.....................3-36
  • Using MPAS Output for WRF Initial and Boundary Conditions..3-37
  • Creating and Editing Vtables .................................................... 3-39
  • Writing Static Data to the Geogrid Binary Format ..................... 3-41
  • Creating an Urban Fraction Field from NLCD Data .................. 3-44
  • Description of Namelist Variables ............................................. 3-46
  • Description of GEOGRID.TBL Options ..................................... 3-52
  • Description of index Options ..................................................... 3-55
  • Description of METGRID.TBL Options ..................................... 3-58
  • Available Interpolation Options in Geogrid and Metgrid ............ 3-61
  • Land Use and Soil Categories in the Static Data ...................... 3-64
  • WPS Output Fields ................................................................... 3-66

WPS中的并行

如果WPS要处理的区域太大,无法容纳在单个CPU的内存中,那么可以在分布式内存配置中运行geogrid和metgrid程序。为了编译geogrid和metgrid以执行分布式内存,用户必须在计算机上安装MPI库,并且必须使用“DM parallel”配置选项编译WPS。编译成功后,geogrid和metgrid程序可以使用mpirun或mpiexec命令运行,也可以通过批处理队列系统运行,具体取决于机器。

如前所述,ungrib程序不适用于并行化,而且,ungrib处理的内存需求独立于geogrid和metgrid的内存需求;因此,不管配置期间是否采用“DM parallel”配置选项,ungrib总是为单个处理器编译并在单个CPU上运行。

每个标准WRF I/O API格式(NetCDF、GRIB1、binary)都有一个对应的并行格式,其编号是通过将标准格式的io_form 值(即io_form_geogrid和io_form_metgrid的值)加100来给出的。不必使用并行io_form,但当使用并行io_form形式时,每个CPU都会将其输入/输出读/写到一个单独的文件中,该文件的名称就是是“串行执行期间使用的名称”+“四位的处理器ID”。例如,在io_form_geogrid=102的四个处理器上运行geogrid将为粗网格创建名为geo_em.d01.nc.0000、geo_em.d01.nc.0001、geo_em.d01.nc.0002和geo_em.d01.nc.0003的输出文件。

在分布式内存执行期间,模型域被分解为矩形块(patches),每个处理器处理单个块。当从WRF I/O API格式读/写时,每个处理器只读/写各自对应的块。因此,如果geogrid的输出选择的是并行io形式,那么运行metgrid时也必须选择相同数量的处理器。类似地,如果为metgrid输出文件选择了并行io形式,则运行real程序时必须使用相同数量的处理器。当然,当在多个处理器上运行时,仍然可以使用标准的io_form,在这种情况下,模型域的所有数据都将在 输入/输出 时 分发/收集。最后,当在多个处理器上运行geogrid或metgrid时,每个处理器都将编写自己的日志文件,日志文件名将附加与用于I/o API文件的相同的四位处理器ID号。

检查WPS输出

在运行WPS时,检查程序生成的输出可能会有所帮助。例如,在确定嵌套的位置时,查看插值的静态地理数据和纬度/经度变量可能会有所帮助。另一个例子是,在将新的数据源(静态数据或气象数据)导入WPS时,检查生成的插值场通常是有帮助的,以便对geogrid或metgrid使用的插值方法进行调整。

如果把geogrid和metgrid I/O 格式设置成NetCDF格式,就可以使用各种读取NetCDF数据的可视化工具来检查geogrid处理的区域文件或metgrid生成的水平插值气象场。为了将geogrid和metgrid的文件格式设置为NetCDF,用户应将WPS namelist文件中的 io_form_geogrid 和io_form_metgrid设置成2(注意:2是这些选项的默认设置):

&share
 io_form_geogrid = 2,
/

&metgrid
 io_form_metgrid = 2,
/

在这些可用的工具中,ncdump、ncview和新的RIP4程序可能会引起兴趣。ncdump程序是一个与NetCDF库一起分发的实用小工具,它能输出NetCDF文件中的变量和属性。这对于检查geogrid区域文件中的网格参数(例如,东西向维度、南北向维度或域中心点)尤其有用。ncview程序提供了一种交互式方式来查看NetCDF文件中的变量。此外,希望生成适合出版的图的用户可能会对新版的RIP4程序的感兴趣。新版的RIP4能够绘制水平等高线,地图背景,并在同一个绘图叠加多个变量。

ungrib程序的输出文件总是以简单的二进制格式(‘WPS’、‘SI’或‘MM5’)编写的,因此无法使用查看NetCDF文件的软件查看。但是,随WPS源代码一起,提供了基于NCAR图形的实用程序plotfmt。这个实用程序可以绘制的等高线图。如果正确安装了NCAR图形库,则在编译WPS时,plotfmt程序将与其他实用程序一起自动编译。(注意:plotfmt和plotgrids程序在WRF4.2.1中不是自动编译的,需要执行./compile plotfmt 和./compile plotgrids命令手动编译)

WPS 实用程序

除了三个主要的WPS程序geogrid、ungrib和metgrid之外,还有许多WPS附带的实用程序,它们被编译在util目录中。这些实用程序可用于检查数据文件、可视化嵌套域的位置、计算气压场和计算平均表面温度场。

A. avg_tsfc.exe

avg_tsfc.exe文件程序以中间格式计算给定输入文件的日平均表面温度。基于namelist.wps文件中“share”部分中指定的日期范围,并考虑中间文件之间的间隔,avg_tsfc.exe文件将使用尽可能多的完整天数的数据来计算平均值,从namelist中指定的开始日期开始。如如果一天的数据不完整,则不会写入输出文件,一旦确定,程序将立即停止。类似地,对于不能作为完整24小时周期的一部分使用的日期的任何中间文件都将被忽略;例如,如果在6小时间隔内有5个中间文件可用,则最后一个文件将被忽略。计算出的平均值变量使用与输入文件相同的中间格式版本写入名为TAVGSFC的新文件。然后,metgrid可以通过在namelist中的“metgrid” 部分中将constants_name变量设定成“TAVGSFC”来获取每日平均表面温度场。

B. mod_levs.exe

mod_levs.exe程序用于从中间格式文件中删除数据的层次。在namelist.wps文件中有一个新的变量,用来说明哪些层次需要保留。

&mod_levs
 press_pa = 201300 , 200100 , 100000 ,
             95000 ,  90000 ,
             85000 ,  80000 ,
             75000 ,  70000 ,
             65000 ,  60000 ,
             55000 ,  50000 ,
             45000 ,  40000 ,
             35000 ,  30000 ,
             25000 ,  20000 ,
             15000 ,  10000 ,
              5000 ,   1000
/

在&mod_levs namelist记录中,变量press_pa用于指定要保留的层次列表;指定的层次应与中间格式文件中xlvl的值匹配(有关中间文件场的更多信息,请参阅WPS中间格式的说明)。mod_levs程序采用两个命令行参数作为输入。第一个参数是要操作的中间文件的名称,第二个参数是要写入的输出文件的名称。

例如,当一个数据集将用于模式的初始条件,而另一个数据集将用于侧边界条件时,从气象数据集中移除指定层次之外的数据是十分有用的。
这个可以通过在(metgrid程序第一次插值的时间段)提供初始状态数据集,在其它所有时刻的边界状态的数据来完成。
例如,当一组数据集用于模型初始条件,而另一组数据集用于侧边界条件时。这可以通过在第一个时间段内提供由metgrid插值的初始条件数据集,以及所有其他时间的边界条件数据集来实现。如果两个数据集有相同数量的垂直层次,那么不需要做任何工作;然而,当这两个数据集有不同数量的层次,这将是必要的,至少,从具有m层的数据集中删除(m-n)的层次,其中m>n(m和n的是两个数据集的层次)。上述做法的原因(在所有文件中有相同数量的垂直层次的必要性)是因为real.exe程序的局限性,它需要一个恒定数量的垂直层次来插值。

mod_levs实用程序是解决容纳两个或更多具有不同垂直级别数的数据集的问题的一种临时解决方案。如果用户选择使用mod_levs,应该注意的是,虽然在数据集之间的垂直层次的位置不需要匹配,所有数据集应该有一个地面层的数据,并且,当运行real.exe和wrf.exe时,p_top的值必须位于在数据集最低的顶层以下。

C. calc_ecmwf_p.exe

在垂直插值气象场的过程中,real程序要求三维气压和位势高度场与其他大气场在同一层次上。calc_ecmwf_p.exe实用程序可用于创建这些场,以便与ECMWF-sigma层次数据集一起使用。给定地面气压场(或地面压力场的对数)和系数a和B的列表,calc_ecmwf_p.exe就可以计算网格点(i,j)在ECMWF-sigma层的第k层处的压力:Pijk = Ak + Bk*Psfcij。计算气压中使用的系数可以从一个合适的表中复制,该表适用于以下链接之一的数据集中的sigma层次数:

http://www.ecmwf.int/en/forecasts/documentation-and-support/16-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/19-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/31-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/40-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/50-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/60-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/62-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/91-model-levels

http://www.ecmwf.int/en/forecasts/documentation-and-support/137-model-levels

此表应以纯文本形式写入当前工作目录中的文件ecmwf_coeffs;例如,对于16层sigma层次,文件ecmwf_coeffs将包含以下内容:

    0         0.000000      0.000000000
    1      5000.000000      0.000000000
    2      9890.519531      0.001720764
    3     14166.304688      0.013197623
    4     17346.066406      0.042217135
    5     19121.152344      0.093761623
    6     19371.250000      0.169571340
    7     18164.472656      0.268015683
    8     15742.183594      0.384274483
    9     12488.050781      0.510830879
   10      8881.824219      0.638268471
   11      5437.539063      0.756384850
   12      2626.257813      0.855612755
   13       783.296631      0.928746223
   14         0.000000      0.972985268
   15         0.000000      0.992281914
   16         0.000000      1.000000000

此外,如果有土壤高度(或土壤位势)、三维温度场和三维比湿场这些变量,calc_ecmwf_p.exe将计算三维位势高度场,这是在real程序中获得精确垂直插值所需的。

给定ungrib生成的一组中间文件和ecmwf_coeffs文件,calc_ecmwf_p循环遍历namelist.wps中的所有时间段。并且每次生成一个额外的中间文件PRES:YYYY-MM-DD_HH,其中包含每个完整sigma层次的气压和位势高度数据,以及三维相对湿度场。应该将这个中间文件以及ungrib生成的中间数据指定给metgrid,方法是将“PRES”添加到fg_name namelist变量中的前缀列表中。

D. height_ukmo.exe

real程序需要三维气压和位势高度场来垂直插值metgrid程序的输出;然而,来自UKMO统一模型的数据集包含一个三维气压场,但不包含一个位势高度场。因此,可以使用height_ukmo.exe程序计算UKMO Unified Model数据集的位势高度场。height_ukmo.exe程序不需要命令行参数,但读取namelist 中的&metgrid记录以获得ungrib.exe创建的中间文件的前缀;由namelist 中的&metgrid记录的fg_name变量的第一个前缀表示的中间文件预计将包含一个SOILHGT变量,hight_ukmo.exe程序在辅助表的帮助下从该变量计算三维位势高度变量。计算的高度变量被写入一个新的中间文件,该文件的前缀为HGT,然后应该在运行metgrid.exe之前将前缀\' HGT \'添加到namelist中的&metgrid部分中的fg_name变量中。包含辅助表的文件的名称目前硬连接在height_ukmo.exe程序的源代码中,用户负责将WPS/util/src/height_ukmo.F中的文件名更改为与ungrib.exe处理的GRIB数据具有相同层次数目的表名;WPS/util目录中提供了38、50和70层的数据表,文件名分别为vertical_grid_38_20m_G3.txt,vertical_grid_50_20m_63km.txt,和vertical_grid_70_20m_80km.txt。

E. plotgrids.ncl

plotgrids.ncl程序是一个基于NCAR图形的实用程序,其目的是绘制namelist.wps文件中定义的所有嵌套的位置。程序对namelist.wps文件进行操作,因此,可以在不运行任何三个WPS主程序的情况下运行。成功完成后,plotgrids将生成一个选定格式的图形文件(有关对输出格式的更改,请参见plotgrids.ncl脚本),绘制粗网格域占整个绘图框,在网格上绘制带有政治边界的地图轮廓,任何嵌套域都被绘制为矩形,勾勒出每个嵌套的范围。这个实用程序可能非常有用,特别是在域的初始设置期间,此时用户可以通过迭代“编辑namelist.wps文件调整嵌套的位置,运行plotgrid.ncl”,从而确定对巢位置的一组调整。要运行这个程序,只需在命令行中WPS/目录中键入\'ncl util/plotgrids.ncl\'。目前,此实用程序不适用于使用经纬度投影的ARW 网格(例如,当map_proj = \'lat-on\')。

F. g1print.exe

g1print.exe程序的输入参数是GRIB Edition 1文件的名称,程序打印出文件中数据的变量、层次和日期的列表。

G. g2print.exe

类似于类似于g1print.exe, g2print.exe程序将GRIB Edition 2文件的名称作为它唯一的命令行参数。程序打印出文件中数据的字段、级别和日期的列表。, g2print.exe程序将GRIB Edition 2文件的名称作为它唯一的命令行参数。程序打印出文件中数据的字段、级别和日期的列表。

H. rd_intermediate.exe

在命令行中给定一个单一中间格式文件的名称,rd_intermediate.exe程序将打印关于文件中包含的字段的信息。

将气象数据写入中间格式

ungrib程序的作用是将GRIB数据集解码为metgrid能够读取的简单中间格式。如果气象数据不是GRIB1或GRIB2版的格式,用户应当将自行其写入中间文件格式。幸运的是,中间格式相对简单,由一系列未格式化的Fortran 写操作完成。需要注意的是,这些未格式化的写操作使用大端字节序,这通常可以用编译器标记来指定。下面,我们描述WPS中间格式;对SI或MM5中间格式感兴趣的用户可以先熟悉WPS格式(这与它们非常类似),然后再研究读写所有这三种中间格式的Fortran子程序(metgrid/src/read_met_module.F和metgrid/src/write_met_module.F)。

当将数据写入WPS中间格式时,二维变量被写入矩形实数数组。三维数组必须在垂直维度上划分为二维数组,然后独立写入这些二维数组的。还应该注意的是,对于全球数据集,必须使用高斯投影或圆柱等距投影,对于区域数据集,可以使用墨卡托投影、兰伯特正形投影、极立体投影或圆柱等距投影。用于以WPS中间格式写入单个二维数组的写入顺序如下(注意,并不是下面声明的所有变量都用于数据的给定投影)。


integer :: version             ! Format version (must =5 for WPS format) !格式版本
integer :: nx, ny              ! x- and y-dimensions of 2-d array        !2维数组的x和y维数
integer :: iproj               ! Code for projection of data in array:   !数组中投影代号
                               !       0 = cylindrical equidistant
                               !       1 = Mercator
                               !       3 = Lambert conformal conic
                               !       4 = Gaussian (global only!)
                               !       5 = Polar stereographic
real :: nlats                  ! Number of latitudes north of equator
                               !       (for Gaussian grids)
real :: xfcst                  ! Forecast hour of data
real :: xlvl                   ! Vertical level of data in 2-d array
real :: startlat, startlon     ! Lat/lon of point in array indicated by
                               !       startloc string
real :: deltalat, deltalon     ! Grid spacing, degrees
real :: dx, dy                 ! Grid spacing, km
real :: xlonc                  ! Standard longitude of projection
real :: truelat1, truelat2     ! True latitudes of projection
real :: earth_radius           ! Earth radius, km
real, dimension(nx,ny) :: slab ! The 2-d array holding the data
logical :: is_wind_grid_rel    ! Flag indicating whether winds are                                         
                               !       relative to source grid (TRUE) or
                               !       relative to earth (FALSE)
character (len=8)  :: startloc ! Which point in array is given by
                               !       startlat/startlon; set either                                       
                               !       to \'SWCORNER\' or \'CENTER  \'
character (len=9)  :: field    ! Name of the field
character (len=24) :: hdate    ! Valid date for data YYYY:MM:DD_HH:00:00
character (len=25) :: units    ! Units of data
character (len=32) :: map_source  !  Source model / originating center
character (len=46) :: desc     ! Short description of data
 
   
!  1) WRITE FORMAT VERSION
write(unit=ounit) version
 
!  2) WRITE METADATA
! Cylindrical equidistant
if (iproj == 0) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, &
                        deltalat, deltalon, earth_radius
 
! Mercator
else if (iproj == 1) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, dx, dy, &
                        truelat1, earth_radius
 
! Lambert conformal
else if (iproj == 3) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, dx, dy, &
                        xlonc, truelat1, truelat2, earth_radius
 
! Gaussian
else if (iproj == 4) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, &
                               nlats, deltalon, earth_radius
 
! Polar stereographic
else if (iproj == 5) then
      write(unit=ounit) hdate, xfcst, map_source, field, &
                        units, desc, xlvl, nx, ny, iproj
      write(unit=ounit) startloc, startlat, startlon, dx, dy, &
                        xlonc, truelat1, earth_radius
    
end if
 
!  3) WRITE WIND ROTATION FLAG
write(unit=ounit) is_wind_grid_rel
 
!  4) WRITE 2-D ARRAY OF DATA
write(unit=ounit) slab

运行WRF所需的气象场

为了成功进行WRF模拟初始化,real.exe程序要求在metgrid.exe程序的输出中至少有一组气象和地表场。因此,这些要求的变量必须在metgrid.exe处理的中间文件中出现。下表中描述了一组必填变量。
In order to successfully initialize a WRF simulation, the real.exe pre-processor requires a minimum set of meteorological and land-surface fields to be present in the output from the metgrid.exe program. Accordingly, these required fields must be available in the intermediate files processed by metgrid.exe. The set of required fields is described in the table, below.

Field name in intermediate file

Units

Description

Notes

TT

K

3-d air temperature

 

RH

%

3-d relative humidity

Not needed if SPECHUMD is available

SPECHUMD

kg kg-1

3-d specific humidity

Not needed if RH is available

UU

m s-1

3-d wind u-component

 

VV

m s-1

3-d wind v-component

 

GHT

m

3-d geopotential height

 

PRESSURE

Pa

3-d pressure

Only needed for non-isobaric datasets

PSFC

Pa

Surface pressure

 

PMSL

Pa

Mean sea-level pressure

 

SKINTEMP

K

Skin temperature

 

SOILHGT

m

Soil height

 

TT

K

2-meter air temperature

 

RH

%

2-meter relative humidity

Not needed if SPECHUMD is available

SPECHUMD

kg kg-1

2-meter specific humidity

Not needed if RH is available

UU

m s-1

10-meter wind u-component

 

VV

m s-1

10-meter wind v-component

 

LANDSEA

fraction

Land-sea mask (0=water, 1=land)

 

SMtttbbb

m3 m-3

Soil moisture

\'ttt\' is the layer top depth in cm, and \'bbb\' is the layer bottom depth in cm

STtttbbb

K

Soil temperature

SOILMmmm

kg m-3

Soil moisture

\'mmm\' is the level depth in cm, not needed if SMtttbbb available

SOILTmmm

K

Soil temperature

使用MPAS输出作为WRF初始和侧边界条件

从WPS的v3.9版本开始,metgrid.exe程序能够读取来自跨尺度预测模型(Model for Prediction Across Scales, MPAS;https://mpas-dev.github.io/)的自定义的无结构化网格的netCDF格式的输出文件;然后metgrid.exe程序可以水平地将MPAS变量直接插入到geogrid.exe程序定义的任何网格,以产生WRF real.exe程序可用的输出文件,其方式与metgrid从中间文件插值后的输出输出完全相同。这样,MPAS的输出可以用来为WRF提供初始和横向边界条件。

当运行MPAS模拟时,输出流必须设置为包含WRF模拟初始化所需的最小变量的集合。对于MPAS v5.x和以后的版本的代码,下面的输出流应该足够了。

<stream name="wrf_ic_bc"
        type="output"
        filename_template="MPAS.$Y-$M-$D_$h.nc"
        output_interval="3:00:00" > 

 <var name="xtime"/>
 <var_array name="scalars"/>
 <var name="pressure"/>
 <var name="zgrid"/>
 <var name="theta"/>
 <var name="uReconstructZonal"/>
 <var name="uReconstructMeridional"/>
 <var name="u10"/>
 <var name="v10"/>
 <var name="q2"/>
 <var name="t2m"/>
 <var name="skintemp"/>
 <var name="surface_pressure"/>
 <var name="mslp"/>
 <var name="tslb"/>
 <var name="smois"/> 

</stream>

在使用定义的适当输出流运行MPAS之后,将生成一组netCDF文件,其中包含本机MPAS网格上的变量。由于这些文件不包含描述MPAS网格单元位置、几何结构和连接性的变量场,因此必须使用MPAS模拟中的“静态”文件将此信息提供给metgrid程序。因此,有必要在&metgrid namelist记录中指定MPAS netCDF文件(前缀为“MPAS:”),其中包含常量constants_name 和fg_name 变量,例如,

&metgrid
 constants_name = ‘mpas:static.nc’
 fg_name = ‘mpas:MPAS’
/

在上面的例子中,metgrid.exe程序将首先读取MPAS的‘static.nc’文件,从而以读取网格信息并计算从MPAS网格到geogrid.exe程序定义的WRF网格的重映射权重,然后将处理前缀为\'MPAS\'(和后缀为YYYY-MM-DD_HH.nc)的MPAS文件的所有时间。real.exe程序可以像往常一样运行。

ungrib.exe程序创建的中间文件中的数据可以与metgrid程序的MPAS数据相结合。这可能是有用的,例如,利用其他来源的海表温度、海冰或陆地表面场。下面显示了一个将MPAS数据与ERA-Interim中间文件与土壤数据(前缀为\'ERAI_SOIL \')相结合的示例。

&metgrid
  constants_name = ‘mpas:static.nc’
  fg_name = ‘mpas:MPAS’, ‘ERAI_SOIL’
/

由于MPAS的\'zgrid\'场不随时间变化,它可以从MPAS周期性输出流中省略;然而,在这种情况下,\'zgrid\'场必须放在它自己的netCDF文件中,该文件还必须将维度\'Time\'定义为netCDF无限维度(unlimited dimension)。然后,这个文件(例如,\'zgrid.nc\')才可以使用constants_name namelist变量提供给metgrid程序,例如,

&metgrid
 constants_name = ‘mpas:static.nc’, ‘mpas:zgrid.nc’
 fg_name = ‘mpas:MPAS’
/

当运行长时间的MPAS模拟时,或当输出流被用作WRF的初始和边界条件以较高时间频率输出时,将“zgrid”变量放在它自己的文件中可以节省相当大的空间。下面的python脚本可以作为示例,演示如何将\'zgrid \'变量解压缩到它自己的netCDF文件中。

from netCDF4 import Dataset

fin = Dataset(\'init.nc\')
fout = Dataset(\'zgrid.nc\',\'w\',format=\'NETCDF3_64BIT\')
 
nCells = fin.dimensions[\'nCells\'].size
nVertLevelsP1 = fin.dimensions[\'nVertLevelsP1\'].size
 
fout.createDimension(dimname=\'Time\',size=None)
fout.createDimension(dimname=\'nCells\',size=nCells)
fout.createDimension(dimname=\'nVertLevelsP1\',size=nVertLevelsP1)
fout.createVariable(varname=\'zgrid\',datatype=\'f\',dimensions=(\'nCells\', \'nVertLevelsP1\'))
fout.variables[\'zgrid\'][:] = fin.variables[\'zgrid\'][:]
fout.close()
fin.close()

值得注意的是,还没有彻底测试使用并行(即“dmpar”)编译的WPS程序,用metgrid.exe程序中使用本地MPAS输出;从WPS v4.0版本开始,建议在处理MPAS数据集时串行运行metgrid.exe。

此外,在大型MPAS网格的情况下,可能需要增加metgrid代码中两个常量的值,这两个常量用于静态分配几个数据结构,这些数据结构用于计算从MPAS网格到WRF域的重映射权值。下面显示的这两个常量位于WPS/src/metgrid/remapper.F文件中。

! should be at least (earth circumference / minimum grid distance)
integer, parameter :: max_queue_length    = 2700
 
! should be at least (nCells/32)
integer, parameter :: max_dictionary_size = 82000  

在更改这些常量的值之后,必须重新编译metgrid。