Regridding BISICLES output with ESMF and NCO

From CliC Wiki
Jump to: navigation, search

Will Roberts (University of Bristol) has had success regridding BISICLES output using ESMF to generate weights and NCO to calculate the regridded data values. This page is adapted from notes provided by Will. ESMF is also the tool used by CESM and CISM, and some tips used by CISM are included below, thanks to Jeremy Fyke. There also an ESMF python interface, ESMPy, see http://www.earthsystemmodeling.org/python_releases/ESMPy_620b10_04/python_doc/html/index.html#module-ESMF but we have not tested this.

Note: For simplicity, the most of the directories shown below are the original ones from Will's notes, and refer to U. Bristol's installations. Remember to adapt them for your own situation!


Aim

Take a BISICLES hdf5 file (an unstructured grid) and regrid it to the 5km ISMIP6/SeaRISE structured grid in NetCDF (.nc) format.

Making sure that the data are in a SCRIP format seems to make things run smoothly.

Steps

  1. Convert B.hdf5 into B.nc
  2. Create SCRIP type grid description file
  3. Create ESMF weights for Greenland_5km_v1.1.nc
  4. Regrid B.nc into B_2.nc using the esmf weights make

hdf5 → nc

Use amr2CF in BISICLES/code/filetools/amrtocf.cpp

cd /data/ggslc/opt/BISICLES/BISICLES/code/filetools
amrtocf2d.Linux.64.g++.gfortran.DEBUG.ex config.amrtocf infile=plot.GrIS.1km.l1l2.4lev.017584.2d.hdf5 outfile=~/ismip6/plot.nc

Create SCRIP grid description file

At present amr2CF won't produce SCRIP-type grid files. Thus you need to mangle the output a little to get SCRIP compatible files. Principally this requires the grid corner matrix to go in a circle (ie enclose the grid box) and the grid bits need to be renamed:

  • grid_corner_lat
  • grid_corner_lon
  • grid_center_lon
  • grid_center_lat
  • grid_dims
  • grid_imask

and you need to have the dimensions grid_corners – how many corners there are to your grid and grid_rank which in our case is just 1 and used by grid_dims, which tells us how many grid boxes we have (this is the same as grid_size in our case).

Example matlab code of how to generate a SCRIP compatible file for CESM and CISM is available on the ftp server (see SCRIP_matlab_stuff.zip in /ISMIP6/initMIP/grid_description_files/SCRIP). Feedback to Jeremy Fyke is welcomed.

Information about SCRIP is here. For more information on SCRIP-format grid description files, see the User's Guide for SCRIP here.

Build ESMF

ESMF's home page is at https://www.earthsystemcog.org/projects/esmf/.

On Macintoshes, ESMF can be easily installed via the MacPorts package manager. MacPorts will also automatically install any other libraries ESMF requires.

For other systems, after downloading and unpacking the source distribution,

Note: Directories shown below are those used at U. Bristol. Adapt to your own installation.
export ESMF_DIR="/home/paleo/ggwhgr/esmf"
export ESMF_NETCDF_LIBPATH="/data/ggslc/opt/lib"
export ESMF_NETCDF="split"
export ESMF_NETCDF_INCLUDE="/data/ggslc/opt/include"
export ESMF_NETCDF_LIBS="-lnetcdf -lnetcdff"
export ESMF_LAPACK_LIBPATH="/data/ggslc/opt/lib"
export ESMF_LAPACK_INCLUDE="/data/ggslc/opt/include/"
export ESMF_LAPACK_LIBS="-llapack -lblas"

make
Note: At Goddard, we also needed to specify export ESMF_F90COMPILEPATHS="-I/usr/include" to tell gfortran where to find the netcdf.mod file.

Use ESMF to create the weights file

Change directories to where ESMF installed its executable files; this may be somewhere beneath esmf/DEFAULTINSTALLDIR/, but the subdirectory will depend on which architechture and compiler you used. Then,

./ESMF_RegridWeightGen -s ~/ismip6/new_bike.nc -d ~/ismip6/SCRIPgrid_gland_5km_c150511.nc -m conserve -i --src_regional --dst_regional --check  -w ~/ismip6/wts.nc

where:

-s
where is the source grid. This is the file created by scrip_from_plot.m in the step above.
-d
where is the destination grid. SCRIPgrid_gland_5km_c150511.nc is a SCRIP grid description file for the standard Greenland 5 km polar-stereographic grid.
-m conserve 
does a conservative regridding
-i 
ignores unmapped destination points
--src_regional --dst_regional
indicates the source and destination grids are not global (seems to work with global too)
--check
runs a check after calculating weights – ensures they actually work
-w 
where do you want the weight file


References:

Grid File Formats (ESMF Reference Manual)
ESMF_RegridWeightGen (ESMF Reference Manual)

Use NCO to apply weights to input file, giving regridded output file

The NCO home page is at http://nco.sourceforge.net/. For information on regridding with NCO, see http://nco.sourceforge.net/nco.html#Regridding.

Requires nco ≥ 4.5.0 (released June 2015)

ncks --map=wts.nc --rgr col_nm=grid_size new_bike.nc out.nc

where:

--map=wts.nc
regrid input file to output file, using wts.nc (created with ESMF_RegridWeightGen in the step above) as the weight (map) file.
--rgr col_nm=grid_size
name of the dimension to be used for the unstructured output grid
new_bike.nc 
input data file, defined on source grid
out.nc 
output file, data regridded to target grid