Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolbox check #214

Merged
merged 10 commits into from
Jan 5, 2022
10 changes: 9 additions & 1 deletion +ndi/+docs/build.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ function build()

ndi.docs.all_documents2markdown();

% make sure we don't traverse the the 'site' directory
ndi_path = ndi_globals.path.path;

if ~isfolder([ndi_path filesep 'site']),
mkdir([ndi_path filesep 'site']);
end;

vlt.file.touch([ndi_path filesep 'site' filesep '.matlab2markdown-ignore']);

disp(['Now writing function reference...']);

ndi_path = ndi_globals.path.path;
ndi_docs = [ndi_path filesep 'docs' filesep 'reference']; % code reference path
ymlpath = 'reference';

Expand Down
56 changes: 54 additions & 2 deletions +ndi/+example/+tutorial/tutorial_02_01.m
Original file line number Diff line number Diff line change
@@ -1,43 +1,86 @@
% This script contains all of the code for
function tutorial_02_01(prefix, testing)
% ndi.example.tutorials.tutorial_02_01 - runs the code in Tutorial 2.1
%
% out = ndi.example.tutorials.tutorial_02_01(PREFIX, [TESTING])
%
% Runs (and tests) the code for
%
% NDI Tutorial 2: Analzying your first electrophysiology experiment with NDI
% Tutorial 2.1: Reading an example dataset
% The tutorial is available at
% https://vh-lab.github.io/NDI-matlab/tutorials/analyzing_first_physiology_experiment/1_example_dataset.md
%
% PREFIX should be the directory that contains the directory 'ts_exper1'. If it is not
% provided or is empty, the default is [userpath filesep 'Documents' filesep 'NDI'].
%
% If TESTING is 1, then PREFIX is taken to be [userpath filesep 'Documents' filesep' NDI filesep 'Test'],
% and the files are copied to the temporary directory before proceeding so that the files
% in the directory called PREFIX are not touched.
%

if nargin<1 | isempty(prefix),
prefix = [userpath filesep 'Documents' filesep 'NDI']; % or '/Users/yourusername/Desktop/' if you put it on the desktop perhaps
end;

if nargin<2,
testing = 0;
end;

tutorial_dir = 'ts_exper1';

if testing, % copy the files to the temp directory
prefix = [userpath filesep 'Documents' filesep 'NDI' filesep 'Test'];
disp(['Assuming clean data files ts_exper1 are in ' prefix '.']);
ndi.globals()
disp(['Clearing any ''' tutorial_dir ''' in the temporary directory']);
try,
rmdir([ndi_globals.path.temppath filesep tutorial_dir],'s');
end;
disp(['Copying ''' tutorial_dir ''' to the temporary directory']);
copyfile([prefix filesep tutorial_dir], [ndi_globals.path.temppath filesep tutorial_dir]);

prefix = ndi_globals.path.temppath;
end

% Code block 2.1.2.1

prefix = [userpath filesep 'Documents' filesep 'NDI']; % or '/Users/yourusername/Desktop/' if you put it on the desktop perhaps
disp(['Code block 2.1.2.1:']);
% prefix line is set above
ls([prefix filesep 'ts_exper1' filesep 't*']); % list all the files in the t0000N folders

% Code block 2.1.2.2

disp(['Code block 2.1.2.2:']);
my_smr_file = fullfile(prefix,'ts_exper1','t00001','spike2data.smr')
ndi.example.tutorial.plottreeshrewdata(my_smr_file);

% Code block 2.1.3.1

disp(['Code block 2.1.3.1:']);
type (fullfile(prefix,'ts_exper1','t00001','probemap.txt'))

% Code block 2.1.3.2

disp(['Code block 2.1.3.2:']);
type (fullfile(prefix,'ts_exper1','t00001','stims.tsv'))

% Code block 2.1.4.1

disp(['Code block 2.1.4.1:']);
S = ndi.session.dir('ts_exper1',[prefix filesep 'ts_exper1'])

% inserted code for the full script:

S.daqsystem_clear() % make sure we don't have old daq systems from the demo

% Code block 2.1.4.2
disp(['Code block 2.1.4.2:']);
disp(['(should return empty)']);
S.getprobes()

% Code block 2.1.4.3

disp(['Code block 2.1.4.3:']);
ced_filenav = ndi.file.navigator(S, {'.*\.smr\>', 'probemap.txt'}, ...
'ndi.epoch.epochprobemap_daqsystem','probemap.txt');
ced_rdr = ndi.daq.reader.mfdaq.cedspike2();
Expand All @@ -47,12 +90,14 @@

% Code block 2.1.4.4

disp(['Code block 2.1.4.4:']);
% let's look at the epochs the daq.system can find
et = ced_system.epochtable() % should see a 4 element answer
f = ced_system.filenavigator.getepochfiles(1) % you should see the files from epoch 1, t00001

% Code block 2.1.4.5

disp(['Code block 2.1.4.5:']);
vis_filenav = ndi.file.navigator(S, {'.*\.smr\>', 'probemap.txt', 'stims.tsv'},...
'ndi.epoch.epochprobemap_daqsystem','probemap.txt');
vis_rdr = ndi.daq.reader.mfdaq.cedspike2();
Expand All @@ -63,11 +108,13 @@

% Code block 2.1.4.6

disp(['Code block 2.1.4.6:']);
nsf = ndi.time.syncrule.filematch(struct('number_fullpath_matches',2));
S.syncgraph_addrule(nsf);

% Code block 2.1.5.1

disp(['Code block 2.1.5.1:']);
p = S.getprobes() % get all of the probes that are in the ndi.session S
for i=1:numel(p), p{i}, end; % display the probe information for each probe

Expand All @@ -79,6 +126,7 @@
epoch_to_read = 1;

% Code block 2.1.5.2
disp(['Code block 2.1.5.2:']);

[data,t,timeref_p_ctx1]=p_ctx1.readtimeseries(epoch_to_read,-Inf,Inf); % read all data from epoch 1
figure(100);
Expand All @@ -89,17 +137,20 @@
box off;

% Code block 2.1.5.3
disp(['Code block 2.1.5.3:']);

p_visstim_list = S.getprobes('name','vis_stim','reference',1) % returns a cell array of matches
p_visstim = p_visstim_list{1}; % take the first one, should be the only one
et = p_visstim.epochtable()
for i=1:numel(et), et(i), end; % display the epoch table entries

% Code block 2.1.5.4
disp(['Code block 2.1.5.4:']);

timeref_p_ctx1

% Code block 2.1.5.5
disp(['Code block 2.1.5.5:']);

[data,t,timeref_stim]=p_visstim.readtimeseries(timeref_p_ctx1,-Inf,Inf); % read all data from epoch 1 of p_ctx1 !
figure(100);
Expand All @@ -108,6 +159,7 @@

% Code block 2.1.5.6

disp(['Code block 2.1.5.6:']);
t, % show timestamps
t.stimon,
data, % show data
Expand Down
70 changes: 70 additions & 0 deletions +ndi/+example/+tutorial/tutorial_02_02.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function tutorial_02_02(prefix, testing)
% ndi.example.tutorials.tutorial_02_02 - runs the code in Tutorial 2.2
%
% out = ndi.example.tutorials.tutorial_02_02(PREFIX, [TESTING])
%
% Runs (and tests) the code for
%
% NDI Tutorial 2: Analzying your first electrophysiology experiment with NDI
% Tutorial 2.2: The automated way
% The tutorial is available at
% https://vh-lab.github.io/NDI-matlab/tutorials/analyzing_first_physiology_experiment/2_theautomatedway
%
% PREFIX should be the directory that contains the directory 'ts_exper2'. If it is not
% provided or is empty, the default is [userpath filesep 'Documents' filesep 'NDI'].
%
% If TESTING is 1, then the files are copied to the temporary directory before proceeding so that the files
% in the directory called PREFIX are not touched.
%

if nargin<1 | isempty(prefix),
prefix = [userpath filesep 'Documents' filesep 'NDI']; % or '/Users/yourusername/Desktop/' if you put it on the desktop perhaps
end;


if nargin<2,
testing = 0;
end;

tutorial_dir = 'ts_exper2';

if testing, % copy the files to the temp directory
ndi.globals()
prefix = [userpath filesep 'Documents' filesep 'NDI' filesep 'Test'];
disp(['Assuming clean data files ts_exper2 are in ' prefix '.']);

disp(['Clearing any ''' tutorial_dir ''' in the temporary directory']);
try,
rmdir([ndi_globals.path.temppath filesep tutorial_dir],'s');
end;
disp(['Copying ''' tutorial_dir ''' to the temporary directory']);
copyfile([prefix filesep tutorial_dir], [ndi_globals.path.temppath filesep tutorial_dir]);

prefix = ndi_globals.path.temppath;
end

% Code block 2.2.7.1

disp(['Code block 2.2.7.1:']);
% prefix line is set above
S = ndi.setup.vhlab('ts_exper2',[prefix filesep 'ts_exper2']);

p_ctx1_list = S.getprobes('name','ctx','reference',1) % returns a cell array of matches
p_ctx1 = p_ctx1_list{1}; % take the first one, should be the only one

epoch_to_read = 1;
[data,t,timeref_p_ctx1]=p_ctx1.readtimeseries(epoch_to_read,-Inf,Inf); % read all data from epoch 1
figure(100);
plot(t,data);
xlabel('Time(s)');
ylabel('Voltage (V)');
set(gca,'xlim',[t(1) t(end)]);
box off;

p_visstim_list = S.getprobes('type','stimulator') % returns a cell array of matches
p_visstim = p_visstim_list{1}; % take the first one, should be the only one
[data,t,timeref_stim]=p_visstim.readtimeseries(timeref_p_ctx1,-Inf,Inf); % read all data from epoch 1 of p_ctx1 !
figure(100);
hold on;
vlt.neuro.stimulus.plot_stimulus_timeseries(7,t.stimon,t.stimoff,'stimid',data.stimid);

Loading