Skip to the content.

Posts/regrid netCDF files

Home Publications WorkExp Projects News Posts

How to regrid the netcdf files?

Here we will discuss two most common methods that are used for regridding: Tempestremap and ncremap

Acknowledgment: Dr. Min Xu and Dr. Forrest M. Hoffman, Oak Ridge National Laboratory


Some points to keep in mind before you use the following techniques:


Steps for redrigging for both techniques:

1.TempestRemap (by Paul Ulrich) is a conservative, consistent and monotone remapping package for arbitrary grid geometry with support for finite volumes and finite elements.

./bin/GenerateRLLMesh --lon 720 --lat 360 --file grid_360x720.g
./bin/GenerateRLLMesh --lon 360 --lat 180 --file grid_180x360.g
./bin/GenerateOverlapMesh --a grid_360x720.g --b grid_180x360.g --out overlap_grid_360to180.g

./bin/GenerateOfflineMap --in_mesh grid_360x720.g --out_mesh grid_180x360.g \
                        --ov_mesh overlap_grid_360to180.g --in_np 2 \
                        --out_map map_tempest_360x720_to_180x360.20210701.nc

./bin/ApplyOfflineMap  --map map_tempest_360x720_to_180x360.20210701.nc --var gpp\
                         --in_data GPP_ANN_CRUNCEPv6_Monthly_1980_2013_Updated.nc\
                         --out_data GPP_ANN_CRUNCEPv6_Monthly_1980_2013_tempest_180x360.nc

2.ncremap has many options of regridding that includes conservative, biliniear, nearest and also sub grade scale (sgs). sgs is especially useful incase the climate variable is dependent on landfrac.

Options:

ncremap -a aave -s src_grd.nc -g dst_grd.nc -m map.nc in.nc out.nc

  • default: bilinear
  • -a aave : for conserve
  • -P sgs: for sub grid scale if you have landfraction
  • src_grd.nc : is source grid scrip file
  • dst_grd.nc : is destination grid scrip file
  • -m map.nc : the weight nc file, (Min Said, if you don’t alreaddy have it, it will be created)
  • in.nc : is the input file
  • out.nc : output file name
export NCO_PATH_OVERRIDE='No'                                                               
export HDF5_USE_FILE_LOCKING=FALSE
module load ncl

ncks --rgr grd_ttl='Equi-Angular grid 192x288'#latlon=192,288#lat_typ=uni#lon_typ=grn_wst \
     --rgr scrip=192x288_SCRIP.20210701.nc \
        CESM2_ssp585_r1i1p1f1_gpp_gCm-2.nc \
        test_foo_cesm.nc

ncks --rgr grd_ttl='Equi-Angular grid 64x128'#latlon=64,128#lat_typ=uni#lon_typ=grn_wst \
     --rgr scrip=64x128_SCRIP.20210701.nc \
         CESM2_ssp585_r1i1p1f1_gpp_gCm-2.nc \
         test_fooo_cesm.nc

ncremap -a aave -P sgs \
            -s 192x288_SCRIP.20210701.nc \
            -g 64x128_SCRIP.20210701.nc \
            -m map_aave_sgs_nco_192x288_and_64x128.20210701.nc \
            CESM2_ssp585_r1i1p1f1_gpp_gCm-2.nc \
            CESM2_ssp585_r1i1p1f1_gpp_gCm-2_nco_sgs_aave_64x128.nc

If you have the access to Cori Nersc, visit the dir : /global/cfs/cdirs/m2467/bharat/Regridding_Techniques. It has observation and model data and scripts designed to regrid them to coarser resolution. The file Regridding_Example.ipynb is designed to test the output of your regrided file and compare with source file.

The comparison of regridded data vs original data: