Skip to content

Commit

Permalink
added function to pull pixel_distance
Browse files Browse the repository at this point in the history
and some minor edits (removed find)
  • Loading branch information
lolaBerkowitz committed Nov 25, 2024
1 parent f7b85d0 commit 061d8a2
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions preprocessing/behavior/update_behavior_from_metadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function update_behavior_from_metadata(metadata_path,varargin)
% update maze size
update_maze_size(basepath,df)

% update behavior.epochs.scale_measurement from maze_size column
update_pixel_distance(basepath,df)


end

Expand Down Expand Up @@ -64,34 +67,70 @@ function main_batch(data_folder,df)
try
general_behavior_file_SNlab('basepath',basepath)
load(fullfile(basepath,[basename,'.animal.behavior.mat']),'behavior')
catch
disp('Failed - check DLC outputs are present')
catch e
disp(e)
continue
end

end

if ~isempty(behavior.trials)
continue
else
%% update behavior.trials from trial_start/stop columns
update_trials(basepath,df)
else
% update behavior.trials from trial_start/stop columns
update_trials(basepath,df)
end

% update behavior.epochs.maze_size from maze_size column
update_maze_size(basepath,df)

% update behavior.epochs.scale_measurement from maze_size column
update_pixel_distance(basepath,df)


end
end

function update_pixel_distance(basepath,df)
% updates behavior.trials from frames in df

% crate basename from basepath
basename = basenameFromBasepath(basepath);
% load session and animal behavior file
load(fullfile(basepath,[basename,'.animal.behavior.mat']),'behavior');

session = loadSession(basepath,basename);

% pull rows from df for this basepath
temp_df = df(contains(df.basename,basename),:);

% setup
vars = fieldnames(temp_df);
col_idx = contains(vars,{'pixel_distance'});

% loop through videos indicated in session.behavioralTracking
for ii = 1:length(session.behavioralTracking)

% load epoch to get start/end for timestamps
epoch = session.behavioralTracking{1,ii}.epoch;
% grap video so we can find row index for a given video
vidname = session.behavioralTracking{1,ii}.notes;
row_idx = contains(temp_df.vidname,extractBefore(vidname,'.avi'));

behavior.epochs{1, epoch}.pixel_distance = table2array(temp_df(row_idx,col_idx));

end
% save behavior file
save(fullfile(basepath,[basename,'.animal.behavior.mat']),'behavior')
end

function update_maze_size(basepath,df)
% updates behavior.trials from frames in df

% crate basename from basepath
basename = basenameFromBasepath(basepath);
% load session and animal behavior file
load(fullfile(basepath,[basename,'.animal.behavior.mat']));
load(fullfile(basepath,[basename,'.animal.behavior.mat']),'behavior');

session = loadSession(basepath,basename);

Expand All @@ -100,7 +139,7 @@ function update_maze_size(basepath,df)

% setup
vars = fieldnames(temp_df);
col_idx = find(contains(vars,{'maze_width_cm','maze_length_cm'}));
col_idx = contains(vars,{'maze_width_cm','maze_length_cm'});

% loop through videos indicated in session.behavioralTracking
for ii = 1:length(session.behavioralTracking)
Expand Down

0 comments on commit 061d8a2

Please sign in to comment.