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

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

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


Revision 1.6 - (hide annotations) (download)
Fri Apr 30 06:32:52 2010 UTC (15 years, 3 months ago) by gforget
Branch: MAIN
Changes since 1.5: +1 -0 lines
added 'clear all;' at the start of tutorial routines

1 gforget 1.6 clear all;
2 gforget 1.1
3     %%%%%%%%%%%%%%%%%
4     %load parameters:
5     %%%%%%%%%%%%%%%%%
6     choiceV3orV4='v4'
7    
8 gforget 1.2 if ~isempty(choiceV3orV4)&isempty(whos('mygrid'));
9 gforget 1.1 gcmfaces_path;
10 gforget 1.5 dir0=[mydir '/sample_input/'];
11 gforget 1.4 dirGrid=[dir0 '/GRID' choiceV3orV4 '/'];
12     dirIn=[dir0 '/SAMPLE' choiceV3orV4 '/'];
13 gforget 1.2 if strcmp(choiceV3orV4,'v4'); nF=5; else; nF=1; end;
14     global mygrid; mygrid=[]; grid_load(dirGrid,nF);
15 gforget 1.1 end;
16    
17     %%%%%%%%%%%%%%%%%%%%%%%
18     %generate delaunay triangulation
19    
20     XC=convert2array(mygrid.XC);
21     YC=convert2array(mygrid.YC);
22    
23     %needed so that we do not loose data
24     XC(isnan(XC))=270;
25     YC(isnan(YC))=180;
26    
27     TRI=delaunay(XC,YC);
28     nxy = prod(size(XC));
29     Stri=sparse(TRI(:,[1 1 2 2 3 3]),TRI(:,[2 3 1 3 1 2]),1,nxy,nxy);
30    
31     %%%%%%%%%%%%%%%%%%%%%%%
32     %generate random data
33    
34     nobs=1e6;
35     lat=(rand(nobs,1)-0.5)*2*90;
36     lon=(rand(nobs,1)-0.5)*2*180; xx=find(lon>180);lon(xx)=lon(xx)-360;
37     obs=(rand(nobs,1)-0.5)*2;
38    
39     %%%%%%%%%%%%%%%%%%%%%%%%
40     %bin average random data
41    
42     OBS=0*XC; NOBS=OBS;
43     ik=dsearch(XC,YC,TRI,lon,lat,Stri);
44     for k=1:length(ik)
45     NOBS(ik(k))=NOBS(ik(k))+1;
46     OBS(ik(k))=OBS(ik(k))+obs(k);
47     end % k=1:length(ik)
48    
49     in=find(NOBS); OBS(in)=OBS(in)./NOBS(in);
50     in=find(~NOBS); OBS(in)=NaN; NOBS(in)=NaN;
51    
52     obsmap=convert2array(OBS,mygrid.XC); %put in gcmfaces format
53     obsmapcompact=convert2gcmfaces(obsmap); %put in gcm input format
54    
55     whos obs* OBS
56    
57     figure; set(gcf,'Units','Normalized','Position',[0.1 0.3 0.4 0.6]);
58     imagescnan(OBS','nancolor',[1 1 1]*0.8); axis xy; caxis([-1 1]/2); colorbar;
59     figure; set(gcf,'Units','Normalized','Position',[0.5 0.3 0.4 0.6]);
60     imagescnan(NOBS','nancolor',[1 1 1]*0.8); axis xy; caxis([0 25]); colorbar;
61    
62     %..... now illustrate the smoothing filter
63     test=input('illustrate smoothing filter? \n type 1 for yes or 0 for no\n');
64     if test; example_smooth; end;
65    
66    

  ViewVC Help
Powered by ViewVC 1.1.22