예제 #1
0
 def logmeta(self):
     """Logs everything important to C:\ExperimentData\ """
     dir = "C:\\ExperimentData\\" + self.static.expid + "\\"
     file = "sweep.log"
     path = os.path.join(dir, file)
     log = ailogger(path)
     log.add(script = self.script)
     log.add(logpath = log.fullPath)
     log.comment(' --------------------Header-------------------------- ')
     log.add(header = str(self.header.text))
     log.comment(' --------------------Timestamps---------------------- ')
     log.add(startdatetime = self.startdatetime)
     log.add(stoptdateime = self.stopdatetime)
     log.add(starttime = self.starttime)
     log.add(stoptime = self.stoptime)
     log.add(durationexpected = isotime(self.sec, 6))
     log.add(durationactual = isotime(self.stoptime-self.starttime,6))
     log.comment(' --------------------Parameters---------------------- ')
     log.add(staticparams = self.static)
     log.add(dynamicparams = self.dynamic)
     #log.add(variables = self.variables)  #needs _repr_ methon in Core.Variables class
     log.add(sweeporder = self.sweeptable.i.tolist())
     log.add(sweeptable = npdict2listdict(self.sweeptable.data))
     log.add(sweeptableformatted = self.sweeptable._pprint())
     log.comment( ' -------------------Dimstim Performance Data-------- ')
     log.add(vsynctable = self.vsynctimer.pprint())
     log.add(vsyncsdisplayed = self.nvsyncsdisplayed)
     log.add(sweepscompleted = self.ii)
     log.add(droppedframes = self.vsynctimer.drops)
     log.close()
예제 #2
0
    def build(self):
        """Builds the SweepTable and the Header for this Experiment"""
        # Build the sweep table
        self.sweeptable = Core.SweepTable(experiment=self)
        self.st = self.sweeptable.data # synonym, used a lot by Experiment subclasses

        # Do time and space conversions of applicable static and dynamic parameters - or maybe do this in init - is this really necessary, can't it be done on the fly, or would that be too slow? If too slow, write it inline in C and use scipy.weave?
        # Is there a better place to store these, rather than polluting self namespace?
        self.xorig = deg2pix(self.static.xorigDeg) + I.SCREENWIDTH / 2 # do this once, since it's static, save time in main loop
        self.yorig = deg2pix(self.static.yorigDeg) + I.SCREENHEIGHT / 2
        self.y = self.static.ypos
        self.x = self.xorig
        self.offscreen = self.off_screen_distance(self.static.terrain.orientation)
        self.encDeg = self.static.encoder.getDegrees()
        
        # Calculate Experiment duration
        self.sec = self.calcduration()
        info('Expected experiment duration: %s' % isotime(self.sec, 6), tolog=False)
예제 #3
0
    def build(self):
        """Builds the SweepTable and the Header for this Experiment"""
        # Build the sweep table
        self.sweeptable = Core.SweepTable(experiment=self)
        self.st = self.sweeptable.data # synonym, used a lot by Experiment subclasses

        # Do time and space conversions of applicable static and dynamic parameters - or maybe do this in init - is this really necessary, can't it be done on the fly, or would that be too slow? If too slow, write it inline in C and use scipy.weave?
        # Is there a better place to store these, rather than polluting self namespace?
        self.xorig = deg2pix(self.static.xorigDeg) + I.SCREENWIDTH / 2 # do this once, since it's static, save time in main loop
        self.yorig = deg2pix(self.static.yorigDeg) + I.SCREENHEIGHT / 2

        # Calculate Experiment duration
        self.sec = self.calcduration()
        info('Expected experiment duration: %s' % isotime(self.sec, 6), tolog=False)

        # Build the Surf file header, the NVS header, and the text header
        self.header = Core.Header(experiment=self)
        info('TextHeader.data:', toscreen=False)
        printf2log(str(self.header.text)) # print text header data to log
예제 #4
0
    def run(self):
        """Run the experiment"""

        # Check it first
        self.check()

        info('Running Experiment script: %s' % self.script)

        # Build the SweepTable and the Header
        self.build()

        self.setgamma(self.static.gamma)

        # Init OpenGL graphics screen
        self.screen = ve.Core.get_default_screen()

        # Create VisionEgg stimuli objects, defined by each specific subclass of Experiment
        self.createstimuli()

        # Create a VisionEgg Viewport
        self.viewport = ve.Core.Viewport(screen=self.screen, stimuli=self.stimuli)

        self.initbackgroundcolor()

        self.fix1stsweeplag() # 1st sweep lag hacks

        # Create the VsyncTimer
        self.vsynctimer = Core.VsyncTimer()

        # Prepare IODAQ
        try:
            self.dOut = DigitalOutput('Dev1')  # device should be read from a config file
            self.dOut.StartTask()
            self.ni = True
        except:
            self.ni = False
            print "NIDAQ could not be initialized! No frame/sweep data will be output."

        self.sweepBit = 0
        self.frameBit = 1
        
        # Events (quit/pause etc)
        self.quit = False # init quit signal
        self.pause = False # init pause signal
        self.paused = False # remembers whether this experiment has been paused
        self.nvsyncsdisplayed = 0 # nvsyncs seen by Surf

        # time-critical stuff starts here
        self.sync2vsync(nswaps=2) # sync up to vsync signal, ensures that all following swap_buffers+glFlush call pairs return on the vsync

        self.startdatetime = datetime.datetime.now()
        self.starttime = time.clock() # precision timestamp

        # Do pre-experiment delay
        self.staticscreen(nvsyncs=sec2intvsync(self.static.preexpSec))

        # Run the main stimulus loop, defined by each specific subclass of Experiment
        self.main()

        # Do post-experiment delay
        self.staticscreen(nvsyncs=sec2intvsync(self.static.postexpSec))

        self.stoptime = time.clock() # precision timestamp
        self.stopdatetime = datetime.datetime.now()
        # time-critical stuff ends here

        if self.ni:
            self.dOut.WriteBit(self.sweepBit, 0) #ensure sweep bit is low
            self.dOut.WriteBit(self.frameBit, 0) #ensure frame bit is low
            self.dOut.ClearTask() #clear NIDAQ
        
        # Close OpenGL graphics screen (necessary when running from Python interpreter)
        self.screen.close()

        # Print messages to VisionEgg log and to screen
        info(self.vsynctimer.pprint())
        info('%d vsyncs displayed, %d sweeps completed' % (self.nvsyncsdisplayed, self.ii))
        info('Experiment duration: %s expected, %s actual' % (isotime(self.sec, 6), isotime(self.stoptime-self.starttime, 6)))
        if self.paused:
            warning('dimstim was paused at some point')
        if self.quit:
            warning('dimstim was interrupted before completion')
        else:
            info('dimstim completed successfully\n')
        printf2log('SWEEP ORDER: \n' + str(self.sweeptable.i.tolist()) + '\n')
        printf2log('SWEEP TABLE: \n' + self.sweeptable._pprint(None) + '\n')
        printf2log('\n' + '-'*80 + '\n') # add minuses to end of log to space it out between sessions
        
        # Log relevent objects to file.
        self.logmeta()
예제 #5
0
    def run(self):
        """Run the experiment"""

        # Check it first
        self.check()

        info('Running Experiment script: %s' % self.script)

        # Build the SweepTable and the Header
        self.build()

        self.setgamma(self.static.gamma)

        # Init OpenGL graphics screen
        self.screen = ve.Core.get_default_screen()

        # Create VisionEgg stimuli objects, defined by each specific subclass of Experiment
        self.createstimuli()

        # Create a VisionEgg Viewport
        self.viewport = ve.Core.Viewport(screen=self.screen, stimuli=self.stimuli)

        self.initbackgroundcolor()

        self.fix1stsweeplag() # 1st sweep lag hacks

        # Create the VsyncTimer
        self.vsynctimer = Core.VsyncTimer()
        
        self.quit = False # init quit signal
        self.pause = False # init pause signal
        self.paused = False # remembers whether this experiment has been paused
        self.nvsyncsdisplayed = 0 # nvsyncs seen by Surf

        # time-critical stuff starts here
        self.sync2vsync(nswaps=2) # sync up to vsync signal, ensures that all following swap_buffers+glFlush call pairs return on the vsync

        self.startdatetime = datetime.datetime.now()
        self.starttime = time.clock() # precision timestamp

        # Do pre-experiment delay
        self.staticscreen(nvsyncs=sec2intvsync(self.static.preexpSec))

        # Run the main stimulus loop, defined by each specific subclass of Experiment
        self.main()

        # Do post-experiment delay
        self.staticscreen(nvsyncs=sec2intvsync(self.static.postexpSec))

        self.stoptime = time.clock() # precision timestamp
        self.stopdatetime = datetime.datetime.now()
        # time-critical stuff ends here
        
        # Close OpenGL graphics screen (necessary when running from Python interpreter)
        self.screen.close()

        # Print messages to VisionEgg log and to screen
        info(self.vsynctimer.pprint())
        info('%d vsyncs displayed, %d sweeps completed' % (self.nvsyncsdisplayed, self.ii))
        info('Experiment duration: %s expected, %s actual' % (isotime(self.sec, 6), isotime(self.stoptime-self.starttime, 6)))
        
        print "Logging Data..."
        self.logmeta()
        print "Logging Completed."
예제 #6
0
    def run(self, caption='Manual bar'):
        """Run the experiment"""
        info('Running Experiment script: %s' % self.script)

        # Init OpenGL graphics windows, one window per requested screen
        platform = pyglet.window.get_platform()
        display = platform.get_default_display()
        self.screens = display.get_screens()
        self.screens = self.screens[:self.nscreens] # keep the first nscreens requested
        self.nscreens = len(self.screens) # update
        self.flashvsyncs = intround(self.flashvsyncs / self.nscreens) # normalize by number of screens to flip in each loop in main()
        self.wins = []
        for screeni, screen in enumerate(self.screens):
            # make all screens fullscreen, except for the first (user) screen
            if screeni == 0:
                win = Window(screen=screen, fullscreen=False, frameless=False)
                win.win.set_location((screen.width - win.win.width)//2,
                                     (screen.height - win.win.height)//2)
                win.win.set_caption(caption)
            else:
                win = Window(screen=screen, fullscreen=True)
            win.win.set_exclusive_mouse(False)
            self.wins.append(win)

        self.setgamma(self.params.gamma)

        # Create VisionEgg stimuli objects, defined by each specific subclass of Experiment
        self.createstimuli()

        # Create viewport(s) with varying stimuli
        self.viewports = []
        for wini, win in enumerate(self.wins):
            if wini == 0:
                self.viewports.append(ve.Core.pyglet_Viewport(window=win, stimuli=self.all_stimuli))
            else:
                self.viewports.append(ve.Core.pyglet_Viewport(window=win, stimuli=self.basic_stimuli))
        self.loadManbar(0) # load settings from Manbar0
        self.bgp.color = self.bgbrightness, self.bgbrightness, self.bgbrightness, 1.0

        # Create the VsyncTimer
        self.vsynctimer = Core.VsyncTimer()
        '''
        # Hack to fix pygame jumping mouse bug in fullscreen mode
        # mousemotion event happens on startup, and then once more due to bug
        for i in range(2):
            pygame.event.peek(pl.MOUSEMOTION)
        pygame.mouse.set_pos(self.x, I.SCREENHEIGHT - 1 - self.y) # set that sucker
        '''
        self.attach_handlers()

        self.nvsyncsdisplayed = 0 # nvsyncs seen by Surf

        self.startdatetime = datetime.datetime.now()
        self.starttime = time.clock() # precision timestamp

        # Run the main stimulus loop, defined by each specific subclass of Experiment
        self.main()

        self.stoptime = time.clock() # precision timestamp
        self.stopdatetime = datetime.datetime.now()

        # Close OpenGL graphics windows (necessary when running from Python interpreter)
        self.wins[0].restore_gamma_ramps() # only needs to be done once
        for win in self.wins:
            win.close()

        #Turn off rotary encoder
        self.encoder.clear()
        
        #Turn off reward
        self.reward.stop()
        self.reward.clear()

        # Print messages to VisionEgg log and to screen
        info(self.vsynctimer.pprint(), toscreen=self.printhistogram, tolog=self.printhistogram)
        info('%d vsyncs displayed' % self.nvsyncsdisplayed)
        info('Experiment duration: %s' % isotime(self.stoptime-self.starttime, 6))
        printf2log('\n' + '-'*80 + '\n') # add minuses to end of log to space it out between sessions
        
        self.logmeta()