/[MITgcm]/MITgcm_contrib/gael/matlab_class/sample_processing/example_griddata.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/sample_processing/example_griddata.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (hide annotations) (download)
Sun Jan 24 16:25:52 2016 UTC (10 years, 9 months ago) by gforget
Branch: MAIN
Changes since 1.14: +3 -4 lines
- gcmfaces_demo.m: improve help section, add comments wrt gcmfaces_global etc
- example*.m: homogeneize treatment of mygrid (don't reload if not needed)
  and path (use just gcmfaces_global)

1 gforget 1.13 function []=example_griddata();
2 gforget 1.8 %object: a griddata example within gcmfaces
3 gforget 1.1
4 gforget 1.14 %%%%%%%%%%%%%%%%%
5     %load grid:
6     %%%%%%%%%%%%%%%%%
7    
8 gforget 1.11 gcmfaces_global;
9 gforget 1.14
10 gforget 1.15 if isempty(mygrid);
11     grid_load;
12     end;
13 gforget 1.14
14 gforget 1.11 if myenv.verbose>0;
15     gcmfaces_msg('===============================================');
16     gcmfaces_msg(['*** entering example_griddata that will define ' ...
17 gforget 1.14 'a 2x2 gridded variable (an bathymetry field here), and then ' ...
18 gforget 1.11 'use griddata to map it to the chosen grid. '],'');
19     end;
20    
21 gforget 1.1 %%%%%%%%%%%%%%%%%%%%%%%
22 gforget 1.12 %get sample data: subsampled mygrid.Depth
23 gforget 1.11 if myenv.verbose>0;
24 gforget 1.12 gcmfaces_msg('* define test case : subsampled bathymetry');
25 gforget 1.11 end;
26 gforget 1.12 original_Depth=mygrid.Depth;
27     original_Depth(original_Depth==0)=NaN;
28     lon=mygrid.XC; lat=mygrid.YC;
29     for ff=1:mygrid.nFaces;
30     lon{ff}(1:2:end,:)=NaN;
31     lat{ff}(1:2:end,:)=NaN;
32     original_Depth{ff}(1:2:end,:)=NaN;
33     lon{ff}(:,1:2:end)=NaN;
34     lat{ff}(:,1:2:end)=NaN;
35     original_Depth{ff}(:,1:2:end)=NaN;
36     end;
37     lon=convert2vector(lon);
38     lat=convert2vector(lat);
39     vec=convert2vector(original_Depth);
40 gforget 1.1
41     %%%%%%%%%%%%%%%%%%%%%%%
42 gforget 1.11 %make sure to accomodate the two longitude conventions:
43     if myenv.verbose>0;
44     gcmfaces_msg('* accomodate both lon. conventions, then convert to data vector');
45     end;
46 gforget 1.12 x=[lon-360;lon;lon+360]; y=[lat;lat;lat]; z=[vec;vec;vec];
47 gforget 1.1 jj=find(~isnan(z)); x=x(jj); y=y(jj); z=z(jj);
48    
49 gforget 1.11 %%%%%%%%%%%%%%%%%%%%%%%
50     %do the interpolation:
51     if myenv.verbose>0;
52     gcmfaces_msg('* map/interpolate data using griddata');
53     end;
54 gforget 1.12 griddata_Depth=gcmfaces(5);
55 gforget 1.8 for ii=1:mygrid.nFaces;
56 gforget 1.12 xi=mygrid.XC{ii}; yi=mygrid.YC{ii};
57     zi = griddata(x',y',z',xi,yi);
58     griddata_Depth{ii}=zi;
59 gforget 1.1 end;
60    
61 gforget 1.12 %msk=mygrid.hFacC(:,:,1); griddata_Depth(find(msk==0))=NaN;
62 gforget 1.1
63     %%%%%%%%%%%%%%%%%%%%%%%
64     %illustrate the result:
65    
66 gforget 1.12 figureL;
67     subplot(2,1,1); set(gca,'FontSize',14);
68     [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,original_Depth);
69     pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat;
70     title('input to griddata');
71     subplot(2,1,2); set(gca,'FontSize',14);
72     [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,griddata_Depth);
73     pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat;
74     title('output of griddata');
75 gforget 1.1
76 gforget 1.11 if myenv.verbose>0;
77     gcmfaces_msg('* note of caution : griddata puts values on land. ');
78     gcmfaces_msg('*** leaving example_griddata');
79     gcmfaces_msg('===============================================');
80     end;

  ViewVC Help
Powered by ViewVC 1.1.22