1 |
% compare finite difference and adjoint gradient |
2 |
% cost function is total sea-ice volume |
3 |
% control variable is surface air temperature |
4 |
|
5 |
path('../../lab_sea/matlab',path); |
6 |
load SSMI |
7 |
fn='../exe/adxx_atemp.0000000000.001.001.data'; |
8 |
a=readbin(fn,[20 16],1,'real*8'); |
9 |
fn='../exe/grad-res.txt'; |
10 |
fin=fopen(fn,'r'); b=0*a; c=0*a; d=0*a; |
11 |
tmp=fgetl(fin); tmp=fgetl(fin); tmp=fgetl(fin); |
12 |
for i=1:150 |
13 |
tmp=fgetl(fin); |
14 |
tmp=fgetl(fin); arr1=sscanf(tmp(10:85),'%f'); |
15 |
tmp=fgetl(fin); arr2=sscanf(tmp(10:85),'%f'); |
16 |
b(arr1(3),arr1(4))=arr2(6); |
17 |
c(arr1(3),arr1(4))=arr2(7); |
18 |
d(arr1(3),arr1(4))=arr2(8); |
19 |
end |
20 |
|
21 |
clf reset, orient tall, wysiwyg |
22 |
cx=[-1 1]; cl=[1 1 1]*.5; sc=3e5; |
23 |
ax=([min(lon) max(lon) min(lat) max(lat)]); |
24 |
subplot(411), mypcolor(lon,lat,b'/sc); caxis(cx), colorbar |
25 |
% plotland('k'), axis(ax), grid |
26 |
% plotland(cl,4), axis(ax) |
27 |
xlabel('Longitude East'), ylabel('Latitude North') |
28 |
title('Adjoint model: gradient of sea-ice volume wrt air temperature') |
29 |
subplot(412), mypcolor(lon,lat,c'/sc); caxis(cx), colorbar |
30 |
% plotland('k'), axis(ax), grid |
31 |
% plotland(cl,4), axis(ax) |
32 |
xlabel('Longitude East'), ylabel('Latitude North') |
33 |
title('Finite-difference: gradient of sea-ice volume w.r.t. air temperature') |
34 |
subplot(413), mypcolor(lon,lat,(c-b)'/sc); caxis(cx/10000), colorbar |
35 |
% plotland('k'), axis(ax), grid |
36 |
% plotland(cl,4), axis(ax) |
37 |
xlabel('Longitude East'), ylabel('Latitude North') |
38 |
title('Finite-difference minus adjoint gradient') |
39 |
subplot(414), mypcolor(lon,lat,d'); caxis([-2 2]), colorbar |
40 |
% plotland('k'), axis(ax), grid |
41 |
% plotland(cl,4), axis(ax) |
42 |
xlabel('Longitude East'), ylabel('Latitude North') |
43 |
title('( adjoint minus finite-difference ) / adjoint') |
44 |
|
45 |
% print -djpeg -r0 FIG1 |
46 |
% print -dpsc FIG1 |
47 |
|
48 |
%% orient tall, wysiwyg, clf |
49 |
%% fn='adxx_atemp.0000000000.001.001.data'; |
50 |
%% a=readbin(fn,[20 16 12],1,'real*8'); |
51 |
%% for i=1:12,subplot(4,3,i) |
52 |
%% mypcolor(lon,lat,a(:,:,i)'); |
53 |
%% caxis([-1 1]),colorbar |
54 |
%% title(['dJ/d(air-temp), day ' int2str(i*10-15)]) |
55 |
%% end |
56 |
%% print -djpeg -r0 FIG1 |
57 |
%% |
58 |
%% clf |
59 |
%% for i=1:11, subplot(4,3,i) |
60 |
%% a=readbin(['AREA.' myint2str(i*240-240,10) '.001.001.data'],[20 16],1,'real*8'); |
61 |
%% a(find(a<1&a>.5))=.75; a(find(a<.5&a>0))=.25; |
62 |
%% mypcolor(lon,lat,a'); colorbar |
63 |
%% title(['sea-ice area on day' int2str(i*10-10)]) |
64 |
%% end |
65 |
%% print -djpeg -r0 FIG2 |