[Dart-dev] [3274] DART/trunk/diagnostics/matlab: Fixed direction of plotting and maintained ability to run with both new and old

thoar at subversion.ucar.edu thoar at subversion.ucar.edu
Mon Mar 17 15:37:18 MDT 2008


An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20080317/5a6ae102/attachment.html
-------------- next part --------------
Modified: DART/trunk/diagnostics/matlab/plot_profile.m
===================================================================
--- DART/trunk/diagnostics/matlab/plot_profile.m	2008-03-17 19:54:37 UTC (rev 3273)
+++ DART/trunk/diagnostics/matlab/plot_profile.m	2008-03-17 21:37:17 UTC (rev 3274)
@@ -121,21 +121,28 @@
       disp(sprintf('%s is a surface field.',plotdat.guessvar))
       error('Cannot display a surface field this way.')
    else
-      plotdat.level         = sort(getnc(fname, guessdims{2}));
+      plotdat.level_org     = getnc(fname, guessdims{2});
       plotdat.level_units   = f{guessdims{2}}.units(:);
       plotdat.nlevels       = length(f{guessdims{2}});
       edgename              = sprintf('%s_edges',guessdims{2});
-      plotdat.level_edges   = sort(getnc(fname,edgename));
-      plotdat.level_strings = GenLevelString(plotdat.level, plotdat.level_edges);
+      plotdat.level_edges   = getnc(fname,edgename);
       plotdat.Yrange        = [min(plotdat.level_edges) max(plotdat.level_edges)];
    end
-  
-   switch plotdat.level_units
-       case 'hPa', 
-            plotdat.YDir = 'reverse';
-       otherwise, 
-            plotdat.YDir = 'normal';
+
+   % Matlab likes strictly ASCENDING order for things to be plotted,
+   % then you can impose the direction. The data is stored in the original
+   % order, so the sort indices are saved to reorder the data.
+
+   if (plotdat.level_org(1) > plotdat.level_org(plotdat.nlevels))
+      plotdat.YDir = 'reverse';
+   else
+      plotdat.YDir = 'normal';
    end
+   [levels, indices]   = sort(plotdat.level_org);
+   plotdat.level       = levels;
+   plotdat.indices     = indices;
+   level_edges         = sort(plotdat.level_edges);
+   plotdat.level_edges = level_edges;
    
    guess = getnc(fname, plotdat.guessvar,-1,-1,-1,-1,-1,-1,0);  
    analy = getnc(fname, plotdat.analyvar,-1,-1,-1,-1,-1,-1,0); 
@@ -199,24 +206,25 @@
 
    % Interlace the [ges,anl] to make a sawtooth plot.
    % By this point, the middle two dimensions are singletons.
-   cg = plotdat.ges_copy(:,:,plotdat.region);
-   ca = plotdat.anl_copy(:,:,plotdat.region);
+   % The data must be sorted to match the order of the levels.
+   cg = plotdat.ges_copy(:,:,plotdat.region); CG = cg(plotdat.indices);
+   ca = plotdat.anl_copy(:,:,plotdat.region); CA = ca(plotdat.indices);
 
-   g = plotdat.ges_Nposs(:,:,plotdat.region);
-   a = plotdat.anl_Nposs(:,:,plotdat.region);
-   nobs_poss   = g;
-   nposs_delta = g - a;
+   g = plotdat.ges_Nposs(:,:,plotdat.region); G = g(plotdat.indices);
+   a = plotdat.anl_Nposs(:,:,plotdat.region); A = a(plotdat.indices);
+   nobs_poss   = G;
+   nposs_delta = G - A;
 
-   g = plotdat.ges_Nused(:,:,plotdat.region);
-   a = plotdat.anl_Nused(:,:,plotdat.region);
-   nobs_used   = g;
-   nused_delta = g - a;
+   g = plotdat.ges_Nused(:,:,plotdat.region); G = g(plotdat.indices);
+   a = plotdat.anl_Nused(:,:,plotdat.region); A = a(plotdat.indices);
+   nobs_used   = G;
+   nused_delta = G - A;
 
    % Determine some quantities for the legend
    nobs = sum(nobs_used);
    if ( nobs > 1 )
-      other_guess = mean(cg(isfinite(cg))); 
-      other_analy = mean(ca(isfinite(ca))); 
+      other_guess = mean(CG(isfinite(CG))); 
+      other_analy = mean(CA(isfinite(CA))); 
    else
       other_guess = NaN;
       other_analy = NaN;
@@ -243,14 +251,15 @@
 
    Stripes(plotdat.Xrange, plotdat.level_edges);
    hold on;
-   h1 = plot(cg,plotdat.level,'k+-',ca,plotdat.level,'k+:');
+   h1 = plot(CG,plotdat.level,'k+-',CA,plotdat.level,'k+:');
    hold off;
    set(h1,'LineWidth',plotdat.linewidth);
-   h = legend(h1,str_other_pr, str_other_po);
+   h = legend(h1,str_other_pr, str_other_po, 'Location', 'East');
    legend(h,'boxoff')
 
    axlims = [plotdat.Xrange plotdat.Yrange];
    axis(axlims)
+
    set(gca,'YDir', plotdat.YDir)
    switch plotdat.copystring
       case 'bias'
@@ -258,6 +267,10 @@
          plotdat.xlabel = sprintf('bias (%s)',plotdat.biasconv);
       otherwise
    end
+
+%   disp(plotdat.myregion)
+%   [plotdat.level CG' CA' ca' cg' plotdat.level_org]
+
    set(gca,'YTick',plotdat.level,'Ylim',plotdat.Yrange)
    ylabel(plotdat.level_units)
    
@@ -398,24 +411,9 @@
 
 
 
-function str = GenLevelString(m,e)
-
-if ( (length(m)+1) ~= length(e) )
-error(sprintf('%d vertical midpoints and %d edges',length(m),length(e)))
-end
-
-nstrings = length(m);
-
-str = cell(nstrings,1);
-for i = 1:nstrings 
-  str{i} =  sprintf('(%.0f - %.0f)',e(i),e(i+1));
-end
-
-
 function Stripes(x,edges)
 % EraseMode: [ {normal} | background | xor | none ]
 
-
 xc = [ x(1) x(2) x(2) x(1) x(1) ];
 
 hold on;
@@ -425,4 +423,3 @@
   'EraseMode','background','EdgeColor','none');
 end
 hold off;
-%get(h)

Modified: DART/trunk/diagnostics/matlab/plot_rmse_xxx_profile.m
===================================================================
--- DART/trunk/diagnostics/matlab/plot_rmse_xxx_profile.m	2008-03-17 19:54:37 UTC (rev 3273)
+++ DART/trunk/diagnostics/matlab/plot_rmse_xxx_profile.m	2008-03-17 21:37:17 UTC (rev 3274)
@@ -122,21 +122,28 @@
       disp(sprintf('%s is a surface field.',plotdat.guessvar))
       error('Cannot display a surface field this way.')
    else
-      plotdat.level         = sort(getnc(fname, guessdims{2}));
+      plotdat.level_org     = getnc(fname, guessdims{2});
       plotdat.level_units   = f{guessdims{2}}.units(:);
       plotdat.nlevels       = length(f{guessdims{2}});
       edgename              = sprintf('%s_edges',guessdims{2});
-      plotdat.level_edges   = sort(getnc(fname,edgename));
-      plotdat.level_strings = GenLevelString(plotdat.level, plotdat.level_edges);
+      plotdat.level_edges   = getnc(fname,edgename);
       plotdat.Yrange        = [min(plotdat.level_edges) max(plotdat.level_edges)];
    end
-   
-   switch plotdat.level_units
-       case 'hPa', 
-            plotdat.YDir = 'reverse';
-       otherwise, 
-            plotdat.YDir = 'normal';
+
+   % Matlab likes strictly ASCENDING order for things to be plotted,
+   % then you can impose the direction. The data is stored in the original
+   % order, so the sort indices are saved to reorder the data.
+
+   if (plotdat.level_org(1) > plotdat.level_org(plotdat.nlevels))
+      plotdat.YDir = 'reverse';
+   else
+      plotdat.YDir = 'normal';
    end
+   [levels, indices]   = sort(plotdat.level_org);
+   plotdat.level       = levels;
+   plotdat.indices     = indices;
+   level_edges         = sort(plotdat.level_edges);
+   plotdat.level_edges = level_edges;
    
    guess = getnc(fname, plotdat.guessvar,-1,-1,-1,-1,-1,-1,0);  
    analy = getnc(fname, plotdat.analyvar,-1,-1,-1,-1,-1,-1,0); 
@@ -203,29 +210,30 @@
 
    % Interlace the [ges,anl] to make a sawtooth plot.
    % By this point, the middle two dimensions are singletons.
-   cg = plotdat.ges_copy(:,:,plotdat.region);
-   ca = plotdat.anl_copy(:,:,plotdat.region);
+   % The data must be sorted to match the order of the levels.
+   cg = plotdat.ges_copy(:,:,plotdat.region); CG = cg(plotdat.indices);
+   ca = plotdat.anl_copy(:,:,plotdat.region); CA = ca(plotdat.indices);
 
-   mg = plotdat.ges_rmse(:,:,plotdat.region);
-   ma = plotdat.anl_rmse(:,:,plotdat.region);
+   mg = plotdat.ges_rmse(:,:,plotdat.region); MG = mg(plotdat.indices);
+   ma = plotdat.anl_rmse(:,:,plotdat.region); MA = ma(plotdat.indices);
 
-   g = plotdat.ges_Nposs(:,:,plotdat.region);
-   a = plotdat.anl_Nposs(:,:,plotdat.region);
-   nobs_poss   = g;
-   nposs_delta = g - a;
+   g = plotdat.ges_Nposs(:,:,plotdat.region); G = g(plotdat.indices);
+   a = plotdat.anl_Nposs(:,:,plotdat.region); A = a(plotdat.indices);
+   nobs_poss   = G;
+   nposs_delta = G - A;
 
-   g = plotdat.ges_Nused(:,:,plotdat.region);
-   a = plotdat.anl_Nused(:,:,plotdat.region);
-   nobs_used   = g;
-   nused_delta = g - a;
+   g = plotdat.ges_Nused(:,:,plotdat.region); G = g(plotdat.indices);
+   a = plotdat.anl_Nused(:,:,plotdat.region); A = a(plotdat.indices);
+   nobs_used   = G;
+   nused_delta = G - A;
 
    % Determine some quantities for the legend
    nobs = sum(nobs_used);
    if ( nobs > 1 )
-      rmse_guess  = mean(mg(isfinite(mg)));   
-      rmse_analy  = mean(ma(isfinite(ma)));   
-      other_guess = mean(cg(isfinite(cg))); 
-      other_analy = mean(ca(isfinite(ca))); 
+      rmse_guess  = mean(MG(isfinite(MG)));   
+      rmse_analy  = mean(MA(isfinite(MA)));   
+      other_guess = mean(CG(isfinite(CG))); 
+      other_analy = mean(CA(isfinite(CA))); 
    else
       rmse_guess  = NaN;
       rmse_analy  = NaN;
@@ -256,18 +264,22 @@
 
    Stripes(plotdat.Xrange, plotdat.level_edges);
    hold on;
-   h1 = plot(mg,plotdat.level,'k+-',ma,plotdat.level,'k+:', ...
-             cg,plotdat.level,'ro-',ca,plotdat.level,'ro:');
+   h1 = plot(MG,plotdat.level,'k+-',MA,plotdat.level,'k+:', ...
+             CG,plotdat.level,'ro-',CA,plotdat.level,'ro:');
    hold off;
    set(h1,'LineWidth',plotdat.linewidth);
-   h = legend(h1, str_rmse_pr, str_rmse_po, str_other_pr, str_other_po);
+   h = legend(h1, str_rmse_pr, str_rmse_po, str_other_pr, str_other_po, ...
+          'Location','East');
    legend(h,'boxoff')
 
    axlims = [plotdat.Xrange plotdat.Yrange];
    axis(axlims)
    set(gca,'YDir', plotdat.YDir)
    hold on; plot([0 0],plotdat.Yrange,'k-')
-   
+
+%   disp(plotdat.myregion)
+%   [plotdat.level CG' CA' MG' MA' ma' mg' ca' cg' plotdat.level_org]
+
    set(gca,'YTick',plotdat.level,'Ylim',plotdat.Yrange)
    ylabel(plotdat.level_units)
    
@@ -292,7 +304,7 @@
    set(h3,'LineStyle','none','Marker','+');   
 
    % use same number of X ticks and the same Y ticks
-   
+  
    xlimits = get(ax2,'XLim');
    xinc   = (xlimits(2)-xlimits(1))/(nXticks-1);
    xticks = xlimits(1):xinc:xlimits(2);
@@ -408,24 +420,9 @@
 
 
 
-function str = GenLevelString(m,e)
-
-if ( (length(m)+1) ~= length(e) )
-error(sprintf('%d vertical midpoints and %d edges',length(m),length(e)))
-end
-
-nstrings = length(m);
-
-str = cell(nstrings,1);
-for i = 1:nstrings 
-  str{i} =  sprintf('(%.0f - %.0f)',e(i),e(i+1));
-end
-
-
 function Stripes(x,edges)
 % EraseMode: [ {normal} | background | xor | none ]
 
-
 xc = [ x(1) x(2) x(2) x(1) x(1) ];
 
 hold on;
@@ -435,4 +432,3 @@
   'EraseMode','background','EdgeColor','none');
 end
 hold off;
-%get(h)


More information about the Dart-dev mailing list