[Dart-dev] [8015] DART/trunk/models/forced_lorenz_96/matlab: Post-STATMOS cleanup.
nancy at ucar.edu
nancy at ucar.edu
Thu May 28 10:24:45 MDT 2015
Revision: 8015
Author: thoar
Date: 2015-05-28 10:24:45 -0600 (Thu, 28 May 2015)
Log Message:
-----------
Post-STATMOS cleanup. These have more accurate help sections,
removed repeated code, and the 'set_extended_state' example
matches the example Doug used for parameter estimation.
Modified Paths:
--------------
DART/trunk/models/forced_lorenz_96/matlab/make_sequence_input.m
DART/trunk/models/forced_lorenz_96/matlab/set_extended_state.m
-------------- next part --------------
Modified: DART/trunk/models/forced_lorenz_96/matlab/make_sequence_input.m
===================================================================
--- DART/trunk/models/forced_lorenz_96/matlab/make_sequence_input.m 2015-05-28 16:12:16 UTC (rev 8014)
+++ DART/trunk/models/forced_lorenz_96/matlab/make_sequence_input.m 2015-05-28 16:24:45 UTC (rev 8015)
@@ -4,6 +4,9 @@
% Just as an example, this will create the text input required
% to create N evenly-spaced observation prototypes. There are no
% observation values in these. The output file name is 'input_to_create_obs_sequence.txt'
+% create_obs_sequence can easily be run by hand for a small number
+% of observations, but it gets tedious for large numbers. This
+% script just saves on some typing - nothing more.
%
% num_obs is the number of observations on the unit circle
% obs_err_var is the observation error variance
@@ -155,320 +158,3 @@
% $URL$
% $Revision$
% $Date$
-
-function make_sequence_input(varargin)
-%% make_sequence_input creates input for create_obs_sequence
-%
-% Just as an example, this will create the text input required
-% to create N evenly-spaced observation prototypes. There are no
-% observation values in these. The output file name is 'input_to_create_obs_sequence.txt'
-%
-% num_obs is the number of observations on the unit circle
-% obs_err_var is the observation error variance
-% loc_offset is a static offset for each observation location.
-% loc_offset = 0.0 will make the initial observation
-% coincident with the model grid.
-%
-% Three Examples:
-% make_sequence_input('num_obs',40)
-% make_sequence_input('num_obs',40,'obs_err_var',1.0)
-% make_sequence_input('num_obs',40,'obs_err_var',1.0,'loc_offset',0.02)
-%
-% Example on how to use the output file ...
-%
-% [unixprompt] ./create_obs_sequence < input_to_create_obs_sequence.txt
-%
-% The output file from create_obs_sequence will be called 'set_def.out'
-% and can be used as input to create_fixed_network_sequence.
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-%%------------------------------------------------------------------------------
-% This bit just parses the input and uses default values if need be.
-
-default_num_obs = 40;
-default_obs_err_var = 1.0;
-default_loc_offset = 0.0;
-default_graphic = 0;
-p = inputParser;
-
-addParamValue(p,'num_obs', default_num_obs, @isnumeric);
-addParamValue(p,'obs_err_var',default_obs_err_var, at isnumeric);
-addParamValue(p,'loc_offset', default_loc_offset, @isnumeric);
-addParamValue(p,'graphic', default_graphic, @isnumeric);
-parse(p,varargin{:});
-
-if ~isempty(fieldnames(p.Unmatched))
- disp('Extra inputs:')
- disp(p.Unmatched)
-end
-
-Nobs = p.Results.num_obs;
-observation_error_variance = p.Results.obs_err_var;
-loc_offset = p.Results.loc_offset;
-graphic = p.Results.graphic;
-
-locations = (0:Nobs-1)/Nobs + loc_offset; % set the location to be uniform.
-newlocs = mod(locations,1.0);
-filename = 'input_to_create_obs_sequence.txt';
-
-%%------------------------------------------------------------------------------
-% Some stuff gets written to the file once at the beginning.
-
-fid = fopen(filename,'w');
-
-fprintf(fid,'%d \n',Nobs); % upper bound on number of obs in sequence
-fprintf(fid,'0 \n'); % number of copies of data
-fprintf(fid,'0 \n'); % number of quality control values per field
-fprintf(fid,'0 \n'); % 0 is a flag to continue
-
-%%------------------------------------------------------------------------------
-% Some stuff gets written for every observation
-
-for i = 1:Nobs
-
- fprintf(fid,'%d \n',1); % observing RAW_STATE_VARIABLE
- fprintf(fid,'%f \n',newlocs(i)); % the unit sphere location
- fprintf(fid,'0 0 \n'); % days and seconds of observation time
- fprintf(fid,'%f \n',observation_error_variance);
-
- if i < Nobs
- fprintf(fid,'0 \n'); % 0 is a flag to continue
- end
-
-end
-
-%%------------------------------------------------------------------------------
-% Some stuff gets written to the file at the end.
-
-fprintf(fid,'set_def.out\n'); % name of observation sequence file prototype
-fclose(fid);
-fprintf('Created %s\n',filename)
-
-%%------------------------------------------------------------------------------
-% Optional visualizer of the observation locations.
-
-if graphic ~= 0
-
- model_size = 40;
- gridlocs = 2*pi*(0:model_size)/model_size;
- x = ones(size(gridlocs));
- h1 = polar(gridlocs,x,'o');
- set(h1,'MarkerSize',10,'LineWidth',2)
- relabel(gca)
-
- hold on;
- y = ones(size(newlocs));
- h2 = polar(2*pi*newlocs,y,'r*');
- set(h2,'MarkerSize',20,'LineWidth',2)
-
- h = title('forced_lorenz_96');
- set(h,'Interpreter','none','FontSize',20,'FontWeight','bold');
- h = xlabel({'unit circle',filename});
- set(h,'Interpreter','none');
-
- h = legend('grid locations','observation locations');
- set(h,'Location','Best','FontSize',14);
- hold off;
-
-end
-
-end % main function
-
-
-%% Helper function below ...
-
-function relabel(handle)
-
-% remove dotted radii and tickmarks and lables (actuall, all text)
-
-t = findall(handle,'type','text'); %get handles for all text in polar plot
-% set(t,'FontSize',20,'FontWeight','bold')
-set(t,'FontSize',20)
-
-for i = 1:numel(t)
- switch get(t(i),'String')
- case {'0'}
- set(t(i),'String',' 0.0', ...
- 'HorizontalAlignment','left')
- case {'90'}
- set(t(i),'String','0.25')
- case {'180'}
- set(t(i),'String','0.50', ...
- 'HorizontalAlignment','right')
- case {'270'}
- set(t(i),'String','0.75')
- otherwise
- set(t(i),'String',' ')
- end
-end
-
-end % function relabel
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
-function make_sequence_input(varargin)
-%% make_sequence_input creates input for create_obs_sequence
-%
-% Just as an example, this will create the text input required
-% to create N evenly-spaced observation prototypes. There are no
-% observation values in these. The output file name is 'input_to_create_obs_sequence.txt'
-%
-% num_obs is the number of observations on the unit circle
-% obs_err_var is the observation error variance
-% loc_offset is a static offset for each observation location.
-% loc_offset = 0.0 will make the initial observation
-% coincident with the model grid.
-%
-% Three Examples:
-% make_sequence_input('num_obs',40)
-% make_sequence_input('num_obs',40,'obs_err_var',1.0)
-% make_sequence_input('num_obs',40,'obs_err_var',1.0,'loc_offset',0.02)
-%
-% Example on how to use the output file ...
-%
-% [unixprompt] ./create_obs_sequence < input_to_create_obs_sequence.txt
-%
-% The output file from create_obs_sequence will be called 'set_def.out'
-% and can be used as input to create_fixed_network_sequence.
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-%%------------------------------------------------------------------------------
-% This bit just parses the input and uses default values if need be.
-
-default_num_obs = 40;
-default_obs_err_var = 1.0;
-default_loc_offset = 0.0;
-default_graphic = 0;
-p = inputParser;
-
-addParamValue(p,'num_obs', default_num_obs, @isnumeric);
-addParamValue(p,'obs_err_var',default_obs_err_var, at isnumeric);
-addParamValue(p,'loc_offset', default_loc_offset, @isnumeric);
-addParamValue(p,'graphic', default_graphic, @isnumeric);
-parse(p,varargin{:});
-
-if ~isempty(fieldnames(p.Unmatched))
- disp('Extra inputs:')
- disp(p.Unmatched)
-end
-
-Nobs = p.Results.num_obs;
-observation_error_variance = p.Results.obs_err_var;
-loc_offset = p.Results.loc_offset;
-graphic = p.Results.graphic;
-
-locations = (0:Nobs-1)/Nobs + loc_offset; % set the location to be uniform.
-newlocs = mod(locations,1.0);
-filename = 'input_to_create_obs_sequence.txt';
-
-%%------------------------------------------------------------------------------
-% Some stuff gets written to the file once at the beginning.
-
-fid = fopen(filename,'w');
-
-fprintf(fid,'%d \n',Nobs); % upper bound on number of obs in sequence
-fprintf(fid,'0 \n'); % number of copies of data
-fprintf(fid,'0 \n'); % number of quality control values per field
-fprintf(fid,'0 \n'); % 0 is a flag to continue
-
-%%------------------------------------------------------------------------------
-% Some stuff gets written for every observation
-
-for i = 1:Nobs
-
- fprintf(fid,'%d \n',1); % observing RAW_STATE_VARIABLE
- fprintf(fid,'%f \n',newlocs(i)); % the unit sphere location
- fprintf(fid,'0 0 \n'); % days and seconds of observation time
- fprintf(fid,'%f \n',observation_error_variance);
-
- if i < Nobs
- fprintf(fid,'0 \n'); % 0 is a flag to continue
- end
-
-end
-
-%%------------------------------------------------------------------------------
-% Some stuff gets written to the file at the end.
-
-fprintf(fid,'set_def.out\n'); % name of observation sequence file prototype
-fclose(fid);
-fprintf('Created %s\n',filename)
-
-%%------------------------------------------------------------------------------
-% Optional visualizer of the observation locations.
-
-if graphic ~= 0
-
- model_size = 40;
- gridlocs = 2*pi*(0:model_size)/model_size;
- x = ones(size(gridlocs));
- h1 = polar(gridlocs,x,'o');
- set(h1,'MarkerSize',10,'LineWidth',2)
- relabel(gca)
-
- hold on;
- y = ones(size(newlocs));
- h2 = polar(2*pi*newlocs,y,'r*');
- set(h2,'MarkerSize',20,'LineWidth',2)
-
- h = title('forced_lorenz_96');
- set(h,'Interpreter','none','FontSize',20,'FontWeight','bold');
- h = xlabel({'unit circle',filename});
- set(h,'Interpreter','none');
-
- h = legend('grid locations','observation locations');
- set(h,'Location','Best','FontSize',14);
- hold off;
-
-end
-
-end % main function
-
-
-%% Helper function below ...
-
-function relabel(handle)
-
-% remove dotted radii and tickmarks and lables (actuall, all text)
-
-t = findall(handle,'type','text'); %get handles for all text in polar plot
-% set(t,'FontSize',20,'FontWeight','bold')
-set(t,'FontSize',20)
-
-for i = 1:numel(t)
- switch get(t(i),'String')
- case {'0'}
- set(t(i),'String',' 0.0', ...
- 'HorizontalAlignment','left')
- case {'90'}
- set(t(i),'String','0.25')
- case {'180'}
- set(t(i),'String','0.50', ...
- 'HorizontalAlignment','right')
- case {'270'}
- set(t(i),'String','0.75')
- otherwise
- set(t(i),'String',' ')
- end
-end
-
-end % function relabel
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
Modified: DART/trunk/models/forced_lorenz_96/matlab/set_extended_state.m
===================================================================
--- DART/trunk/models/forced_lorenz_96/matlab/set_extended_state.m 2015-05-28 16:12:16 UTC (rev 8014)
+++ DART/trunk/models/forced_lorenz_96/matlab/set_extended_state.m 2015-05-28 16:24:45 UTC (rev 8015)
@@ -1,9 +1,9 @@
function set_extended_state(fname, varargin)
%% set_extended_state modifies the extended state portion of the perfect_ics file.
%
-% Just as an example, this will create the text input required
-% to create N evenly-spaced observation prototypes. There are no
-% observation values in these. The output file name is 'input_to_create_obs_sequence.txt'
+% The forced_lorenz_96 model has 40 state variables and 40 forcing variables.
+% This function simply makes it easy to set the 40 forcing variables rather
+% than edit the filter_ics file(s) by hand.
%
% fname is the name of the file to read AND WRITE.
% forcing is the forcing for the extended state - may either be a scalar
@@ -11,14 +11,14 @@
%
% (bad) Example (produces a plot):
% fname = 'perfect_ics';
-% forcing = randn(1,40) * 8.0;
+% forcing = randn(1,40) + 8.0;
% set_extended_state(fname,'forcing',forcing)
%
% Example - no graphic output:
% set_extended_state(fname,'forcing',forcing,'graphic',0)
%
% Example - unusual forcing:
-% forcing = [ones(1,10)*8 ones(1,30)*7] + randn(1,40);
+% forcing = [ones(1,30)*6 ones(1,10)*12] + randn(1,40);
% set_extended_state(fname,'forcing',forcing)
%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
@@ -121,252 +121,3 @@
% $URL$
% $Revision$
% $Date$
-
-function set_extended_state(fname, varargin)
-%% set_extended_state modifies the extended state portion of the perfect_ics file.
-%
-% Just as an example, this will create the text input required
-% to create N evenly-spaced observation prototypes. There are no
-% observation values in these. The output file name is 'input_to_create_obs_sequence.txt'
-%
-% fname is the name of the file to read AND WRITE.
-% forcing is the forcing for the extended state - may either be a scalar
-% or an array with exactly 40 elements.
-%
-% (bad) Example (produces a plot):
-% fname = 'perfect_ics';
-% forcing = randn(1,40) * 8.0;
-% set_extended_state(fname,'forcing',forcing)
-%
-% Example - no graphic output:
-% set_extended_state(fname,'forcing',forcing,'graphic',0)
-%
-% Example - unusual forcing:
-% forcing = [ones(1,10)*8 ones(1,30)*7] + randn(1,40);
-% set_extended_state(fname,'forcing',forcing)
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-%%------------------------------------------------------------------------------
-% This bit just parses the input and uses default values if need be.
-
-default_forcing = 40;
-default_graphic = 1;
-p = inputParser;
-
-addRequired(p,'fname', at ischar);
-addParamValue(p,'forcing',default_forcing, at isnumeric);
-addParamValue(p,'graphic',default_graphic, at isnumeric);
-parse(p, fname, varargin{:});
-
-if ~isempty(fieldnames(p.Unmatched))
- disp('Extra inputs:')
- disp(p.Unmatched)
-end
-
-forcing = p.Results.forcing;
-graphic = p.Results.graphic;
-
-if (exist(fname,'file') ~= 2), error('file <%s> does not exist',fname), end
-
-%%------------------------------------------------------------------------------
-% Read the existing data
-% Check to make sure the read was successful.
-
-fid = fopen(fname,'r');
-timeline = fgetl(fid); % first record is the valid time of the model state
-[modelstate, nlines] = fscanf(fid,'%f'); % vectorized read of the rest of the file.
-fclose(fid);
-
-if (nlines ~= 80)
- fprintf('Read %d elements for the model state.\n',nlines)
- fprintf('Expected to read 80 elements.\n')
- error('%s not the correct size for forced_lorenz_96.',fname)
-end
-
-%%------------------------------------------------------------------------------
-% Check user input for sanity
-
-if numel(forcing) == 1
- modelstate(41:80) = forcing;
-elseif numel(forcing) == 40
- modelstate(41:80) = forcing;
-else
- fprintf('forcing array can have exactly 1 or exactly 40 values.\n')
- error('forcing array had %d values.',numel(forcing))
-end
-
-%%------------------------------------------------------------------------------
-% open the file
-% write the timestamp
-% write the model state.
-
-fid = fopen(fname,'w');
-fprintf(fid,'%s\n',timeline);
-fprintf(fid,' %.14g\n',modelstate);
-fclose(fid);
-
-%%------------------------------------------------------------------------------
-% Optional visualizer of the observation locations.
-
-if graphic ~= 0
-
- xax = 1:40;
-
- figure; clf
-
- subplot(3,1,1)
- h1 = plot(xax,modelstate(1:40),'k*-');
- set(h1,'MarkerSize',10,'LineWidth',2)
- title('Original model state','FontSize',14)
- xlabel('state index')
-
- subplot(3,1,2)
- h2 = plot(xax+40,modelstate(41:80),'b*-');
- set(h2,'MarkerSize',20,'LineWidth',2)
- title('Forcing','FontSize',14);
- xlabel('"extended" state index')
-
- subplot(3,1,3)
- h3 = plot(modelstate,'b*-');
- set(h3,'MarkerSize',10,'LineWidth',1.5)
- title('Entire model state','FontSize',14);
- xlabel('state index')
-
-end
-
-end % main function
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
-function set_extended_state(fname, varargin)
-%% set_extended_state modifies the extended state portion of the perfect_ics file.
-%
-% Just as an example, this will create the text input required
-% to create N evenly-spaced observation prototypes. There are no
-% observation values in these. The output file name is 'input_to_create_obs_sequence.txt'
-%
-% fname is the name of the file to read AND WRITE.
-% forcing is the forcing for the extended state - may either be a scalar
-% or an array with exactly 40 elements.
-%
-% (bad) Example (produces a plot):
-% fname = 'perfect_ics';
-% forcing = randn(1,40) * 8.0;
-% set_extended_state(fname,'forcing',forcing)
-%
-% Example - no graphic output:
-% set_extended_state(fname,'forcing',forcing,'graphic',0)
-%
-% Example - unusual forcing:
-% forcing = [ones(1,10)*8 ones(1,30)*7] + randn(1,40);
-% set_extended_state(fname,'forcing',forcing)
-
-%% DART software - Copyright 2004 - 2013 UCAR. This open source software is
-% provided by UCAR, "as is", without charge, subject to all terms of use at
-% http://www.image.ucar.edu/DAReS/DART/DART_download
-%
-% DART $Id$
-
-%%------------------------------------------------------------------------------
-% This bit just parses the input and uses default values if need be.
-
-default_forcing = 40;
-default_graphic = 1;
-p = inputParser;
-
-addRequired(p,'fname', at ischar);
-addParamValue(p,'forcing',default_forcing, at isnumeric);
-addParamValue(p,'graphic',default_graphic, at isnumeric);
-parse(p, fname, varargin{:});
-
-if ~isempty(fieldnames(p.Unmatched))
- disp('Extra inputs:')
- disp(p.Unmatched)
-end
-
-forcing = p.Results.forcing;
-graphic = p.Results.graphic;
-
-if (exist(fname,'file') ~= 2), error('file <%s> does not exist',fname), end
-
-%%------------------------------------------------------------------------------
-% Read the existing data
-% Check to make sure the read was successful.
-
-fid = fopen(fname,'r');
-timeline = fgetl(fid); % first record is the valid time of the model state
-[modelstate, nlines] = fscanf(fid,'%f'); % vectorized read of the rest of the file.
-fclose(fid);
-
-if (nlines ~= 80)
- fprintf('Read %d elements for the model state.\n',nlines)
- fprintf('Expected to read 80 elements.\n')
- error('%s not the correct size for forced_lorenz_96.',fname)
-end
-
-%%------------------------------------------------------------------------------
-% Check user input for sanity
-
-if numel(forcing) == 1
- modelstate(41:80) = forcing;
-elseif numel(forcing) == 40
- modelstate(41:80) = forcing;
-else
- fprintf('forcing array can have exactly 1 or exactly 40 values.\n')
- error('forcing array had %d values.',numel(forcing))
-end
-
-%%------------------------------------------------------------------------------
-% open the file
-% write the timestamp
-% write the model state.
-
-fid = fopen(fname,'w');
-fprintf(fid,'%s\n',timeline);
-fprintf(fid,' %.14g\n',modelstate);
-fclose(fid);
-
-%%------------------------------------------------------------------------------
-% Optional visualizer of the observation locations.
-
-if graphic ~= 0
-
- xax = 1:40;
-
- figure; clf
-
- subplot(3,1,1)
- h1 = plot(xax,modelstate(1:40),'k*-');
- set(h1,'MarkerSize',10,'LineWidth',2)
- title('Original model state','FontSize',14)
- xlabel('state index')
-
- subplot(3,1,2)
- h2 = plot(xax+40,modelstate(41:80),'b*-');
- set(h2,'MarkerSize',20,'LineWidth',2)
- title('Forcing','FontSize',14);
- xlabel('"extended" state index')
-
- subplot(3,1,3)
- h3 = plot(modelstate,'b*-');
- set(h3,'MarkerSize',10,'LineWidth',1.5)
- title('Entire model state','FontSize',14);
- xlabel('state index')
-
-end
-
-end % main function
-
-% <next few lines under version control, do not edit>
-% $URL$
-% $Revision$
-% $Date$
-
More information about the Dart-dev
mailing list