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