• Discoverability Visible
  • Join Policy Restricted
  • Created 01 Jul 2022

Regridding BISICLES output with ESMF and NCO

Version 6
by (unknown)
Version 7
by (unknown)

Deletions or items before changed

Additions or items after changed

1 ==Introduction==
2
3 In order to '''intercompare different models''', they must be interpolated from the native grid on which they were calculated to a common output grid. This procedure is known as '''regridding or remapping'''.
4
5 Fundamentally, '''regridding consists of two steps''':
6
7 # Creation of an interpolation matrix (weights file), which gives the amount that each point on the source grid contributes to each point on the target grid. These weights will depend on the type of interpolation desired. ISMIP6 has standardized on First-order Conservative Remapping (Jones, P.W. 1999, Monthly Weather Review, 127, 2204-2210), which does a better job preserving fluxes (or other integrals) than, eg., bilinear interpolation.
8 # For each point on the target grid, sum the data values on the source grid multiplied by the corresponding weights. The same weights file may be used for more than one input variable, provided all are defined on the same source grid.
9 Different software may do one or the other or both of these steps.
10
11 To create the weights file, you must have ''grid description files'' for your source and target grids. These files give the latitudes and longitudes of every grid point, along with the corners of the boundary of its surrounding cell. There are several ways to write these files, depending on the software you're using.
12
13 Will Roberts (University of Bristol) has had success regridding '''BISICLES''' output using [https://earthsystemmodeling.org/regrid/ ESMF] to generate weights and [https://nco.sourceforge.net/ 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 is also an ESMF python interface, [https://earthsystemmodeling.org/esmpy/ ESMPy] (ESMF Python Regridding Interface), although we have not tested this ourselves.
14
15 '''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!''
16
17 [[Image(ice_sheet_image_thin.png)]]
18
19 =Aim=
20 Take a BISICLES hdf5 file (an unstructured grid) and regrid it to the 5km ISMIP6/!SeaRISE structured grid in !NetCDF (.nc) format.
21
22 Making sure that the data are in a SCRIP format seems to make things run smoothly.
23
24 ==='''Steps:'''===
25 # Convert B.hdf5 into B.nc
26 # Create SCRIP type grid description file
27 # Create ESMF weights for Greenland_5km_v1.1.nc
28 # Regrid B.nc into B_2.nc using the esmf weights make
29
30 +
----
31 =hdf5 → nc=
32 Use amr2CF in BISICLES/code/filetools/amrtocf.cpp
33 {{{
34 cd /data/ggslc/opt/BISICLES/BISICLES/code/filetools
35 amrtocf2d.Linux.64.g++.gfortran.DEBUG.ex config.amrtocf infile=plot.GrIS.1km.l1l2.4lev.017584.2d.hdf5 outfile=~/ismip6/plot.nc
36 }}}
37
38 +
----
39 =Create SCRIP grid description file=
40 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 (i.e. enclose the grid box) and the grid bits need to be renamed:
41 * grid_corner_lat
42 * grid_corner_lon
43 * grid_center_lon
44 * grid_center_lat
45 * grid_dims
46 * grid_imask
47
48 '''Note''': 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).
49
50 '''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.
51
52 For information about SCRIP and access to SCRIP-format grid description files, contact ismip6@gmail.com
53
54 +
----
55 =Build ESMF=
56 Find more detailed instructions at [https://www.earthsystemcog.org/projects/esmf/ ESMF's home page].
57
58 On Macintoshes, ESMF can be easily installed via the !MacPorts package manager at https://www.macports.org/. !MacPorts will also automatically install any other libraries ESMF requires.
59
60 For other systems, after downloading and unpacking the source distribution,
61
62 '''Note''': Directories shown below are those used at U. Bristol. Adapt to your own installation.
63 {{{
64 export ESMF_DIR="/home/paleo/ggwhgr/esmf"
65 export ESMF_NETCDF_LIBPATH="/data/ggslc/opt/lib"
66 export ESMF_NETCDF="split"
67 export ESMF_NETCDF_INCLUDE="/data/ggslc/opt/include"
68 export ESMF_NETCDF_LIBS="-lnetcdf -lnetcdff"
69 export ESMF_LAPACK_LIBPATH="/data/ggslc/opt/lib"
70 export ESMF_LAPACK_INCLUDE="/data/ggslc/opt/include/"
71 export ESMF_LAPACK_LIBS="-llapack -lblas"
72
73 make
74 }}}
75 '''Note''': At Goddard, we also needed to specify `export ESMF_F90COMPILEPATHS="-I/usr/include"` to tell gfortran where to find the netcdf.mod file.
76
77 -
+
----
78 =Use ESMF to create the weights file=
79 Change directories to where ESMF installed its executable files; this may be somewhere beneath `esmf/DEFAULTINSTALLDIR/`, but the subdirectory will depend on which architecture and compiler you used.
80 Then,
81 {{{
82 ./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
83 }}}
84 '''where:'''
85
86 `-s`
87 where is the source grid. This is the file created by scrip_from_plot.m in the step above.
88
89 `-d`
90 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.
91
92 `-m conserve`
93 does a conservative regridding
94
95 `-i`
96 ignores unmapped destination points
97
98 `--src_regional --dst_regional`
99 indicates the source and destination grids are not global (seems to work with global too)
100
101 `--check`
102 runs a check after calculating weights – ensures they actually work
103
104 `-w`
105 where do you want the weight file
106
107 +
----
108 ==References:==
109
110 Grid File Formats [https://earthsystemmodeling.org/docs/release/ESMF_8_1_1/ESMF_refdoc.pdf (ESMF Reference Manual, section 12.8)]
111
112 ESMF_!RegridWeightGen [https://earthsystemmodeling.org/docs/release/ESMF_8_1_1/ESMF_refdoc.pdf (ESMF Reference Manual, section 12.9)]
113
114 +
----
115 =Use NCO to apply weights to input file, giving regridded output file=
116 The NCO home page is at http://nco.sourceforge.net/. For information on regridding with NCO, see http://nco.sourceforge.net/nco.html#Regridding.
117
118 '''Note''': Requires nco ≥ 4.5.0 (released June 2015)
119
120 `ncks --map=wts.nc --rgr col_nm=grid_size new_bike.nc out.nc`
121
122 '''where:'''
123
124 `--map=wts.nc`
125 regrid input file to output file, using wts.nc (created with ESMF_!RegridWeightGen in the step above) as the weight (map) file.
126
127 `--rgr col_nm=grid_size`
128 name of the dimension to be used for the unstructured output grid
129
130 `new_bike.nc `
131 input data file, defined on source grid
132
133 `out.nc`
134 output file, data regridded to target grid
135
136 [[Image(ice_sheet_image_thin_2.png)]]