source: LMDZ6/branches/contrails/libf/phylmd/ecrad/test/ckdmip/evaluate_ckd_lw_fluxes.m

Last change on this file was 4773, checked in by idelkadi, 12 months ago
  • Update of Ecrad in LMDZ The same organization of the Ecrad offline version is retained in order to facilitate the updating of Ecrad in LMDZ and the comparison between online and offline results. version 1.6.1 of Ecrad (https://github.com/lguez/ecrad.git)
  • Implementation of the double call of Ecrad in LMDZ


File size: 8.2 KB
Line 
1function stats = evaluate_ckd_lw_fluxes(ref_file, ckd_file_in, model_name, scenario_title)
2% Evaluate the fluxes and heating rates from a CKD model with
3% line-by-line benchmark calculations for a CKDMIP scenario
4
5ickd_stats = 1; % Which CKD model do we show the stats for (0=none)
6
7if iscell(ckd_file_in)
8  ckd_file = ckd_file_in;
9else
10  ckd_file = {ckd_file_in};
11end
12
13if iscell(model_name)
14  titles = model_name;
15else
16  titles = {model_name}
17end
18
19combined_titles = '';
20for ie = 1:length(titles)
21  combined_titles = [combined_titles titles{ie} '_'];
22end
23ickd = 1:length(ckd_file);
24
25col_ref = 'k';
26cols = {'r','b','g','m','c'};
27alpha= [0.2 0.3 0.25 0.25 0.1 0.1];
28
29dflux_axis = [-4 4];
30%dfluxscatter_axis = [-8 8];
31dfluxscatter_axis = [-4 4];
32hr_axis = [-1 1];
33
34if length(ckd_file) > 1
35  do_legend = 1;
36else
37  do_legend = 0;
38end
39
40legfontsize = 7;
41error_save = [];
42
43
44[ref,attr_ref] = loadnc(ref_file);
45if ~exist('scenario_title','var')
46  scenario_title = attr_ref.global.scenario;
47end
48
49hr_ref = calc_hr(ref,'lw')';
50
51for ie = 1:length(ckd_file)
52  ckd{ie} = loadnc(ckd_file{ie});
53  hr_ckd{ie} = calc_hr(ckd{ie},'lw')';
54end
55
56% Pressure in hPa at full levels and half levels
57p_fl_hPa = 0.01.*0.5.*(ref.pressure_hl(1:end-1,:) + ref.pressure_hl(2:end,:));
58p_hl_hPa = 0.01.*ref.pressure_hl;
59
60iprof = 1:size(ref.pressure_hl,2);
61
62xloc = 0.025;yloc = 0.95;
63
64if nargout == 0
65  do_plot = 1;
66else
67  do_plot = 0;
68end
69
70if do_plot
71clf
72set(gcf,'paperposition',[0.5 0.5 27 25]);
73set(gcf,'defaultaxeslayer','top','defaultlinelinewidth',0.5,'defaulttextfontsize',10);
74
75% Plot reference flux and heating-rate profiles
76subplot(3,3,1)
77semilogy(ref.flux_up_lw(:,iprof), p_hl_hPa(:,iprof), col_ref);
78set(gca,'ydir','reverse');
79ylim([0.01 1000]);
80ylabel('Pressure (hPa)');
81xlabel('Upwelling longwave flux (W m^{-2})');
82title('Reference profiles')
83text(xloc, yloc, '\bf(a)','units','normalized');
84
85subplot(3,3,4)
86semilogy(ref.flux_dn_lw(:,iprof), p_hl_hPa, col_ref);
87set(gca,'ydir','reverse');
88ylim([0.01 1000]);
89ylabel('Pressure (hPa)');
90xlabel('Downwelling longwave flux (W m^{-2})');
91text(xloc, yloc, '\bf(d)','units','normalized');
92
93subplot(3,3,7)
94semilogy(hr_ref(:,iprof), p_fl_hPa(:,iprof), col_ref);
95set(gca,'ydir','reverse');
96ylim([0.01 1000]);
97ylabel('Pressure (hPa)');
98xlabel('Heating rate (K d^{-1})');
99xlim([-25 5]);
100text(xloc, yloc, '\bf(g)','units','normalized');
101
102% Plot random errors and biases in flux and heating-rate profiles
103subplot(3,3,8)
104end
105
106ileg = 1;
107leg = {};
108for ie = ickd
109  err = calc_hr_error(p_hl_hPa(:,iprof), hr_ckd{ie}(:,iprof),hr_ref(:,iprof), [0.02 4]);
110  err4 = calc_hr_error(p_hl_hPa(:,iprof), hr_ckd{ie}(:,iprof),hr_ref(:,iprof), [4 1100]);
111  leg{ileg} = [titles{ie} ' (RMSE=' num2str(err,'%0.3f') ' K d^{-1})'];
112  ileg = ileg+1;
113  error_save(1,ie) = err;
114  error_save(2,ie) = err4;
115
116  if do_plot
117    plot(-1,-1,cols{ie},'linewidth',1.5);
118    hold on
119  end
120end
121
122
123if do_plot
124for ie = ickd
125  hr_error = hr_ckd{ie}(:,iprof) - hr_ref(:,iprof);
126  hr_bias = mean(hr_error');
127  hr_ci = std(hr_error').*1.96;
128  hr_errmin = min(hr_error,[],2);
129  hr_errmax = max(hr_error,[],2);
130  pp = mean(p_fl_hPa');
131  h=fill([hr_bias+hr_ci flip(hr_bias-hr_ci)],...
132         [pp flip(pp)],'r');
133  set(h,'facecolor',cols{ie}(1),'edgecolor','none','facealpha',alpha(ie));
134  hold on
135  plot(hr_bias,pp,cols{ie},'linewidth',1.5);
136%  plot(hr_errmin,pp,[cols{ie}(1) '--'])
137%  plot(hr_errmax,pp,[cols{ie}(1) '--'])
138end
139plot(hr_axis,[0.02 0.02],'k:');
140plot(hr_axis,[4 4],'k:');
141set(gca,'ydir','reverse');
142set(gca,'yscale','log');
143ylim([0.01 1000]);
144ylabel('Pressure (hPa)');
145xlabel('Heating rate error (K d^{-1})');
146xlim(hr_axis);
147plot([0 0],[0.01 1000],'k:');
148%if do_legend
149%  set(legend(leg,'location','south'),'fontsize',legfontsize','box','on');
150  %end
151text(xloc, yloc, '\bf(h)','units','normalized');
152
153subplot(3,3,2)
154for ie = ickd
155  plot(-1,-1,cols{ie},'linewidth',1.5);
156  hold on
157end
158for ie = ickd
159  flux_error = ckd{ie}.flux_up_lw(:,iprof) - ref.flux_up_lw(:,iprof);
160  flux_bias = mean(flux_error');
161  flux_ci = std(flux_error').*1.96;
162  flux_errmin = min(flux_error,[],2);
163  flux_errmax = max(flux_error,[],2);
164  pp = mean(p_hl_hPa');
165  h=fill([flux_bias+flux_ci flip(flux_bias-flux_ci)],...
166         [pp flip(pp)],'r');
167  set(h,'facecolor',cols{ie}(1),'edgecolor','none','facealpha',alpha(ie));
168  hold on
169  plot(flux_bias,pp,cols{ie},'linewidth',1.5);
170end
171set(gca,'ydir','reverse','yscale','log');
172ylim([0.01 1000]);
173plot([0 0],[0.01 1000],'k:');
174ylabel('Pressure (hPa)');
175xlabel('Upwelling flux error (W m^{-2})');
176xlim(dflux_axis);
177title('Errors in profiles')
178if do_legend
179  set(legend(titles{ickd},'location','best'),'fontsize',legfontsize','box','on');
180end
181text(xloc, yloc, '\bf(b)','units','normalized');
182
183subplot(3,3,5)
184for ie = ickd
185  flux_error = ckd{ie}.flux_dn_lw(:,iprof) - ref.flux_dn_lw(:,iprof);
186  flux_bias = mean(flux_error');
187  flux_ci = std(flux_error').*1.96;
188  flux_errmin = min(flux_error,[],2);
189  flux_errmax = max(flux_error,[],2);
190  pp = mean(p_hl_hPa');
191  h=fill([flux_bias+flux_ci flip(flux_bias-flux_ci)],...
192         [pp flip(pp)],'r');
193  set(h,'facecolor',cols{ie}(1),'edgecolor','none','facealpha',alpha(ie));
194  hold on
195  plot(flux_bias,pp,cols{ie},'linewidth',1.5);
196end
197set(gca,'ydir','reverse','yscale','log');
198ylim([0.01 1000]);
199plot([0 0],[0.01 1000],'k:');
200ylabel('Pressure (hPa)');
201xlabel('Downwelling flux error (W m^{-2})');
202xlim(dflux_axis);
203text(xloc, yloc, '\bf(e)','units','normalized');
204
205subplot(3,3,3)
206ileg = 1;
207leg = {};
208end
209
210for ie = ickd
211  mydiff = ckd{ie}.flux_up_lw(1,iprof)-ref.flux_up_lw(1,iprof);
212  err = sqrt(mean(mydiff.^2));
213  leg{ileg} = [titles{ie} ' (RMSE=' num2str(err,'%0.2f') ' W m^{-2})'];
214  error_save(3,ie) = err;
215  error_save(4,ie) = mean(mydiff);
216  %plot(-1,-1,cols{ie},'linewidth',1.5);
217  ileg = ileg+1;
218  if do_plot
219    plot(ref.flux_up_lw(1,iprof), mydiff, ...
220         [cols{ie}(1) 'o']);
221    hold on
222  end
223end
224if do_plot
225if do_legend
226  set(legend(leg,'location','best'),'fontsize',legfontsize','box','on')
227end
228xlabel('Reference TOA upwelling (W m^{-2})');
229ylabel('TOA upwelling error (W m^{-2})');
230xlim([0 400]);
231plot(xlim,[0 0],'k:','linewidth',0.5);
232ylim(dfluxscatter_axis);
233title('Errors at surface and TOA');
234text(xloc, yloc, '\bf(c)','units','normalized');
235
236subplot(3,3,6)
237end
238ileg = 1;
239leg = {};
240for ie = ickd
241  mydiff = ckd{ie}.flux_dn_lw(end,iprof)-ref.flux_dn_lw(end,iprof);
242  err = sqrt(mean(mydiff.^2));
243  leg{ileg} = [titles{ie} ' (RMSE=' num2str(err,'%0.2f') ' W m^{-2})'];
244  error_save(5,ie) = err;
245  error_save(6,ie) = mean(mydiff);
246  ileg = ileg+1;
247  if do_plot
248    plot(ref.flux_dn_lw(end,iprof), mydiff, ...
249         [cols{ie}(1) 'o']);
250    hold on
251  end
252end
253if do_plot
254if do_legend
255  set(legend(leg,'location','best'),'fontsize',legfontsize')
256end
257xlabel('Reference surface downwelling (W m^{-2})');
258ylabel('Surface downwelling error (W m^{-2})');
259plot(xlim,[0 0],'k:','linewidth',0.5);
260ylim(dfluxscatter_axis);
261text(xloc, yloc, '\bf(f)','units','normalized');
262
263h=subplot(3,3,9);
264set(h,'visible','off')
265
266xstart = -0.15;
267text(xstart,0.95,['\bfScenario: ' scenario_title],'fontsize',12);
268
269if ickd_stats > 0
270  for ie = ickd_stats
271    text(xstart,0.85,['\bfCKD model: ' titles{ie}],'fontsize',12);
272    ystart = 0.75; %-0.4.*(ie-1);
273    %text(xstart,ystart,['\bfRMS errors in ' titles{ie} ':'],'units','normalized');
274    text(xstart,ystart,['Bias TOA upwelling: ' num2str(error_save(4,ie),'%0.2f') ' W m^{-2}'],'units','normalized');
275    text(xstart,ystart-0.1,['Bias surface downwelling: ' num2str(error_save(6,ie),'%0.2f') ' W m^{-2}'],'units','normalized');
276    text(xstart,ystart-0.2,['RMSE TOA upwelling: ' num2str(error_save(3,ie),'%0.2f') ' W m^{-2}'],'units','normalized');
277    text(xstart,ystart-0.3,['RMSE surface downwelling: ' num2str(error_save(5,ie),'%0.2f') ' W m^{-2}'],'units','normalized');
278    text(xstart,ystart-0.4,['RMSE heating rate (0.02-4 hPa):  ' num2str(error_save(1,ie),'%0.3f') ' K d^{-1}'],'units','normalized');
279    text(xstart,ystart-0.5,['RMSE heating rate (4-1100 hPa):  ' num2str(error_save(2,ie),'%0.3f') ' K d^{-1}'],'units','normalized');
280   
281  end
282end
283
284drawnow
285end
286%print('-dpng','-painters','-r100',[combined_titles 'evaluation1_fluxes_' scenario '.png']);
287%end
288
289if nargin > 0
290  stats.toa_up_bias = error_save(4,:);
291  stats.surf_dn_bias= error_save(6,:);
292  stats.toa_up_rmse = error_save(3,:);
293  stats.surf_dn_rmse= error_save(5,:);
294  stats.heating_rate_low_rmse=error_save(1,:);
295  stats.heating_rate_high_rmse=error_save(2,:);
296end
297
Note: See TracBrowser for help on using the repository browser.