source: trunk/src/proj_grid.m @ 405

Last change on this file since 405 was 38, checked in by sommeria, 15 years ago

field transforms put in subdir transform_field. cleaning of obsolete functions

File size: 4.2 KB
RevLine 
[8]1%'proj_grid': project  fields with unstructured coordinantes on a regular grid
2% -------------------------------------------------------------------------
3% function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
4
5
6function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
7    if length(vec_Y)<2
[38]8        msgbox_uvmat('ERROR','less than 2 points in proj_grid.m');
[8]9        return;
10    end
11    diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
12    index=find(diffy);% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)
[38]13    if isempty(index); msgbox_uvmat('ERROR','points aligned along abscissa in proj_grid.m'); return; end;%points aligned% A FAIRE: switch to line plot.
[8]14    diff2=diff(diffy(index));% diff2 = fluctuations of the detected vertical grid mesh dy
15    if max(abs(diff2))>0.001*abs(diffy(index(1))) % if max(diff2) is larger than 1/1000 of the first mesh dy
16        % the data are not regularly spaced and must be interpolated  on a regular grid
17        if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
18            rangx=rgx_in; % first and last positions
19            rangy=rgy_in;
20%             npxy=npxy_in;
21            dxy(1)=1/(npxy_in(1)-1);%grid mesh in y
22            dxy(2)=1/(npxy_in(2)-1);%grid mesh in x
23            dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);%grid mesh in y
24            dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);%grid mesh in x
25        else % interpolation grid automatically determined
26            rangx(1)=min(vec_X);
27            rangx(2)=max(vec_X);
28            rangy(2)=min(vec_Y);
29            rangy(1)=max(vec_Y);
30            dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X));
31            dxy=[-dxymod/4 dxymod/4];% increase the resolution 4 times
32        end
33        xi=[rangx(1):dxy(2):rangx(2)];
34        yi=[rangy(1):dxy(1):rangy(2)];
35        [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
36        A=griddata_uvmat(vec_X,vec_Y,vec_A,xi,yi');
37        A=reshape(A,length(yi),length(xi));
38    else
39        x=vec_X(1:index(1));% the set of abscissa (obtained on the first line)
40        indexend=index(end);% last vector index of line change
41        ymax=vec_Y(indexend+1);% y coordinate AFTER line change
42        ymin=vec_Y(index(1));
43        %y=[vec_Y(index) ymax]; % the set of y ordinates including the last one
44        y=vec_Y(index);
45        y(length(y)+1)=ymax;
46        nx=length(x);   %number of grid points in x
47        ny=length(y);   % number of grid points in y
48        B=(reshape(vec_A,nx,ny))'; %vec_A reshaped as a rectangular matrix
49        [X,Y]=meshgrid(x,y);% positions X and Y also reshaped as matrix
50       
51        %linear interpolation to improve the image resolution and/or adjust
52        %to prescribed positions
53        test_interp=1;
54        if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
55            rangx=rgx_in; % first and last positions
56            rangy=rgy_in;
57            npxy=npxy_in;
58        else       
59            rangx=[vec_X(1) vec_X(nx)];% first and last position found for x
60%             rangy=[ymin ymax];
61              rangy=[max(ymax,ymin) min(ymax,ymin)];
62            if max(nx,ny) <= 64 & isequal(npxy_in,'np>256')
63                npxy=[8*ny 8*nx];% increase the resolution 8 times
64            elseif max(nx,ny) <= 128 & isequal(npxy_in,'np>256')
65                npxy=[4*ny 4*nx];% increase the resolution 4 times
66            elseif max(nx,ny) <= 256 & isequal(npxy_in,'np>256')
67                npxy=[2*ny 2*nx];% increase the resolution 2 times
68            else
69                npxy=[ny nx];
70                test_interp=0; % no interpolation done
71            end
72        end
73        if test_interp==1%if we interpolate
74            xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)];
75            yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)];
76            [XI,YI]=meshgrid(xi,yi);
77            A = interp2(X,Y,B,XI,YI);
78        else %no interpolation for a resolution higher than 256
79            A=B;
80            XI=X;
81            YI=Y;
82        end
83    end
Note: See TracBrowser for help on using the repository browser.