PageRenderTime 28ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/surfacevel2strain/matlab/util_est/socal_gps_figs.m

http://compearth.googlecode.com/
Objective C | 335 lines | 278 code | 57 blank | 0 comment | 54 complexity | f0b4e4b7120e5196fe3e9994dceded3c MD5 | raw file
  1. %
  2. % socal_gps_figs.m
  3. %
  4. % I THINK THIS FUNCTION IS NOW OBSOLETE.
  5. %
  6. % called by surfacevel2strain_figs.m
  7. %
  8. disp('socal_gps_figs.m: additional figures for socal');
  9. disp(' THESE ARE TEST FIGURES THAT WILL BE RE-PLOTTED GMT.');
  10. % output directory for writing files
  11. %odir = '/home/carltape/gmt/gps_figs/data_for_plots/';
  12. odir = dir_output;
  13. % file prefix
  14. prefix = ['multiscale_' slabel '_d' sprintf('%2.2i',dopt) ];
  15. % color scale for velocity
  16. % first two rows are for overal and secular field
  17. % remaining rows are for residual fields
  18. cmat2 = [ repmat([-35 5],2,1) ; repmat([-5 5],nump-2,1)];
  19. figure; nc=3; nr=nump;
  20. mm = counter2(5,3); im = 1;
  21. % velocity field: Ve and Vs as MULTI-SCALE
  22. cfac = 0.8;
  23. vpmask = ones(nplot,1);
  24. for kk=1:2
  25. if kk==1, fvec = fe; stlab = 'veast'; end
  26. if kk==2, fvec = fs; stlab = 'vsouth'; end
  27. % plot spline gridpoints by order q
  28. for ip=1:nump
  29. inds = [iqr(ip,1) : iqr(ip,2)];
  30. if imask==1
  31. pinds = inds;
  32. if ip == 1, pinds = inds_qmax; end
  33. [m_ikeep,m_inum] = spline_thresh(G0_plot(:,pinds),m_ntrsh,m_qtrsh,[1 0]);
  34. vpmask = NaN * ones(nplot,1); vpmask(m_ikeep) = 1;
  35. end
  36. vplot = G0_plot(:,inds)*fvec(inds)*1e3 .* vpmask;
  37. vmax = cfac*max(abs(vplot));
  38. %subplot(nr,nc,ip+1); hold on;
  39. subplot(nr,nc,mm(im)); im=im+1; hold on;
  40. [X,Y,Z] = griddataXB(dlon_plot,dlat_plot,vplot,npts,'cubic');
  41. pcolor(X,Y,Z); shading flat;
  42. %plot(glon(inds),glat(inds),'k.');
  43. axis equal, axis(ax1); caxis(cmat2(ip,1:2));
  44. colorbar('vert');
  45. if kk==1, title([stqs{ip} ', ' stis{ip}]); end
  46. if iwrite==1
  47. fid = fopen([odir prefix '_' stlab '_' stqtag{ip} '.dat'],'w');
  48. for iz=1:nplot
  49. fprintf(fid,'%18.8e%18.8e%18.8e\n',dlon_plot(iz),dlat_plot(iz),vplot(iz));
  50. end
  51. fclose(fid);
  52. end
  53. end
  54. end
  55. % uniform vector field for plotting
  56. numx_plot = 16;
  57. [vlon_plot,vlat_plot] = gridvec(lonmin,lonmax,numx_plot,latmin,latmax);
  58. nvplot = length(vlon_plot);
  59. vG0_plot = spline_vals_mat(spline_tot, vlon_plot, vlat_plot);
  60. % plot uniform vector fields for the estimations
  61. s = 1;
  62. vpmask = ones(nvplot,1);
  63. for ip=1:nump
  64. inds = [iqr(ip,1) : iqr(ip,2)];
  65. if imask==1
  66. pinds = inds;
  67. if ip == 1, pinds = inds_qmax; end
  68. [m_ikeep,m_inum] = spline_thresh(vG0_plot(:,pinds),m_ntrsh,m_qtrsh,[1 0]);
  69. vpmask = NaN * ones(nvplot,1); vpmask(m_ikeep) = 1;
  70. end
  71. ve_plot = vG0_plot(:,inds)*fe(inds)*1e3;
  72. vs_plot = vG0_plot(:,inds)*fs(inds)*1e3;
  73. subplot(nr,nc,mm(im)); im=im+1; hold on;
  74. quiver(vlon_plot,vlat_plot,ve_plot.*vpmask,-vs_plot.*vpmask,'b');
  75. axis equal, axis(ax1);
  76. if iwrite==1
  77. % write uniform velocity vector field to file
  78. if 1==1
  79. % list only those vectors inside the mask
  80. igood = find(~isnan(vpmask)==1);
  81. ngood = length(igood);
  82. disp([num2str(ngood) ' vectors for the regular field']);
  83. fid = fopen([odir prefix '_vec_' stqtag{ip} '.dat'],'w');
  84. for jj=1:length(igood)
  85. k = igood(jj);
  86. fprintf(fid,'%18.8e%18.8e%18.8e%18.8e\n',vlon_plot(k),vlat_plot(k),ve_plot(k),-vs_plot(k));
  87. end
  88. fclose(fid);
  89. else
  90. % list all vectors
  91. fid = fopen([odir prefix '_vec_' stqtag{ip} '.dat'],'w');
  92. for jj=1:nvplot
  93. fprintf(fid,'%18.8e%18.8e%18.8e%18.8e\n',vlon_plot(jj),vlat_plot(jj),ve_plot(jj),-vs_plot(jj));
  94. end
  95. fclose(fid);
  96. end
  97. end
  98. end
  99. fontsize(8), orient tall, wysiwyg
  100. % additional files for GMT plotting
  101. % q grid indexes for the plots
  102. fid = fopen([odir prefix '_iqvec.dat'],'w');
  103. for jj=1:nump
  104. fprintf(fid,'%10i%10i\n',iqvec(jj,1),iqvec(jj,2));
  105. end
  106. fclose(fid);
  107. % color scale
  108. fid = fopen([odir prefix '_vel_colors.dat'],'w');
  109. for jj=1:nump
  110. fprintf(fid,'%18.8e%18.8e\n',cmat2(jj,1),cmat2(jj,2));
  111. end
  112. fclose(fid);
  113. % bounds
  114. if iwrite==1
  115. fid = fopen([odir prefix '_bounds.dat'],'w');
  116. fprintf(fid,'%18.8e%18.8e%18.8e%18.8e\n',ax1(1),ax1(2),ax1(3),ax1(4));
  117. fclose(fid);
  118. end
  119. if imask==1
  120. % mask files for each level
  121. % GMT mask: estimated points where you WANT to plot data
  122. for ip=1:nump
  123. pinds = [iqr(ip,1) : iqr(ip,2)];
  124. if ip == 1, pinds = inds_qmax; end
  125. [m_ikeep,m_inum] = spline_thresh(G0_plot(:,pinds),m_ntrsh,m_qtrsh,[1 0]);
  126. vpmask = NaN * ones(nplot,1); vpmask(m_ikeep) = 1;
  127. if iwrite==1
  128. fid = fopen([odir prefix '_interior_pts_' stqtag{ip} '.dat'],'w');
  129. for ii=1:num
  130. if vpmask(ii) ~= 1
  131. fprintf(fid,'%18.8e%18.8e\n',dlon_plot(ii), dlat_plot(ii));
  132. end
  133. end
  134. fclose(fid);
  135. end
  136. end
  137. end
  138. %--------------------------------------------
  139. % plot the vector field residuals
  140. figure; nc=2; nr=ceil(nump/nc);
  141. s = 1;
  142. % overal estimated field
  143. ve0 = ve*1e3; vs0 = vs*1e3;
  144. stmag = [' |vmean| = ' num2str(sprintf('%.3f', mean(sqrt(ve0.^2 + vs0.^2)))) ' mm/yr'];
  145. subplot(nr,nc,1);
  146. quiver(dlon,dlat,ve0,-vs0,s); axis equal, axis(ax1);
  147. xlabel(' Latitude'); ylabel(' Longitude');
  148. title([' Data : ' stmag]);
  149. for ip=2:nump
  150. inds = [iqr(ip,1) : iqr(ip,2)];
  151. ve_temp = G0(:,inds)*fe(inds)*1e3;
  152. vs_temp = G0(:,inds)*fs(inds)*1e3;
  153. ve0 = ve0 - ve_temp;
  154. vs0 = vs0 - vs_temp;
  155. stmag = [' |vmean| = ' num2str(sprintf('%.3f', mean(sqrt(ve0.^2 + vs0.^2)))) ' mm/yr'];
  156. subplot(nr,nc,ip);
  157. quiver(dlon,dlat,ve0,-vs0,s); axis equal, axis(ax1);
  158. xlabel(' Latitude'); ylabel(' Longitude');
  159. title({[' Data minus (q = 0-' num2str(iqvec(ip,2)) ')'], stmag});
  160. if iwrite==1
  161. fid = fopen([odir prefix '_data_remove_' stqtag{ip} '.dat'],'w');
  162. for k=1:ndata
  163. fprintf(fid,'%18.8e%18.8e%18.8e%18.8e\n',dlon(k),dlat(k),ve0(k),-vs0(k));
  164. end
  165. fclose(fid);
  166. end
  167. end
  168. fontsize(9), orient tall, wysiwyg
  169. %--------------------------------------------
  170. % scalar quantities from tensors
  171. % datapoints for plotting
  172. r = earthr*ones(nplot,1);
  173. th = (90 - dlat_plot)/deg;
  174. ph = dlon_plot/deg;
  175. figure; nc=3; nr=nump;
  176. im = 1;
  177. % hand-picked color plotting: cmin/cmax/cpwr, where max(z) = cmax * 10^cpwr
  178. % shear, rotation, dilatation
  179. if 1==1
  180. cmat = [
  181. 0 3.0 -7 0 3.0 -7 -3.0 3.0 -7
  182. 0 0.5 -7 0 0.5 -7 -0.5 0.5 -7
  183. 0 0.8 -7 0 0.8 -7 -0.8 0.8 -7
  184. 0 1.0 -7 0 1.0 -7 -1.0 1.0 -7
  185. 0 3.0 -7 0 3.0 -7 -3.0 3.0 -7
  186. ];
  187. end
  188. % write color axis limits to file
  189. fid = fopen([odir prefix '_spline_colors.dat'],'w');
  190. for jj=1:length(cmat(:,1))
  191. fprintf(fid,'%12.3f%12.3f%12.3f%12.3f%12.3f%12.3f%12.3f%12.3f%12.3f\n',...
  192. cmat(jj,1),cmat(jj,2),cmat(jj,3),cmat(jj,4),cmat(jj,5),cmat(jj,6),cmat(jj,7),cmat(jj,8),cmat(jj,9));
  193. end
  194. fclose(fid);
  195. for ip=1:nump
  196. %for ip=1:1
  197. % horizontal velocity field
  198. inds = [iqr(ip,1) : iqr(ip,2)];
  199. vph = G0_plot(:,inds)*fe(inds);
  200. vth = G0_plot(:,inds)*fs(inds);
  201. % spatial derivatives (note minus sign for vn --> vth)
  202. dvphdph = G0dph_plot(:,inds)*fe(inds);
  203. dvthdph = G0dph_plot(:,inds)*fs(inds);
  204. dvphdth = G0dth_plot(:,inds)*fe(inds);
  205. dvthdth = G0dth_plot(:,inds)*fs(inds);
  206. % ignore gradients with respect to vertical
  207. %dvrdth = 0*dvrdth;
  208. %dvrdph = 0*dvrdph;
  209. % velocity gradient tensor
  210. [D, W] = vel2Lmat([r th ph], [vr vth vph], dvrtpdr, ...
  211. [dvrdth dvthdth dvphdth], ...
  212. [dvrdph dvthdph dvphdph], [1 1]);
  213. % strain: six unique components
  214. Drr = D(:,1);
  215. Drth = D(:,2);
  216. Drph = D(:,3);
  217. Dthth = D(:,5);
  218. Dphph = D(:,9);
  219. Dthph = D(:,6);
  220. % rotation: three unique components
  221. Wrth = D(:,2);
  222. Wrph = D(:,3);
  223. Wthph = D(:,6);
  224. %----------------------------------------------
  225. % compute scalar quantities from tensors (see MMA notes)
  226. % (1) first invariant of strain: dilatation
  227. dilat = Drr + Dthth + Dphph;
  228. % (2) shear : sqrt[I2(devD)]
  229. shear = sqrt( Drth.^2 + Drph.^2 + Dthph.^2 + (1/3) * ...
  230. (Drr.^2 + Dthth.^2 + Dphph.^2 ...
  231. - Drr.*Dthth - Drr.*Dphph - Dthth.*Dphph ) ); % deviatoric
  232. %shear = sqrt( Drth.^2 + Drph.^2 + Dthph.^2 ...
  233. % - Drr.*Dthth - Drr.*Dphph - Dthth.*Dphph); % non-deviatoric
  234. % (3) rotat : sqrt[-I2(W)], W = devW
  235. % SEE MALVERN P. 131 FOR ROTATION VECTOR DETAILS
  236. rotat = sqrt( Wrth.^2 + Wrph.^2 + Wthph.^2 );
  237. vpmask = ones(nplot,1);
  238. if imask==1
  239. pinds = inds;
  240. if ip == 1, pinds = inds_qmax; end
  241. [m_ikeep,m_inum] = spline_thresh(G0_plot(:,pinds),m_ntrsh,m_qtrsh,[1 0]);
  242. vpmask = NaN * ones(nplot,1); vpmask(m_ikeep) = 1;
  243. shear = shear .* vpmask;
  244. rotat = rotat .* vpmask;
  245. dilat = dilat .* vpmask;
  246. end
  247. %===============
  248. for kk=1:3
  249. switch kk
  250. case 1, vplot = shear;
  251. case 2, vplot = rotat;
  252. case 3, vplot = dilat;
  253. end
  254. % color scale
  255. itemp = 3*kk-2 : 3*kk;
  256. ctemp = cmat(ip,itemp);
  257. clim = ctemp(1:2);
  258. cnorm = 10^ctemp(3);
  259. %subplot(nr,nc,ip+1); hold on;
  260. subplot(nr,nc,im); im=im+1; hold on;
  261. [X,Y,Z] = griddataXB(dlon_plot,dlat_plot,vplot/cnorm,npts,'cubic');
  262. pcolor(X,Y,Z); shading flat;
  263. %plot(glon(inds),glat(inds),'k.');
  264. axis equal, axis(ax1); caxis(clim);
  265. colorbar('vert');
  266. end
  267. if iwrite==1
  268. fid = fopen([odir prefix '_strain_' stqtag{ip} '.dat'],'w');
  269. for iz=1:nplot
  270. fprintf(fid,'%18.8e%18.8e%18.8e%18.8e%18.8e\n',...
  271. dlon_plot(iz),dlat_plot(iz),shear(iz),rotat(iz),dilat(iz));
  272. end
  273. fclose(fid);
  274. end
  275. end
  276. fontsize(8), orient tall, wysiwyg
  277. break
  278. %========================================================