<p>Using Python, the best solution I've been able to find is pyresample. See this <a href="http://earthpy.org/interpolation_between_grids_with_pyresample.html" rel="nofollow noreferrer">blog post</a>.</p>

CC BY-SA 4.0
2018-09-02T00:43:34.113Z
2018-09-02T00:43:34.113Z
Hypercube
<h1>climate data operators (CDO)</h1>

<h2>define grid</h2>

<p>We define a lat-lon target grid with 1°x1° grid cell size 30x30 grid cells starting at 40°N and -10°E (=10°W):</p>

<pre><code>gridtype = lonlat 
xsize    =  30 
ysize    =  30 
xfirst   = -10 
xinc     =   1 
yfirst   =  40 
yinc     =   1
</code></pre>

<p>This text is written into a text file. See <a href="https://code.zmaw.de/projects/cdo/embedded/index.html#x1-150001.3.2">section 1.3.2 CDO Manual</a> for details and further examples.</p>

<p>If you already have a netCDF file which has data on your target grid, you can also extract the grid definition from that file:</p>

<pre><code>cdo griddes FILE_WITH_TARGET_GRID.nc &gt; myGridDef
</code></pre>

<p><code>myGridDef</code> is a text file.</p>

<h2>interpolate data</h2>

<p>I assume that we do a bilinear interpolation. This is done with the <code>remapbil</code> operator via:</p>

<pre><code>cdo remapbil,myGridDef INPUT_FILE.nc OUTPUT_FILE.nc
</code></pre>

<p>The grid of your input data needs to be properly defined in your input file (that is often a problem).</p>

<h2>'properly defined' grid</h2>

<h3>Alternative 1</h3>

<p>The spatial dimensions of the data variable (SST in the example below) need to be named <code>lon</code> and <code>lat</code>. Additionally, coordinate variables <code>lon</code> and <code>lat</code> have to exist (time independent!). These need to have correct coordinate variable attributes (see example below).</p>

<p>Example:</p>

<pre><code>dimensions:
    lon = 30 ;
    lat = 30 ;
    time = UNLIMITED ; // (24 currently)
variables:
    double lon(lon) ;
            lon:standard_name = "longitude" ;
            lon:long_name = "longitude" ;
            lon:units = "degrees_east" ;
            lon:axis = "X" ;
    double lat(lat) ;
            lat:standard_name = "latitude" ;
            lat:long_name = "latitude" ;
            lat:units = "degrees_north" ;
            lat:axis = "Y" ;
    double time(time) ;
            time:standard_name = "time" ;
            time:long_name = "time" ;
            time:units = "seconds since 1900-01-01 00:00:00" ;
            time:calendar = "standard" ;
            time:axis = "T" ;
    float SST(time, lat, lon) ;
            SST:long_name = "sea_surface_temperature" ;
            SST:units = "degree celsius" ;
            SST:_FillValue = NaNf ;
            SST:missing_value = NaNf ;
            SST:var_desc = "sea surface temperature" ;
</code></pre>

<h3>Alternative 2</h3>

<p>The spatial dimensions and corresponding variables exist in the source file but are not denoted as <code>lon</code> and <code>lat</code>. Then each data variable (SST, in this example) needs to have an attribute <code>coordinates</code> that holds the names of the coordinate variables.</p>

<pre><code>SST:coordinates = "lon lat" ;
</code></pre>

<p>Example:</p>

<pre><code>dimensions:
    TSTEP = UNLIMITED ; // (24 currently)
    COL = 112 ;
    ROW = 106 ;
variables:                     " ;
    double lon(ROW, COL) ;
        lon:standard_name = "longitude" ;
        lon:long_name = "longitude coordinate" ;
        lon:units = "degrees_east" ;
        lon:_CoordinateAxisType = "Lon" ;
    double lat(ROW, COL) ;
        lat:standard_name = "latitude" ;
        lat:long_name = "latitude coordinate" ;
        lat:units = "degrees_north" ;
        lat:_CoordinateAxisType = "Lat" ;
    double time(TSTEP) ;
        time:standard_name = "time" ;
        time:long_name = "time" ;
        time:units = "seconds since 1900-01-01 00:00:00" ;
        time:calendar = "standard" ;
    float SST(TSTEP, ROW, COL) ;
        SST:long_name = "sea_surface_temperature" ;
        SST:units = "degree celsius" ;
        SST:coordinates = "lon lat" ;
        SST:var_desc = "sea surface temperature" ;
</code></pre>

<h3>Note:</h3>

<p>If the coordinate variables are missing, then they can be created via the <code>setgrid</code> operator. If we want to add a grid definition to the source file then we need the source file's grid definition in the text file (see 'define grid').</p>

<pre><code>cdo setgrid,mySourceGridDef INFILE_NO_COORDS.nc INFILE_WI_COORDS.nc
</code></pre>

CC BY-SA 3.0
2017-11-02T09:18:37.883Z
Is there an equally simple way to proceed when setting coordinates for a projected coordinate system? I didn't understand much from the documentation.
Janina
CC BY-SA 3.0
2017-11-02T09:48:48.330Z
@Janina You mean when you have some projection, which does not project your model grid on a regular lat-lon grid? Do you mean interpolation or just setting a grid definition? Better you ask a new question (refer to this one) including an example of your data set.
daniel.heydebreck
CC BY-SA 3.0
2017-11-02T10:19:52.053Z
yes, exactly, something like Lambert Conformal Conic etc. Essentially, I wanted to set the grid definition, so that for example in Panoply it would plot the data in the correct geographic location. And yes, ultimately I'm interested in regridding. Ok, I guess I'll turn this into a question... :-)
Janina
CC BY-SA 3.0
2017-11-02T10:31:24.757Z
@Janina I just re-read my answer. It actually solves your issue if you already have your coordinates available in one netCDF file.
daniel.heydebreck
CC BY-SA 3.0
2017-11-03T10:01:59.643Z
You are right, actually. After some trial-and-error progress I was able to do the regridding successfully - thank you for your detailed description! But the validity of my workflow is questionable. I created and saved the data in R with original coordinates in [EPSG:3333](http://spatialreference.org/ref/epsg/3333/). I solved the georeferencing problem by adding projection metadata. I did the transformation to WGS84 to get the cell centre coordinates in lat-long and saved them to variables lon and lat (just like your alternative 2). The output of `griddes` for this file was a curvilinear grid.
Janina
CC BY-SA 3.0
2016-05-30T13:40:32.007Z
2016-05-30T15:50:17.233Z
2016-05-30T15:50:17.233Z
daniel.heydebreck
<p>I want to regrid GCM data available on Gaussian grids to regular grids, say at 1 deg X 1 deg.
How to do this using <code>CDO</code> or <code>Python</code> or <code>MATLAB</code>.</p>

<p><strong>Edit 1:</strong> Data format is <code>netcdf</code>.</p>

CC BY-SA 3.0
2016-05-30T12:45:10.867Z
For the usage of CDO: Do you have your data available as netCDF files? How is your output grid exactly defined? The easiest way with cdo: create a grid description file of the target grid (with `griddes` from an existing target grid netCDF file) and apply an interpolation routine (e.g. `remapbil`) on your files that should be converted.
daniel.heydebreck
CC BY-SA 3.0
2016-05-30T15:53:15.217Z
With respect to Matlab: The second and third search result (when I just searched it) provide the [interp2](http://de.mathworks.com/help/matlab/ref/interp2.html) and [griddedInterpolant](http://de.mathworks.com/help/matlab/examples/grid-based-interpolation.html?requestedDomain=www.mathworks.com) functions which seem to be what you need. Please provide more information if you need further help.
daniel.heydebreck
CC BY-SA 3.0
2016-05-31T06:39:16.870Z
@daniel.neumann thanks for your valuable suggestion, my data is in `netcdf` format. I am not sure whether `interp2` can be applied on `Gussian Grids` though I have used this function heavily for `rectilinear grids`.
dsbisht
<meteorology><atmosphere-modelling><weather-forecasting><climate-models>
Interpolate Gaussian grids to regular fixed grids using bilinear interpolation?
dsbisht
# Interpolate Gaussian grids to regular fixed grids using bilinear interpolation?

(Asked by: username_0 on 2016-05-30)

I want to regrid GCM data available on Gaussian grids to regular grids, say at 1 deg X 1 deg.
How to do this using `CDO` or `Python` or `MATLAB`.

**Edit 1:** Data format is `netcdf`.

**Tags:** meteorology, atmosphere-modelling, weather-forecasting, climate-models

> **Comments:**
> **username_1**: For the usage of CDO: Do you have your data available as netCDF files? How is your output grid exactly defined? The easiest way with cdo: create a grid description file of the target grid (with `griddes` from an existing target grid netCDF file) and apply an interpolation routine (e.g. `remapbil`) on your files that should be converted.  
> **username_1**: With respect to Matlab: The second and third search result (when I just searched it) provide the [interp2](http://de.mathworks.com/help/matlab/ref/interp2.html) and [griddedInterpolant](http://de.mathworks.com/help/matlab/examples/grid-based-interpolation.html?requestedDomain=www.mathworks.com) functions which seem to be what you need. Please provide more information if you need further help.  
> **username_0**: @daniel.neumann thanks for your valuable suggestion, my data is in `netcdf` format. I am not sure whether `interp2` can be applied on `Gussian Grids` though I have used this function heavily for `rectilinear grids`.  

---

## 2 answers

### Answer by username_1 on 2016-05-30. Score: 10 | Accepted answer

climate data operators (CDO)
define grid
We define a lat-lon target grid with 1°x1° grid cell size 30x30 grid cells starting at 40°N and -10°E (=10°W):
gridtype = lonlat 
xsize    =  30 
ysize    =  30 
xfirst   = -10 
xinc     =   1 
yfirst   =  40 
yinc     =   1

This text is written into a text file. See section 1.3.2 CDO Manual for details and further examples.
If you already have a netCDF file which has data on your target grid, you can also extract the grid definition from that file:
cdo griddes FILE_WITH_TARGET_GRID.nc > myGridDef

myGridDef is a text file.
interpolate data
I assume that we do a bilinear interpolation. This is done with the remapbil operator via:
cdo remapbil,myGridDef INPUT_FILE.nc OUTPUT_FILE.nc

The grid of your input data needs to be properly defined in your input file (that is often a problem).
'properly defined' grid
Alternative 1
The spatial dimensions of the data variable (SST in the example below) need to be named lon and lat. Additionally, coordinate variables lon and lat have to exist (time independent!). These need to have correct coordinate variable attributes (see example below).
Example:
dimensions:
    lon = 30 ;
    lat = 30 ;
    time = UNLIMITED ; // (24 currently)
variables:
    double lon(lon) ;
            lon:standard_name = "longitude" ;
            lon:long_name = "longitude" ;
            lon:units = "degrees_east" ;
            lon:axis = "X" ;
    double lat(lat) ;
            lat:standard_name = "latitude" ;
            lat:long_name = "latitude" ;
            lat:units = "degrees_north" ;
            lat:axis = "Y" ;
    double time(time) ;
            time:standard_name = "time" ;
            time:long_name = "time" ;
            time:units = "seconds since 1900-01-01 00:00:00" ;
            time:calendar = "standard" ;
            time:axis = "T" ;
    float SST(time, lat, lon) ;
            SST:long_name = "sea_surface_temperature" ;
            SST:units = "degree celsius" ;
            SST:_FillValue = NaNf ;
            SST:missing_value = NaNf ;
            SST:var_desc = "sea surface temperature" ;

Alternative 2
The spatial dimensions and corresponding variables exist in the source file but are not denoted as lon and lat. Then each data variable (SST, in this example) needs to have an attribute coordinates that holds the names of the coordinate variables.
SST:coordinates = "lon lat" ;

Example:
dimensions:
    TSTEP = UNLIMITED ; // (24 currently)
    COL = 112 ;
    ROW = 106 ;
variables:                     " ;
    double lon(ROW, COL) ;
        lon:standard_name = "longitude" ;
        lon:long_name = "longitude coordinate" ;
        lon:units = "degrees_east" ;
        lon:_CoordinateAxisType = "Lon" ;
    double lat(ROW, COL) ;
        lat:standard_name = "latitude" ;
        lat:long_name = "latitude coordinate" ;
        lat:units = "degrees_north" ;
        lat:_CoordinateAxisType = "Lat" ;
    double time(TSTEP) ;
        time:standard_name = "time" ;
        time:long_name = "time" ;
        time:units = "seconds since 1900-01-01 00:00:00" ;
        time:calendar = "standard" ;
    float SST(TSTEP, ROW, COL) ;
        SST:long_name = "sea_surface_temperature" ;
        SST:units = "degree celsius" ;
        SST:coordinates = "lon lat" ;
        SST:var_desc = "sea surface temperature" ;

Note:
If the coordinate variables are missing, then they can be created via the setgrid operator. If we want to add a grid definition to the source file then we need the source file's grid definition in the text file (see 'define grid').
cdo setgrid,mySourceGridDef INFILE_NO_COORDS.nc INFILE_WI_COORDS.nc

> **Comments:**
> **username_3**: Is there an equally simple way to proceed when setting coordinates for a projected coordinate system? I didn't understand much from the documentation.  
> **username_1**: @username_3 You mean when you have some projection, which does not project your model grid on a regular lat-lon grid? Do you mean interpolation or just setting a grid definition? Better you ask a new question (refer to this one) including an example of your data set.  
> **username_3**: yes, exactly, something like Lambert Conformal Conic etc. Essentially, I wanted to set the grid definition, so that for example in Panoply it would plot the data in the correct geographic location. And yes, ultimately I'm interested in regridding. Ok, I guess I'll turn this into a question... :-)  
> **username_1**: @username_3 I just re-read my answer. It actually solves your issue if you already have your coordinates available in one netCDF file.  
> **username_3**: You are right, actually. After some trial-and-error progress I was able to do the regridding successfully - thank you for your detailed description! But the validity of my workflow is questionable. I created and saved the data in R with original coordinates in [EPSG:3333](http://spatialreference.org/ref/epsg/3333/). I solved the georeferencing problem by adding projection metadata. I did the transformation to WGS84 to get the cell centre coordinates in lat-long and saved them to variables lon and lat (just like your alternative 2). The output of `griddes` for this file was a curvilinear grid.  

---

### Answer by username_2 on 2018-09-02. Score: 0

Using Python, the best solution I've been able to find is pyresample. See this [blog post](http://earthpy.org/interpolation_between_grids_with_pyresample.html).


---

