1 |
gforget |
1.1 |
function []=insitu_cost(dirData,doComp,varargin); |
2 |
|
|
%[]=insitu_cost(dirData,listData,listVar,varargin); |
3 |
|
|
%object: computes or displays cost function statistics |
4 |
|
|
%input: dirData is the data main directory name |
5 |
|
|
% doComp states whether to compute & save (1) or load & display (0) |
6 |
|
|
%optional must take the following form {'name',param1,param2,...} Active ones are |
7 |
|
|
% {'subdirData',subdirData} is the data subdirectory name ('profiles/output/' by default) |
8 |
|
|
% {'listData',data1,data2,...} where data1 e.g. is 'argo_indian.nc' |
9 |
|
|
% {'listVar',var1,var2} where var1 and var2 are 'T' and 'S' |
10 |
|
|
% {'years',year0,year1} to limit computation to [year0 year1] interval |
11 |
|
|
% {'subdirMat',subdirMat} where subdirMat is the output subdirectory ('mat/' by default) |
12 |
|
|
% {'suffMat',suffMat} is the mat file suffix ('all' by default) |
13 |
|
|
% {'subdirTex',subdirTex} where subdirTex is the tex directory ('tex/' by default) |
14 |
|
|
% {'addToTex',addToTex} states whether (1) or not (0 default) to |
15 |
|
|
% augment an ongoing tex file (see write2tex.m, subdirTex) |
16 |
|
|
% |
17 |
|
|
%example: insitu_cost('./',1,{'listData','argo_in*'}); |
18 |
|
|
|
19 |
|
|
%load paths and grid: |
20 |
|
|
%-------------------- |
21 |
|
|
global mygrid; if isempty(mygrid); grid_load('GRID/',5,'compact'); end; |
22 |
|
|
|
23 |
|
|
%set more optional paramaters to default values |
24 |
|
|
year0=1992; year1=2008; |
25 |
gforget |
1.2 |
listData={'WOD09_XBT*','WOD09_CTD*','argo_in*','argo_at*','argo_pa*','seals*'}; |
26 |
|
|
listVar={'T','S'}; |
27 |
|
|
%shorter test case: listData={'argo_in*'}; listVar={'T'}; |
28 |
gforget |
1.1 |
subdirData='/profiles/output/'; |
29 |
|
|
subdirMat='mat/'; suffMat='_all'; |
30 |
|
|
subdirTex='tex/'; addToTex=0; |
31 |
|
|
%set more optional paramaters to user defined values |
32 |
|
|
for ii=1:nargin-2; |
33 |
|
|
if strcmp(varargin{ii}{1},'listData'); listData={varargin{ii}{2:end}}; |
34 |
|
|
elseif strcmp(varargin{ii}{1},'listVar'); listVar={varargin{ii}{2:end}}; |
35 |
|
|
elseif strcmp(varargin{ii}{1},'years'); year0=varargin{ii}{2}; year1=varargin{ii}{3}; |
36 |
|
|
elseif strcmp(varargin{ii}{1},'subdirMat'); subdirMat=varargin{ii}{2}; |
37 |
|
|
elseif strcmp(varargin{ii}{1},'suffMat'); suffMat=['_' varargin{ii}{2}]; |
38 |
|
|
elseif strcmp(varargin{ii}{1},'subdirTex'); subdirTex=varargin{ii}{2}; |
39 |
|
|
elseif strcmp(varargin{ii}{1},'addToTex'); addToTex=varargin{ii}{2}; |
40 |
|
|
elseif strcmp(varargin{ii}{1},'subdirData'); subdirData=varargin{ii}{2}; |
41 |
|
|
else; |
42 |
|
|
warning('inputCheck:insitu_cost',... |
43 |
|
|
['unknown option ''' varargin{ii}{1} ''' was ignored']); |
44 |
|
|
end; |
45 |
|
|
end; |
46 |
|
|
|
47 |
|
|
if doComp; |
48 |
|
|
|
49 |
|
|
%time limits: |
50 |
|
|
date0=datenum(year0,1,1); date1=datenum(year1,12,31); |
51 |
|
|
|
52 |
|
|
for vv=1:length(listVar); |
53 |
|
|
varCur=listVar{vv}; |
54 |
|
|
|
55 |
|
|
%get the cost square root: |
56 |
|
|
[MITprof]=MITprof_stats_load([dirData '/' subdirData],listData,varCur); |
57 |
|
|
|
58 |
|
|
%mask out values that are not in year range: |
59 |
|
|
ii=find(MITprof.prof_date<date0|MITprof.prof_date>date1); |
60 |
|
|
MITprof.prof(ii,:)=NaN; |
61 |
|
|
|
62 |
|
|
%mean and median: |
63 |
|
|
costCur=[nanmean(MITprof.prof(:).^2) nanmedian(MITprof.prof(:).^2)]; |
64 |
|
|
fprintf('mean cost for %s: %0.3g (median: %0.3g) \n',varCur,costCur); |
65 |
|
|
eval(['costAve' varCur '.mean=costCur(1);']); |
66 |
|
|
eval(['costAve' varCur '.median=costCur(2);']); |
67 |
|
|
|
68 |
|
|
%depth/time mean cost: |
69 |
|
|
tmp_date=(MITprof.prof_date-date0)/365; |
70 |
|
|
% [x,y,z,n]=MITprof_stats(MITprof.prof_depth,MITprof.prof_depth,... |
71 |
|
|
[x,y,z,n]=MITprof_stats(MITprof.prof_depth,[0:200:1000 1500:500:6000],... |
72 |
|
|
tmp_date,[0:1/4:1+(year1-year0)],'mean',MITprof.prof.^2); |
73 |
|
|
z(n==0)=NaN; n(n==0)=NaN; |
74 |
|
|
eval(['depthTimeCost' varCur '.x=x;']); eval(['depthTimeCost' varCur '.y=y;']); |
75 |
|
|
eval(['depthTimeCost' varCur '.z=z;']); eval(['depthTimeCost' varCur '.n=n;']); |
76 |
|
|
|
77 |
|
|
%latitudinal distribution: |
78 |
|
|
[x,y,z,n]=MITprof_stats(MITprof.prof_lat,[-90:5:90],MITprof.prof,[-5:0.25:5]); |
79 |
|
|
z(n==0)=NaN; n(n==0)=NaN; |
80 |
|
|
eval(['misfitDistrib' varCur '.x=x;']); eval(['misfitDistrib' varCur '.y=y;']); |
81 |
|
|
eval(['misfitDistrib' varCur '.z=z;']); eval(['misfitDistrib' varCur '.n=n;']); |
82 |
|
|
|
83 |
|
|
end; |
84 |
|
|
|
85 |
|
|
eval(['save ' dirData '/' subdirMat 'insitu_cost' suffMat '.mat costAve* misfitDistrib* depthTimeCost* year* listData listVar;']); |
86 |
|
|
|
87 |
|
|
else;%display result |
88 |
|
|
|
89 |
|
|
eval(['load ' dirData '/' subdirMat 'insitu_cost' suffMat '.mat;']); |
90 |
|
|
|
91 |
|
|
figureL; |
92 |
|
|
|
93 |
|
|
for vv=1:length(listVar); |
94 |
|
|
varCur=listVar{vv}; |
95 |
|
|
|
96 |
|
|
eval(['costCur=[costAve' varCur '.mean costAve' varCur '.median];']); |
97 |
|
|
|
98 |
|
|
eval(['x=depthTimeCost' varCur '.x;']); eval(['y=depthTimeCost' varCur '.y;']); |
99 |
|
|
eval(['z=depthTimeCost' varCur '.z;']); eval(['n=depthTimeCost' varCur '.n;']); |
100 |
|
|
z(n<1e2)=NaN; |
101 |
|
|
subplot(2,length(listVar),vv); depthStretchPlot('pcolor',{y,x,z},[0:200:1000 1500:500:6000],[0 1000 4000]); |
102 |
|
|
caxis([0 8]); shading flat; colorbar; ylabel('depth (in m)'); |
103 |
|
|
xlabel(['date (in years since ' num2str(year0) ')']); |
104 |
|
|
title(sprintf('mean cost for %s: %0.3g (median: %0.3g)',varCur,costCur)); |
105 |
|
|
|
106 |
|
|
%latitudinal distribution: |
107 |
|
|
eval(['x=misfitDistrib' varCur '.x;']); eval(['y=misfitDistrib' varCur '.y;']); |
108 |
|
|
eval(['z=misfitDistrib' varCur '.z;']); eval(['n=misfitDistrib' varCur '.n;']); |
109 |
|
|
tmp1=(nansum(n,2)>1e4)*ones(1,size(n,2)); z(tmp1==0)=NaN; |
110 |
|
|
subplot(2,length(listVar),vv+length(listVar)); contourf(x,y,z,[0:0.05:0.5]); grid on; |
111 |
|
|
caxis([0 0.5]); colorbar; ylabel('normalized misfit'); xlabel('latitude'); title('pdf'); |
112 |
|
|
|
113 |
|
|
end; |
114 |
|
|
|
115 |
|
|
myCaption={'in situ profiles cost function'}; |
116 |
|
|
if addToTex; write2tex([dirData '/' subdirTex '/myPlots.tex'],2,myCaption,gcf); end; |
117 |
|
|
|
118 |
|
|
end; |
119 |
|
|
|
120 |
|
|
|