/[MITgcm]/MITgcm_contrib/gael/matlab_class/ecco_v4/cost_bp.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/ecco_v4/cost_bp.m

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


Revision 1.13 - (hide annotations) (download)
Thu Jan 28 01:38:47 2016 UTC (9 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.12: +4 -3 lines
- minor changes.

1 gforget 1.6 function []=cost_bp(dirModel,dirMat,doComp,dirTex,nameTex);
2 gforget 1.1 %object: compute cost function term for grace data
3     %inputs: dimodel is the model directory
4 gforget 1.4 % dirMat is the directory where diagnozed .mat files will be saved
5     % -> set it to '' to use the default [dirModel 'mat/']
6 gforget 1.1 % doComp is a switch (1->compute; 0->display)
7 gforget 1.4 %optional: dirTex is the directory where tex and figures files are created
8     % (if not specified then display all results to screen instead)
9 gforget 1.6 % nameTex is the tex file name (default : 'myPlots')
10 gforget 1.1
11 gforget 1.12 if isempty(dirMat); dirMat=[dirModel 'mat' filesep]; else; dirMat=[dirMat filesep]; end;
12 gforget 1.10 if isempty(dir(dirMat)); mkdir([dirMat]); end;
13 gforget 1.4
14     %determine if and where to create tex and figures files
15 gforget 1.12 dirMat=[dirMat filesep];
16 gforget 1.4 if isempty(who('dirTex'));
17     addToTex=0;
18     else;
19     if ~ischar(dirTex); error('mis-specified dirTex'); end;
20 gforget 1.6 addToTex=1;
21     if isempty(who('nameTex')); nameTex='myPlots'; end;
22 gforget 1.12 fileTex=[dirTex filesep nameTex '.tex'];
23 gforget 1.4 end;
24 gforget 1.1
25     if doComp;
26    
27     %load grid
28 gforget 1.3 gcmfaces_global;
29     if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end;
30     if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end;
31 gforget 1.1
32 gforget 1.11 if isempty(dir([dirModel 'barfiles']));
33     dirEcco=dirModel;
34     else;
35     dirEcco=[dirModel 'barfiles' filesep];
36     end;
37    
38 gforget 1.13 nameSigma='GRACE_CSR_withland_err';
39     if ~isempty([dirModel nameSigma]);
40 gforget 1.11 dirSigma=dirModel;
41     else;
42 gforget 1.13 error(['could not find ' nameSigma]);
43 gforget 1.11 end;
44    
45 gforget 1.1 %read model cost output
46 gforget 1.11 fld_dat=rdmds2gcmfaces([dirEcco 'bpdatanom_smooth']);
47     fld_dif=rdmds2gcmfaces([dirEcco 'bpdifanom_smooth']);
48 gforget 1.1
49     %mask:
50 gforget 1.11 fld_msk=rdmds2gcmfaces([dirEcco 'bpdatanom_raw']);
51 gforget 1.1 fld_msk(find(fld_msk~=0))=1;
52     fld_msk(find(fld_msk==0))=NaN;
53    
54     fld_dif=fld_dif.*fld_msk;
55     fld_dat=fld_dat.*fld_msk;
56     fld_mod=fld_dat+fld_dif;%compute model values
57    
58     %read uncertainty fields
59 gforget 1.13 fld_err=read2memory([dirSigma nameSigma],[90 1170]);
60 gforget 1.1 fld_err=convert2gcmfaces(fld_err);
61     fld_err(find(fld_err==0))=NaN;
62    
63     %compute weight
64     fld_w=fld_err.^-2;
65    
66     %compute cost
67 gforget 1.9 fld_cost=mk3D(fld_w,fld_dif).*(fld_dif.^2);
68 gforget 1.1 fld_cost=nanmean(fld_cost,3);
69    
70     fld_dif=nanstd(fld_dif,[],3);
71     fld_mod=nanstd(fld_mod,[],3);
72     fld_dat=nanstd(fld_dat,[],3);
73    
74 gforget 1.9 if ~isdir([dirMat 'cost/']); mkdir([dirMat 'cost/']); end;
75     eval(['save ' dirMat '/cost/cost_bp.mat fld_err fld_dif fld_mod fld_dat fld_cost;']);
76 gforget 1.1
77     else;%display previously computed results
78    
79     global mygrid;
80    
81 gforget 1.8 if isdir([dirMat 'cost/']); dirMat=[dirMat 'cost/']; end;
82    
83 gforget 1.4 eval(['load ' dirMat '/cost_bp.mat;']);
84 gforget 1.1
85     %figure; m_map_gcmfaces(fld_cost,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
86     figure; m_map_gcmfaces(fld_dif,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
87 gforget 1.2 myCaption={'modeled-observed rms -- bottom pressure (cm)'};
88 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
89 gforget 1.1
90     figure; m_map_gcmfaces(fld_mod,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
91     myCaption={'rms modeled -- bottom pressure (cm)'};
92 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
93 gforget 1.1
94     figure; m_map_gcmfaces(fld_dat,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
95     myCaption={'rms observed -- bottom pressure (cm)'};
96 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
97 gforget 1.1
98 gforget 1.7 figure; m_map_gcmfaces(fld_cost,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
99     myCaption={'Cost function'};
100     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
101    
102 gforget 1.1 end;
103    

  ViewVC Help
Powered by ViewVC 1.1.22