[Dart-dev] [5733] DART/branches/development/matlab: Adding partial support for CLM.

nancy at ucar.edu nancy at ucar.edu
Wed May 9 16:05:38 MDT 2012


Revision: 5733
Author:   thoar
Date:     2012-05-09 16:05:37 -0600 (Wed, 09 May 2012)
Log Message:
-----------
Adding partial support for CLM.
There are many more functions that need to be implemented.

Modified Paths:
--------------
    DART/branches/development/matlab/CheckModel.m
    DART/branches/development/matlab/GetNCindices.m
    DART/branches/development/matlab/PlotCorrel.m
    DART/branches/development/matlab/plot_bins.m
    DART/branches/development/matlab/plot_correl.m

-------------- next part --------------
Modified: DART/branches/development/matlab/CheckModel.m
===================================================================
--- DART/branches/development/matlab/CheckModel.m	2012-05-09 21:36:00 UTC (rev 5732)
+++ DART/branches/development/matlab/CheckModel.m	2012-05-09 22:05:37 UTC (rev 5733)
@@ -1,11 +1,11 @@
 function vars = CheckModel(fname)
-%% CheckModel   tries to ensure that a netcdf file has what we expect. 
+%% CheckModel   tries to ensure that a netcdf file has what we expect.
 %
 % vars is a structure containing a minimal amount of metadata about the netCDF file.
-% 
+%
 % EXAMPLE:
 % fname = 'Prior_Diag.nc';
-% vars = CheckModel(fname) 
+% vars = CheckModel(fname)
 
 %% 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
@@ -32,7 +32,7 @@
 
 clear times timeunits timebase timeorigin
 
-if (isempty(model)) 
+if (isempty(model))
    error('%s has no ''model'' global attribute.',fname)
 end
 
@@ -43,7 +43,7 @@
       num_vars      = dim_length(fname,'StateVariable'); % determine # of state varbls
       StateVariable =  nc_varget(fname,'StateVariable');
 
-      def_state_vars = zeros(1,num_vars);    % for use as a subscript array, 
+      def_state_vars = zeros(1,num_vars);    % for use as a subscript array,
       def_state_vars(:) = StateVariable(:);  % def_state_vars must be a row vector.
 
       vars = struct('model',model, ...
@@ -65,7 +65,7 @@
       num_vars      = dim_length(fname,'StateVariable'); % determine # of state varbls
       StateVariable =  nc_varget(fname,'StateVariable');
 
-      % The only trick is to pick an equally-spaced subset of state 
+      % The only trick is to pick an equally-spaced subset of state
       % variables for the default.
 
       def_state_vars = round([1 , num_vars/3 , 2*num_vars/3]);
@@ -96,7 +96,7 @@
 
       num_vars = dim_length(fname,'StateVariable'); % determine # of state varbls
 
-      % The only trick is to pick an equally-spaced subset of state 
+      % The only trick is to pick an equally-spaced subset of state
       % variables for the default.
 
       def_state_vars = round([1 , num_model_vars/3 , 2*num_model_vars/3]);
@@ -132,7 +132,7 @@
       num_Y  = dim_length(fname,'Ydim'); % # of Y variables
       Ydim   =  nc_varget(fname,'Ydim');
 
-      % The only trick is to pick an equally-spaced subset of state 
+      % The only trick is to pick an equally-spaced subset of state
       % variables for the default.
 
       def_X_inds = round([1 , num_X/3 , 2*num_X/3]);
@@ -209,7 +209,24 @@
 
       vars.vars  = varnames;
       vars.fname = fname;
-     
+
+   case {'clm'}
+
+      varnames = get_DARTvars(fname);
+      num_vars = length(varnames);
+      dinfo    = nc_getdiminfo(fname,'levtot');
+      nlevels  = dinfo.Length;
+
+      vars = struct('model',model, ...
+              'num_state_vars',num_vars, ...
+              'num_ens_members',num_copies, ...
+              'time_series_length',num_times, ...
+              'min_ens_mem',min(copy), ...
+              'max_ens_mem',max(copy) );
+
+      vars.vars  = varnames;
+      vars.fname = fname;
+
    case {'cam','tiegcm','fms_bgrid','pe2lyr','mitgcm_ocean','pbl_1d','mpas_atm'}
 
       varnames = get_DARTvars(fname);
@@ -227,7 +244,7 @@
 
       vars.vars  = varnames;
       vars.fname = fname;
-      
+
    otherwise
 
       error('model %s unknown',model)
@@ -237,7 +254,7 @@
 
 function x = dim_length(fname,dimname)
 % Check for the existence of the named dimension and return it
-% if it exists. If it does not, error out with a useful message. 
+% if it exists. If it does not, error out with a useful message.
 
 info = nc_info(fname);
 n    = length(dimname);

Modified: DART/branches/development/matlab/GetNCindices.m
===================================================================
--- DART/branches/development/matlab/GetNCindices.m	2012-05-09 21:36:00 UTC (rev 5732)
+++ DART/branches/development/matlab/GetNCindices.m	2012-05-09 22:05:37 UTC (rev 5733)
@@ -17,7 +17,7 @@
 %                    pinfo.stateindex
 %                    pinfo.regionindex
 %
-% whichfile          is a character string specifying which 
+% whichfile          is a character string specifying which
 %                    filename component of 'pinfo' will be used.
 %                    ['prior','posterior','truth','diagn','fname']
 % varname            is the netcdf variable being extracted.
@@ -127,11 +127,11 @@
 start   = zeros(1,ndims);
 count   = zeros(1,ndims);
 
-% varinfo.Dimension is a cell array of the Dimension strings 
+% varinfo.Dimension is a cell array of the Dimension strings
 % varinfo.Size is an N-D array describing the variable shape
 % varinfo.Attribute is a struct holding the variable attribues
 
-% loop over all of the variables dimensions and 
+% loop over all of the variables dimensions and
 % build up the start/endpoint arrays
 
 for i = 1:ndims
@@ -146,10 +146,10 @@
    % ditto for lat, lon ... (on staggered grids, for example)
    % So the XG coordinate dimension has 'cartesian_axis = X',
    % for example.
-   
+
    [len, status, value] = is_dimension_cartesian(fname, diminfo.Name);
-   
-   if (status > 0) 
+
+   if (status > 0)
       dimname = value;
    else
       % Then there is no 'cartesian_axis' attribute and the best we can
@@ -164,7 +164,7 @@
            case 'copy'
                start(i) = copy1;
                count(i) = copyN;
-           case {'surf','unde','hlev','mlev','plev','heig','leve','bott','ilev','nver'}
+           case {'surf','unde','hlev','mlev','plev','heig','leve','bott','ilev','nver','levt','levs'}
                start(i) = level1;
                count(i) = levelN;
            case {'tmpj','sout'}
@@ -218,9 +218,9 @@
 value    = [];
 
 if ( nc_isvar(fname,dimname) )
-    
+
     % Good - the coordinate variable exists.
-    
+
     Cvarinfo = nc_getvarinfo(fname, dimname);
 
    for j = 1:length(Cvarinfo.Attribute);
@@ -236,6 +236,6 @@
    end
 
 else % there is no coordinate variable ... use something else
-    
+
 end
 

Modified: DART/branches/development/matlab/PlotCorrel.m
===================================================================
--- DART/branches/development/matlab/PlotCorrel.m	2012-05-09 21:36:00 UTC (rev 5732)
+++ DART/branches/development/matlab/PlotCorrel.m	2012-05-09 22:05:37 UTC (rev 5733)
@@ -62,7 +62,7 @@
       state_var = get_hyperslab('fname',pinfo.fname, 'varname',pinfo.base_var, ...
                   'copyindex1',pinfo.ensemble_indices(1),'copycount',pinfo.num_ens_members, ...
                   'state1',pinfo.min_state_var,'statecount',pinfo.num_state_vars);
-      
+
       % It is efficient to preallocate correl storage ...
       correl = zeros(pinfo.num_state_vars,pinfo.time_series_length);
 
@@ -359,7 +359,7 @@
       axis image
       colorbar;
 
-   case {'tiegcm'}
+   case 'tiegcm'
 
       % We are going to correlate one var/time/lvl/lat/lon  with
       % all other lats/lons for a var/time/lvl
@@ -415,7 +415,7 @@
       axis image
       colorbar;
 
-   case {'mpas_atm'}
+   case 'mpas_atm'
 
       %% We are going to correlate one var/time/lvl/location  with
       %  all other locations for a var/time/lvl
@@ -462,6 +462,72 @@
       axis([-10 370 -Inf Inf])
       colorbar;
 
+   case 'clm'
+
+      % We are going to correlate one var/time/lvl/lat/lon  with
+      % all other lats/lons for a var/time/lvl
+
+      clf;
+
+      lats     = nc_varget(pinfo.fname,'lat'); ny = length(lats);
+      lons     = nc_varget(pinfo.fname,'lon'); nx = length(lons);
+      latunits = nc_attget(pinfo.fname,'lat','units');
+      lonunits = nc_attget(pinfo.fname,'lon','units');
+
+      nxny     = nx*ny;
+
+      %% CLM variables must be reconstituted into grid cell values for
+      %  each ensemble member.
+      %  Need all copies  ... base_mem has shape [1,nmembers]
+      %  Need all copies  ... comp_ens has shape [nmembers,nxny]
+
+      metadata    = nc_varget(pinfo.fname,'CopyMetaData');      % get all the metadata
+      copyindices = strmatch('ensemble member',metadata); % find all 'member's
+      nmembers    = length(copyindices);
+
+      base_mem = zeros(1,nmembers);
+      comp_ens = zeros(nmembers,nxny);
+      corr     = zeros(nxny,1);
+
+      for imem = 1:nmembers,
+
+         copystring = sprintf('ensemble member %d',imem);
+         base  = clm_get_var(pinfo.fname, pinfo.base_var, copystring, ...
+                                    pinfo.base_lvlind, pinfo.base_tmeind);
+         base_mem(imem) = base.datmat(pinfo.base_latind, pinfo.base_lonind);
+
+         comp  = clm_get_var(pinfo.fname, pinfo.comp_var, copystring, ...
+                                  pinfo.comp_lvlind, pinfo.base_tmeind);
+         comp_ens(imem,:) = comp.datmat(:);
+
+      end
+
+      for i = 1:nxny,
+         x = corrcoef(base_mem, comp_ens(:, i));
+         corr(i) = x(1, 2);
+      end
+
+      correl = reshape(corr,[ny nx]);
+
+%     contour(lons,lats,correl,[-1:0.2:-0.2 0.2:0.2:1.0]); hold on;
+      h3 = imagesc(lons,lats,correl); set(gca,'YDir','normal');
+      set(h3,'AlphaData',~isnan(correl))
+      hold on;
+      plot(pinfo.base_lon, pinfo.base_lat, 'pk', ...
+                 'MarkerSize',12,'MarkerFaceColor','k');
+      s1 = sprintf('%s Correlation of ''%s'', level %d, (%.2f,%.2f) T = %f', ...
+           model, pinfo.base_var, pinfo.base_lvl, ...
+             pinfo.base_lat, pinfo.base_lon, pinfo.base_time);
+
+      s2 = sprintf('against ''%s'', entire level %d, same time, %d ensemble members', ...
+               pinfo.comp_var, pinfo.comp_lvl, nmembers);
+      title({s1,s2,pinfo.fname},'interpreter','none','fontweight','bold')
+      xlabel(sprintf('longitude (%s)',lonunits),'interpreter','none')
+      ylabel(sprintf('latitude (%s)',latunits),'interpreter','none')
+      worldmap('hollow');
+      axis image
+      h = colorbar;
+
    otherwise
 
       error('model %s not implemented yet', pinfo.model)

Modified: DART/branches/development/matlab/plot_bins.m
===================================================================
--- DART/branches/development/matlab/plot_bins.m	2012-05-09 21:36:00 UTC (rev 5732)
+++ DART/branches/development/matlab/plot_bins.m	2012-05-09 22:05:37 UTC (rev 5733)
@@ -1,4 +1,4 @@
-%% DART:plot_bins Plots ensemble rank histograms 
+%% DART:plot_bins Plots ensemble rank histograms
 %
 % plot_bins    interactively queries for the information needed to create
 %              ensemble rank histograms. Since different models potentially
@@ -24,12 +24,12 @@
 % $Revision$
 % $Date$
 
-% error_checking ... 
-% exist('bob') == 1   means the variable exists. 
+% error_checking ...
+% exist('bob') == 1   means the variable exists.
 %                     the value of the variable is checked later.
 
-if (exist('truth_file','var') ~= 1) 
-   disp('Input name of True State file:') 
+if (exist('truth_file','var') ~= 1)
+   disp('Input name of True State file:')
    truth_file = input('<cr> for True_State.nc\n','s');
    if isempty(truth_file)
       truth_file = 'True_State.nc';
@@ -37,7 +37,7 @@
 end
 
 if (exist('diagn_file','var') ~=1)
-   disp('Input name of prior or posterior diagnostics file:') 
+   disp('Input name of prior or posterior diagnostics file:')
    diagn_file = input('<cr> for Prior_Diag.nc\n','s');
    if isempty(diagn_file)
       diagn_file = 'Prior_Diag.nc';
@@ -71,6 +71,10 @@
 
       pinfo = GetCamInfo(pinfo, diagn_file, 'PlotBins');
 
+   case 'clm'
+
+      pinfo = GetClmInfo(pinfo, diagn_file, 'PlotBins');
+
    case 'wrf'
 
       pinfo = GetWRFInfo(pinfo, diagn_file, 'PlotBins');
@@ -84,7 +88,7 @@
       pinfo = GetMITgcm_oceanInfo(pinfo, diagn_file, 'PlotBins');
 
    case 'mpas_atm'
-       
+
       pinfo = GetMPAS_ATMInfo(pinfo, diagn_file, 'PlotBins');
 
    otherwise

Modified: DART/branches/development/matlab/plot_correl.m
===================================================================
--- DART/branches/development/matlab/plot_correl.m	2012-05-09 21:36:00 UTC (rev 5732)
+++ DART/branches/development/matlab/plot_correl.m	2012-05-09 22:05:37 UTC (rev 5733)
@@ -1,11 +1,11 @@
-%% DART:plot_correl Plots space-time series of correlation between a given variable 
-%               at a given time and other variables at all times in an 
+%% DART:plot_correl Plots space-time series of correlation between a given variable
+%               at a given time and other variables at all times in an
 %               ensemble time sequence.
 %
 % plot_correl  interactively queries for the information needed to create
 %              the desired correlations.
-%              Since different models potentially need different pieces 
-%              of information ... the model types are determined and 
+%              Since different models potentially need different pieces
+%              of information ... the model types are determined and
 %              additional user input may be queried.
 
 %% DART software - Copyright 2004 - 2011 UCAR. This open source software is
@@ -24,7 +24,7 @@
    if isempty(diagn_file)
       diagn_file = 'Prior_Diag.nc';
    end
-end 
+end
 
 if ( exist(diagn_file,'file') ~= 2 ), error('%s does not exist.',diagn_file); end
 
@@ -103,6 +103,10 @@
 
       pinfo = GetCamInfo(pinfo, diagn_file, 'PlotCorrel');
 
+   case 'clm'
+
+      pinfo = GetClmInfo(pinfo, diagn_file, 'PlotCorrel');
+
    case 'wrf'
 
       pinfo = GetWRFInfo(pinfo, diagn_file, 'PlotCorrel');


More information about the Dart-dev mailing list