forked from PeterRochford/SkillMetricsToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_check_stats.m
89 lines (80 loc) · 2.5 KB
/
error_check_stats.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function [p,r] = error_check_stats(predicted,reference,field)
%ERROR_CHECK_STATS Checks the arguments provided to the statistics functions for the target and Taylor diagrams.
%
% [P,R] = ERROR_CHECK_STATS(PREDICTED,REFERENCE,FIELD)
% Checks the arguments provided to the statistics functions for the
% target and Taylor diagrams. The data is provided in the predicted
% field (PREDICTED) and the reference field (REFERENCE).
%
% If a dictionary is provided for PREDICTED or REFERENCE, then
% the name of the field must be supplied in FIELD.
%
% The function currently supports only data structures for the PREDICTED
% and REFERENCE variables.
%
% Output:
% P : predicted field values
% R : reference field values
% Author: Peter A. Rochford
% Symplectic, LLC
% www.thesymplectic.com
% Check for valid arguments
if isstruct(predicted)
if ~exist('field')
error('FIELD argument not supplied.');
end
if ~isfield(predicted, field)
error(['Field is not in predicted data structure: ' field]);
else
p = getfield(predicted,field);
end
elseif isnumeric(predicted)
p = predicted;
else
error('PREDICTED argument must be a data structure.');
end
if isstruct(reference)
if ~exist('field')
error('FIELD argument not supplied.');
end
if ~isfield(reference, field)
error(['Field is not in reference data structure: ' field]);
else
r = getfield(reference,field);
end
elseif isnumeric(reference)
r = reference;
else
error('REFERENCE argument must be a data structure.');
end
% Check that dimensions of predicted and reference fields match
pdims= size(p);
rdims= size(r);
if length(pdims) ~= length(rdims)
error(['Number of predicted and reference field dimensions do not' ...
' match.\n' ...
'length(predicted)= ' num2str(length(size(p))) ...
', length(reference)= ' num2str(length(size(r))) ...
],class(pdims));
end
for i=1:length(pdims)
if pdims(i) ~= rdims(i)
error(['Predicted and reference field dimensions do not' ...
' match.\n' ...
'size(predicted)= ' num2str(size(p)) ...
', size(reference)= ' num2str(size(r)) ...
],class(pdims));
end
end
% Check that all values are finite
test = isfinite(p);
if ~all(test)
error('PREDICTED field has non-finite values');
end
test = isfinite(r);
if ~all(test)
error('REFERENCE field has non-finite values');
end
return;
end