forked from m053m716/-io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_intan.m
60 lines (55 loc) · 2.06 KB
/
load_intan.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
function data = load_intan(SUBJ, YYYY, MM, DD, BLOCK, type, rootdir, options)
%LOAD_INTAN Reader entry point for INTAN data files.
%
% Syntax:
% data = io.load_intan(SUBJ, YYYY, MM, DD, BLOCK, type, rootdir);
%
% 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)
% BLOCK - Recording block index (numeric scalar)
% type - '.rhd' | '.rhs' (leaving extensible for other future filetypes)
% 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:
% data - Data struct with basically all the fieldnames that would
% normally be returned to the base workspace as variables using
% the default Intan reader functions, except now they're in a
% data struct.
%
% See also: Contents
arguments
SUBJ
YYYY
MM
DD
BLOCK
type
rootdir
options.Verbose (1,1) logical = true;
end
tank = sprintf("%s_%04d_%02d_%02d", SUBJ, YYYY, MM, DD);
root_input = fullfile(rootdir, SUBJ);
root_meta = fullfile(root_input, sprintf('%s.xlsx', tank));
if exist(root_meta,'file')==0
error("No such file: %s\n\t->\tNeed a spreadsheet with 2 columns (Block | File) where first is the block index and second is the file location relative to the data tank folder in the same folder where this spreadsheet exists (e.g. Max_2022_12_15_221215_135949/Max_2022_12_15_221215_144440.rhd", root_meta);
end
T = readtable(root_meta);
iRow = T.Block == BLOCK;
if sum(iRow) ~= 1
error("BLOCK:%d matched %d rows (should only match 1).", BLOCK, sum(iRow));
end
fname = fullfile(root_input, tank, T.File{iRow});
switch type
case {'rhd', '.rhd'}
data = io.read_Intan_RHD2000_file(fname, 'Verbose', options.Verbose);
case {'rhs', '.rhs'}
data = io.read_Intan_RHS2000_file(fname, 'Verbose', options.Verbose);
otherwise
error("Not setup to handle loading .rhs (need to download reader).");
end
end