forked from jessedmarshall/CAPTURE_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess_dannce.m
116 lines (93 loc) · 3.79 KB
/
preprocess_dannce.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
%[fList,pList] = matlab.codetools.requiredFilesAndProducts('preprocess_dannce.m');
% File Here to preprocess
function ratception_struct = preprocess_dannce(filein,fileoutput,animalname,input_params)
% Inputs: filein: a .mat file containing a predictions.mat DANNCE struct, with a
% struct containing each markers x-y-z prediction
%
% fileoutput: a .mat file
%
% animalname: the name of the animal (default - "rats") that
% defines the number of links and markers to use for a given
% dataset in load_link_files.m. Other pre-defined options
% include: 'mouse' (14 marker) kyle_mouse (20 marker)
%
% input_params: a struct containing experiment specific
% information: the markers to use as
% SpineF (SpineF_marker) and SpineM (SpineM_marker)
% to align the animal, the relative framerate to 300
% Hz (repfactor = 300/experiment framerate),
% conversion factor (to scale the outputs)
%% check the input -- no input means run with defaults
if isempty(filein)
datahere = load('C:\Users\Jesse Marshall\Documents\GitHub\Movement_analysis\Cortex_analysis\DemoRepo\Data\predictions.mat');
else
datahere = load(filein);
end
if isempty(fileoutput)
fileoutput = 'test_ratceptionstruct.mat';
end
if isempty(animalname)
animalname = 'rats';
end
if ~isempty(input_params)
if isfield(input_params,'SpineF_marker')
f = fieldnames(datahere.predictions);
v = struct2cell(datahere.predictions);
f{strmatch(input_params.SpineF_marker,f,'exact')} = 'SpineF';
f{strmatch(input_params.SpineM_marker,f,'exact')} = 'SpineM';
a = cell2struct(v,f);
disp(a)
datahere.predictions=a;
end
end
%do some surgery on names -- important for
if isfield(datahere.predictions,'sampleID')
datahere.sampleID = datahere.predictions.sampleID;
datahere.predictions =rmfield(datahere.predictions,'sampleID');
end
if ~isempty(input_params)
if isfield(input_params,'conversion_factor')
markernames = fieldnames(datahere.predictions);
for lk=1:numel(markernames)
datahere.predictions.(markernames{lk}) = ...
input_params.conversion_factor.*datahere.predictions.(markernames{lk});
end
end
end
if isempty(input_params) || ~isfield(input_params,'repfactor')
params.repfactor =10;
else
params.repfactor = input_params.repfactor;
end
% file specific changes in names
if isfield(datahere.predictions,'HeadBR')
f = fieldnames(datahere.predictions);
v = struct2cell(datahere.predictions);
f{strmatch('HeadBR',f,'exact')} = 'HeadB';
f{strmatch('HeadBL',f,'exact')} = 'HeadL';
a = cell2struct(v,f);
disp(a)
datahere.predictions=a;
end
% parameters for preprocessing
preprocessing_parameters = struct();
preprocessing_parameters.median_filt_length = 5;
preprocessing_parameters.bad_frame_vel_thresh = 150; %this effectively turns the velocity criteria off
preprocessing_parameters.bad_frame_surround_flag = 0;
preprocessing_parameters.bad_frame_surround_number = 1;
preprocessing_parameters.interpolation_max_length = 5;
preprocessing_parameters.meanvelocity_lowpass = 60;
preprocessing_parameters.meanvelocity_lowpass = 60;
preprocessing_parameters.fastvelocity_threshold = 0.01;% 0.1;
preprocessing_parameters.moving_threshold = 0.00001;%0.015;
preprocessing_parameters.moving_framewindow = 600;
% the difference in framerate between the video and the canonical motion capture
% datasets
ratception_struct = preprocess_ratception_struct_demo(datahere,preprocessing_parameters,params);
%% load
[links,colors] = load_link_files(animalname);
ratception_struct.links = links;
ratception_struct.markercolor = colors;
ratception_struct.markercolor = colors;
%% save
save(fileoutput,'ratception_struct','-v7.3')