-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate_NRpars.m
95 lines (79 loc) · 3.36 KB
/
update_NRpars.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
89
90
91
92
93
94
95
function update_NRpars(base_dir, feature_function, action)
% This convenience function updates or erases parameter files.
% SYNTAX
% update_NRpars(base_dir, feature_function, action)
% SEMANTICS
% This convenience function helps the user update or erase parameter
% files.
%
% Input Parameters:
% base_dir = Path to directory where NR features and NR parameters are stored.
%
% feature_function = Function call to compute the feature.
% This no-reference feature function (NRFF) must adhere to the
% interface specified in calculate_NRpars.m.
%
% action = string specifying the requested action:
% 'update_pars' = the 'pars' portion of 'feature_function' was
% updated. All NRpars.mat files will be removed and
% recalculated. Feature files will not be touched, so
% recalculating should be relatively fast.
% Note: the NRpars.mat files will be moved
% in sub-folder, 'previous_NRpars'.
% 'version' = the version of the NRMetricFramework library was
% updated. All NRpars.mat files must be updated.
% Create a variable that has a path to this NRFF's directory
if base_dir(length(base_dir)) ~= '\'
base_dir = [base_dir '\'];
end
nrff_dir = [base_dir 'group_' feature_function('group') '\'];
if ~exist(nrff_dir)
error('NR parameter has not yet been calculated. Directory does not exist: %s', nrff_dir);
end
% update all NRpars.mat files that contain the old fields
if strcmp(action,'version')
list = ls([nrff_dir '*NRpars_*']);
for cnt=1:size(list,1)
parfile = [nrff_dir list(cnt,:)];
try
% Load previously calculated NR parameters
load(parfile, 'NRpars');
% if the NRpars variable has the version 1 field name
% 'test", replace this with the version 2 field name
% 'dataset_name' and overwrite.
fields = fieldnames(NRpars);
if strcmp(fields(5),'test') == 1
NRpars.dataset_name = NRpars.test;
NRpars = rmfield(NRpars,'test');
save (parfile, 'NRpars');
end
if isfield(NRpars, 'version') == 0
NRpars.version = 2;
save (parfile, 'NRpars');
else
if NRpars.version <= 2;
NRpars.version = 2;
save (parfile, 'NRpars');
else
error('NR parameter version is greater than 2');
end
end
catch
warning('Version update of NRpars file failed: %s', parfile);
end
end
return;
end
% erase all NRpars.mat files
if strcmp(action,'update_pars')
mkdir([nrff_dir 'previous_NRpars'])
list = ls([nrff_dir '*NRpars_*']);
for cnt=1:size(list,1)
parfile = [nrff_dir list(cnt,:)];
move_parfile = [nrff_dir 'previous_NRpars\' list(cnt,:)];
movefile(parfile, move_parfile);
end
return;
end
error('Action option not recognized');
end