[Dart-dev] [5473] DART/branches/development/models/cam/matlab/hop_test_check.m: Creates a 3panel plot of metrics to interpret whether or not

nancy at ucar.edu nancy at ucar.edu
Fri Dec 30 16:02:26 MST 2011


Revision: 5473
Author:   thoar
Date:     2011-12-30 16:02:26 -0700 (Fri, 30 Dec 2011)
Log Message:
-----------
Creates a 3panel plot of metrics to interpret whether or not
the difference from a single hop and a double hop is meaningful.
The bottom panel is the time tendency as defined by the single hop.
The middle panel is the difference between one-hop and two-hop.
The top panel is a histogram of the differences.
If the variables have a 'units' attribute, it is used.
There is no attempt at annotating any coordinate varibles.

Modified Paths:
--------------
    DART/branches/development/models/cam/matlab/hop_test_check.m

-------------- next part --------------
Modified: DART/branches/development/models/cam/matlab/hop_test_check.m
===================================================================
--- DART/branches/development/models/cam/matlab/hop_test_check.m	2011-12-29 21:28:45 UTC (rev 5472)
+++ DART/branches/development/models/cam/matlab/hop_test_check.m	2011-12-30 23:02:26 UTC (rev 5473)
@@ -1,8 +1,8 @@
-function hop_test_check(file0, file1, file2)
+function hop_test_check(file0, file1, file2, varname)
 % DART hop_test_check 
 %
 % USAGE:
-% x = hop_test_check(file0, file1, file2);
+% hop_test_check(file0, file1, file2);
 %
 % file0    is the filename of the initial state 
 % file1    is the filename of the 'long hop' case
@@ -16,7 +16,14 @@
 % file0 = '/gpfs/ptmp/thoar/restarts/CAM/caminput_1.nc';
 % file1 = '/glade/scratch/thoar/archive/hop_24/rest/2008-11-01-00000/hop_24.cam_0001.i.2008-11-01-00000.nc';
 % file2 = '/glade/scratch/thoar/archive/hop_12/rest/2008-11-01-00000/hop_12.cam_0001.i.2008-11-01-00000.nc';
-% x     = hop_test_check(file0, file1, file2);
+% hop_test_check(file0, file1, file2)
+%
+% Example:
+%
+% file3 = '/gpfs/ptmp/thoar/restarts/CLM/clminput_1.nc';
+% file4 = '/glade/scratch/thoar/archive/hop_24/rest/2008-11-01-00000/hop_24.clm2_0001.r.2008-11-01-00000.nc';
+% file5 = '/glade/scratch/thoar/archive/hop_12/rest/2008-11-01-00000/hop_12.clm2_0001.r.2008-11-01-00000.nc';
+% hop_test_check(file3, file4, file5)
 
 %% DART software - Copyright 2004 - 2011 UCAR. This open source software is
 % provided by UCAR, "as is", without charge, subject to all terms of use at
@@ -50,75 +57,149 @@
 
 bob = jet128; colormap(bob);
 
+if (nargin > 3)
+    vars = {varname};
+    pausecmd = 'fprintf(''pausing at level %d ... hit a key to continue\n'',ilevel), pause';
+else
+    pausecmd = 'fprintf(''           level %d ... \n'',ilevel); pause(0.1)';
+end
+
 for i = 1:length(vars)
-
-   fprintf('Comparing %s\n',vars{i})
     
-   varinfo       = nc_getvarinfo(file0,vars{i});
+   varinfo = nc_getvarinfo(file0,vars{i});
+   if (varinfo.Nctype == 2)
+       % Character string variables need not be checked.
+       fprintf('Skipping   %s\n',vars{i})
+       continue
+   else
+       fprintf('Comparing  %s\n',vars{i})
+   end
    nonsingletons = (varinfo.Size > 1);
    mydimnames    = varinfo.Dimension(nonsingletons);
    mydimsizes    = varinfo.Size(nonsingletons);
    levdim        = find(strcmp(mydimnames,'lev'));
-   
+
+   myunits       = GetAttribute(file0,vars{i},'units');
    start         = nc_varget(file0,vars{i});
    onehop        = nc_varget(file1,vars{i});
    twohop        = nc_varget(file2,vars{i});
    tendency      = onehop - start;
    change        = twohop - onehop;
-
-   % Need to also plot vars that do not have a 'lev' dimension
-   % PS only defined on surface, for example.
    
-   for ilevel = 1:mydimsizes(levdim)
-       myplot(vars{i}, ilevel, change, tendency)
-       fprintf('          level %d ... \n',ilevel)
-       pause(0.1)
+   if (length(mydimsizes) == 1)
+       continue % How do we compare 1D arrays?
+   elseif (isempty(levdim))
+       % We still have a multimensional object... 
+       my2dplot(vars{i}, change, tendency, mydimnames, myunits)
+       disp('          pausing - hit any key to continue ...')
+       pause
+   else
+       for ilevel = 1:mydimsizes(levdim)
+           myplot(vars{i}, ilevel, change, tendency, mydimnames, myunits)
+           eval(pausecmd)
+       end  
    end
-   
+ 
 end
 
 
-function myplot(varname,levelindx,diffmat,tendmat)
+function my2dplot(varname,slab,orgslab,dimnames,units)
 %% Make some plots
-% To be comparable with the other figures in the article, the hemispheres 
-% need to be [-180,180], the major ticks and labels are every 30 degrees.
-% no titles.
-% bigger fonts
-% Peter wanted .eps or .ps - good - can use 'painters'
+%
 
+slabmin = min(slab(:));
+slabmax = max(slab(:));
+
+orgmin = min(orgslab(:));
+orgmax = max(orgslab(:));
+datmax = max(abs([orgmin orgmax]));
+
+if orgmin == orgmax
+    clim = [-1 1];
+else
+    clim = [-datmax datmax];
+end
+
+sbpos = [0.10 0.06 0.80 0.28; 
+         0.10 0.43 0.80 0.28;
+         0.10 0.80 0.80 0.15]; 
+
+% Need to know what dimensions we are plotting
+
+figure(1); clf; orient tall; 
+
+subplot('position',sbpos(3,:))
+   hist(slab(:),50)
+   title(sprintf('(min %0.5g %s) hopping difference histogram (max %0.5g %s)',slabmin,units, slabmax,units))
+   xlabel(units)
+
+subplot('position',sbpos(2,:))
+   imagesc(slab,clim);
+   set(gca,'YDir','normal','TickDir','out','XMinorTick','on','FontSize',14)
+   title(sprintf('%s difference from hopping',varname))
+   axis image
+   ylabel(sprintf('%s (index)',dimnames{1}))
+   h = colorbar('vert');
+   set(get(h,'YLabel'),'String',units)
+   
+subplot('position',sbpos(1,:))
+   imagesc(orgslab,clim);
+   set(gca,'YDir','normal','TickDir','out','XMinorTick','on','FontSize',14)
+   title(sprintf('%s tendency',varname))
+   axis image
+   ylabel(sprintf('%s (index)',dimnames{1}))
+   xlabel(sprintf('%s (index)',dimnames{2}))
+   h = colorbar('vert');
+   set(get(h,'YLabel'),'String',units)
+
+
+function myplot(varname,levelindx,diffmat,tendmat,dimnames,units)
+%% Make some plots
+%
+
 slab = squeeze(diffmat(levelindx,:,:));
 slabmin = min(slab(:));
 slabmax = max(slab(:));
-clim = [slabmin slabmax];
 
+if slabmin == slabmax, return; end
+
 orgslab = squeeze(tendmat(levelindx,:,:));
 orgmin = min(orgslab(:));
 orgmax = max(orgslab(:));
 datmax = max(abs([orgmin orgmax]));
 clim = [-datmax datmax];
 
-if slabmin == slabmax, return; end
+sbpos = [0.10 0.06 0.80 0.28; 
+         0.10 0.43 0.80 0.28;
+         0.10 0.80 0.80 0.15]; 
 
 figure(1); clf; orient tall; 
-subplot(2,1,1)
+subplot('position',sbpos(3,:))
+   hist(slab(:),50)
+   title(sprintf('(min %0.5g %s) hopping difference histogram (max %0.5g %s)',slabmin,units,slabmax,units))
+   xlabel(units)
+
+subplot('position',sbpos(2,:))
    imagesc(slab,clim);
    set(gca,'YDir','normal','TickDir','out','XMinorTick','on','FontSize',14)
    title(sprintf('%s level %d difference from hopping',varname,levelindx))
    axis image
+   ylabel(sprintf('%s (index)',dimnames{2}))
    h = colorbar('vert');
+   set(get(h,'YLabel'),'String',units)
    
-   subplot(2,1,2)
+subplot('position',sbpos(1,:))
    imagesc(orgslab,clim);
    set(gca,'YDir','normal','TickDir','out','XMinorTick','on','FontSize',14)
    title(sprintf('%s level %d tendency',varname,levelindx))
    axis image
+   ylabel(sprintf('%s (index)',dimnames{2}))
+   xlabel(sprintf('%s (index)',dimnames{3}))
    h = colorbar('vert');
+   set(get(h,'YLabel'),'String',units)
 
 
 
-
-
-
 function vars = FindProgVars(fname)
 %% Determine the multi-dimensional variables that are not coordinate variables.
 % These are probably the variables of interest.
@@ -164,4 +245,12 @@
 x = jet(128);
 x(64:65,:) = 1;
 
-
+function attvalue = GetAttribute(fname,varname,attname)
+varinfo = nc_getvarinfo(fname,varname);
+attvalue = [];
+for i = 1:length(varinfo.Attribute)
+   if (strcmp(varinfo.Attribute(i).Name,attname))
+      attvalue = varinfo.Attribute(i).Value;
+      break
+   end
+end


More information about the Dart-dev mailing list