/[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.13 - (hide annotations) (download)
Fri Mar 20 15:41:43 2015 UTC (11 years, 7 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
Changes since 1.12: +4 -13 lines
- remove deprecated choiceGrid (or choiceV3orV4) switches and arguments

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

  ViewVC Help
Powered by ViewVC 1.1.22