Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
85 changes: 85 additions & 0 deletions schemas/+opt/BarMap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
%{
opt.BarMap (imported) # retinotopic mapping with moving bars. Average
->opt.Sync
-----
bar_phase_map : longblob # phase of the response at the stimulus frequency
bar_amp_map : longblob # amplitude of the response at the stimulus frequency
freq : longblob # entire frequecy chain
freq_rel : double # stimulus frequency of this session
range_factor : double # range of frequency included in the map, [freq_rel*(1-range_factor), freq_rel*(1+range_factor)]
direction : double # direction of the moving bar
ntrials : int # number of trials on this session
%}

classdef BarMap < dj.Relvar & dj.AutoPopulate
properties
popRel = opt.Sync & psy.MovingBar
end

methods
function self = BarMap(varargin)
self.restrict(varargin)
end
end

methods(Access=protected)

function makeTuples(self, key)
disp 'loading movie...'
tic
filename = fullfile(...
fetch1(common.OpticalSession(key), 'opt_path'),...
[fetch1(common.OpticalMovie(key), 'filename') '.h5']);
[X, framerate] = opt.utils.getOpticalData(getLocalPath(filename),'mov');
toc

trialRel = opt.Sync(key)*psy.Trial*psy.MovingBar & 'trial_idx between first_trial and last_trial';
trials = fetch(trialRel, 'flip_times', 'direction');
trial_duration = fetch(psy.MovingBar & trialRel, 'trial_duration');
trial_duration = trial_duration(1).trial_duration;
freq_rel = 1/trial_duration;

% time of the scans on the stimulus clock
times = fetch1(opt.Sync(key), 'frame_times');

% take out the movie with stimulus on
onset = trials(1).flip_times(2);
offset = trials(end).flip_times(end);
ix = (times>=onset & times<offset);
X_rel = X(ix,:,:);
X_rel = bsxfun(@minus,max(X_rel,[],1), X_rel);

disp 'Fourier transform...'
tic
x_dfft = fft(X_rel);
toc
duration = size(X_rel,1)/framerate;
freq = 1/duration*(0:length(X_rel)-1);


% get the Fourier transform at the frequency of stimulus frequency
disp 'Caculating phase and amplitude...'
tic
amp = abs(x_dfft);
phase = angle(x_dfft);
range_factor = 0.1;
amp_rel = squeeze(mean(amp(freq>freq_rel*(1-range_factor) & freq<freq_rel*(1+range_factor), :,:)));
phase_rel = squeeze(mean(phase(freq>freq_rel*(1-range_factor) & freq<freq_rel*(1+range_factor),:,:)));
toc

disp 'Insert key...'
tic
key.bar_phase_map = phase_rel;
key.bar_amp_map = amp_rel;
% key.amp = amp;
% key.phase = phase;
key.range_factor = range_factor;
key.freq_rel = freq_rel;
key.ntrials = length(trials);
key.direction = trials(1).direction;
key.freq = freq;
self.insert(key)
toc
end
end
end
55 changes: 55 additions & 0 deletions schemas/+opt/BarrelMap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
%{
opt.BarrelMap (imported) # get a map for barrel field, with single whisker stimulation
->common.OpticalMovie
-----
barrel_amp : longblob # amplitude map of barrel cortex, difference between on and off time period.
stimulus : longblob # raw stimulus signal from the piezo
mov_time : longblob # time of each frame of the movie, in sec
mov_ind : longblob # indicator of stimulus on off for each frame
%}

classdef BarrelMap < dj.Relvar & dj.AutoPopulate

properties
popRel = common.OpticalMovie & 'purpose="whisker"'
end

methods(Access=protected)

function makeTuples(self, key)

disp 'loading movie...'

filename = fullfile(...
fetch1(common.OpticalSession(key), 'opt_path'),...
[fetch1(common.OpticalMovie(key), 'filename') '.h5']);
[X, framerate, stim, pdFs] = opt.utils.getOpticalData(getLocalPath(filename),'pd');

stim_ind = conv(abs(diff(stim)),gausswin(10),'same')>0.05;

stim_time = (1:length(stim_ind))/pdFs;

key.mov_time = (1:size(X,1))/framerate;
key.mov_ind = logical(interp1(stim_time, double(stim_ind)', key.mov_time, 'nearest','extrap'));

onset = find(diff(key.mov_ind)==1);

dt = 1/framerate;
off_period = floor(-2/dt):1:0;
on_period = floor(0/dt):1:floor(2/dt);
barrel_map = zeros(length(onset)-2,size(X,2),size(X,3));

for iTrial = 1:length(onset)-2
off_amp = mean(X(onset(iTrial+1) + off_period, :,:));
on_amp = mean(X(onset(iTrial+1) + on_period, :,:));
barrel_map(iTrial,:,:) = on_amp - off_amp;
end

key.barrel_amp = squeeze(mean(barrel_map));
key.stimulus = stim;

self.insert(key)
end
end

end
15 changes: 4 additions & 11 deletions schemas/+opt/SpotMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
%}

%spot_psth : longblob # average stimulus-locked response
classdef SpotMap < dj.Relvar & dj.AutoPopulate
classdef SpotMap < dj.Imported

properties(Constant)
table = dj.Table('opt.SpotMap')
popRel = opt.Sync & psy.Grating
end

methods
function self = SpotMap(varargin)
self.restrict(varargin)
end
end
properties
popRel = opt.Sync & psy.Grating
end

methods(Access=protected)

Expand Down
58 changes: 58 additions & 0 deletions schemas/+opt/SpotMap2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
%{
opt.SpotMap2 (imported) # retinotopic mapping with grating spots. Average
-> opt.Sync
-----
spot_amp : longblob # percent, response amplitude of each spot
%}

classdef SpotMap2 < dj.Relvar & dj.AutoPopulate

properties(Constant)
table = dj.Table('opt.SpotMap2')
popRel = opt.Sync & psy.Grating
end

methods
function self = SpotMap2(varargin)
self.restrict(varargin)
end
end

methods(Access=protected)

function makeTuples(self, key)
disp 'loading movie...'

filename = fullfile(...
fetch1(common.OpticalSession(key), 'opt_path'),...
[fetch1(common.OpticalMovie(key), 'filename') '.h5']);
[X, framerate] = opt.utils.getOpticalData(getLocalPath(filename),'mov');
sz = size(X);
trialRel = opt.Sync(key)*psy.Trial*psy.Grating & 'trial_idx between first_trial and last_trial';
trials = fetch(trialRel, 'aperture_x*1000+aperture_y->position', 'flip_times');
nTrials = length(trials);
[conds,~,condIdx] = unique([trials.position]);
nConds = length(conds);
ntrials = nTrials/nConds;
times = fetch1(opt.Sync(key), 'frame_times');

X_amp = zeros(sz(2),sz(3),nConds,ntrials);
cnt = ones(1,nConds); % counter for the trials of each condition

for iTrial = 1:length(trials)
trial = trials(iTrial);
onset = trial.flip_times(2); % the second flip is the start of the drift
offset = trial.flip_times(end);
cond = condIdx(iTrial);
ix_on = (times>=onset & times < offset);
ix_off = (times>onset - 2*framerate & times<onset);
X_temp = (squeeze(mean(X(ix_on,:,:))) - squeeze(mean(X(ix_off,:,:))))./squeeze(mean(X(ix_off,:,:)));
X_amp(:,:,cond,cnt(cond)) = X_temp;
cnt(cond) = cnt(cond)+1;
end
key.spot_amp = squeeze(mean(X_amp,4));

self.insert(key)
end
end
end
5 changes: 2 additions & 3 deletions schemas/+opt/Structure.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
structure_mask : longblob # mask of craniotomy
%}

classdef Structure < dj.Relvar & dj.AutoPopulate
classdef Structure < dj.Imported

properties(Constant)
table = dj.Table('opt.Structure')
properties
popRel = common.OpticalMovie('purpose="structure"')
end

Expand Down
5 changes: 2 additions & 3 deletions schemas/+opt/StructureMask.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
structure_mask : longblob # mask of craniotomy
%}

classdef StructureMask < dj.Relvar & dj.AutoPopulate
classdef StructureMask < dj.Imported

properties(Constant)
table = dj.Table('opt.StructureMask')
popRel = opt.Structure;
popRel = opt.Structure
end

methods
Expand Down
15 changes: 4 additions & 11 deletions schemas/+opt/Sync.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@

%}

classdef Sync < dj.Relvar & dj.AutoPopulate
classdef Sync < dj.Imported

properties(Constant)
table = dj.Table('opt.Sync')
properties
popRel = common.OpticalMovie('purpose="stimulus"')
end

methods
function self = Sync(varargin)
self.restrict(varargin)
end
end

end

methods(Access=protected)

function makeTuples(self, key)
Expand Down
Loading