Wednesday, 12 February 2014

Read Wind Data from NetCDF File in Matlab

Wednesday, 12 February 2014 | by Riza | | 3 comments

The steps similar with previous post about how to read SST file ......

Before create a script, make sure your Matlab has integrated with NetCDF toolbox, if don't have, you can search in google or any search engine to get toolbox, but in this post I use nctoolbox, for further information such as installation, guide and download nctoolbox open this site.

  • Wind data used here are data from EMCWF which can be downloaded here.
  • Download coastline data, you can use GSHHS or Coastline extractor from NOAA here,  both Matlab Script is a bit different, if you use GSHHS, the script to show coastline is similar with previous post, so in here I use coastline from Coastline extractor. 
  • Open Matlab and use this script.
clc
clear all
close all

coast_line=load('korea-japan.dat');

north =   max(coast_line(:,2));  
south =   min(coast_line(:,2));  
west  =   min(coast_line(:,1));  
east  =   max(coast_line(:,1));  

nc=ncgeodataset('korea-japan-angin.nc');

lat=nc.data('latitude'); 
lon=nc.data('longitude');

tgl=nc.time('time'); 
date=datestr(tgl); 

v=nc{'v10'}(1,:,:);
v=reshape(v,size(v,2),size(v,3)); 
u=nc{'u10'}(1,:,:);
u=reshape(u,size(u,2),size(u,3));
        
dx_r=0.5;       
[lon_x,lat_x]=meshgrid(west:dx_r:east+2,south:dx_r:north+2);

u_wind_x=interp2(lon,lat,u,lon_x,lat_x,'spline');       
v_wind_x=interp2(lon,lat,v,lon_x,lat_x,'spline');

u_mag=sqrt(u_wind_x.^2+v_wind_x.^2);

pcolorjw(lon_x,lat_x,u_mag);shading('interp')
hold on
quiver(lon_x,lat_x,u_wind_x,v_wind_x,'k','Linewidth',1.2);
plot(coast_line(:,1),coast_line(:,2),'k','LineWidth',1.2)
axis equal
axis([min(coast_line(:,1)) max(coast_line(:,1)) min(coast_line(:,2)) max(coast_line(:,2))])
caxis([1 10])
     
h=colorbar;
set(get(h,'title'),'String','v (m/s)','FontWeight','Bold');
title(['Kecepatan Angin Pada ' date(1,:)],'FontWeight','Bold'); 
set(gcf,'PaperPositionMode','auto');    

Here some sample I have,





Refference
agusset.files.wordpress.com/2008/02/modul_membaca_netcdf.pdf‎

3 comments:

  1. Hi,
    Thanks for your code; I try running your code ; But my result looks so bad. Could you send me your animation code. Thanks

    ReplyDelete
  2. HI, Thanks for you code .. but i can't accept wind data please your sample file and cod and animation code

    my email "ym91206@naver.com" thank you

    ReplyDelete
  3. Hi, you have got a goor script. I have used it for plotting some maps from netcdf file, but in "interp2" and "quiver" functions it turns in a problem, because matrix must be agree, but latitude is 241, longitude is 480, and u and v arrays are [240 380], so it cannot plot yet!
    What could I do for get plot it?

    ReplyDelete