diff --git a/legacy_schemas/+reso/Align.m b/legacy_schemas/+reso_old/Align.m similarity index 100% rename from legacy_schemas/+reso/Align.m rename to legacy_schemas/+reso_old/Align.m diff --git a/legacy_schemas/+reso/AxonEffect.m b/legacy_schemas/+reso_old/AxonEffect.m similarity index 100% rename from legacy_schemas/+reso/AxonEffect.m rename to legacy_schemas/+reso_old/AxonEffect.m diff --git a/legacy_schemas/+reso/AxonMask.m b/legacy_schemas/+reso_old/AxonMask.m similarity index 100% rename from legacy_schemas/+reso/AxonMask.m rename to legacy_schemas/+reso_old/AxonMask.m diff --git a/legacy_schemas/+reso/Axons.m b/legacy_schemas/+reso_old/Axons.m similarity index 100% rename from legacy_schemas/+reso/Axons.m rename to legacy_schemas/+reso_old/Axons.m diff --git a/legacy_schemas/+reso/Bead.m b/legacy_schemas/+reso_old/Bead.m similarity index 100% rename from legacy_schemas/+reso/Bead.m rename to legacy_schemas/+reso_old/Bead.m diff --git a/legacy_schemas/+reso/BeadStack.m b/legacy_schemas/+reso_old/BeadStack.m similarity index 100% rename from legacy_schemas/+reso/BeadStack.m rename to legacy_schemas/+reso_old/BeadStack.m diff --git a/legacy_schemas/+reso/CaOpt.m b/legacy_schemas/+reso_old/CaOpt.m similarity index 100% rename from legacy_schemas/+reso/CaOpt.m rename to legacy_schemas/+reso_old/CaOpt.m diff --git a/legacy_schemas/+reso/ConditionMap.m b/legacy_schemas/+reso_old/ConditionMap.m similarity index 100% rename from legacy_schemas/+reso/ConditionMap.m rename to legacy_schemas/+reso_old/ConditionMap.m diff --git a/legacy_schemas/+reso/Conditions.m b/legacy_schemas/+reso_old/Conditions.m similarity index 100% rename from legacy_schemas/+reso/Conditions.m rename to legacy_schemas/+reso_old/Conditions.m diff --git a/legacy_schemas/+reso/Cos2Map.m b/legacy_schemas/+reso_old/Cos2Map.m similarity index 100% rename from legacy_schemas/+reso/Cos2Map.m rename to legacy_schemas/+reso_old/Cos2Map.m diff --git a/legacy_schemas/+reso/Effect.m b/legacy_schemas/+reso_old/Effect.m similarity index 100% rename from legacy_schemas/+reso/Effect.m rename to legacy_schemas/+reso_old/Effect.m diff --git a/legacy_schemas/+reso/EphysTime.m b/legacy_schemas/+reso_old/EphysTime.m similarity index 100% rename from legacy_schemas/+reso/EphysTime.m rename to legacy_schemas/+reso_old/EphysTime.m diff --git a/legacy_schemas/+reso/Indicator.m b/legacy_schemas/+reso_old/Indicator.m similarity index 100% rename from legacy_schemas/+reso/Indicator.m rename to legacy_schemas/+reso_old/Indicator.m diff --git a/legacy_schemas/+reso/IndicatorSet.m b/legacy_schemas/+reso_old/IndicatorSet.m similarity index 100% rename from legacy_schemas/+reso/IndicatorSet.m rename to legacy_schemas/+reso_old/IndicatorSet.m diff --git a/legacy_schemas/+reso/Jobs.m b/legacy_schemas/+reso_old/Jobs.m similarity index 100% rename from legacy_schemas/+reso/Jobs.m rename to legacy_schemas/+reso_old/Jobs.m diff --git a/legacy_schemas/+reso/ManualSegment.m b/legacy_schemas/+reso_old/ManualSegment.m similarity index 100% rename from legacy_schemas/+reso/ManualSegment.m rename to legacy_schemas/+reso_old/ManualSegment.m diff --git a/legacy_schemas/+reso/ManualSegmentGlia.m b/legacy_schemas/+reso_old/ManualSegmentGlia.m similarity index 100% rename from legacy_schemas/+reso/ManualSegmentGlia.m rename to legacy_schemas/+reso_old/ManualSegmentGlia.m diff --git a/legacy_schemas/+reso/MiniStack.m b/legacy_schemas/+reso_old/MiniStack.m similarity index 100% rename from legacy_schemas/+reso/MiniStack.m rename to legacy_schemas/+reso_old/MiniStack.m diff --git a/legacy_schemas/+reso/Motion3D.m b/legacy_schemas/+reso_old/Motion3D.m similarity index 100% rename from legacy_schemas/+reso/Motion3D.m rename to legacy_schemas/+reso_old/Motion3D.m diff --git a/legacy_schemas/+reso/OriDesign.m b/legacy_schemas/+reso_old/OriDesign.m similarity index 100% rename from legacy_schemas/+reso/OriDesign.m rename to legacy_schemas/+reso_old/OriDesign.m diff --git a/legacy_schemas/+reso/OriMap.m b/legacy_schemas/+reso_old/OriMap.m similarity index 100% rename from legacy_schemas/+reso/OriMap.m rename to legacy_schemas/+reso_old/OriMap.m diff --git a/legacy_schemas/+reso/ScanInfo.m b/legacy_schemas/+reso_old/ScanInfo.m similarity index 100% rename from legacy_schemas/+reso/ScanInfo.m rename to legacy_schemas/+reso_old/ScanInfo.m diff --git a/legacy_schemas/+reso/Segment.m b/legacy_schemas/+reso_old/Segment.m similarity index 100% rename from legacy_schemas/+reso/Segment.m rename to legacy_schemas/+reso_old/Segment.m diff --git a/legacy_schemas/+reso/SegmentGlia.m b/legacy_schemas/+reso_old/SegmentGlia.m similarity index 100% rename from legacy_schemas/+reso/SegmentGlia.m rename to legacy_schemas/+reso_old/SegmentGlia.m diff --git a/legacy_schemas/+reso/Sync.m b/legacy_schemas/+reso_old/Sync.m similarity index 100% rename from legacy_schemas/+reso/Sync.m rename to legacy_schemas/+reso_old/Sync.m diff --git a/legacy_schemas/+reso/Trace.m b/legacy_schemas/+reso_old/Trace.m similarity index 100% rename from legacy_schemas/+reso/Trace.m rename to legacy_schemas/+reso_old/Trace.m diff --git a/legacy_schemas/+reso/TraceGlia.m b/legacy_schemas/+reso_old/TraceGlia.m similarity index 100% rename from legacy_schemas/+reso/TraceGlia.m rename to legacy_schemas/+reso_old/TraceGlia.m diff --git a/legacy_schemas/+reso/TraceVonMises.m b/legacy_schemas/+reso_old/TraceVonMises.m similarity index 100% rename from legacy_schemas/+reso/TraceVonMises.m rename to legacy_schemas/+reso_old/TraceVonMises.m diff --git a/legacy_schemas/+reso/Trial.m b/legacy_schemas/+reso_old/Trial.m similarity index 100% rename from legacy_schemas/+reso/Trial.m rename to legacy_schemas/+reso_old/Trial.m diff --git a/legacy_schemas/+reso/TrialSet.m b/legacy_schemas/+reso_old/TrialSet.m similarity index 100% rename from legacy_schemas/+reso/TrialSet.m rename to legacy_schemas/+reso_old/TrialSet.m diff --git a/legacy_schemas/+reso/TrialTrace.m b/legacy_schemas/+reso_old/TrialTrace.m similarity index 100% rename from legacy_schemas/+reso/TrialTrace.m rename to legacy_schemas/+reso_old/TrialTrace.m diff --git a/legacy_schemas/+reso/TrialTraceSet.m b/legacy_schemas/+reso_old/TrialTraceSet.m similarity index 100% rename from legacy_schemas/+reso/TrialTraceSet.m rename to legacy_schemas/+reso_old/TrialTraceSet.m diff --git a/legacy_schemas/+reso/VolumeSlice.m b/legacy_schemas/+reso_old/VolumeSlice.m similarity index 100% rename from legacy_schemas/+reso/VolumeSlice.m rename to legacy_schemas/+reso_old/VolumeSlice.m diff --git a/legacy_schemas/+reso/getReader.m b/legacy_schemas/+reso_old/getReader.m similarity index 100% rename from legacy_schemas/+reso/getReader.m rename to legacy_schemas/+reso_old/getReader.m diff --git a/legacy_schemas/+reso/getSchema.m b/legacy_schemas/+reso_old/getSchema.m similarity index 100% rename from legacy_schemas/+reso/getSchema.m rename to legacy_schemas/+reso_old/getSchema.m diff --git a/legacy_schemas/+reso/makeMovie.m b/legacy_schemas/+reso_old/makeMovie.m similarity index 100% rename from legacy_schemas/+reso/makeMovie.m rename to legacy_schemas/+reso_old/makeMovie.m diff --git a/legacy_schemas/+reso/plots.m b/legacy_schemas/+reso_old/plots.m similarity index 100% rename from legacy_schemas/+reso/plots.m rename to legacy_schemas/+reso_old/plots.m diff --git a/legacy_schemas/+reso/reader.m b/legacy_schemas/+reso_old/reader.m similarity index 100% rename from legacy_schemas/+reso/reader.m rename to legacy_schemas/+reso_old/reader.m diff --git a/legacy_schemas/+reso/run.m b/legacy_schemas/+reso_old/run.m similarity index 100% rename from legacy_schemas/+reso/run.m rename to legacy_schemas/+reso_old/run.m diff --git a/legacy_schemas/+reso/work1.m b/legacy_schemas/+reso_old/work1.m similarity index 100% rename from legacy_schemas/+reso/work1.m rename to legacy_schemas/+reso_old/work1.m diff --git a/legacy_schemas/+reso/work2.m b/legacy_schemas/+reso_old/work2.m similarity index 100% rename from legacy_schemas/+reso/work2.m rename to legacy_schemas/+reso_old/work2.m diff --git a/schemas/+opt/BarMap.m b/schemas/+opt/BarMap.m new file mode 100644 index 0000000..a6061f7 --- /dev/null +++ b/schemas/+opt/BarMap.m @@ -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 & timesfreq_rel*(1-range_factor) & freqfreq_rel*(1-range_factor) & freqcommon.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 \ No newline at end of file diff --git a/schemas/+opt/SpotMap.m b/schemas/+opt/SpotMap.m index 350f657..0380581 100644 --- a/schemas/+opt/SpotMap.m +++ b/schemas/+opt/SpotMap.m @@ -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) diff --git a/schemas/+opt/SpotMap2.m b/schemas/+opt/SpotMap2.m new file mode 100644 index 0000000..3bc0840 --- /dev/null +++ b/schemas/+opt/SpotMap2.m @@ -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 & times1 + uicontrol('string','<<','units','pixels','position',[0 5 50 20],'tag','prev','callback',@opt.plots.SpotMapMerge) + uicontrol('style','text','units','pixels','position',[60 5 50 20],'tag','index','string',[num2str(d.keyInd) '/' num2str(length(d.key))]) + uicontrol('string','>>','units','pixels','position',[120 5 50 20],'tag','next','callback',@opt.plots.SpotMapMerge) + end + end + + key = d.key(d.keyInd); + % fetch spotmap + if d.type==1 + [amp, p] = fetch1(opt.SpotMap & key, 'spot_amp', 'spot_fp'); + else + amp = fetch1(opt.SpotMap2 & key , 'spot_amp'); + end + % fetch structure + structKey.animal_id=key.animal_id; + structKey.opt_sess=key.opt_sess; + structImg = fetchn(opt.Structure & structKey,'structure_img'); + structMask = fetchn(opt.StructureMask & structKey,'structure_mask'); + if length(structImg)>1 + structNum = length(structImg); + num = input(['Please enter which structure image do you need 1-' num2str(structNum) ': ']); + structImg = structImg{num}; + structMask = structMask{num}; + structImg = double(structImg.*uint8(structMask)); + amp = bsxfun(@times, amp, double(structMask)); + else + structImg=double(structImg{1}.*uint8(structMask{1})); + amp = bsxfun(@times, amp, double(structMask{1})); + end + + % filter spotmap + k = hamming(5); + k = k/sum(k); + amp = imfilter(amp,k,'symmetric'); + amp = imfilter(amp,k','symmetric'); + img = amp; + + % Spot map + figure(101) + if size(amp,3)==1 + % One spot + subplot(2,1,1) + hold off + h=imagesc(img,[-1 1]*max(abs(img(:)))); + set(h,'buttondownfcn',@opt.plots.moveMarker); + colormap('summer') + axis image + set(gca,'xdir','reverse','xtick',[],'ytick',[]) + + p=get(gca,'position'); + p=[p(1) p(2)-.01 p(3) .03]; + c=caxis; + uicontrol('style','slider','min',c(1)-.005,'max',c(1)+.005,'value',c(1),'units','normalized','position',p,'tag','min','callback',@opt.plots.slider,'userdata',gca); + uicontrol('style','slider','min',c(2)-.005,'max',c(2)+.005,'value',c(2),'units','normalized','position',p-[0 .03 0 0],'tag','max','callback',@opt.plots.slider,'userdata',gca); + elseif size(amp,3)==4 + + % Four spots - separate subplots + pos=[1 5 2 6]; + for i=1:4 + subplot(2,4,pos(i)) + hold off + img = amp(:,:,i); + h=imagesc(img,[-1 1]*max(abs(img(:)))); + set(h,'buttondownfcn',@opt.plots.moveMarker); + colormap('bone') + axis image + set(gca,'xdir','reverse','xtick',[],'ytick',[]) + p=get(gca,'position'); + p=[p(1) p(2)-.01 p(3) .03]; + c=caxis; + uicontrol('style','slider','min',c(1)-.005,'max',c(1)+.005,'value',c(1),'units','normalized','position',p,'tag','min','callback',@opt.plots.slider,'userdata',gca); + uicontrol('style','slider','min',c(2)-.005,'max',c(2)+.005,'value',c(2),'units','normalized','position',p-[0 .03 0 0],'tag','max','callback',@opt.plots.slider,'userdata',gca); + end + + % Four spots - mgyb + subplot(1,2,2) + hold off + for ii = 1:4 + im = squeeze(amp(:,:,ii)); + amp2(:,:,ii) = info.plots.normalize(im); + end + + m = cat(3,1,0,1); + y = cat(3,1,1,0); + b = 1-y; + g = 1-m; + img = bsxfun(@times, amp2(:,:,1), g) ... + + bsxfun(@times, amp2(:,:,2), b) ... + + bsxfun(@times, amp2(:,:,3), y) ... + + bsxfun(@times, amp2(:,:,4), m); + + R = img(:,:,1); + G = img(:,:,2); + B = img(:,:,3); + + img = cat(3,R,G,B)*3+0.1; + img = max(0, min(1, img)); + % % Luminance info + + h=imshow(img); + set(h,'buttondownfcn',@opt.plots.moveMarker); + keyTitle(key); + axis image + set(gca,'xdir','reverse') + + else + error('Can only plot for 1 or 4 spots'); + end + + + % Structural image + figure(102) + hold off + h=imagesc(structImg); colormap('gray'); + set(h,'buttondownfcn',@opt.plots.moveMarker); + keyTitle(structKey); + axis image + set(gca,'xdir','reverse','xtick',[],'ytick',[]) + p=get(gca,'position'); + p=[p(1) p(2)-.03 p(3) .03]; + uicontrol('style','slider','min',0,'max',127,'value',0,'units','normalized','position',p,'tag','min','callback',@opt.plots.slider,'userdata',gca); + uicontrol('style','slider','min',128,'max',255,'value',255,'units','normalized','position',p-[0 .03 0 0],'tag','max','callback',@opt.plots.slider,'userdata',gca); + + h = [findobj(101,'type','axes');findobj(102,'type','axes')]; + for i=1:length(h) + if isempty(get(h(i),'userdata')) || ~ishandle(get(h(i),'userdata')) + axes(h(i)); + hold on + pHandle = plot(0,0,'marker','x','linewidth',2); + set(h(i),'userdata',pHandle); + end + end + figure(103) + img2 = rgb2hsv(img); + structImg = convn(structImg, gausswin(5)*gausswin(5)', 'valid'); + structImg = (structImg-min(structImg(:)))./(max(structImg(:))-min(structImg(:))); + img2(:,:,3) = structImg; + img3 = hsv2rgb(img2); + image(img3); + set(gca,'xdir','reverse','xtick',[],'ytick',[]) + axis image + keyTitle(structKey); + information.img = img2; + information.key = structKey; + uicontrol('style','slider','min',0,'max',0.1,'value',0,'units','normalized','position',p,'tag','min','callback',@opt.plots.SliderMerge,'userdata',information); + uicontrol('style','slider','min',0.9,'max',1,'value',1,'units','normalized','position',p-[0 .03 0 0],'tag','max','callback',@opt.plots.SliderMerge,'userdata',information); + + end function Structure(varargin) @@ -216,6 +412,251 @@ function Structure(varargin) set(gca,'xdir','reverse') end end + function SliderMerge(src,event) + figure(103) + information = get(src,'userdata'); + structImg = squeeze(information.img(:,:,3)); + img = information.img; + v = get(src,'value'); + t = get(src,'tag'); + + switch t + case 'min' + structImg(structImgquantile(structImg(:),v)) = quantile(structImg(:),v); + + end + structImg = (structImg-min(structImg(:)))./(max(structImg(:))-min(structImg(:))); + img(:,:,3) = structImg; + img = hsv2rgb(img); + image(img); + set(gca,'xdir','reverse','xtick',[],'ytick',[]) + axis image + keyTitle(information.key); + + end + + function BarMap(varargin) + + % merge the SpotMap on top of the vessels + if ishandle(varargin{1}) + src = varargin{1}; + t = get(src,'tag'); + d = get(101,'userdata'); + switch t + case 'prev' + if d.keyInd == 1 + return + end + + d.keyInd = max(1,d.keyInd-1); + case 'next' + if d.keyInd == length(d.key) + return + end + d.keyInd = min(length(d.key),d.keyInd+1); + end + set(101,'userdata',d); + h = findobj(101,'tag','index'); + set(h,'string',[num2str(d.keyInd) '/' num2str(length(d.key))]); + else + + d.key = fetch(opt.BarMap(varargin{:}))'; + if isempty(d.key) + warning('No tuples found'); + return + end + d.keyInd = 1; + figure(101) + set(101,'userdata',d); + if length(d.key)>1 + uicontrol('string','<<','units','pixels','position',[0 5 50 20],'tag','prev','callback',@opt.plots.BarMap) + uicontrol('style','text','units','pixels','position',[60 5 50 20],'tag','index','string',[num2str(d.keyInd) '/' num2str(length(d.key))]) + uicontrol('string','>>','units','pixels','position',[120 5 50 20],'tag','next','callback',@opt.plots.BarMap) + end + end + + key = d.key(d.keyInd); + % fetch barmap + [imP,imA] = fetch1(opt.BarMap(key), 'bar_phase_map', 'bar_amp_map'); + % fetch structure + structKey.animal_id=key.animal_id; + structKey.opt_sess=key.opt_sess; + structImg=fetchn(opt.Structure(structKey),'structure_img'); + structMask=fetchn(opt.StructureMask(structKey),'structure_mask'); + if length(structImg)>1 + structNum = length(structImg); + num = input(['Please enter which structure image do you need 1-' num2str(structNum) ': ']); + structImg=structImg(num); + structMask=structMask(num); + + + + + end + structImg=double(structImg{1}.*uint8(structMask{1})); + + + % filter spotmap + % set parameters for the filtering + params.sigma = 2; %sigma of the gaussian filter + params.exp = 1; % exponent factor of rescaling + params.reverse = 1; % reverse the axis + params.range = 3.14/2; % angle limit + + imA(imA>prctile(imA(:),99)) = prctile(imA(:),99); + [h1,h2] = hist(reshape(imP(imP~=0),[],1),100); + mxv = h2(h1 == max(h1)); + imP = imP - mxv(1); + imP(imP<-3.14) = imP(imP<-3.14) +3.14*2; + imP(imP>3.14) = imP(imP>3.14) -3.14*2; + imP(imP<0) = -exp((imP(imP<0)+ params.range)*params.exp); + imP(imP>0) = exp((abs(imP(imP>0)- params.range))*params.exp); + + h = normalize(imP); + h = bsxfun(@times, h, double(structMask{1})); + s = ones(size(imP)); + v = normalize(imA); + v = bsxfun(@times, v, double(structMask{1})); + s2 = normalize(imA); + s2 = bsxfun(@times, s2, double(structMask{1})); + v2 = normalize(structImg); + + + % bar map + figure(101) + + set(gcf,'position',[50 200 920 435]) + + subplot(121) + im = (hsv2rgb(cat(3,h,cat(3,s,v)))); +% im = convn(im, gausswin(params.sigma)*gausswin(params.sigma)', 'valid'); + imshow(im) + if params.reverse + set(gca,'xdir','reverse') + end + + subplot(122) + im = (hsv2rgb(cat(3,h,cat(3,s2,v2)))); +% im = convn(im, gausswin(params.sigma)*gausswin(params.sigma)', 'valid'); + imshow(im) + + if params.reverse + set(gca,'xdir','reverse') + end + keyTitle(key); + + + end + function BarrelMap(varargin) + + % set the GUI environment + if ishandle(varargin{1}) + src = varargin{1}; + t = get(src,'tag'); + d = get(101,'userdata'); + switch t + case 'prev' + if d.keyInd == 1 + return + end + + d.keyInd = max(1,d.keyInd-1); + case 'next' + if d.keyInd == length(d.key) + return + end + d.keyInd = min(length(d.key),d.keyInd+1); + end + set(101,'userdata',d); + h = findobj(101,'tag','index'); + set(h,'string',[num2str(d.keyInd) '/' num2str(length(d.key))]); + else + d.key = fetch(opt.BarrelMap & varargin{:})'; + if isempty(d.key) + warning('No tuples found'); + return + end + d.keyInd = 1; + figure(101) + set(101,'userdata',d); + if length(d.key)>1 + uicontrol('string','<<','units','pixels','position',[0 5 50 20],'tag','prev','callback',@opt.plots.BarrelMap) + uicontrol('style','text','units','pixels','position',[60 5 50 20],'tag','index','string',[num2str(d.keyInd) '/' num2str(length(d.key))]) + uicontrol('string','>>','units','pixels','position',[120 5 50 20],'tag','next','callback',@opt.plots.BarrelMap) + end + end + + % fetch barrel map + key = d.key(d.keyInd); + amp = fetch1(opt.BarrelMap & key,'barrel_amp'); + + % fetch structure + structKey.animal_id=key.animal_id; + structKey.opt_sess=key.opt_sess; + structImg=fetchn(opt.Structure(structKey),'structure_img'); + structMask=fetchn(opt.StructureMask(structKey),'structure_mask'); + if length(structImg)>1 + structImg=structImg{end}; + warning('More than one structural image for this session. Using {end}'); + end + + if length(structMask)>1 + structMask=structMask{1}; + warning('More than one structural mask for this session. Using {1}'); + end + + structImg=double(structImg{1}.*uint8(structMask{1})); + + amp = bsxfun(@times, amp, double(structMask{1})); + + % filter spotmap + k = hamming(5); + k = k/sum(k); + amp = imfilter(amp,k,'symmetric'); + amp = imfilter(amp,k','symmetric'); + img = amp; + + + % plot barrel map + figure(101) + h=imagesc(img,[-1 1]*max(abs(img(:)))); + + set(h,'buttondownfcn',@opt.plots.moveMarker); + colormap('gray') + axis image + set(gca,'xdir','reverse','xtick',[],'ytick',[]) + + p=get(gca,'position'); + p=[p(1) p(2)-.01 p(3) .03]; + c=caxis; + uicontrol('style','slider','min',c(1)-.005,'max',c(1)+.005,'value',c(1),'units','normalized','position',p,'tag','min','callback',@opt.plots.slider,'userdata',gca); + uicontrol('style','slider','min',c(2)-.005,'max',c(2)+.005,'value',c(2),'units','normalized','position',p-[0 .03 0 0],'tag','max','callback',@opt.plots.slider,'userdata',gca); + + % Structural image + figure(102) + hold off + h=imagesc(structImg); colormap('gray'); + set(h,'buttondownfcn',@opt.plots.moveMarker); + keyTitle(structKey); + axis image + set(gca,'xdir','reverse','xtick',[],'ytick',[]) + p=get(gca,'position'); + p=[p(1) p(2)-.03 p(3) .03]; + uicontrol('style','slider','min',0,'max',127,'value',0,'units','normalized','position',p,'tag','min','callback',@opt.plots.slider,'userdata',gca); + uicontrol('style','slider','min',128,'max',255,'value',255,'units','normalized','position',p-[0 .03 0 0],'tag','max','callback',@opt.plots.slider,'userdata',gca); + + h = [findobj(101,'type','axes');findobj(102,'type','axes')]; + for i=1:length(h) + if isempty(get(h(i),'userdata')) || ~ishandle(get(h(i),'userdata')) + axes(h(i)); + hold on + pHandle = plot(0,0,'marker','x','linewidth',2); + set(h(i),'userdata',pHandle); + end + end + end end end \ No newline at end of file