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

Last change on this file since 27540 was 27540, checked in by eyhli, 2 years ago

Added correct scaling for zoom in with gridded option

File size: 4.1 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
[24762]13islevelset = exist(options,'levelset');
14if 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]20end
21
[7197]22%check is2d
23if ~is2d,
24 error('buildgridded error message: gridded not supported for 3d meshes, project on a layer');
25end
26
27%Get xlim and ylim (used to extract radar image)
28xlim=getfieldvalue(options,'xlim',[min(x) max(x)]);
29ylim=getfieldvalue(options,'ylim',[min(y) max(y)]);
[27540]30
31isAxis = exist(options, 'axis');
32if isAxis
33 myaxis = getfieldvalue(options,'axis');
34 xlim = [myaxis(1), myaxis(2)];
35 ylim = [myaxis(3), myaxis(4)];
36end
37
[20670]38postx=getfieldvalue(options,'posting',diff(xlim)/1000);
39posty=getfieldvalue(options,'posting',diff(ylim)/1000);
[7197]40
41%Interpolating data on grid
[21828]42x_m = xlim(1):postx:xlim(2);
43y_m = ylim(1):posty:ylim(2);
44data_grid=InterpFromMeshToGrid(elements,x,y,data,x_m,y_m,NaN);
[15399]45data_grid_save = data_grid;
[10413]46if 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]48end
[7197]49
[24762]50%Mask values if levelset>0
51if islevelset
52 ls_grid=InterpFromMeshToGrid(elements,x,y,levelset,x_m,y_m,NaN);
53 data_grid(ls_grid>0) = NaN;
54end
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]58if 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);
64else
65 data_min=min(data_grid(:));
66 data_max=max(data_grid(:));
67end
68
69%Select plot area
[12732]70subplotmodel(plotlines,plotcols,i,options);
[7197]71
72%shading interp;
[15400]73map = getcolormap(options);
[15399]74image_rgb = ind2rgb(uint16((data_grid - data_min)*(length(map)/(data_max-data_min))),map);
75if 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]101end
[15399]102
103% set novalues / NaN to black color
104if ~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);
107end
108
109%plot grid
110h=imagesc(xlim,ylim,image_rgb);
[14411]111axis xy
[7197]112
113%last step: mesh gridded?
114if 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]117end
118
119%Apply options
[19026]120if ~isnan(data_min) & ~isinf(data_min),
[15399]121 options=changefieldvalue(options,'caxis',[data_min data_max]); % force caxis so that the colorbar is ready
122end
[15400]123options=addfielddefault(options,'axis','xy equal'); % default axis
[7197]124applyoptions(md,data,options);
[21240]125
126function 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
134if nargin < 2
135 n = 0.5;
136end
137y = sort(x(:));
138y = interp1(sort(y),n*(length(y)-1) + 1);
Note: See TracBrowser for help on using the repository browser.