How to regrid/interpolate netCDF data (2.5x2.5 degree) to higher resolution (e.g. 0.25x0.25 degree)?

4 views (last 30 days)
I am trying to use the script below by Hongxiao Jin in her Master thesis to regrid my netCDF NCEP Reanalysis II data to higher resolution at 0.25x0.25 degree. However, there are some errors in the script occurred. I installed mexcdf package to analyze netCDF data. Some errors occurred include: 1) Undefined function 'netcdf' for input arguments of type 'char'; 2) The expression to the left of the equals sign is not a valid target for an assignment in line 6. Thanks for your help.
%Extracting Air relative humidity Example 2004
nc = netcdf('rhum.mon.mean.nc', 'nowrite'); %matlab function
description = nc.description(:); % Global attribute.
variables = var(nc); % Get variable data.
Rhum2004=squeeze(variables{6}(301:312,1,:,:));%variables{6} 360X17X73X144
Rhum2004(find(Rhum2004==32766|Rhum2004==-32767)=nan;
nc = close(nc);
Rhum2004=permute(Rhum2004,[3 1 2]);%144X12X73 0->360
Rhum2004=[Rhum2004(73:144,:,:);Rhum2004(1:72,:,:)];%-180->180
Rhum2004=permute(Rhum2004,[2 3 1]);%12X73X144
Rhum2004=Rhum2004.*0.01+302.65;
[OX,OY]=meshgrid(-180:2.5:177.5,90:-2.5:-90);
[NX,NY]=meshgrid(-179.875:0.25:179.875,89.875:-0.25:-89.875);
RH2004=nan(12,720,1440);
for i=1:12
RH2004(i,:,:) = single(interp2(OX,OY,squeeze(Rhum2004(i,:,:)),NX,NY,'bilinear'));
end
save RH2004 RH2004
  3 Comments
tchu
tchu on 28 Jan 2014
I am using Matlab R2013a with mexcdf package. If I change netcdf to ncread, remove some lines including description, variables, permute; and change the order of lon and lat values in meshgrid function, then it works. I am checking the result to see whether it is correct and compatible to the original data (before interpolation). Thanks for your suggestion.

Sign in to comment.

Accepted Answer

tchu
tchu on 30 Jan 2014
%Regrid Air relative humidity Example 2004
rhum = ncread('rhum.mon.mean.nc','rhum');
Rhum2004 = squeeze(rhum(:,:,:,301:312));
size(Rhum2004)
Rhum2004(find(Rhum2004==32766|Rhum2004==-32767))=nan;
Rhum2004=[Rhum2004(73:144,:,:);Rhum2004(1:72,:,:)];%-180->180
[OY,OX]=meshgrid(90:-2.5:-90, -180:2.5:177.5);
[NY,NX]=meshgrid(89.875:-0.25:-89.875,-179.875:0.25:179.875);
RH2004=nan(1440,720,12);
for i=1:12
RH2004(:,:,i) = ...
single(interp2(OY,OX,Rhum2004(:,:,i),NY,NX,'bilinear'));
end
save RH2004 RH2004

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!