1% Orthogonalize EOF modes. 2% 3% [U3,WE] = divand_orthogonalize_mode(mask,pmn,U) 4% 5% The modes U are orthogonalized using the mask and metric (pmn). WE is square 6% root of norm. Diagonal of WE.^2 is the surface of corresponding cell (units: 7% m). The output U3 represent the normalized EOFs (units: m-1) 8 9function [U3,WE] = divand_orthogonalize_modes(mask,pmn,U); 10 11pmn = cat_cell_array(pmn); 12% number of dimensions 13n = size(pmn,ndims(pmn)); 14 15sv = statevector_init(mask); 16d = statevector_pack(sv,1./(prod(pmn,n+1))); 17 18% spare root of the norm 19WE = sparse_diag(sqrt(d)); 20 21U2 = statevector_pack(sv,U); 22U2 = WE * U2; 23 24r = size(U2,2); 25[U3,S3,V3] = svds(U2,r); 26%U3 = reshape(U3,[size(mask) r]); 27 28U3 = inv(WE) * U3; 29 30%assert(U3' * WE^2 * U3, eye(r),1e-8) 31 32U3 = statevector_unpack(sv,U3); 33 34 35% Copyright (C) 2014 Alexander Barth <a.barth@ulg.ac.be> 36% 37% This program is free software; you can redistribute it and/or modify it under 38% the terms of the GNU General Public License as published by the Free Software 39% Foundation; either version 2 of the License, or (at your option) any later 40% version. 41% 42% This program is distributed in the hope that it will be useful, but WITHOUT 43% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 45% details. 46% 47% You should have received a copy of the GNU General Public License along with 48% this program; if not, see <http://www.gnu.org/licenses/>. 49