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