/[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.14 - (hide annotations) (download)
Mon Jan 11 17:30:11 2016 UTC (10 years, 9 months ago) by gforget
Branch: MAIN
Changes since 1.13: +11 -12 lines
- revise handing of path, grid and input files, warnings and messages:

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

  ViewVC Help
Powered by ViewVC 1.1.22