1 | function plot_gridded(md,data,options,plotlines,plotcols,i)
|
---|
2 | %PLOT_OVERLAY - superimpose radar image to a given field
|
---|
3 | %
|
---|
4 | % Usage:
|
---|
5 | % plot_gridded(md,options,plotlines,plotcols,i)
|
---|
6 | %
|
---|
7 | % See also: PLOTMODEL
|
---|
8 |
|
---|
9 | %process mesh and data
|
---|
10 | [x y z elements is2d isplanet]=processmesh(md,[],options);
|
---|
11 | [data datatype]=processdata(md,data,options);
|
---|
12 |
|
---|
13 | %check is2d
|
---|
14 | if ~is2d,
|
---|
15 | error('buildgridded error message: gridded not supported for 3d meshes, project on a layer');
|
---|
16 | end
|
---|
17 |
|
---|
18 | %Get xlim and ylim (used to extract radar image)
|
---|
19 | xlim=getfieldvalue(options,'xlim',[min(x) max(x)]);
|
---|
20 | ylim=getfieldvalue(options,'ylim',[min(y) max(y)]);
|
---|
21 | postx=getfieldvalue(options,'posting',diff(xlim)/1000);
|
---|
22 | posty=getfieldvalue(options,'posting',diff(ylim)/1000);
|
---|
23 |
|
---|
24 | %Interpolating data on grid
|
---|
25 | x_m = xlim(1):postx:xlim(2);
|
---|
26 | y_m = ylim(1):posty:ylim(2);
|
---|
27 | data_grid=InterpFromMeshToGrid(elements,x,y,data,x_m,y_m,NaN);
|
---|
28 | data_grid_save = data_grid;
|
---|
29 | if size(data_grid,1)<3 | size(data_grid,2)<3,
|
---|
30 | error('data_grid size too small in plot_gridded, check posting and units');
|
---|
31 | end
|
---|
32 |
|
---|
33 | %Process data_grid: add white in NaN and correct caxis accordingly
|
---|
34 | [data_nani data_nanj]=find(isnan(data_grid) | data_grid==-9999);
|
---|
35 | if exist(options,'caxis'),
|
---|
36 | caxis_opt=getfieldvalue(options,'caxis');
|
---|
37 | data_grid(find(data_grid<caxis_opt(1)))=caxis_opt(1);
|
---|
38 | data_grid(find(data_grid>caxis_opt(2)))=caxis_opt(2);
|
---|
39 | data_min=caxis_opt(1);
|
---|
40 | data_max=caxis_opt(2);
|
---|
41 | else
|
---|
42 | data_min=min(data_grid(:));
|
---|
43 | data_max=max(data_grid(:));
|
---|
44 | end
|
---|
45 |
|
---|
46 | %Select plot area
|
---|
47 | subplotmodel(plotlines,plotcols,i,options);
|
---|
48 |
|
---|
49 | %shading interp;
|
---|
50 | map = getcolormap(options);
|
---|
51 | image_rgb = ind2rgb(uint16((data_grid - data_min)*(length(map)/(data_max-data_min))),map);
|
---|
52 | if exist(options,'shaded'),
|
---|
53 | a = -45;
|
---|
54 | scut = 0.2;
|
---|
55 | c = 1;
|
---|
56 | % computes lighting from elevation gradient
|
---|
57 | [fx,fy] = gradient(data_grid_save,x_m,y_m);
|
---|
58 | fxy = -fx*sind(a) - fy*cosd(a);
|
---|
59 | clear fx fy % free some memory...
|
---|
60 | fxy(isnan(fxy)) = 0;
|
---|
61 |
|
---|
62 | % computes maximum absolute gradient (median-style), normalizes, saturates and duplicates in 3-D matrix
|
---|
63 | r = repmat(max(min(fxy/nmedian(abs(fxy),1 - scut/100),1),-1),[1,1,3]);
|
---|
64 |
|
---|
65 | % applies contrast using exponent
|
---|
66 | rp = (1 - abs(r)).^c;
|
---|
67 | image_rgb = image_rgb.*rp;
|
---|
68 |
|
---|
69 | % lighter for positive gradient
|
---|
70 | k = find(r > 0);
|
---|
71 | image_rgb(k) = image_rgb(k) + (1 - rp(k));
|
---|
72 | end
|
---|
73 |
|
---|
74 | % set novalues / NaN to black color
|
---|
75 | if ~isempty(data_nani)
|
---|
76 | nancolor=getfieldvalue(options,'nancolor',[1 1 1]);
|
---|
77 | image_rgb(sub2ind(size(image_rgb),repmat(data_nani,1,3),repmat(data_nanj,1,3),repmat(1:3,size(data_nani,1),1))) = repmat(nancolor,size(data_nani,1),1);
|
---|
78 | end
|
---|
79 |
|
---|
80 | %plot grid
|
---|
81 | h=imagesc(xlim,ylim,image_rgb);
|
---|
82 | axis xy
|
---|
83 |
|
---|
84 | %last step: mesh gridded?
|
---|
85 | if exist(options,'edgecolor'),
|
---|
86 | A=elements(:,1); B=elements(:,2); C=elements(:,3);
|
---|
87 | patch('Faces',[A B C],'Vertices', [x y z],'FaceVertexCData',data_grid(1)*ones(size(x)),'FaceColor','none','EdgeColor',getfieldvalue(options,'edgecolor'));
|
---|
88 | end
|
---|
89 |
|
---|
90 | %Apply options
|
---|
91 | if ~isnan(data_min) & ~isinf(data_min),
|
---|
92 | options=changefieldvalue(options,'caxis',[data_min data_max]); % force caxis so that the colorbar is ready
|
---|
93 | end
|
---|
94 | options=addfielddefault(options,'axis','xy equal'); % default axis
|
---|
95 | applyoptions(md,data,options);
|
---|
96 |
|
---|
97 | function y = nmedian(x,n)
|
---|
98 | %NMEDIAN Generalized median filter
|
---|
99 | % NMEDIAN(X,N) sorts elemets of X and returns N-th value (N normalized).
|
---|
100 | % So:
|
---|
101 | % N = 0 is minimum value
|
---|
102 | % N = 0.5 is median value
|
---|
103 | % N = 1 is maximum value
|
---|
104 |
|
---|
105 | if nargin < 2
|
---|
106 | n = 0.5;
|
---|
107 | end
|
---|
108 | y = sort(x(:));
|
---|
109 | y = interp1(sort(y),n*(length(y)-1) + 1);
|
---|