source: trunk/src/export_fct/decimate_arrows.m

Last change on this file was 1199, checked in by sommeria, 6 hours ago

bugs repaired

File size: 4.1 KB
RevLine 
[1199]1%'decimate_arrows': plot 2D arrays of vector fields with color according to vector modulus, and save figures
2%------------------------------------------------------------------------
3
4%INPUT:
5% handles: Matlab structure containing all the information displayed in the GUI uvmat
6
7function decimate_arrows(handles)
8%------------------------------------------------------------------------
9
10%% get input data
11Data_uvmat=get(handles.uvmat,'UserData');
12Data=Data_uvmat.Field; %get the current plotted field
13requested=isfield(Data,'coord_x')&&isfield(Data,'coord_y')&&isfield(Data,'U')&&isfield(Data,'V')&&isfield(Data,'norm');
14if ~requested
15    msgbox_uvmat('ERROR','unappropriate data: need vectors U, V on a regular grid')
16    return
17end
18RootPath=get(handles.RootPath,'String');
19RootFile=get(handles.RootFile,'String');
20FileIndex=get(handles.FileIndex,'String');
21
22%% Calibration:
23% plot parameters
24nBits = 64;
25scale = 0.05;
26decimation = 8;
27% filtering procedure
28method = 'gaussian';
29window = 24;
30
31%% get colormap
32load('BuYlRd.mat','BuYlRd')
33BuYlRd = BuYlRd(1:floor(size(BuYlRd,1)/nBits):end,:);
34
35%% reduce the number of arrows
36x = Data.coord_x(1:decimation:end);
37y = Data.coord_y(1:decimation:end);
38[X,Y] = meshgrid(x,y);
39X=reshape(X,1,[]);
40Y=reshape(Y,1,[]);
41% Filtering data to take away spurious subsampling issues (see Shannon Theorem)
42filtU = smoothdata(Data.U,method,window,'omitnan');
43filtV = smoothdata(Data.V,method,window,'omitnan');
44
45U = reshape(filtU(1:decimation:end,1:decimation:end),1,[]);
46V = reshape(filtV(1:decimation:end,1:decimation:end),1,[]);
47S = sqrt(U.*U+V.*V);
48zmin = min(S);
49zmax = max(S);
50bins = linspace(zmin,zmax,nBits);
51plot_scale=sqrt((x(2)-x(1))*(y(2))-y(1));% typical distance between arrows
52scale_factor=plot_scale/zmax; % set the maximum arrow length to the typical distance between arrows
53U=scale_factor*U;
54V=scale_factor*V;
55
56%% plot size and position in the figure
57width = 6.75;     % Width in inches
58height = 6;    % Height in inches
59fsz = 12;      % Fontsize
60lw = 1.25;      % LineWidth 
61
62%% make the plot 
63figure(1)
64clf
65ax2 = axes('Visible','off','HandleVisibility','off');
66pos = get(1, 'Position');
67set(1, 'Position', [pos(1) pos(2) width*100, height*100]); %<- Set size
68set(ax2, 'FontSize', fsz, 'LineWidth', lw); %<- Set properties
69set(1, 'defaultTextInterpreter','latex');
70for i = 1:nBits-1
71    ii=find((S - bins(i+1) <= 0).*(S - bins(i) > 0));
72    quiver(X(ii),Y(ii),U(ii),V(ii),'off','Color',BuYlRd(i,:),'LineWidth',1.2,'MaxHeadSize',scale_factor*bins(i))
73    hold on
74end
75%quiver(X,Y,U,V)
76cc=colorbar;
77set(cc,'TickLabelInterpreter','latex')
78cc.Label.String='cm/s';
79clim([zmin zmax])
80axis equal
81xlim([Data.coord_x(1),Data.coord_x(end)])
82ylim([Data.coord_y(1),Data.coord_y(end)])
83hold off
84xlabel('$x(cm)$')
85ylabel('$y(cm)$')
86
87%% Set the figure size
88set(1,'InvertHardcopy','on');
89set(1,'PaperUnits', 'centimeters');
90papersize = get(1, 'PaperSize');
91left = (papersize(1)- width)/2;
92bottom = (papersize(2)- height)/2;
93myfiguresize = [left, bottom, width, height];
94set(1,'PaperPosition', myfiguresize);
95
96%% Save the figure as a pdf file in the appropriate figure folder
97[pp,camera]=fileparts(RootPath);
98[ppp,exp]=fileparts(pp);
99FigPath=fullfile(fileparts(ppp),'0_FIG')
100if ~exist(FigPath,'dir')
101    [s,msg]=mkdir(FigPath); %create the folder if it does not exist
102    if s
103        disp([FigPath ' created'])
104    else
105        msgbox_uvmat('ERROR',msg)
106        return
107    end
108end
109exppath = fullfile(FigPath,exp);
110if ~exist(exppath,'dir')
111    [s,msg]=mkdir(exppath);%create the folder if it does not exist
112    if s
113        disp([exppath ' created'])
114    else
115        msgbox_uvmat('ERROR',msg)
116        return
117    end
118end
119camerapath=fullfile(exppath,camera);
120if ~exist(camerapath,'dir')
121    [s,msg]=mkdir(camerapath);%create the folder if it does not exist
122    if s
123        disp([camerapath ' created'])
124    else
125        msgbox_uvmat('ERROR',msg)
126        return
127    end
128end
129
130outputname=fullfile(camerapath,[RootFile FileIndex '.pdf']);
131print(1,outputname,'-dpdf')
132 
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135
Note: See TracBrowser for help on using the repository browser.