page header
 

Running 4D-VAR

Reference: Download the tutorial presentation

source code

Get the pre-compiled code, if you have not done so.

WRFDA/var/build/da_wrfvar.exe

is the executable that will be used in the 4D-VAR session. The pre-compiled code was compiled for 4DVAR, so if you are using code you compiled code, make sure this executable was compiled for 4DVAR, or 4DVAR assimilation will not work!

The pre-compiled code was compiled for 4DVAR, so if you are using code you compiled yourself, make sure this executable was compiled for 4DVAR, or 4DVAR assimilation will not work! Click here to compile the code for 4DVAR, otherwise follow the above link to get the pre-compiled code.


Choice of your working directory

We recommend running each session in a separate directory, so that it will be easier to check for the necessary input files and look for what output files are created after a successful run.

We recommend you create /classroom/users/${USER}/DA/4dvar and cd there to be your working directory for this session.

mkdir /classroom/users/${USER}/DA/4dvar
cd /classroom/users/${USER}/DA/4dvar

Input data

For running 3D-VAR, the 3 major input files are observations (ob.ascii), background error statistics (be.dat) and first guess (fg). For 4D-VAR, the similar concept holds except that now the observations need to be processed into multiple time-slot files.

This case utilizes a western Pacific, 51x51 gridpoints, 31 vertical levels, and 60km resolution (it can be found at /classroom/wrfhelp/DATA/WRFDA/4dvar). This is a much lower resolution than should normally be run to see good results; the test is kept small for tutorial purposes. The exact area of the domain is shown at right.

It features Tropical Storm Nanmadol striking southern Japan on July 04, 2017. Due to the low resolution, the typhoon is not well-resolved in this case, but you should be able to see it in the wind field with the ncview utility.

Domain of this test case
  • Observations

    You should already have created observation files for this case in the obsproc practice; if you haven't, go back and finish the exercise.

  • First guess

    /classroom/wrfhelp/DATA/WRFDA/4dvar/rc/2017070400/wrfinput_d01
    /classroom/wrfhelp/DATA/WRFDA/4dvar/rc/2017070400/wrfbdy_d01

  • Background error statistics

    For this exercise, we will use the built-in CV3 option (included in the source code under /classroom/users/${USER}/DA/WRFDA/var/run/be.dat.cv3)

Linking files

Compared to 3DVAR, several more input files are necessary for 4DVAR runs. Most of these are static data files, necessary for running the nonlinear model as part of the 4DVAR assimilation.

ln -fs /classroom/users/${USER}/DA/WRFDA/run/RRTM_DATA_DBL ./RRTM_DATA

ln -fs /classroom/users/${USER}/DA/WRFDA/run/*.TBL .

Link first guess and boundary files. The "wrfinput_d01" file should be linked both as "fg" and "wrfinput_d01". wrfbdy_d01 (WRF boundary conditions file) is also needed for running the nonlinear model.

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/rc/2017070400/wrfinput_d01 ./fg

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/rc/2017070400/wrfinput_d01 .

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/rc/2017070400/wrfbdy_d01 .

Link observation files (if you haven't created these yet, go back and finish the OBSPROC exercise)

ln -fs /classroom/users/${USER}/DA/obsproc_4dvar/obs_gts_2017-07-04_00:00:00.4DVAR ./ob01.ascii

ln -fs /classroom/users/${USER}/DA/obsproc_4dvar/obs_gts_2017-07-04_01:00:00.4DVAR ./ob02.ascii

ln -fs /classroom/users/${USER}/DA/obsproc_4dvar/obs_gts_2017-07-04_02:00:00.4DVAR ./ob03.ascii

ln -fs /classroom/users/${USER}/DA/obsproc_4dvar/obs_gts_2017-07-04_03:00:00.4DVAR ./ob04.ascii

Link the background error file (we will use the built-in CV3 option here for demonstration purposes)

ln -fs /classroom/users/${USER}/DA/WRFDA/var/run/be.dat.cv3 ./be.dat

Edit namelists

A very basic namelist.input for running the 4D-VAR tutorial case is available at /classroom/wrfhelp/DATA/WRFDA/4dvar/namelist.input

cp /classroom/wrfhelp/DATA/WRFDA/4dvar/namelist.input .

vi namelist.input

Pay special attention to the following namelist variables.

&wrfvar1
var4d=true,
var4d_lbc=false,
var4d_bin=3600,
/
&wrfvar18
analysis_date='2017-07-04_00:00:00",
/
&wrfvar21
time_window_min="2017-07-04_00:00:00",
/
&wrfvar22

time_window_max="2017-07-04_03:00:00",
/
&time_control
run_hours=3,
start_year=2017,
start_month=07,
start_day=04,
start_hour=00,
end_year=2017,
end_month=07,
end_day=04,
end_hour=03,
interval_seconds=10800,
/
&domains
time_step=300,
e_we=51,
e_sn=51,
e_vert=31,
dx=60000,
dy=60000,
/
&perturbation
trajectory_io=true,
enable_identity=false,
jcdfi_use=true,
jcdfi_diag=1,
jcdfi_penalty=1000.0,
/

Running 4D-VAR

mpirun -np 6 /classroom/users/${USER}/DA/WRFDA/var/build/da_wrfvar.exe >& var4d.log &

The "&" at the end of the above command tells WRFDA to run in the background. Because the command line is now usable even as WRFDA runs, you can use the "tail" command to follow the progress of WRFDA as it writes the log files:

tail -f rsl.out.0000

Helpful tip!
If you didn't include the "&" at the end of your run command, you can still tell the program to run in the background. After submitting an MPI job like this, if you decide you don't want to sit around without being able to see the progress of your run, hit control+z on your keyboard. This will suspend the job; to run it in the background, type "bg" and enter. Now, you can use the "tail" command to see the log files in real time!

This exercise will take about 5 minutes to complete on the classroom computers. Press control+c at any time to quit "tail"

Check output

When WRFDA is completed, you should see the same diagnostic files as you saw for 3dvar. Check the rsl.out.0000 file if you haven't already. You will notice a lot more messages from the tangent linear and adjoint models that can clutter up the file. If you just want to see the minimization statistics, try the command

grep minimize_cg rsl.out.0000

The output of this command will be just the minimization statistics with the columns from left-to-right representing the outer loop number,the inner loop iteration number, the cost function for that step, the gradient for that step, and the difference from the previous step:

minimize_cg   1   0   6.670523547286229D+03   1.235674209228231D+03   0.000000000000000D+00
minimize_cg   1   1   6.094285968854392D+03   4.486864126290913D+02   7.547856032550747D-04
minimize_cg   1   2   5.894594518831930D+03   3.321543365876553D+02   1.983826237590016D-03
minimize_cg   1   3   5.743138255238884D+03   2.929501038341248D+02   2.745600722285196D-03
minimize_cg   1   4   5.575849602250371D+03   3.096085705139210D+02   3.898604388658698D-03
minimize_cg   1   5   5.443471209318681D+03   2.288983423896116D+02   2.761983957295956D-03
minimize_cg   1   6   5.350146255017395D+03   1.688390541749637D+02   3.562398393539970D-03
minimize_cg   1   7   5.276423887650688D+03   1.744673947850436D+02   5.172296911705198D-03
minimize_cg   1   8   5.194897998764329D+03   1.779845975978887D+02   5.356695826746165D-03

Using lateral boundary control variables

WRFDA 4DVAR has the option to add an additional cost function term based on the lateral boundary conditions. You can activate it by setting var4d_lbc=true in &wrfvar1, and linking the following files.

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/rc/2017070403/wrfinput_d01 ./fg02

cp ./fg02 ./ana02

"fg02" and "ana02" are the same file, and are the "first guess" field for the same domain at the end of the 4DVAR assimilation window (in this case, the analysis at 2017-07-04 03Z). Run the case again and see if you notice any differences in the output (especially the cost_fn and grad_fn files).


You are now done with the basic 4DVAR practice case. If you still have time, you can try some additional exercises below:

Additional practice

Try using PREPBUFR data instead of ASCII format data. Since PREPBUFR files from GDAS contain 6 hours of data which is different from our 6-hour assimlation window (PREPBUFR files contain data from 21z–03z, 03z–09z, etc.) you will need to link two different observation files to cover the whole assimilation window:

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/ob/2017070400/gdas1.t00z.prepbufr.nr ./ob01.bufr

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/ob/2017070406/gdas1.t06z.prepbufr.nr ./ob02.bufr

Radiance assimilation works in much the same way, since radiance data in GDAS BUFR files follows the same time window conventions.

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/ob/2017070400/gdas1.t00z.1bamua.tm00.bufr_d ./amsua01.bufr

ln -fs /classroom/wrfhelp/DATA/WRFDA/4dvar/ob/2017070406/gdas1.t06z.1bamua.tm00.bufr_d ./amsua02.bufr

Don't forget to change the appropriate namelist options and link the necessary radiance files/directories! Reference the 3DVAR and radiance practice if you forgot how, or you can check the Users Guide.



Try setting up a different 4D-VAR run using CONUS60 case (/classroom/wrfhelp/DATA/WRFDA/CONUS60) and compare the results with the 3D-VAR run. Use the same namelist from the 3dvar case, and modify the following settings:

cp /classroom/users/${USER}/DA/3dvar/namelist.input .

vi namelist.input

Pay special attention to the following namelist variables, which are essential for 4DVAR runs

&wrfvar1
var4d=true,
var4d_lbc=false,
var4d_bin=3600,
/
&wrfvar6
ntmax=4 # for testing purpose only; this reduces the maximum iterations, since this 4DVAR case takes a long time to run
/
&wrfvar18
analysis_date="2008-02-05_12:00:00",
/
&wrfvar21
time_window_min="2008-02-05_12:00:00",
/
&wrfvar22
time_window_max="2008-02-05_18:00:00",
/
&time_control
run_hours=6,
start_year=2008,
start_month=02,
start_day=05,
start_hour=12,
end_year=2008,
end_month=02,
end_day=05,
end_hour=18,
interval_seconds=21600,
/
&domains
time_step=300,
e_we=90,
e_sn=60,
e_vert=41,
dx=60000,
dy=60000,
/
&dynamics
w_damping=1,
diff_opt=1,
km_opt=4,
dampcoef=0.01,
time_step_sound=4,
base_temp=290.0,
use_baseparam_fr_nml=true,
/
&perturbation
trajectory_io=true,
enable_identity=false,
jcdfi_use=true,
jcdfi_diag=1,
jcdfi_penalty=1000.0,
/
&bdy_control
specified=true,
real_data_init_type=3,
/

  • Observations

    /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob/2008020512/ob.ascii+
    /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob/2008020513/ob.ascii
    /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob/2008020514/ob.ascii
    /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob/2008020515/ob.ascii
    /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob/2008020516/ob.ascii
    /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob/2008020517/ob.ascii
    /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob/2008020518/ob.ascii-

  • First guess

    /classroom/wrfhelp/DATA/WRFDA/CONUS60/rc/2008020512/wrfinput_d01
    /classroom/wrfhelp/DATA/WRFDA/CONUS60/rc/2008020512/wrfbdy_d01

  • Background error statistics

    /classroom/wrfhelp/DATA/WRFDA/CONUS60/be/be.dat


You can also try assimilating PREPBUFR and radiance data, as described above. Those observation files can be found in the appropriate sub-directories in /classroom/wrfhelp/DATA/WRFDA/CONUS60/ob

NOTE: The CONUS60 case will take more than 15 minutes to complete on the classroom computers, even with a low value of ntmax=4.
This is why a much smaller, simplified case is provided for the basic tutorial above.

 


back to top
 
practice_page_header