-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_tmsi_mat.m
68 lines (61 loc) · 1.99 KB
/
load_tmsi_mat.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
function x = load_tmsi_mat(SUBJ, YYYY, MM, DD, ARRAY, BLOCK, rootdir)
%LOAD_TMSI_MAT Loads "raw" data block that was saved via TMSiServer MATLAB API
%
% Syntax:
% x = io.load_tmsi_mat(subj, yyyy, mm, dd, array, block);
%
% Example:
% x = io.load_tmsi_mat('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 - struct with fields similar to TMSiSAGA.Data object
%
% See also: Contents, parseXML, TMSiSAGA.Poly5.read, io.load_tmsi_raw
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_mat(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);
if exist(strcat(f.Raw.Block, '.mat'),'file')==0
me = MException('io:missing_file:raw', ...
'No file named "%s" exists.', ...
f.Raw.Block);
throw(me);
end
tic;
fprintf(1, 'Reading <strong>%s</strong>...', f.Block);
x = load(f.Raw.Block);
x.name = f.Block;
x.num_samples = size(x.samples, 2);
if ~isfield(x, 'sample_rate')
x.sample_rate = 4000; % Default sample rate.
end
fprintf(1, 'complete.\n');
end