source: issm/trunk-jpl/src/m/plot/plot_gridded.m@ 21240

Last change on this file since 21240 was 21240, checked in by Mathieu Morlighem, 8 years ago

CHG: added nmedian

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