123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- function runstim_THINGS(T_Trl)
- global Par %global parameters
- Par.Mouserun = 0;
- dasusemouse( 0 );
- preloaded_pics = 40;
- ncount = 4;
- monkey = 'monkeyN';
- % cogstd('sPriority','high')
- LOG.fn = 'runstim_THINGS';
- DateString = datestr(now,'yyyymmddHHMMSS'); % get date-timestamp
- ds_yyyymmdd = DateString(1:8); % date for session
- logs_dir = ['\\vs03\VS03-VandC-2\THINGS\Passive_Fixation\',monkey,'\_logs\'];
- data_dir = ['\\vs03\VS03-VandC-2\THINGS\Passive_Fixation\',monkey,'\',ds_yyyymmdd,'\'];
- fn_randtab = [logs_dir,'RANDTAB_THINGS_',monkey,'.mat'];
- fn_paths = [logs_dir,'things_imgs.mat'];
- load(fn_paths)
- load(fn_randtab)
- fn = input('Enter BLOCK number (e.g. 1), blank = don"t save logs\n','s');
- if ~isempty(fn)
- if ~exist(data_dir, 'dir')
- mkdir(data_dir);
- end
- %Copy the run stime
- logname = ['THINGS_',monkey,'_',ds_yyyymmdd,'_B',fn];
- fnrs = [logs_dir,logname,'_','runstim.m'];
- disp(['logfile: ',logname])
- cfn = [mfilename('fullpath') '.m'];
- copyfile(cfn,fnrs)
- block_dir = [data_dir,'Block_',fn,'\'];
- if ~exist(block_dir, 'dir')
- mkdir(block_dir);
- end
- %Save json metadata
- json.version = '1.0';
- json.project = 'THINGS';
- json.dataset = 'passive_fixation';
- json.date = ds_yyyymmdd;
- json.subject = monkey;
- json.investigator = 'Paolo_Papale';
- json.setup = 'monkey_setup_4';
- json.condition = 'awake';
- json.stimulus = 'natural_images';
- json.logfile = logname;
- savejson('', json, [block_dir,logname,'_session.json']);
- end
- if isempty(fn)
- logon = 0;
- else
- logon = 1;
- fn_randtab_hist = [logs_dir,'RANDTAB_',logname,'.mat'];
- fn = [logs_dir,'THINGS_',monkey,'_',ds_yyyymmdd,'_B',fn];
- save(fn,'LOG')
- end
- %Tracker times
- FIXT = 200; %time to fix before stim onset
- STIMT = 200; %Exposure
- ITI_short = 200;
- ITI = 200;
- FixWinSizex = 1.0; %1.1
- FixWinSizey = 1.0; %1.1
- rand('state',sum(clock))
- cgfont('Arial' ,30)
- %Global properties
- frame = 1./85;
- FixDotSize = 0.3;
- FixPix = Par.PixPerDeg.*FixDotSize;
- Px = 0;
- Py = 0;
- picx = 100;
- picy = -100;
- %Set grey to be halfway between darkest and brightest luminace to acheive
- %maxuimum possible contrast range
- %gammacon converts between rgb and luminace given the known gamma curve of
- %the montior
- % maxlum = gammacon2(1,'rgb2lum');
- % minlum = gammacon2(0,'rgb2lum');
- % greylum = (maxlum+minlum)./2;
- % grey = gammacon2(greylum,'lum2rgb');
- grey = .5;
- Par.grey = grey;
- Times = Par.Times; %copy timing structure
- %timing
- PREFIXT = Times.ToFix; %time to enter fixation window
- %Create log file
- LOG.Par = Par;
- LOG.Times = Times;
- LOG.Frame = frame;
- LOG.FIXT = FIXT;
- LOG.STIMT = STIMT;
- LOG.ScreenX = 1024;
- LOG.Screeny = 768;
- %pre-LOAD n-imgs imgs
- all_remainings = 1:size(RANDTAB,1);
- for p = 1:preloaded_pics
- if RANDTAB(p,2) > 0
- trl = RANDTAB(p,2);
- cgloadbmp(p,train_imgs(trl).local_path);
- else
- trl = RANDTAB(p,3);
- cgloadbmp(p,test_imgs(trl).local_path)
- end
- end
- [~] = input('Ready? Press ENTER to start!');
- %////YOUR STIMULATION CONTROL LOOP /////////////////////////////////
- Hit = 2;
- TZ = 0;
- Par.ESC = false; %escape has not been pressed
- while ~Par.ESC
-
- %Windows (fix and target)
- WIN = [0 0 Par.PixPerDeg.*FixWinSizex Par.PixPerDeg.*FixWinSizey 0];
- Par.WIN = WIN';
-
- %/////////////////////////////////////////////////////////////////////
- %START THE TRIAL
- %set control window positions and dimensions
- refreshtracker(1) %for your control display
- SetWindowDas %for the dascard
- Abort = false; %whether subject has aborted before end of trial
- ncount_done = 0;
- sprites_to_delete = [];
- %///////// EVENT 0 START FIXATING //////////////////////////////////////
- Par.Updatxy = 1;
- cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f') %the red fixation dot on the screen
- drawdiode(0) %the diode cue
- cgflip(grey,grey,grey)
-
- dasreset(0)
- %subject has to start fixating central dot
- Par.SetZero = false; %set key to false to remove previous presses
- Par.Updatxy = 1; %centering key is enabled
- Time = 1;
- Hit = 0;
- while Time < PREFIXT && Hit == 0
- dasrun(5)
- [Hit Time] = DasCheck; %retrieve position values and plot on Control display
- end
-
- %///////// EVENT 1 KEEP FIXATING or REDO ////////////////////////////////////
- Par.Updatxy = 1;
- if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time
- dasreset(1); %test for exiting fix window
-
- Time = 1;
- Hit = 0;
- while Time < FIXT && Hit == 0
- %Check for 5 ms
- dasrun(5)
- %or just pause for 5ms?
- [Hit Time] = DasCheck;
- end
-
- if Hit ~= 0 %eye has left fixation to early
- %possibly due to eye overshoot, give another chance
- dasreset(0);
- Time = 1;
- Hit = 0;
- while Time < PREFIXT && Hit == 0
- dasrun(5)
- [Hit Time] = DasCheck; %retrieve position values and plot on Control display
- end
- if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time
- dasreset(1); %test for exiting fix window
-
- Time = 1;
- Hit = 0;
- while Time < FIXT && Hit == 0
- %Check for 5 ms
- dasrun(5)
- % dasrun(5)
- [Hit Time] = DasCheck;
- end
- else
- Hit = -1; %the subject did not fixate
- end
- end
-
- else
- Hit = -1; %the subject did not fixate
- end
-
- %///////// EVENT 2 DISPLAY STIMULUS //////////////////////////////////////
- if Hit == 0 %subject kept fixation, display stimulus
- Par.Updatxy = 1;
-
- for count = 1:ncount
-
- TrialPic = all_remainings(1);
-
- dasreset(1); %test for exiting fix window
- Time = 0;
- %StimFlg = true;
- stimbitdone = 0;
- stimcorrdone = 0;
- while Time < STIMT+ITI_short && Hit == 0 %Keep fixating till target onset
-
- if Time < STIMT %present stim no longer than stim time
-
- cgdrawsprite(TrialPic,picx,picy);
- cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f'); %the red fixation dot on the screen
- drawdiode(1); %the diode cue
- if ~stimbitdone
- dasbit(Par.StimB, 1);
- stimbitdone = 1;
- %This means file will be created
- %Update counter
- end
- end
-
- %..............................................................
- if Time > STIMT %&& StimFlg %present stim no longer than stim time
- if ~stimcorrdone
- dasbit(Par.CorrectB, 1);
- Par.Corrcount = Par.Corrcount + 1;
- stimcorrdone = 1;
- end
- %StimFlg = false;
- cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f'); %the red fixation dot on the screen
- drawdiode(0); %the diode cue
- end
- cgflip(grey,grey,grey);
- %Check for 5 ms
- dasrun(2); %%%%%%%%%%%%%%% was 2
- [Hit Time] = DasCheck;
- end
- if stimbitdone
- TZ = TZ+1;
- if stimcorrdone
- ncount_done = ncount_done + 1;
- sprites_to_delete = [sprites_to_delete TrialPic];
- MAT(TZ,:) = [RANDTAB(1,:) count 1];
- if size(RANDTAB,1) == 1
- save(fn,'*');
- end
- RANDTAB(1,:) = [];
- all_remainings(1) = [];
- else
- MAT(TZ,:) = [RANDTAB(1,:) count 0];
- end
- end
- for i = [0 1 2 3 4 5 6 7] %Error, Stim, Saccade, Trial, Correct,
- dasbit(i, 0);
- end
- dasclearword;
- end
-
-
- %///////// EVENT 3 TARGET ONSET, REACTION TIME //////////////////////////////////////
- Par.Updatxy = 1;
- if Hit == 0 %subject kept fixation, subject may make an eye movement
- cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f') %the red fixation dot on the screen
- cgflip(grey,grey,grey);
- Hit = 2;
- else
- Abort = true;
- end
- %END EVENT 3
- else
- Abort = true;
- end
- %END EVENT 2
-
- for i=1:ncount_done
- p = preloaded_pics + sprites_to_delete(i);
- r_idx = preloaded_pics - ncount_done + i;
- if r_idx <= size(RANDTAB,1)
- cgfreesprite(sprites_to_delete(i))
- if RANDTAB(r_idx,2) > 0
- trl = RANDTAB(r_idx,2);
- cgloadbmp(p,train_imgs(trl).local_path);
- else
- trl = RANDTAB(r_idx,3);
- cgloadbmp(p,test_imgs(trl).local_path);
- end
- end
- end
-
- %///////// POSTTRIAL AND REWARD //////////////////////////////////////
- if Hit ~= 0 && ~Abort %has entered a target window (false or correct)
-
- if Par.Mouserun
- HP = line('XData', Par.ZOOM * (LPStat(2) + Par.MOff(1)), 'YData', Par.ZOOM * (LPStat(3) + Par.MOff(2)), 'EraseMode','none');
- else
- HP = line('XData', Par.ZOOM * LPStat(2), 'YData', Par.ZOOM * LPStat(3), 'EraseMode','none');
- end
- set(HP, 'Marker', '+', 'MarkerSize', 20, 'MarkerEdgeColor', 'm');
-
- if Hit == 2
-
- dasbit(Par.RewardB, 1);
- dasjuice(6);
- pause(Par.RewardTime); %RewardTime is in seconds
- dasjuice(0.0);
- dasbit(Par.RewardB, 0);
-
- else
-
- Hit = 0;
- end
-
- %keep following eye motion
- dasrun(5);
- DasCheck; %keep following eye motion
-
- end
-
- %///////////////////////INTERTRIAL AND CLEANUP
-
- %reset all bits to null
- for i = [0 1 2 3 4 5 6 7] %Error, Stim, Saccade, Trial, Correct,
- dasbit(i, 0);
- end
- dasclearword;
-
- %Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session
- %tracker('update_trials', gcbo, [], guidata(gcbo)) %displays number of trials, corrects and errors
- Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session
- SCNT = {'TRIALS'};
- SCNT(2) = { ['N: ' num2str(Par.Trlcount) ]};
- SCNT(3) = { ['C: ' num2str(Par.Corrcount) ] };
- SCNT(4) = { ['E: ' num2str(Par.Errcount) ] };
- set(T_Trl, 'String', SCNT ) %display updated numbers in GUI
-
-
- cgflip(grey,grey,grey)
-
- Time = 0;
- dasreset(1);
- while Time < ITI
- dasrun(5)
- [Hit Time] = DasCheck;
- end
-
- if TZ > 0
- save(fn,'LOG','MAT','RANDTAB')
- end
- end %WHILE_NOT_ESCAPED%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- if TZ > 0
- save(fn,'*')
- if logon
- save(fn_randtab,'RANDTAB')
- save(fn_randtab_hist,'RANDTAB')
- end
- end
- cogstd('sPriority','normal')
|