| 1 | function plot_overlay(md,data,options,plotlines,plotcols,i)
|
|---|
| 2 | %PLOT_OVERLAY - superimpose radar image to a given field
|
|---|
| 3 | %
|
|---|
| 4 | % Usage:
|
|---|
| 5 | % plot_overlay(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 | if strcmpi(data,'none'),
|
|---|
| 12 | radaronly=1;
|
|---|
| 13 | data=NaN*ones(md.mesh.numberofvertices,1);
|
|---|
| 14 | datatype=1;
|
|---|
| 15 | else
|
|---|
| 16 | radaronly=0;
|
|---|
| 17 | [data datatype]=processdata(md,data,options);
|
|---|
| 18 | end
|
|---|
| 19 |
|
|---|
| 20 | %check is2d
|
|---|
| 21 | if ~is2d,
|
|---|
| 22 | error('buildoverlay error message: overlay not supported for 3d meshes, project on a layer');
|
|---|
| 23 | end
|
|---|
| 24 | if datatype==3,
|
|---|
| 25 | error('buildoverlay error message: overlay not supported for quiver plots');
|
|---|
| 26 | end
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | %radar power
|
|---|
| 30 | if ~any(isnan(md.radaroverlay.x)) & ~any(isnan(md.radaroverlay.y)) & ~any(isnan(md.radaroverlay.pwr)),
|
|---|
| 31 | disp('plot_overlay info: the radar image held by the model is being used');
|
|---|
| 32 | xlim=[min(md.radaroverlay.x) max(md.radaroverlay.x)];
|
|---|
| 33 | ylim=[min(md.radaroverlay.y) max(md.radaroverlay.y)];
|
|---|
| 34 | else
|
|---|
| 35 | disp('Extracting radar image...');
|
|---|
| 36 | %Get xlim and ylim (used to extract radar image)
|
|---|
| 37 | xlim=getfieldvalue(options,'xlim',[min(x) max(x)])/getfieldvalue(options,'unit',1);
|
|---|
| 38 | ylim=getfieldvalue(options,'ylim',[min(y) max(y)])/getfieldvalue(options,'unit',1);
|
|---|
| 39 | options=addfielddefault(options,'xlim',xlim);
|
|---|
| 40 | options=addfielddefault(options,'ylim',ylim);
|
|---|
| 41 | md=radarpower(md,options);
|
|---|
| 42 | end
|
|---|
| 43 |
|
|---|
| 44 | %InterpFromMeshToGrid
|
|---|
| 45 | xmin=min(md.radaroverlay.x);
|
|---|
| 46 | ymax=max(md.radaroverlay.y);
|
|---|
| 47 | xspacing=(max(md.radaroverlay.x)-min(md.radaroverlay.x))/(length(md.radaroverlay.x));
|
|---|
| 48 | yspacing=(max(md.radaroverlay.y)-min(md.radaroverlay.y))/(length(md.radaroverlay.y));
|
|---|
| 49 | nlines=length(md.radaroverlay.y);
|
|---|
| 50 | ncols =length(md.radaroverlay.x);
|
|---|
| 51 | disp('Interpolating data on grid...');
|
|---|
| 52 | [x_m y_m data_grid]=InterpFromMeshToGrid(elements,x/getfieldvalue(options,'unit',1),y/getfieldvalue(options,'unit',1),...
|
|---|
| 53 | data,xmin,ymax,xspacing,yspacing,nlines,ncols,NaN);
|
|---|
| 54 |
|
|---|
| 55 | %Process data_grid
|
|---|
| 56 | pos=find(isinf(data_grid));
|
|---|
| 57 | if ~isempty(pos),
|
|---|
| 58 | disp('Warning: removing Infs from vector (probably log(0)?)');
|
|---|
| 59 | data_grid(pos)=NaN;
|
|---|
| 60 | end
|
|---|
| 61 | if exist(options,'caxis'),
|
|---|
| 62 | caxis_opt=getfieldvalue(options,'caxis');
|
|---|
| 63 | data_grid(find(data_grid<caxis_opt(1)))=caxis_opt(1);
|
|---|
| 64 | data_grid(find(data_grid>caxis_opt(2)))=caxis_opt(2);
|
|---|
| 65 | data_min=caxis_opt(1);
|
|---|
| 66 | data_max=caxis_opt(2);
|
|---|
| 67 | else
|
|---|
| 68 | data_min=min(data_grid(:));
|
|---|
| 69 | data_max=max(data_grid(:));
|
|---|
| 70 | end
|
|---|
| 71 | data_nan=find(isnan(data_grid));
|
|---|
| 72 |
|
|---|
| 73 | %Generate HSV image
|
|---|
| 74 | contrast=getfieldvalue(options,'contrast',1);
|
|---|
| 75 | transparency=getfieldvalue(options,'alpha',1);
|
|---|
| 76 | data_grid(data_nan)=data_min;
|
|---|
| 77 |
|
|---|
| 78 | colorm=getfieldvalue(options,'colormap','Rignot');
|
|---|
| 79 | if strcmpi(colorm,'Rignot'),
|
|---|
| 80 | %hue (H)
|
|---|
| 81 | h_data=(data_grid-data_min)/(data_max-data_min+eps);
|
|---|
| 82 | if radaronly, h_data(:)=0; end
|
|---|
| 83 | %saturation (S)
|
|---|
| 84 | s_data=max(min((0.1+h_data).^(1/transparency),1),0);
|
|---|
| 85 | elseif strcmpi(colorm,'Seroussi'),
|
|---|
| 86 | %hue (H)
|
|---|
| 87 | h_data=1-(data_grid-data_min)/(data_max-data_min+eps)*0.7;
|
|---|
| 88 | %h_data=(data_grid-data_min)/(data_max-data_min)*2/3;
|
|---|
| 89 | if radaronly, h_data(:)=0; end
|
|---|
| 90 | %saturation (S)
|
|---|
| 91 | s_data=max(min((0.1+h_data).^(1/transparency),1),0);
|
|---|
| 92 | elseif strcmpi(colorm,'redblue')
|
|---|
| 93 | data_mean=data_min+(data_max-data_min)/2;
|
|---|
| 94 | %hue (H)
|
|---|
| 95 | %h_data=0.7*ones(size(data_grid));
|
|---|
| 96 | %h_data(find(data_grid>data_mean))=1;
|
|---|
| 97 | h_data=1*ones(size(data_grid));
|
|---|
| 98 | h_data(find(data_grid<data_mean))=0.7;
|
|---|
| 99 | %saturation (S)
|
|---|
| 100 | s_data=max(min(abs(data_grid-data_mean)/(data_max-data_mean) ,1),0);
|
|---|
| 101 | else
|
|---|
| 102 | error('colormap not supported yet. (''Rignot'' and ''redblue'' are the only cupported colormaps)');
|
|---|
| 103 | end
|
|---|
| 104 |
|
|---|
| 105 | %Saturation is 0 in NaNs
|
|---|
| 106 | s_data(data_nan)=0;
|
|---|
| 107 | %intensity (V)
|
|---|
| 108 | radar=(md.radaroverlay.pwr).^(contrast);
|
|---|
| 109 | v_data=radar/max(radar(:)); %use radar power as intensity
|
|---|
| 110 |
|
|---|
| 111 | %Change background from black to white
|
|---|
| 112 | %pos=find(v_data==0);v_data(pos)=1;
|
|---|
| 113 |
|
|---|
| 114 | %Transform HSV to RGB
|
|---|
| 115 | image_hsv=zeros(size(data_grid,1),size(data_grid,2),3);
|
|---|
| 116 | image_hsv(:,:,1)=h_data;
|
|---|
| 117 | image_hsv(:,:,2)=s_data;
|
|---|
| 118 | image_hsv(:,:,3)=v_data;
|
|---|
| 119 | image_rgb=hsv2rgb(image_hsv);
|
|---|
| 120 |
|
|---|
| 121 | %Select plot area
|
|---|
| 122 | subplot(plotlines,plotcols,i);
|
|---|
| 123 |
|
|---|
| 124 | %Plot:
|
|---|
| 125 | imagesc(md.radaroverlay.x*getfieldvalue(options,'unit',1),md.radaroverlay.y*getfieldvalue(options,'unit',1),image_rgb);set(gca,'YDir','normal');
|
|---|
| 126 |
|
|---|
| 127 | %last step: mesh overlay?
|
|---|
| 128 | if exist(options,'edgecolor'),
|
|---|
| 129 | hold on
|
|---|
| 130 | A=elements(:,1); B=elements(:,2); C=elements(:,3);
|
|---|
| 131 | patch('Faces',[A B C],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none',...
|
|---|
| 132 | 'EdgeColor',getfieldvalue(options,'edgecolor'),'LineWidth',getfieldvalue(options,'linewidth',1));
|
|---|
| 133 | end
|
|---|
| 134 |
|
|---|
| 135 | %Apply options, without colorbar and without grid
|
|---|
| 136 | options=changefieldvalue(options,'colormap',colorm); %We used an HSV colorbar
|
|---|
| 137 | if ~isnan(data_min),
|
|---|
| 138 | options=changefieldvalue(options,'caxis',[data_min data_max]); %force caxis so that the colorbar is ready
|
|---|
| 139 | end
|
|---|
| 140 | options=addfielddefault(options,'axis','equal off'); %default axis
|
|---|
| 141 | applyoptions(md,data,options);
|
|---|