[Dart-dev] [5065] DART/trunk/matlab: Adding support for CAM ... in suppor
nancy at ucar.edu
nancy at ucar.edu
Fri Jul 8 14:41:18 MDT 2011
Revision: 5065
Author: thoar
Date: 2011-07-08 14:41:18 -0600 (Fri, 08 Jul 2011)
Log Message:
-----------
Adding support for CAM ... in support of perfect model experiments.
Modified Paths:
--------------
DART/trunk/matlab/GetCamInfo.m
DART/trunk/matlab/PlotBins.m
DART/trunk/matlab/PlotEnsErrSpread.m
DART/trunk/matlab/PlotEnsMeanTimeSeries.m
DART/trunk/matlab/PlotEnsTimeSeries.m
DART/trunk/matlab/plot_bins.m
DART/trunk/matlab/plot_ens_err_spread.m
-------------- next part --------------
Modified: DART/trunk/matlab/GetCamInfo.m
===================================================================
--- DART/trunk/matlab/GetCamInfo.m 2011-07-08 16:28:41 UTC (rev 5064)
+++ DART/trunk/matlab/GetCamInfo.m 2011-07-08 20:41:18 UTC (rev 5065)
@@ -2,9 +2,9 @@
%% GetCamInfo prepares a structure of information needed by the subsequent "routine"
% The information is gathered via rudimentary "input" routines.
%
-% pinfo = GetCamInfo(fname,routine);
+% pinfo = GetCamInfo(pstruct,routine);
%
-% fname Name of the DART netcdf file
+% pstruct structure containing the names of the truth_file and the diagn_file of the DART netcdf file
% routine name of subsequent plot routine.
%% DART software - Copyright 2004 - 2011 UCAR. This open source software is
@@ -17,22 +17,26 @@
% $Revision$
% $Date$
-if ( exist(pstruct.truth_file,'file') )
+if (isfield(pstruct,'truth_file') && exist(pstruct.truth_file,'file') )
fname = pstruct.truth_file;
-elseif ( exist(pstruct.diagn_file,'file') )
+elseif (isfield(pstruct,'diagn_file') && exist(pstruct.diagn_file,'file') )
fname = pstruct.diagn_file;
-elseif ( exist(pstruct.prior_file,'file') )
+elseif (isfield(pstruct,'prior_file') && exist(pstruct.prior_file,'file') )
fname = pstruct.prior_file;
-elseif ( exist(pstruct.posterior_file,'file') )
+elseif (isfield(pstruct,'posterior_file') && exist(pstruct.posterior_file,'file') )
fname = pstruct.posterior_file;
+elseif (isfield(pstruct,'fname') && exist(pstruct.fname,'file') )
+ fname = pstruct.fname;
end
-model = nc_attget(fname,nc_global,'model');
+model = nc_attget(fname,nc_global,'model');
-if strcmp(lower(model),'cam') ~= 1
+if strcmpi(model,'cam') ~= 1
error('Not so fast, this is not a cam model.')
end
+pinfo = pstruct;
+
copy = nc_varget(fname,'copy');
times = nc_varget(fname,'time');
ilevel = nc_varget(fname,'ilev'); % interfaces
@@ -59,13 +63,16 @@
[lat , latind] = GetLatitude( pgvar,lat);
[lon , lonind] = GetLongitude(pgvar,lon);
- pinfo = struct('model',model, ...
- 'fname',fname, ...
- 'var_names',pgvar, ...
- 'level' ,level, 'levelindex',lvlind, ...
- 'longitude',lon , 'lonindex',lonind, ...
- 'latitude' ,lat , 'latindex',latind);
+ pinfo.model = model;
+ pinfo.var = pgvar;
+ pinfo.level = level;
+ pinfo.levelindex = lvlind;
+ pinfo.longitude = lon;
+ pinfo.lonindex = lonind;
+ pinfo.latitude = lat;
+ pinfo.latindex = latind;
+
case 'plotcorrel'
disp('Getting information for the ''base'' variable.')
@@ -77,16 +84,23 @@
disp('Getting information for the ''comparison'' variable.')
comp_var = GetVar(prognostic_vars, base_var);
- [comp_lvl, comp_lvlind] = GetLevel( comp_var,levels, base_lvl);
+ [comp_lvl, comp_lvlind] = GetLevel( comp_var,levels, base_lvlind);
- pinfo = struct('model',model , 'fname' , fname, ...
- 'base_var' ,base_var , 'comp_var' , comp_var, ...
- 'base_time',base_time, 'base_tmeind', base_tmeind, ...
- 'base_lvl' ,base_lvl , 'base_lvlind', base_lvlind, ...
- 'base_lat' ,base_lat , 'base_latind', base_latind, ...
- 'base_lon' ,base_lon , 'base_lonind', base_lonind, ...
- 'comp_lvl' ,comp_lvl , 'comp_lvlind', comp_lvlind);
+ pinfo.model = model;
+ pinfo.base_var = base_var;
+ pinfo.comp_var = comp_var;
+ pinfo.base_time = base_time;
+ pinfo.base_tmeind = base_tmeind;
+ pinfo.base_lvl = base_lvl;
+ pinfo.base_lvlind = base_lvlind;
+ pinfo.base_lat = base_lat;
+ pinfo.base_latind = base_latind;
+ pinfo.base_lon = base_lon;
+ pinfo.base_lonind = base_lonind;
+ pinfo.comp_lvl = comp_lvl;
+ pinfo.comp_lvlind = comp_lvlind;
+
case 'plotvarvarcorrel'
disp('Getting information for the ''base'' variable.')
@@ -98,19 +112,27 @@
disp('Getting information for the ''comparison'' variable.')
comp_var = GetVar(prognostic_vars, base_var);
- [comp_lvl, comp_lvlind] = GetLevel( comp_var,levels, base_lvl);
+ [comp_lvl, comp_lvlind] = GetLevel( comp_var,levels, base_lvlind);
[comp_lat, comp_latind] = GetLatitude( comp_var,lat,base_lat);
[comp_lon, comp_lonind] = GetLongitude(comp_var,lon,base_lon);
- pinfo = struct('model',model , 'fname' , fname, ...
- 'base_var' ,base_var , 'comp_var' , comp_var, ...
- 'base_time',base_time, 'base_tmeind', base_tmeind, ...
- 'base_lvl' ,base_lvl , 'base_lvlind', base_lvlind, ...
- 'base_lat' ,base_lat , 'base_latind', base_latind, ...
- 'base_lon' ,base_lon , 'base_lonind', base_lonind, ...
- 'comp_lvl' ,comp_lvl , 'comp_lvlind', comp_lvlind, ...
- 'comp_lat' ,comp_lat , 'comp_latind', comp_latind, ...
- 'comp_lon' ,comp_lon , 'comp_lonind', comp_lonind);
+ pinfo.model = model;
+ pinfo.base_var = base_var;
+ pinfo.comp_var = comp_var;
+ pinfo.base_time = base_time;
+ pinfo.base_tmeind = base_tmeind;
+ pinfo.base_lvl = base_lvl;
+ pinfo.base_lvlind = base_lvlind;
+ pinfo.base_lat = base_lat;
+ pinfo.base_latind = base_latind;
+ pinfo.base_lon = base_lon;
+ pinfo.base_lonind = base_lonind;
+ pinfo.comp_lvl = comp_lvl;
+ pinfo.comp_lvlind = comp_lvlind;
+ pinfo.comp_lat = comp_lat;
+ pinfo.comp_latind = comp_latind;
+ pinfo.comp_lon = comp_lon;
+ pinfo.comp_lonind = comp_lonind;
case 'plotsawtooth'
@@ -121,17 +143,21 @@
[ lon, lonind] = GetLongitude(pgvar,lon);
% [ lon, lonind] = GetCopies(pgvar,xxx);
- pinfo = struct('model' , model, ...
- 'var_names' , pgvar, ...
- 'truth_file' , [], ...
- 'prior_file' , pstruct.prior_file, ...
- 'posterior_file', pstruct.posterior_file, ...
- 'level' , level, 'levelindex', lvlind, ...
- 'latitude' , lat, 'latindex', latind, ...
- 'longitude' , lon, 'lonindex', lonind, ...
- 'copies' , 0,'copyindices', []);
+ pinfo.model = model;
+ pinfo.var_names = pgvar;
+ pinfo.truth_file = [];
+ pinfo.prior_file = pstruct.prior_file;
+ pinfo.posterior_file = pstruct.posterior_file;
+ pinfo.level = level;
+ pinfo.levelindex = lvlind;
+ pinfo.latitude = lat;
+ pinfo.latindex = latind;
+ pinfo.longitude = lon;
+ pinfo.lonindex = lonind;
+ pinfo.copies = 0;
+ pinfo.copyindices = [];
- if ( exist(pstruct.truth_file) )
+ if ( exist(pstruct.truth_file,'file') )
pinfo.truth_file = pstruct.truth_file;
end
@@ -146,13 +172,13 @@
disp('Getting information for the ''Y'' variable.')
var2 = GetVar(prognostic_vars, var1 );
- [var2_lvl, var2_lvlind] = GetLevel( var2, levels, var1_lvl);
+ [var2_lvl, var2_lvlind] = GetLevel( var2, levels, var1_lvlind);
[var2_lat, var2_latind] = GetLatitude( var2, lat, var1_lat);
[var2_lon, var2_lonind] = GetLongitude(var2, lon, var1_lon);
disp('Getting information for the ''Z'' variable.')
var3 = GetVar(prognostic_vars, var1 );
- [var3_lvl, var3_lvlind] = GetLevel( var3, levels, var1_lvl);
+ [var3_lvl, var3_lvlind] = GetLevel( var3, levels, var1_lvlind);
[var3_lat, var3_latind] = GetLatitude( var3, lat, var1_lat);
[var3_lon, var3_lonind] = GetLongitude(var3, lon, var1_lon);
@@ -164,23 +190,36 @@
s1 = input('Input line type string. <cr> for ''k-'' ','s');
if isempty(s1), ltype = 'k-'; else ltype = s1; end
- pinfo = struct('model',model, 'fname' ,fname, ...
- 'var1name' ,var1, 'var2name' ,var2, 'var3name' ,var3, ...
- 'var1_lvl' , var1_lvl, 'var1_lvlind', var1_lvlind, ...
- 'var1_lat' , var1_lat, 'var1_latind', var1_latind, ...
- 'var1_lon' , var1_lon, 'var1_lonind', var1_lonind, ...
- 'var2_lvl' , var2_lvl, 'var2_lvlind', var2_lvlind, ...
- 'var2_lat' , var2_lat, 'var2_latind', var2_latind, ...
- 'var2_lon' , var2_lon, 'var2_lonind', var2_lonind, ...
- 'var3_lvl' , var3_lvl, 'var3_lvlind', var3_lvlind, ...
- 'var3_lat' , var3_lat, 'var3_latind', var3_latind, ...
- 'var3_lon' , var3_lon, 'var3_lonind', var3_lonind, ...
- 'ens_mem' , ens_mem , 'ltype',ltype);
+ pinfo.model = model;
+ pinfo.var1name = var1;
+ pinfo.var2name = var2;
+ pinfo.var3name = var3;
+ pinfo.var1_lvl = var1_lvl;
+ pinfo.var1_lvlind = var1_lvlind;
+ pinfo.var1_lat = var1_lat;
+ pinfo.var1_latind = var1_latind;
+ pinfo.var1_lon = var1_lon;
+ pinfo.var1_lonind = var1_lonind;
+ pinfo.var2_lvl = var2_lvl;
+ pinfo.var2_lvlind = var2_lvlind;
+ pinfo.var2_lat = var2_lat;
+ pinfo.var2_latind = var2_latind;
+ pinfo.var2_lon = var2_lon;
+ pinfo.var2_lonind = var2_lonind;
+ pinfo.var3_lvl = var3_lvl;
+ pinfo.var3_lvlind = var3_lvlind;
+ pinfo.var3_lat = var3_lat;
+ pinfo.var3_latind = var3_latind;
+ pinfo.var3_lon = var3_lon;
+ pinfo.var3_lonind = var3_lonind;
+ pinfo.ens_mem = ens_mem;
+ pinfo.ltype = ltype;
otherwise
end
+
function pgvar = GetVar(prognostic_vars, defvar)
%----------------------------------------------------------------------
if (nargin == 2), pgvar = defvar; else pgvar = 'PS'; end
@@ -196,7 +235,6 @@
if ~isempty(varstring), pgvar = strtrim(varstring); end
inds = strfind(pgvar,',');
pgvar(inds) = '';
-a = strread(pgvar,'%s','delimiter',' ');
function [time, timeind] = GetTime(pgvar, times, deftime)
@@ -222,7 +260,7 @@
% shouldn't for cam ... but for future expansion ...
if (nargin == 3), lvlind = deflevel; else lvlind = 1; end
-if strcmp(lower(pgvar),'ps') ==1
+if strcmpi(pgvar,'ps') ==1
disp('''PS'' only has one level, using it.')
level = 1;
lvlind = 1;
Modified: DART/trunk/matlab/PlotBins.m
===================================================================
--- DART/trunk/matlab/PlotBins.m 2011-07-08 16:28:41 UTC (rev 5064)
+++ DART/trunk/matlab/PlotBins.m 2011-07-08 20:41:18 UTC (rev 5065)
@@ -39,7 +39,7 @@
% $Revision$
% $Date$
-pinfo = CheckModelCompatibility(pinfo)
+pinfo = CheckModelCompatibility(pinfo);
% Get the state for the truth
truth_index = get_copy_index(pinfo.truth_file,'true state');
@@ -123,7 +123,7 @@
axis tight
end
- case {'fms_bgrid','pe2lyr','mitgcm_ocean'}
+ case {'fms_bgrid','pe2lyr','mitgcm_ocean','cam'}
% It is intended that all 3D models have all the required information
% set in the corresponding Get<model>Info.m script.
Modified: DART/trunk/matlab/PlotEnsErrSpread.m
===================================================================
--- DART/trunk/matlab/PlotEnsErrSpread.m 2011-07-08 16:28:41 UTC (rev 5064)
+++ DART/trunk/matlab/PlotEnsErrSpread.m 2011-07-08 20:41:18 UTC (rev 5065)
@@ -146,7 +146,7 @@
ylabel('distance')
end
- case {'fms_bgrid','pe2lyr','mitgcm_ocean'}
+ case {'fms_bgrid','pe2lyr','mitgcm_ocean','cam'}
clf;
@@ -209,8 +209,8 @@
count(i) = tendind - tstartind + 1;
break
otherwise
+ end
end
-end
var = nc_varget(fname, pinfo.var, start, count);
Modified: DART/trunk/matlab/PlotEnsMeanTimeSeries.m
===================================================================
--- DART/trunk/matlab/PlotEnsMeanTimeSeries.m 2011-07-08 16:28:41 UTC (rev 5064)
+++ DART/trunk/matlab/PlotEnsMeanTimeSeries.m 2011-07-08 20:41:18 UTC (rev 5065)
@@ -184,7 +184,7 @@
legend boxoff
end
- case {'fms_bgrid','pe2lyr','mitgcm_ocean','wrf'}
+ case {'fms_bgrid','pe2lyr','mitgcm_ocean','wrf','cam'}
clf;
@@ -218,53 +218,7 @@
xlabel(sprintf('time (%s) %d timesteps',timeunits, num_times))
ylabel(varunits)
- case 'cam'
- clf;
-
- var_names = strread(pinfo.var_names,'%s','delimiter',' ');
- nfigs = length(var_names); % each variable gets its own figure
- iplot = 0;
-
- for ivar = 1:nfigs
-
- iplot = iplot + 1;
- figure(iplot); clf;
-
- pinfo.var = var_names{ivar};
-
- timeunits = nc_attget(pinfo.diagn_file, 'time', 'units');
- varunits = nc_attget(pinfo.diagn_file, pinfo.var, 'units');
-
- subplot(2,1,1)
- PlotLocator(pinfo);
-
- ens_mean = GetCopy(pinfo.diagn_file, ens_mean_index, pinfo, ...
- pinfo.diagn_time(1), pinfo.diagn_time(2)) ;
- subplot(2,1,2)
- plot(times,ens_mean,'r','LineWidth',2);
- legend('Ensemble Mean', 0)
- s1 = sprintf('%s model ''%s'' Ensemble Mean', pinfo.model, pinfo.var);
- s2 = sprintf('level index %d lat %.2f lon %.2f', ...
- pinfo.levelindex, pinfo.latitude, pinfo.longitude);
-
- if ( have_truth )
- truth = GetCopy(pinfo.truth_file, truth_index, pinfo, ...
- pinfo.truth_time(1), pinfo.truth_time(2)) ;
- hold on; plot(times,truth,'b','LineWidth',2); hold off;
- legend('Ensemble Mean','True State',0);
- s1 = sprintf('%s model ''%s'' Truth and Ensemble Mean', ...
- pinfo.model, pinfo.var);
- end
-
- %plot(times,ens_mean,'r','LineWidth',2); % again - on top
-
- title({s1,s2,pinfo.diagn_file},'interpreter','none','fontweight','bold')
- xlabel(sprintf('time (%s) %d timesteps',timeunits, num_times))
- ylabel(varunits)
- legend boxoff
- end
-
otherwise
error('model %s unknown.',pinfo.model)
Modified: DART/trunk/matlab/PlotEnsTimeSeries.m
===================================================================
--- DART/trunk/matlab/PlotEnsTimeSeries.m 2011-07-08 16:28:41 UTC (rev 5064)
+++ DART/trunk/matlab/PlotEnsTimeSeries.m 2011-07-08 20:41:18 UTC (rev 5065)
@@ -98,7 +98,7 @@
plot(times, ens_mean,'r','LineWidth',2.0); hold on;
plot(times,ens_members,'g');
- if (exist('legendstr'))
+ if (exist('legendstr','var'))
legend(legendstr, 'Ensemble Mean', sprintf('Ensemble Members (%d)',nmembers), 0);
plot(pinfo.truth_times, truth,'b','LineWidth',2); % again, to put 'on top'
else
@@ -138,7 +138,7 @@
plot(times, ens_mean,'r','LineWidth',2.0); hold on;
plot(times,ens_members,'g');
- if (exist('legendstr'))
+ if (exist('legendstr','var'))
legend(legendstr, 'Ensemble Mean', sprintf('Ensemble Members (%d)',nmembers), 0);
plot(pinfo.truth_times, truth,'b','LineWidth',2); % again, to put 'on top'
else
@@ -168,7 +168,7 @@
title(sprintf('%s Attractors for %s', pinfo.model, pinfo.diagn_file), ...
'interpreter','none','fontweight','bold');
- if (exist('legendstr'))
+ if (exist('legendstr','var'))
legend(legendstr,'Ensemble Mean',0);
else
legend( 'Ensemble Mean',0);
@@ -203,7 +203,7 @@
plot(times, ens_mean,'r','LineWidth',2); hold on;
plot(times,ens_members,'g');
- if (exist('legendstr'))
+ if (exist('legendstr','var'))
legend(legendstr, 'Ensemble Mean', sprintf('Ensemble Members (%d)',nmembers), 0);
plot(pinfo.truth_times, truth,'b','LineWidth',2); % again, to put 'on top'
else
@@ -218,7 +218,7 @@
legend boxoff
end
- case {'fms_bgrid','pe2lyr','mitgcm_ocean','wrf'}
+ case {'fms_bgrid','pe2lyr','mitgcm_ocean','wrf','cam'}
clf;
@@ -245,7 +245,7 @@
plot(times, ens_mean,'r','LineWidth',2); hold on;
plot(times,ens_members,'g');
- if (exist('legendstr'))
+ if (exist('legendstr','var'))
legend(legendstr, 'Ensemble Mean', sprintf('Ensemble Members (%d)',nmembers), 0);
plot(pinfo.truth_times, truth,'b','LineWidth',2); % again, to put 'on top'
else
@@ -262,60 +262,6 @@
ylabel(varunits);
legend boxoff
- case 'cam'
-
- clf;
-
- var_names = strread(pinfo.var_names,'%s','delimiter',' ');
- nfigs = length(var_names); % each variable gets its own figure
- iplot = 0;
-
- for ivar = 1:nfigs
-
- iplot = iplot + 1;
- figure(iplot); clf;
-
- pinfo.var = var_names{ivar};
-
- timeunits = nc_attget(pinfo.diagn_file, 'time', 'units');
- varunits = nc_attget(pinfo.diagn_file, pinfo.var, 'units');
-
- subplot(2,1,1)
- PlotLocator(pinfo);
-
- subplot(2,1,2)
-
- if ( have_truth )
- truth = GetCopy(pinfo.truth_file, truth_index, pinfo );
- plot(pinfo.truth_times, truth,'b','LineWidth',2); hold on;
- legendstr = 'True State';
- end
-
- ens_mean = GetCopy(pinfo.diagn_file, ens_mean_index, pinfo );
- ens_members = GetEns( pinfo.diagn_file, pinfo );
- nmembers = size(ens_members,2);
-
- plot(times, ens_mean,'r','LineWidth',2); hold on;
- plot(times,ens_members,'g');
-
- if (exist('legendstr'))
- legend(legendstr, 'Ensemble Mean', sprintf('Ensemble Members (%d)',nmembers), 0);
- plot(pinfo.truth_times, truth,'b','LineWidth',2); % again, to put 'on top'
- else
- legend( 'Ensemble Mean', sprintf('Ensemble Members (%d)',nmembers), 0);
- end
-
- s1 = sprintf('%s model ''%s'' %s Ensemble Members ', ...
- pinfo.model, pinfo.var, pinfo.diagn_file);
- s2 = sprintf('level index %d lat %.2f lon %.2f', ...
- pinfo.levelindex, pinfo.latitude, pinfo.longitude);
- title({s1,s2},'interpreter','none','fontweight','bold');
- xlabel(sprintf('time (%s) %d timesteps',timeunits,num_times));
- ylabel(varunits);
- legend boxoff
- hold off;
- end
-
otherwise
error('model %s unknown.',pinfo.model)
Modified: DART/trunk/matlab/plot_bins.m
===================================================================
--- DART/trunk/matlab/plot_bins.m 2011-07-08 16:28:41 UTC (rev 5064)
+++ DART/trunk/matlab/plot_bins.m 2011-07-08 20:41:18 UTC (rev 5065)
@@ -55,10 +55,10 @@
'lorenz_04', 'forced_lorenz_96','ikeda','simple_advection'}
varid = SetVariableID(vars); % queries for variable IDs
- pinfo = setfield(pinfo, 'truth_file', truth_file);
- pinfo = setfield(pinfo, 'diagn_file', diagn_file);
- pinfo = setfield(pinfo, 'var' , varid.var);
- pinfo = setfield(pinfo, 'var_inds' , varid.var_inds);
+ pinfo.truth_file = truth_file;
+ pinfo.diagn_file = diagn_file;
+ pinfo.var = varid.var;
+ pinfo.var_inds = varid.var_inds;
clear varid
case 'fms_bgrid'
@@ -67,7 +67,8 @@
case 'cam'
- pinfo = GetCamInfo(pinfo, diagn_file, 'PlotBins');
+ pinfo = CombineStructs(pinfo,vars);
+ pinfo = GetCamInfo(pinfo, 'PlotBins');
case 'pe2lyr'
Modified: DART/trunk/matlab/plot_ens_err_spread.m
===================================================================
--- DART/trunk/matlab/plot_ens_err_spread.m 2011-07-08 16:28:41 UTC (rev 5064)
+++ DART/trunk/matlab/plot_ens_err_spread.m 2011-07-08 20:41:18 UTC (rev 5065)
@@ -47,10 +47,10 @@
'lorenz_04','forced_lorenz_96','ikeda','simple_advection'}
varid = SetVariableID(vars);
- pinfo = setfield(pinfo,'truth_file', truth_file);
- pinfo = setfield(pinfo,'diagn_file', diagn_file);
- pinfo = setfield(pinfo,'var' , varid.var);
- pinfo = setfield(pinfo,'var_inds' , varid.var_inds);
+ pinfo.truth_file = truth_file;
+ pinfo.diagn_file = diagn_file;
+ pinfo.var = varid.var;
+ pinfo.var_inds = varid.var_inds;
%pinfo = struct('truth_file', truth_file, ...
% 'diagn_file', diagn_file, ...
% 'var' , varid.var, ...
@@ -68,9 +68,8 @@
case 'cam'
- pinfo = GetCamInfo(pinfo, truth_file, 'PlotEnsErrSpread');
- pinfo.truth_file = truth_file;
- pinfo.diagn_file = diagn_file;
+ pinfo = CombineStructs(pinfo,vars);
+ pinfo = GetCamInfo(pinfo, 'PlotEnsErrSpread');
case 'pe2lyr'
More information about the Dart-dev
mailing list