Changeset 581 for trunk/src/filter_tps.m
 Timestamp:
 Mar 12, 2013, 12:52:13 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/filter_tps.m
r494 r581 1 1 %'filter_tps': find the thin plate spline coefficients for interpolationsmoothing 2 2 % 3 % [SubRange,Nb Sites,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold)3 % [SubRange,NbCentres,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold) 4 4 % 5 5 % OUTPUT: 6 6 % SubRange(NbCoord,NbSubdomain,2): range (min, max) of the coordiantes x and y respectively, for each subdomain 7 % Nb Sites(NbSubdomain): number of source points for each subdomain7 % NbCentres(NbSubdomain): number of source points for each subdomain 8 8 % FF: false flags 9 9 % U_smooth, V_smooth: filtered velocity components at the positions of the initial data 10 % Coord_tps(Nb Sites,NbCoord,NbSubdomain): positions of the tps centres10 % Coord_tps(NbCentres,NbCoord,NbSubdomain): positions of the tps centres 11 11 % U_tps,V_tps: weight of the tps for each subdomain 12 12 % to get the interpolated field values, use the function calc_field.m … … 19 19 % Subdomain: estimated number of data points in each subdomain 20 20 21 function [SubRange,NbSites,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold) 22 %subdomain decomposition 21 function [SubRange,NbCentres,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold) 22 23 %% adjust subdomain decomposition 23 24 warning off 24 nbvec=size(Coord,1); 25 W_tps=[];%default 26 W_smooth=[]; 25 NbVec=size(Coord,1); 27 26 NbCoord=size(Coord,2); 28 NbSubDomain=nbvec/SubDomain; 29 MinCoord=min(Coord,[],1); 30 MaxCoord=max(Coord,[],1); 27 MinCoord=min(Coord,[],1);%lower coordinate bounds 28 MaxCoord=max(Coord,[],1);%upper coordinate bounds 31 29 Range=MaxCoordMinCoord; 32 30 AspectRatio=Range(2)/Range(1); 31 NbSubDomain=NbVec/SubDomain; 33 32 NbSubDomainX=max(floor(sqrt(NbSubDomain/AspectRatio)),1); 34 33 NbSubDomainY=max(floor(sqrt(NbSubDomain*AspectRatio)),1); … … 41 40 CentreY=reshape(CentreY,1,[]);% Y positions of subdomain centres 42 41 CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres 43 rho=Siz(1)*Siz(2)*Rho/1000;%optimum rho increase as the area of the subdomain (division by 10^6 to reach good values with the default GUI input) 44 U_tps_sub=zeros(nbvec,NbSubDomain);%default spline 45 V_tps_sub=zeros(nbvec,NbSubDomain);%default spline 46 Indices_tps=zeros(nbvec,NbSubDomain);%default indices 47 U_smooth=zeros(nbvec,1); 48 V_smooth=zeros(nbvec,1); 49 nb_select=zeros(nbvec,1); 50 FF=zeros(nbvec,1); 42 43 %% smoothing parameter 44 rho=Siz(1)*Siz(2)*Rho/1000;%optimum rho increase as the area of the subdomain (division by 1000 to reach good values with the default GUI input) 45 46 %% default output 47 SubRange=zeros(NbCoord,2,NbSubDomain);%initialise the positions of subdomains 48 NbCentres=zeros(NbSubDomain);%number of interpolated values per subdomain, =0 by default 49 Coord_tps=zeros(NbVec,NbCoord,NbSubDomain);% default positions of the tps source= initial positions of the good vectors sorted by subdomain 50 U_tps=zeros(NbVec,NbSubDomain);%default spline 51 V_tps=zeros(NbVec,NbSubDomain);%default spline 52 W_tps=[];%default (2 component case) 53 U_smooth=zeros(NbVec,1); % smoothed velocity U at the initial positions 54 V_smooth=zeros(NbVec,1);% smoothed velocity V at the initial positions 55 W_smooth=[];%default (2 component case) 56 FF=zeros(NbVec,1); 57 nb_select=zeros(NbVec,1); 51 58 check_empty=zeros(1,NbSubDomain); 52 SubRange=zeros(NbCoord,2,NbSubDomain);%initialise the positions of subdomains 53 % SubRangy=zeros(NbSubDomain,2);59 60 %% calculate tps coeff in each subdomain 54 61 for isub=1:NbSubDomain 55 62 SubRange(1,:,isub)=[CentreX(isub)0.55*Siz(1) CentreX(isub)+0.55*Siz(1)]; … … 57 64 ind_sel_previous=[]; 58 65 ind_sel=0; 59 while numel(ind_sel)>numel(ind_sel_previous) %increase the subdomain during four iterations at most 66 %increase iteratively the subdomain if it contains less than SubDomainNbVec/4 source vectors 67 while numel(ind_sel)>numel(ind_sel_previous) 60 68 ind_sel_previous=ind_sel; 61 69 ind_sel=find(Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub)); 62 70 % if no vector in the subdomain, skip the subdomain 63 71 if isempty(ind_sel) 64 check_empty(isub)=1; 72 check_empty(isub)=1; 65 73 U_tps(1,isub)=0;%define U_tps and V_tps by default 66 74 V_tps(1,isub)=0; … … 70 78 SubRange(:,1,isub)=SubRange(:,1,isub)Siz'/4; 71 79 SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4; 72 else 80 else 73 81 [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel,:),U(ind_sel),rho); 74 82 [V_smooth_sub,V_tps_sub]=tps_coeff(Coord(ind_sel,:),V(ind_sel),rho); … … 78 86 ind_ind_sel=1:numel(ind_sel);%default 79 87 if exist('Threshold','var') 80 FF(ind_sel)=20*(NormDiff>Threshold);%put FF value to 20 to identify the criterium of elimmination81 ind_ind_sel=find(FF(ind_sel)==0); % select the indices of ind_sel corresponding to the remaining vectors88 FF(ind_sel)=20*(NormDiff>Threshold);%put FF value to 20 to identify the criterium of elimmination 89 ind_ind_sel=find(FF(ind_sel)==0); % select the indices of ind_sel corresponding to the remaining vectors 82 90 end 83 91 % if no value exceeds threshold, the result is recorded … … 85 93 U_smooth(ind_sel)=U_smooth(ind_sel)+U_smooth_sub; 86 94 V_smooth(ind_sel)=V_smooth(ind_sel)+V_smooth_sub; 87 Nb Sites(isub)=numel(ind_sel);88 Coord_tps(1:Nb Sites(isub),:,isub)=Coord(ind_sel,:);89 U_tps(1:Nb Sites(isub)+3,isub)=U_tps_sub;90 V_tps(1:Nb Sites(isub)+3,isub)=V_tps_sub;95 NbCentres(isub)=numel(ind_sel); 96 Coord_tps(1:NbCentres(isub),:,isub)=Coord(ind_sel,:); 97 U_tps(1:NbCentres(isub)+3,isub)=U_tps_sub; 98 V_tps(1:NbCentres(isub)+3,isub)=V_tps_sub; 91 99 nb_select(ind_sel)=nb_select(ind_sel)+1; 92 100 display('good') 93 101 break 94 % if too few selected vectors, increase the subrange for next iteration102 % if too few selected vectors, increase the subrange for next iteration 95 103 elseif numel(ind_ind_sel)<SubDomain/4 && ~isequal( ind_sel,ind_sel_previous); 96 104 SubRange(:,1,isub)=SubRange(:,1,isub)Siz'/4; 97 105 SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4; 98 % else interpolationsmoothing is done again with the selected vectors106 % else interpolationsmoothing is done again with the selected vectors 99 107 else 100 108 [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),U(ind_sel(ind_ind_sel)),rho); 101 109 [V_smooth_sub,V_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),V(ind_sel(ind_ind_sel)),rho); 102 110 U_smooth(ind_sel(ind_ind_sel))=U_smooth(ind_sel(ind_ind_sel))+U_smooth_sub; 103 V_smooth(ind_sel(ind_ind_sel))=V_smooth(ind_sel(ind_ind_sel))+V_smooth_sub; 104 Nb Sites(isub)=numel(ind_ind_sel);105 Coord_tps(1:Nb Sites(isub),:,isub)=Coord(ind_sel(ind_ind_sel),:);106 U_tps(1:Nb Sites(isub)+3,isub)=U_tps_sub;107 V_tps(1:Nb Sites(isub)+3,isub)=V_tps_sub;111 V_smooth(ind_sel(ind_ind_sel))=V_smooth(ind_sel(ind_ind_sel))+V_smooth_sub; 112 NbCentres(isub)=numel(ind_ind_sel); 113 Coord_tps(1:NbCentres(isub),:,isub)=Coord(ind_sel(ind_ind_sel),:); 114 U_tps(1:NbCentres(isub)+3,isub)=U_tps_sub; 115 V_tps(1:NbCentres(isub)+3,isub)=V_tps_sub; 108 116 nb_select(ind_sel(ind_ind_sel))=nb_select(ind_sel(ind_ind_sel))+1; 109 117 display('good2') … … 113 121 end 114 122 end 123 124 %% remove empty subdomains 115 125 ind_empty=find(check_empty); 116 %remove empty subdomains117 126 if ~isempty(ind_empty) 118 127 SubRange(:,:,ind_empty)=[]; … … 121 130 V_tps(:,ind_empty)=[]; 122 131 end 123 nb_select(nb_select==0)=1;%ones(size(find(nb_select==0))); 124 U_smooth=U_smooth./nb_select; 132 133 %% final adjustments 134 nb_select(nb_select==0)=1; 135 U_smooth=U_smooth./nb_select;% take the average at the intersection of several subdomains 125 136 V_smooth=V_smooth./nb_select; 126 137 fill=zeros(NbCoord+1,NbCoord,size(SubRange,3)); %matrix of zeros to complement the matrix Data.Civ1_Coord_tps (conveninent for file storage)
Note: See TracChangeset
for help on using the changeset viewer.