Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the resolution (Regrid) of netCDF using bi-linear interpolation in R?

I have netCDF files downloaded from here. They are at 0.5*0.5 resolution. I want to re-grid these files at a coarser resolution of 1*1. I found some links. First link talks about re-grid in R, but without using bi-linear interpolation. The second link deals with bi-linear interpolation, but using climate data operator (to which I am not very much familiar). Then I came across an R package HiClimR. In this package, a command coarseR reduces the resolution of data. I converted netCDF file into an excel file and used coarseR. But after getting results I found that this command actually skipped longitude latitude in some way and reduced the resolution to 1*1. In nut shell, my problems are

(1) Is it right to use coarseRfor reducing resolution? (2) How can bi-linear transformation be used for my specific problem in R?

Many thanks in advance.

like image 758
Pankaj Avatar asked Feb 10 '16 20:02

Pankaj


1 Answers

CDO has some very nice regridding functions built in that you can now access directly from within R using the package climate operators. After installation with

devtools::install_github("markpayneatwork/ClimateOperators")

you load it with

library(ClimateOperators)

For example to regrid to 1x1 regular grid using bilinear interpolation as you ask, from a linux command line you would simply do:

cdo remapbil,r720x360 in.nc out.nc

Which using the climate operators package in R, would translate to

cdo("remapbil,r720x360","in.nc","out.nc") 

(you can see how the command is built up without running it using the option "debug=True" in the call).

However, if you are converting to a coarser grid then it may be advisable to use a conservative remapping technique, otherwise you can miss points out during the remapping. This is especially important for highly heterogeneous fields such as precipitation. In this case, CDO offers both first and second order conservative remapping techniques. To use the first order technique

cdo remapcon,r720x360 in.nc out.nc

(Note that occasionally you may find CDO throwing a wobbly due to loss of precision during the conversion if the data is "packed" and in this case it will suggest you use the option "-b f32" or "-b f64".)

Common regridding options to consider are:

  • remapbil: Bilinear interpolation
  • remapnn: Nearest neighbour interpolation (i.e. takes value from closest cell)
  • remapcon: First order conservative remapping
  • remapcon2: Second order conservative remapping

An explanation on regridding technique and how to implement them with CDO is given in more detail in my youtube video guide on climate unboxed.

like image 65
Adrian Tompkins Avatar answered Sep 16 '22 21:09

Adrian Tompkins