# How to Regrid the netcdf data in order to achieve smaller/greater spatial resolution?

90 views (last 30 days)
Behzad Navidi on 6 Oct 2019
Commented: Behzad Navidi on 7 Oct 2019
I have a netcdf file with 0.5*0.5 degree (Lat*Lon) grided resolution for precipitation from 1982-2015 in all around the globe. now I want to interpolate (regrid) this file to 0.25*0.25 degree without changing the time. In fact I want to interpolate the precipitation data in 0.25*0.25 lat and lon.
Best Regards,

Chad Greene on 7 Oct 2019
This is pretty straightforward: Just use interp2.
When reading the data from the NetCDF file you might need to rotate and flip the grid to get the orientation right, but then let longitude act as the x variable and let latitude act as the y variable.
You can create the quarter-degree grid in one step with cdtgrid like this:
[lati,loni] = cdtgrid(1/4);
or you can create it manually by
[loni,lati] = meshgrid(min(lon):1/4max(lon),max(lat):-1/4:min(lat));
Then use interp2 like
zi = interp2(lon,lat,z,loni,lati);
Hope that helps.

#### 1 Comment

Behzad Navidi on 7 Oct 2019
Thank you for your answer. I do wath you say and I faced this error. do you have any idea?
my script is:
clc
clear
format compact
close all
filename='precip.mon.total.v2018.nc';
ncdisp(filename)
lat=double(lat);
lon=double(lon);
precip=double(precip);
t=double(t);
index=find(precip==-9.969209968386869e+36);
precip(index)=nan;
[lati,loni] = cdtgrid(1/4);
zi = interp2(lon,lat,precip,loni,lati);
command window show:
Source:
Format:
netcdf4_classic
Global Attributes:
Original_Source = 'http://www.dwd.de/en/FundE/Klima/KLIS/int/GPCC/GPCC.htm
Reference = 'Users of the data sets are kindly requested to give feed back and to refer to GPCC publications on this webpage: http://www.dwd.de/bvbw/appmanager/bvbw/dwdwwwDesktop/?_nfpb=true&_pageLabel=_dwdwww_klima_umwelt_datenzentren_wzn&T12404518261141645246564gsbDocumentPath=Content%2FOeffentlichkeit%2FKU%2FKU4%2FKU42%2Fteaser__product__access.html&_state=maximized&_windowLabel=T12404518261141645246564&lastPageLabel=_dwdwww_klima_umwelt_datenzentren_wzn'
Conventions = 'CF 1.0'
dataset_title = 'Global Precipitation Climatology Centre (GPCC)'
References = 'https://www.esrl.noaa.gov/psd/data/gridded/data.gpcc.html'
title = 'GPCC Full Data Reanalysis Version 2018 0.5x0.5 Monthly Total'
history = 'Created 09/2018 based on V2018 data obtained via ftp'
data_modified = '2019-03-12'
_NCProperties = 'version=2,netcdf=4.6.3,hdf5=1.10.5'
Dimensions:
lat = 360
lon = 720
nbnds = 2
time = 1512 (UNLIMITED)
Variables:
lat
Size: 360x1
Dimensions: lat
Datatype: single
Attributes:
long_name = 'Latitude'
units = 'degrees_north'
standard_name = 'latitude'
axis = 'Y'
coordinate_defines = 'point'
actual_range = [89.75 -89.75]
lon
Size: 720x1
Dimensions: lon
Datatype: single
Attributes:
long_name = 'Longitude'
units = 'degrees_east'
standard_name = 'longitude'
actual_range = [0.25 359.75]
axis = 'X'
coordinate_defines = 'point'
time
Size: 1512x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
units = 'days since 1800-1-1 00:00:00'
delta_t = '0000-01-00 00:00:00'
avg_period = '0000-01-00 00:00:00'
standard_name = 'time'
axis = 'T'
coordinate_defines = 'start'
actual_range = [33237 79227]
precip
Size: 720x360x1512
Dimensions: lon,lat,time
Datatype: single
Attributes:
missing_value = -9.969209968386869e+36
units = 'mm'
var_desc = 'Precipitation'
level_desc = 'Surface'
parent_stat = 'Observations'
long_name = 'GPCC Monthly total of precipitation'
valid_range = [0 8000]
statistic = 'Total'
level = 'Surface'
actual_range = [0 4552.4302]
dataset = 'GPCC Precipitation 0.5degree V2018 Full Reanalysis'
Error using .'
Transpose on ND array is not defined. Use PERMUTE instead.
Error in interp2 (line 122)
V = V.';
Error in test100 (line 23)
zi = interp2(lon,lat,precip,loni,lati);