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

Last change on this file since 22701 was 22701, checked in by Mathieu Morlighem, 7 years ago

CHG: added dem field if dem is not the same as field

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