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

Last change on this file since 24762 was 24762, checked in by Mathieu Morlighem, 5 years ago

NEW: better handling of plotmodel with levelset: use 'gridded',1,'levelset',md.results.TransientSolution(end).MaskIceLevelset

File size: 3.8 KB
Line 
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
10[x y z elements is2d isplanet]=processmesh(md,[],options);
11[data datatype]=processdata(md,data,options);
12
13islevelset = exist(options,'levelset');
14if islevelset
15 levelset = getfieldvalue(options,'levelset');
16 [levelset datatype]=processdata(md,levelset,options);
17end
18
19%check is2d
20if ~is2d,
21 error('buildgridded error message: gridded not supported for 3d meshes, project on a layer');
22end
23
24%Get xlim and ylim (used to extract radar image)
25xlim=getfieldvalue(options,'xlim',[min(x) max(x)]);
26ylim=getfieldvalue(options,'ylim',[min(y) max(y)]);
27postx=getfieldvalue(options,'posting',diff(xlim)/1000);
28posty=getfieldvalue(options,'posting',diff(ylim)/1000);
29
30%Interpolating data on grid
31x_m = xlim(1):postx:xlim(2);
32y_m = ylim(1):posty:ylim(2);
33data_grid=InterpFromMeshToGrid(elements,x,y,data,x_m,y_m,NaN);
34data_grid_save = data_grid;
35if size(data_grid,1)<3 | size(data_grid,2)<3,
36 error('data_grid size too small in plot_gridded, check posting and units');
37end
38
39%Mask values if levelset>0
40if islevelset
41 ls_grid=InterpFromMeshToGrid(elements,x,y,levelset,x_m,y_m,NaN);
42 data_grid(ls_grid>0) = NaN;
43end
44
45%Process data_grid: add white in NaN and correct caxis accordingly
46[data_nani data_nanj]=find(isnan(data_grid) | data_grid==-9999);
47if 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);
53else
54 data_min=min(data_grid(:));
55 data_max=max(data_grid(:));
56end
57
58%Select plot area
59subplotmodel(plotlines,plotcols,i,options);
60
61%shading interp;
62map = getcolormap(options);
63image_rgb = ind2rgb(uint16((data_grid - data_min)*(length(map)/(data_max-data_min))),map);
64if exist(options,'shaded'),
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
71 a = -45;
72 scut = 0.2;
73 c = 1;
74 % computes lighting from elevation gradient
75 [fx,fy] = gradient(dem_grid,x_m,y_m);
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));
90end
91
92% set novalues / NaN to black color
93if ~isempty(data_nani)
94 nancolor=getfieldvalue(options,'nancolor',[1 1 1]);
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);
96end
97
98%plot grid
99h=imagesc(xlim,ylim,image_rgb);
100axis xy
101
102%last step: mesh gridded?
103if exist(options,'edgecolor'),
104 A=elements(:,1); B=elements(:,2); C=elements(:,3);
105 patch('Faces',[A B C],'Vertices', [x y z],'FaceVertexCData',data_grid(1)*ones(size(x)),'FaceColor','none','EdgeColor',getfieldvalue(options,'edgecolor'));
106end
107
108%Apply options
109if ~isnan(data_min) & ~isinf(data_min),
110 options=changefieldvalue(options,'caxis',[data_min data_max]); % force caxis so that the colorbar is ready
111end
112options=addfielddefault(options,'axis','xy equal'); % default axis
113applyoptions(md,data,options);
114
115function 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
123if nargin < 2
124 n = 0.5;
125end
126y = sort(x(:));
127y = interp1(sort(y),n*(length(y)-1) + 1);
Note: See TracBrowser for help on using the repository browser.