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 | post=getfieldvalue(options,'posting',diff(xlim)/1000);
|
---|
22 |
|
---|
23 | %Interpolating data on grid
|
---|
24 | [x_m y_m data_grid]=InterpFromMeshToGrid(elements,x,y,data,xlim(1),ylim(2),post,post,round(diff(ylim)/post),round(diff(xlim)/post),NaN);
|
---|
25 | data_grid_save = data_grid;
|
---|
26 | if size(data_grid,1)<3 | size(data_grid,2)<3,
|
---|
27 | error('data_grid size too small in plot_gridded, check posting and units');
|
---|
28 | end
|
---|
29 |
|
---|
30 | %Get and change colormap
|
---|
31 | map = getcolormap(options);
|
---|
32 | lenmap = size(map,1);
|
---|
33 | map = [1 1 1; map];
|
---|
34 | options=changefieldvalue(options,'colormap',map);
|
---|
35 |
|
---|
36 | %Process data_grid: add white in NaN and correct caxis accordingly
|
---|
37 | [data_nani data_nanj]=find(isnan(data_grid) | data_grid==-9999);
|
---|
38 | if exist(options,'caxis'),
|
---|
39 | caxis_opt=getfieldvalue(options,'caxis');
|
---|
40 | data_grid(find(data_grid<caxis_opt(1)))=caxis_opt(1);
|
---|
41 | data_grid(find(data_grid>caxis_opt(2)))=caxis_opt(2);
|
---|
42 | data_min=caxis_opt(1);
|
---|
43 | data_max=caxis_opt(2);
|
---|
44 | else
|
---|
45 | data_min=min(data_grid(:));
|
---|
46 | data_max=max(data_grid(:));
|
---|
47 | end
|
---|
48 |
|
---|
49 | %Select plot area
|
---|
50 | subplotmodel(plotlines,plotcols,i,options);
|
---|
51 |
|
---|
52 | %shading interp;
|
---|
53 | image_rgb = ind2rgb(uint16((data_grid - data_min)*(length(map)/(data_max-data_min))),map);
|
---|
54 | if exist(options,'shaded'),
|
---|
55 | a = -45;
|
---|
56 | scut = 0.2;
|
---|
57 | c = 1;
|
---|
58 | % computes lighting from elevation gradient
|
---|
59 | [fx,fy] = gradient(data_grid_save,x_m,y_m);
|
---|
60 | fxy = -fx*sind(a) - fy*cosd(a);
|
---|
61 | clear fx fy % free some memory...
|
---|
62 | fxy(isnan(fxy)) = 0;
|
---|
63 |
|
---|
64 | % computes maximum absolute gradient (median-style), normalizes, saturates and duplicates in 3-D matrix
|
---|
65 | r = repmat(max(min(fxy/nmedian(abs(fxy),1 - scut/100),1),-1),[1,1,3]);
|
---|
66 |
|
---|
67 | % applies contrast using exponent
|
---|
68 | rp = (1 - abs(r)).^c;
|
---|
69 | image_rgb = image_rgb.*rp;
|
---|
70 |
|
---|
71 | % lighter for positive gradient
|
---|
72 | k = find(r > 0);
|
---|
73 | image_rgb(k) = image_rgb(k) + (1 - rp(k));
|
---|
74 | end
|
---|
75 |
|
---|
76 | % set novalues / NaN to black color
|
---|
77 | if ~isempty(data_nani)
|
---|
78 | nancolor=getfieldvalue(options,'nancolor',[0 0 0]);
|
---|
79 | 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);
|
---|
80 | end
|
---|
81 |
|
---|
82 | %plot grid
|
---|
83 | h=imagesc(xlim,ylim,image_rgb);
|
---|
84 | axis xy
|
---|
85 |
|
---|
86 | %last step: mesh gridded?
|
---|
87 | if exist(options,'edgecolor'),
|
---|
88 | A=elements(:,1); B=elements(:,2); C=elements(:,3);
|
---|
89 | patch('Faces',[A B C],'Vertices', [x y z],'FaceVertexCData',data_grid(1)*ones(size(x)),'FaceColor','none','EdgeColor',getfieldvalue(options,'edgecolor'));
|
---|
90 | end
|
---|
91 |
|
---|
92 | %Apply options
|
---|
93 | if ~isnan(data_min),
|
---|
94 | options=changefieldvalue(options,'caxis',[data_min data_max]); % force caxis so that the colorbar is ready
|
---|
95 | end
|
---|
96 | options=addfielddefault(options,'axis','xy equal off'); % default axis
|
---|
97 | applyoptions(md,data,options);
|
---|