Showing posts with label Ocean Matlab. Show all posts
Showing posts with label Ocean Matlab. Show all posts

Thursday, 13 February 2014

Read Ocean Current Data from NetCDF File in Matlab

Thursday, 13 February 2014 | by Riza | | 4 comments

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.
  • Sea current data used here is NetCDF file, for example I use current data from Ocean Surface Current Analyses - Real time (OSCAR) NOAA which can be downloaded here.
  • Download GSHHS shapefile here as a coastline.
  • Open Matlab and use this script.
clc
clear all
close all

uc=ncgeodataset('arusindian.nc');

lat=uc.data('lat');
lon=uc.data('lon');
for i=find(lon>180):length(lon)
    lon(i)=lon(i)-360;
end

time=uc.time('time');%result 754324
tgl=datestr(time);

north =   max(lat);  % batas utara
south =   min(lat);  % batas selatan
west  =   min(lon);  % batas barat
east  =   max(lon);  % batas timur

s=gshhs('gshhs_l.b',[double(south) double(north)], [double(west) double(east)]);

    
arus_u=uc{'u'}(1,1,:,:);
arus_u=reshape(arus_u,size(arus_u,3),size(arus_u,4));

arus_v=uc{'v'}(1,1,:,:);
arus_v=reshape(arus_v,size(arus_v,3),size(arus_v,4));

dx=0.1;
[lon_r,lat_r]=meshgrid(west:dx:east+2,south:dx:north+2);
ucur=interp2(lon,lat,arus_u,lon_r,lat_r,'cubic'); 
vcur=interp2(lon,lat,arus_v,lon_r,lat_r,'cubic');

da=1.7;
[lon_a,lat_a]=meshgrid(west:da:east,south:da:north);
ucura=interp2(lon,lat,arus_u,lon_a,lat_a,'cubic');
vcura=interp2(lon,lat,arus_v,lon_a,lat_a,'cubic');

mag=sqrt(ucur.^2+vcur.^2);

quiver(lon_a,lat_a,ucura,vcura,'k','LineWidth',1.13);
hold on
pcolorjw(lon_r,lat_r,mag);
geoshow(s,'facecolor',[0 0 0]);
z=colorbar;
set(get(z,'ylabel'),'String','Speed (Knots)','fontweight','bold');

axis equal
axis([west east south north]);
caxis([0 1])
xlabel('Longitude','fontweight','bold');
ylabel('Latitude','fontweight','bold');
title(['Arus Muka Laut Pada ' tgl(1,:)],'fontweight','bold');
set(gcf,'renderer','zbuffer','paperpositionmode','auto');

here some sample I get,






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‎

Tuesday, 11 February 2014

Read Sea Surface Temperature (SST) Data from NetCDF File in Matlab

Tuesday, 11 February 2014 | by Riza | | 2 comments

It's simple, just follow this step.....

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.
  • SST file used here is NetCDF file, for example I use SST data from Earth System Research Laboratory (ESRL) NOAA which can be downloaded here.
  • Download GSHHS Shapefile here as a coastline.
  • Open Matlab and use this script.
clc
clear all
close all

utara=7;
selatan=-11;
barat=95;
timur=140;

negara=gshhs('gshhs_l.b',[selatan utara],[barat timur]);

dt=ncgeodataset('sst.mnmean.nc');

lon=dt.data('lon');
lat=dt.data('lat');
time=dt.data('time');
tgl=datestr(dt.time('time'));

for i=find(lon>180):length(lon)
    lon(i)=lon(i)-360;
end

sst=dt{'sst'}(length(time),:,:);
sst=reshape(sst,size(sst,2),size(sst,3));

dx=1;
[lon_r,lat_r]=meshgrid(barat:dx:timur+2,selatan:dx:utara+2);
sst_x=interp2(lon,lat,sst,lon_r,lat_r,'spline');
pcolorjw(lon_r,lat_r,sst_x); shading interp;
hold on
geoshow (negara,'FaceColor',[.1 .7 .1]);
level=[negara.Level];
geoshow(negara(level==2),'Facecolor',[0 0 1]);

axis equal
axis([barat timur selatan utara])
%caxis([25 30])
title(['Suhu Permukaan Laut Pada ' tgl(length(time),:)],'FontWeight','Bold');
xlabel('Longitude','FontWeight','Bold');
ylabel('Latitude','FontWeight','Bold');

h=colorbar;
set(get(h,'title'),'String','Suhu (^{\circ}C)','FontWeight','Bold');
set(gcf,'PaperPositionmode','auto');

here some sample I get,






Thursday, 6 February 2014

Create Bathymetry Map in Matlab from xyz Data

Thursday, 6 February 2014 | by Riza | , | 41 comments

Matlab is a high-level computing language. There are many purpose using this program. In this post, I will describe how to make bathymetry map from xyz data in Matlab. Main idea of the process is only make x data, y data and z data to be a grid because of use surf command, so simple.

OK lets start .....

Before make a Matlab script, you must have xyz data, as an example I use data from  ETOPO 1 National Geophysical Data Center (NGDC) NOAA, you can download here. Select your area of interest and choose xyz data as an output format.

Steps in Matlab :
  • Load your xyz data.
  • x data is longitude, y data is latitude and z data is depth.
  • Use unique command for x data and y data.
lon = unique(yourdata(:,1));
lat = unique(yourdata(:,2));
  • Make a grid from lon and lat data
[LAT LON]=meshgrid(lat,lon);
  • Make z data as a grid using this command.
for n=1:length(yourdata)
   ilon = find(lon==yourdata(n,1));
   ilat = find(lat==yourdata(n,2));
   depth(ilon,ilat) = yourdata(n,3);
end
  • Use surf command.
surf(LON,LAT,depth);
shading interp;
  • Run your matlab script.
This is example of resulting display

Bathymetry Map of England


Bathymetry Map of Indonesia


Bathymetry Map of Japan