5

Let's assume I have 2 netCDF data files with data for the same region (like South America, Africa, etc) but the different grid sizes as 0.5 degrees x 0.5 degrees and 1.0 degrees x 1.0 degrees in another. I want to increase or decrease its grid size to a different value such as 0.25 x 0.25 or 1.0 x 1.0 so that I can use this easily for raster calculations and comparison, etc.

Is there a method to do this using any bash script, CDO, etc.

A sample data can be downloaded from here. https://www.dropbox.com/sh/0vdfn20p355st3i/AABKYO4do_raGHC34VnsXGPqa?dl

Can different methods be followed for this like bilinear interpolation or cubic interpolation? This is quite easy with ArcGIS and other software but is there a way to do it for a big netCDF file with large datasets. Assume that this is just a subset of the data. What I will be later converting is a whole set of yearly data.

The resulted file should be a .nc file with the changed grid size as defined by the user.

Ep1c1aN
  • 683
  • 9
  • 25

2 Answers2

12

You can use cdo to remap grids, e.g. to a regular 1 degree grid you can use:

cdo remapcon,r360x180 input.nc output.nc

As well as conservative first order remapping (remapcon), other options are :

remapbil : bilinear interpolation
remapnn  : nearest neighbour interpolation
remapcon2 : 2nd order conservative remapping

It is also possible to remap one file to the grid used in another if you prefer:

cdo remapcon,my_target_file.nc in.nc out.nc 

EDIT 2021: new video available...

To answer the comment below asking about which method to use, for a full guide on these interpolation methods and the issues you have to look out for regarding subsampling when coarse graining data, you can refer to my "regridding and interpolation" video guide on youtube.

In general if you are interpolating from high resolution to low resolution ("coarse gridding") by more than a factor of 2 you don't want to use bilinear interpolation as it will essentially subsample the field. This is especially problematic for non-smooth, highly heterogeneous fields such as precipitation. In those cases I would always suggest to use a conservative method (remapcon or remapcon2). See my video guide for details.

Another tip for speed is that, if you are performing the same interpolation procedure on many input files with the same resolution, then you can calculate the interpolation weights once using genbil, gencon etc, and then do the remapping function using those in the loop over the file. This is much faster, as the generation of the weights is the slow part of remapcon

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • Thank you, Adrian. I always get confused as to which method to use when increasing or decreasing the grid size of a raster file (as will the end result differ very much in case of changing raster size). Which one is the best to use or any hand rule you might know of for this when you increase a raster size and when you decrease a raster size? – Ep1c1aN Apr 18 '19 at 18:46
7

NCO's ncremap has a one-line solution as well. Consider regriding a.nc to be on the same grid as b.nc. We will name the answer c.nc (this is the regridded a.nc).

ncremap -d b.nc a.nc c.nc

To choose conservative instead of bilinear interpolation (the default), use -a:

ncremap -a conserve -d b.nc a.nc c.nc
Charlie Zender
  • 5,929
  • 14
  • 19