Replacing fields in wrfinput

From mn/geo/geoit
Revision as of 11:18, 4 January 2017 by Irenebn@uio.no (talk | contribs) (Created page with "Category:Models Category:WRF Category:Tools If your simulation involves changing initial conditions, you need to replace one or more fields in your wrfinput_d0x...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


If your simulation involves changing initial conditions, you need to replace one or more fields in your wrfinput_d0x file. You can do this using CDO and R, quite simply.

Preparations

First you have to run all parts of your model up to real.exe before this step. Real.exe gives you wrfbdy_d01 and d02; wrfinput_d01 and d02; and wrflowinp_d01 and 02 (if you have varying SST). You also need something to replace into wrfinp_d0x.

I want to use the ground fields from a 9-month long spinup simulation for d01 as initial conditions for d02. Kjetil had the idea that you might regrid the d01 spinup and replace it into wrfinput_d02, saving months of simulation time, and many clock hours on Abel.

Replacement

cdo: regridding

First, create symbolic links to the d01 file you want to use as spinup and the wrfinput_d02 that does not have those variables spun up. You'll save space if you create a symbolic link instead of copying it.

ln -s /work/users/irenebn/spinup-simulation-d01/wrfrst_d01_2014-06-11_00\:00\:00 
ln -s /work/users/irenebn/real_simulation_two_domains/wrfinput_d02

Extract the fields you want to regrid.

cdo selname,ISNOW,SNOW,SNOWC,SNOALB,SNOWH,TSK,SMOIS,SOILCBOT,SOILCTOP,T_INIT wrfrst_d01_2014-06-11_00\:00\:00 spun-upvars_d01_2014-06-11

Create a text file describing the d02 grid (griddes.txt)

cdo griddes wrfinput_d02 >> griddes.txt

Remap using one of the remap functions. Remap-bil means bilinear interpolation.

cdo remapbil,griddes.txt spun-upvars_d01_2014-06-11 remapped_spinup_d02_2014-06-11 # bilinear interpolation

Unfortunately, the cdo command to replace the regridded fields into the orignal wrfinput_d02 field gave an error message (see "potential error messages" below). Thus,

## cdo delname,SMOIS,SNOW,SNOWH,SNOWC,TSK,ISNOW,SOILCBOT,SOILCTOP,T_INIT,SNOALB wrfinput_d02-with_spunup_variables2 out.nc # before merging, remove the fields you have changed.
## cdo merge out.nc remapped_spinup_d02_2014-06-11 wrfinput_2014-06-11  # merge two files. This does not give a wrfinput_d02 file that wrf can recognise...

R: replace fields

################################################################################
# Replace initial values in d02 with remapped and spun-up variables (from cdo).
# Written by IBN, 28.12.2016.
# Remember to replace 1995 with 2014 if you want to change the year.
################################################################################
#
# spinudir <- file.path(wrfPath,"regrid", paste("remapped_spinup_d02_1995-05-12", sep=""))
# wrfindir <- file.path(wrfPath,"regrid", paste("wrfinput_d02-1995spinup", sep=""))
 spinudir <- file.path(wrfPath,"regrid", paste("remapped_spinup_d02_2014-07-11", sep=""))
 wrfindir <- file.path(wrfPath,"regrid", paste("wrfinput_d02_2014-07-11", sep=""))
# spinudir <- file.path(wrfPath,"regrid", paste("remapped_spinup_d02_2014-06-26", sep=""))
# wrfindir <- file.path(wrfPath,"regrid", paste("wrfinput_d02_2014-06-26", sep=""))

 wrfin <- nc_open(wrfindir, write=TRUE)
 spinu <- nc_open(spinudir)
 ncvar_put(wrfin, 'SNOW', ncvar_get(spinu,'SNOW')[,1:186])
 ncvar_put(wrfin, 'SNOWH', ncvar_get(spinu,'SNOWH')[,1:186])
 ncvar_put(wrfin, 'SNOWC', ncvar_get(spinu,'SNOWC')[,1:186])
 ncvar_put(wrfin, 'ISNOW', ncvar_get(spinu,'ISNOW')[,1:186])
 ncvar_put(wrfin, 'SNOALB', ncvar_get(spinu,'SNOALB')[,1:186])
 ncvar_put(wrfin, 'TSK', ncvar_get(spinu,'TSK')[,1:186])
 ncvar_put(wrfin, 'T_INIT', ncvar_get(spinu,'T_INIT')[,1:186,])
 ncvar_put(wrfin, 'SMOIS', ncvar_get(spinu,'SMOIS')[,1:186,])
 ncvar_put(wrfin, 'SOILCBOT', ncvar_get(spinu,'SOILCBOT')[,1:186,])
 ncvar_put(wrfin, 'SOILCTOP', ncvar_get(spinu,'SOILCTOP')[,1:186,])
 nc_close(wrfin)
 nc_close(spinu)


Potential errors

*************************************
d01 2014-05-12_00:00:00 *** Initializing nest domain # 2 from an input file. ***
-------------- FATAL CALLED ---------------
FATAL CALLED FROM FILE:  <stdin>  LINE:      70
program wrf: error opening wrfinput_d02 for reading ierr=          -8
-------------------------------------------


Final remarks

Good luck!

-Irene Brox Nilsen