-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_tmsi_raw.m
121 lines (113 loc) · 3.35 KB
/
load_tmsi_raw.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function [x, info] = load_tmsi_raw(SUBJ, YYYY, MM, DD, ARRAY, BLOCK, rootdir)
%LOAD_TMSI_RAW Loads raw data block
%
% Syntax:
% [x, info] = io.load_tmsi_raw(subj, yyyy, mm, dd, array, block);
%
% Example:
% x = io.load_tmsi_raw('Ollie', 2021, 11, 4, "B", 16);
% % This would return block 97 with array "B" data. Specify "*" to return
% % either block.
%
% Inputs:
% subj - String: should be name of subject (e.g. "Rupert" or "Frank")
% yyyy - year (numeric scalar)
% mm - month (numeric scalar)
% dd - day (numeric scalar)
% array - String: "A" or "B" or "*" for array identifier
% block - Recording block index (numeric scalar)
% rootdir - (Opt) The root folder where all the raw data stuff is kept.
% This should normally stay the same unless we move
% our data share.
%
% Output:
% x - TMSiSAGA.Data object
% info - Information about the file.
%
% See also: Contents, parseXML, TMSiSAGA.Poly5.read,
% parse_polybench_data_manager_notes
if nargin < 7
rootdir = parameters('raw_data_folder');
end
if (numel(BLOCK) > 1) || (numel(ARRAY) > 1)
x = cell(numel(BLOCK), numel(ARRAY));
for iB = 1:numel(BLOCK)
for iA = 1:numel(ARRAY)
x{iB, iA} = io.load_tmsi_raw(SUBJ, YYYY, MM, DD, ARRAY(iA), BLOCK(iB), rootdir);
end
end
x = vertcat(x{:});
x = reshape(x, numel(BLOCK), numel(ARRAY));
return;
end
[YYYY, MM, DD] = utils.parse_date_args(YYYY, MM, DD);
if ~isnumeric(BLOCK)
BLOCK = str2double(BLOCK);
end
f = utils.get_block_name(SUBJ, YYYY, MM, DD, ARRAY, BLOCK, 'rootdir_raw', rootdir);
str = fullfile(f.Raw.Tank, sprintf('%s_%s_%d*', f.Tank, ARRAY, BLOCK));
F = dir(str);
if isempty(F)
x = [];
info = [];
fprintf(1, 'No recording matches expression: <strong>%s</strong>\n', str);
return;
elseif numel(F) > 1
iUse = nan;
for iF = 1:numel(F)
tmp = strsplit(F(iF).name, '-');
recname = strip(tmp{1});
if strcmpi(recname, f.Block)
iUse = iF;
break;
end
end
if isnan(iUse)
x = [];
info = [];
fprintf(1, 'Multiple recordings match expression, but no exact match for: <strong>%s</strong>\n', f.Block);
return;
end
end
tic;
fprintf(1, 'Reading <strong>%s</strong>...', F(1).name);
fname = strrep(F(1).name, ' ', '');
fname = strcat(fname, '.DATA.Poly5');
full_fname = fullfile(F(1).folder, F(1).name, fname);
if exist(full_fname, 'file')==0
p = fullfile(F(1).folder, F(1).name);
F2 = dir(fullfile(p, '*.Poly5'));
if numel(F2) == 0
throw(MException('Poly5:read', sprintf('Could not find file: <strong>%s</strong>', b)));
else
full_fname = fullfile(F2(1).folder, F2(1).name);
end
end
try
x = TMSiSAGA.Poly5.read(full_fname);
catch me
if strcmp(me.identifier, 'Poly5:read')
warning('Could not open file for some reason; check if it is open elsewhere?');
disp(me);
x = [];
info = [];
return;
else
rethrow(me);
end
end
x.name = f.Block;
if nargout > 1
info = dir(full_fname);
try
[info.Annotation, info.Operator, info.Recording] = ...
io.parse_polybench_data_manager_notes(info.folder);
catch me
disp(me);
info.Annotation = "";
info.Operator = "?";
info.Recording = info.name;
end
end
fprintf(1, 'complete.\n');
end