From b3a0dfe2eb6e80b1656dac503471f7f0cc07fd62 Mon Sep 17 00:00:00 2001 From: JonKing93 Date: Mon, 11 Nov 2019 12:37:48 -0700 Subject: [PATCH] Updated tutorials and debugged for run --- 1. Grid files/@gridFile/gridFile.m | 8 ++++---- 1. Grid files/@gridFile/meta.m | 12 ++++++------ 1. Grid files/@gridFile/new.m | 5 ++++- 1. Grid files/@gridFile/rewriteMetadata.m | 2 +- .../@varDesign/varDesign.m | 2 +- 4. DA Analyses/@kalmanFilter/settings.m | 14 ++++++++------ 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/1. Grid files/@gridFile/gridFile.m b/1. Grid files/@gridFile/gridFile.m index 0e3edbf7..a61e88d2 100644 --- a/1. Grid files/@gridFile/gridFile.m +++ b/1. Grid files/@gridFile/gridFile.m @@ -36,9 +36,12 @@ % Create a metadata structure for a grid or gridded data [meta] = defineMetadata( varargin ) + + % Exract metadata from existing .grid file + [meta, dimID, gridSize] = meta( file ); % Create new grid file - new( filename, type, source, varName, dimOrder, atts, varargin ); + grid = new( filename, type, source, varName, dimOrder, atts, varargin ); end @@ -48,9 +51,6 @@ % Adds data to a .grid file addData( obj, type, source, varName, dimOrder, meta ); - % Exract metadata from existing .grid file - [meta, dimID, gridSize] = meta( obj ); - % Increase the size of a dimension in a .grid file. expand( obj, dim, newMeta ); diff --git a/1. Grid files/@gridFile/meta.m b/1. Grid files/@gridFile/meta.m index 79fd64b7..fc512280 100644 --- a/1. Grid files/@gridFile/meta.m +++ b/1. Grid files/@gridFile/meta.m @@ -1,4 +1,4 @@ -function[meta, dimID, gridSize] = meta( obj ) +function[meta, dimID, gridSize] = meta( file ) %% Returns a structure with metadata for a gridded .mat file. % % [meta, dimID, gridSize] = gridFile.meta( file ) @@ -19,12 +19,12 @@ % ----- Written By ----- % Jonathan King, University of Arizona, 2019 -% Update in case changes occured -obj.update; +% Check the file is real +grid = gridFile(file); % Extract the output fields -meta = obj.metadata; -dimID = obj.dimOrder; -gridSize = obj.gridSize; +meta = grid.metadata; +dimID = grid.dimOrder; +gridSize = grid.gridSize; end \ No newline at end of file diff --git a/1. Grid files/@gridFile/new.m b/1. Grid files/@gridFile/new.m index aa14ebd9..75a02edb 100644 --- a/1. Grid files/@gridFile/new.m +++ b/1. Grid files/@gridFile/new.m @@ -1,4 +1,4 @@ -function[] = new( filename, meta, attributes ) +function[grid] = new( filename, meta, attributes ) %% Initializes a new gridded data (.grid) file. This is a container object that % contains instructions on reading data from different sources, including: % NetCDF files, .mat Files, and Matlab numeric arrays. @@ -67,4 +67,7 @@ m.dimLimit = []; m.valid = true; +% Return the object as output +grid = gridFile( filename ); + end \ No newline at end of file diff --git a/1. Grid files/@gridFile/rewriteMetadata.m b/1. Grid files/@gridFile/rewriteMetadata.m index 57fc69d2..cefefe59 100644 --- a/1. Grid files/@gridFile/rewriteMetadata.m +++ b/1. Grid files/@gridFile/rewriteMetadata.m @@ -13,7 +13,7 @@ % dimension. % Update in case the matfile changed -obj.udpate; +obj.update; % Check the dim is an ID if ~isstrflag( dim ) diff --git a/2. State Vectors and Ensembles/@varDesign/varDesign.m b/2. State Vectors and Ensembles/@varDesign/varDesign.m index 501fd166..51fd9d04 100644 --- a/2. State Vectors and Ensembles/@varDesign/varDesign.m +++ b/2. State Vectors and Ensembles/@varDesign/varDesign.m @@ -55,7 +55,7 @@ obj.file = string(file); % Get the grid file metadata - [meta, dimID, dimSize] = gridFile.meta( file ); + [meta, dimID, dimSize] = gridFile.meta( obj.file ); % Ensure that the gridfile contains all known IDs allID = getDimIDs; diff --git a/4. DA Analyses/@kalmanFilter/settings.m b/4. DA Analyses/@kalmanFilter/settings.m index a23caa3c..68ca3fea 100644 --- a/4. DA Analyses/@kalmanFilter/settings.m +++ b/4. DA Analyses/@kalmanFilter/settings.m @@ -81,18 +81,20 @@ error('Cannot compute only the ensemble mean when returning full ensemble deviations.'); end +nState = size(obj.M,1); +nObs = size(obj.D,1); if ~isempty(weights) if strcmpi(type,'joint') if ( ~iscell(weights) || numel(weights)~=2 ) error(['Localization weights for joint updates must be provided as the 2-element cell: {w, yloc}\n',... 'Please see dash.localizationWeights for details.'] ); - elseif ~isnumeric(weights{2}) || ~isreal(weights{2}) || ~ismatrix(weights{2}) || ~isequal(size(weights{2}), [obj.nObs, obj.nObs]) - error('The second element of joint localization weights must be a %.f x %.f numeric matrix', obj.nObs, obj.nObs ); - elseif ~isnumeric(weights{1}) || ~isreal(weights{1}) || ~ismatrix(weights{1}) || ~isequal(size(weights{1}), [obj.nState, obj.nObs]) - error('The first element of joint localization weights must be a %.f x %.f numeric matrix.', obj.nState, obj.nObs ); + elseif ~isnumeric(weights{2}) || ~isreal(weights{2}) || ~ismatrix(weights{2}) || ~isequal(size(weights{2}), [nObs, nObs]) + error('The second element of joint localization weights must be a %.f x %.f numeric matrix', nObs, nObs ); + elseif ~isnumeric(weights{1}) || ~isreal(weights{1}) || ~ismatrix(weights{1}) || ~isequal(size(weights{1}), [nState, nObs]) + error('The first element of joint localization weights must be a %.f x %.f numeric matrix.', nState, nObs ); end - elseif strcmpi(type, 'serial') && ( ~isnumeric(weights) || ~isreal(weights) || ~ismatrix(weights) || ~isequal(size(weights), [obj.nState, obj.nObs]) ) - error('serial localization weights must be a %.f x %.f numeric matrix.', obj.nState, obj.nObs ); + elseif strcmpi(type, 'serial') && ( ~isnumeric(weights) || ~isreal(weights) || ~ismatrix(weights) || ~isequal(size(weights), [nState, nObs]) ) + error('serial localization weights must be a %.f x %.f numeric matrix.', nState, nObs ); end end