/[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.3 - (hide annotations) (download)
Thu Feb 18 01:10:59 2010 UTC (15 years, 5 months ago) by gforget
Branch: MAIN
Changes since 1.2: +1 -1 lines
guiding the user to change path names

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

  ViewVC Help
Powered by ViewVC 1.1.22