1% A realistic example of divand in 2 dimensions
2% with salinity observations in the Mediterranean Sea at 30m.
3%
4% Data is available at
5% http://modb.oce.ulg.ac.be/mediawiki/index.php/Divand
6
7% load observations
8
9load data.dat
10
11% extract columns of data
12lonobs = data(:,1);
13latobs = data(:,2);
14S = data(:,3);
15
16% load bathymetry
17% bath is negative in water and positive in air
18bat = ncread('diva_bath.nc','bat');
19lon = ncread('diva_bath.nc','lon');
20lat = ncread('diva_bath.nc','lat');
21
22% compute grid metric
23% pm and pn are in meters^-1
24[lon,lat] = ndgrid(lon,lat);
25[pm,pn] = divand_metric(lon,lat);
26
27% compute mean and anomalies
28Smean = mean(S);
29Sanom = S - mean(S);
30
31% correlation length (in meters)
32len = 200e3;
33len = 100e3;
34% signal-to-noise ratio
35lambda = 50.5;
36
37% land-sea mask
38% mask everything below 30 m
39mask = bat < -30;
40
41% mask for the analysis
42maska = mask;
43% remove Atlantic
44maska(1:60,130:end) = 0;
45% remove Black Sea
46maska(323:end,100:end) = 0;
47
48% make analysis
49Sa =  divand(maska,{pm,pn},{lon,lat},{lonobs,latobs},Sanom,len,lambda);
50
51% add mean back
52Sa2 = Sa + Smean;
53
54% create plots
55
56% color axis
57ca = [36.2520   39.4480];
58
59% aspect ratio
60ar = [1  cos(mean(lat(:)) * pi/180) 1];
61
62
63subplot(2,1,1);
64scatter(lonobs,latobs,10,S)
65caxis(ca);
66colorbar
67hold on, contour(lon,lat,mask,0.5,'k')
68xlim(lon([1 end]))
69ylim(lat([1 end]))
70title('Observations');
71set(gca,'DataAspectRatio',ar,'Layer','top')
72
73subplot(2,1,2);
74pcolor(lon,lat,Sa2), shading flat,colorbar
75hold on
76plot(lonobs,latobs,'k.','MarkerSize',1)
77caxis(ca)
78contour(lon,lat,mask,0.5,'k')
79xlim(lon([1 end]))
80ylim(lat([1 end]))
81title('Analysis');
82set(gca,'DataAspectRatio',ar,'Layer','top')
83
84set(gcf,'PaperUnits','centimeters','PaperPosition',[0 0 15 15 ]);
85print -dpng divand_realistic_example.png
86% Copyright (C) 2014 Alexander Barth <a.barth@ulg.ac.be>
87%
88% This program is free software; you can redistribute it and/or modify it under
89% the terms of the GNU General Public License as published by the Free Software
90% Foundation; either version 2 of the License, or (at your option) any later
91% version.
92%
93% This program is distributed in the hope that it will be useful, but WITHOUT
94% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
95% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
96% details.
97%
98% You should have received a copy of the GNU General Public License along with
99% this program; if not, see <http://www.gnu.org/licenses/>.
100