Exemple #1
0
    def load(self):
        f = open(self.path, 'rb')
        self.din = np.fromfile(f, dtype=np.int64).reshape(-1, 2) # reshape to nrows x 2 cols
        f.close()
        try:
            txthdrpath = rstrip(self.path, '.din') + '.textheader'
            f = open(txthdrpath, 'rU') # use universal newline support
            self.textheader = f.read() # read it all in
            f.close()
        except IOError:
            warn("couldn't load text header associated with '%s'" % self.name)
            self.textheader = '' # set to empty

        treestr = self.level*TAB + self.name + '/'
        # print string to tree hierarchy and screen
        self.writetree(treestr + '\n')
        print(treestr)

        if self.textheader != '':
            # comment out all lines starting with "from dimstim"
            self.textheader = self.textheader.replace('from dimstim', '#from dimstim')
            names1 = locals().copy() # namespace before execing the textheader
            exec(self.textheader)
            names2 = locals().copy() # namespace after
            # names that were added to the namespace, excluding the 'names1' name itself:
            newnames = [ n2 for n2 in names2 if n2 not in names1 and n2 != 'names1' ]
            try:
                # dimstim up to Cat 15 didn't have a version, neither did NVS display
                self.__version__ = eval('__version__')
            except NameError:
                self.__version__ = 0.0
            if self.__version__ >= 0.16: # after major refactoring of dimstim
                for newname in newnames:
                    # bind each variable in the textheader as an attrib of self
                    self.__setattr__(newname, eval(newname))
                self.sweeptable = SweepTable(experiment=self.e) # build the sweep table
                self.st = self.sweeptable.data # synonym, used a lot by experiment subclasses
                # this doesn't work for textheaders generated by dimstim 0.16, since
                # xorigDeg and yorigDeg were accidentally omitted from all the experiment
                # scripts and hence the textheaders too:
                '''
                self.e.xorig = deg2pix(self.e.static.xorigDeg, self.I) + self.I.SCREENWIDTH / 2
                self.e.yorig = deg2pix(self.e.static.yorigDeg, self.I) + self.I.SCREENHEIGHT / 2
                '''
                self.REFRESHTIME = intround(1 / float(self.I.REFRESHRATE) * 1000000) # us
                # prevent replication of movie frame data in memory
                if type(self.e) == Movie:
                    fname = os.path.split(self.e.static.fname)[-1] # pathless fname
                    if fname not in _MOVIES:
                        # add movie experiment, indexed according to movie data file name,
                        # to prevent from ever loading its frames more than once
                        _MOVIES[fname] = e
            else:
                self.oldparams = dictattr()
                for newname in newnames:
                    # bind each variable in the textheader to oldparams
                    self.oldparams[newname] = eval(newname)
                self.loadCat15exp()
        else:
            # use the time difference between the first two din instead
            self.REFRESHTIME = self.din[1, 0] - self.din[0, 0]

        # add an extra refresh time after last din, that's when screen actually turns off
        self.trange = (self.din[0, 0], self.din[-1, 0] + self.REFRESHTIME)
Exemple #2
0
    def load_din(self):
        self.din = np.fromfile(self.path,
                               dtype=np.int64).reshape(-1,
                                                       2)  # reshape to 2 cols
        # look for a .textheader:
        try:
            txthdrpath = rstrip(self.path, '.din') + '.textheader'
            f = open(txthdrpath, 'rU')  # use universal newline support
            self.textheader = f.read()  # read it all in
            f.close()
        except IOError:
            print("WARNING: couldn't load text header associated with '%s'" %
                  self.name)
            self.textheader = ''  # set to empty

        if self.textheader != '':
            # comment out all lines starting with "from dimstim"
            self.textheader = self.textheader.replace('from dimstim',
                                                      '#from dimstim')
            # execute any remaining 'import' lines first, so that any modules imported
            # aren't artefactually detected as having been added to the namespace:
            for line in self.textheader.splitlines():
                if line.startswith('import'):
                    exec(line)
            thns = {}  # textheader namespace
            # compiling to code and then executing it is supposed to be faster than directly
            # executing a string, according to
            # http://lucumr.pocoo.org/2011/2/1/exec-in-python/, but doesn't seem to make
            # a difference here:
            code = compile(self.textheader, "<string>", "exec")
            # don't exec in current namespace, load name:val pairs into thns instead:
            exec(code, None, thns)
            try:
                # dimstim up to ptc15 didn't have a version, neither did NVS display
                self.__version__ = thns['__version__']  # a string
            except KeyError:
                self.__version__ = '0.0'
            if float(self.__version__
                     ) >= 0.16:  # after major refactoring of dimstim
                for name, val in thns.items():
                    # bind each variable in the textheader as an attrib of self
                    self.__setattr__(name, val)
                # this doesn't work for textheaders generated by dimstim 0.16, since
                # xorigDeg and yorigDeg were accidentally omitted from all the experiment
                # scripts and hence the textheaders too:
                '''
                self.e.xorig = deg2pix(self.e.static.xorigDeg, self.I) + self.I.SCREENWIDTH / 2
                self.e.yorig = deg2pix(self.e.static.yorigDeg, self.I) + self.I.SCREENHEIGHT / 2
                '''
                self.REFRESHTIME = intround(1 / float(self.I.REFRESHRATE) *
                                            1000000)  # us
                # prevent replication of movie frame data in memory
                if type(self.e) == Movie:
                    fname = os.path.split(
                        self.e.static.fname)[-1]  # pathless fname
                    uns = get_ipython().user_ns
                    if fname not in uns['MOVIES']:
                        # add movie experiment, indexed according to movie data file name,
                        # to prevent from ever loading its frames more than once
                        uns['MOVIES'][fname] = self.e
            else:
                self.oldparams = dictattr()
                for name, val in thns.items():
                    # bind each variable in the textheader to oldparams
                    self.oldparams[name] = val
                self.loadptc15exp()
        else:
            # use the time difference between the first two din instead
            self.REFRESHTIME = self.din[1, 0] - self.din[0, 0]

        # add an extra refresh time after last din, that's when screen actually turns off
        self.trange = (self.din[0, 0], self.din[-1, 0] + self.REFRESHTIME)
Exemple #3
0
    def load(self):
        f = open(self.path, 'rb')
        self.din = np.fromfile(f, dtype=np.int64).reshape(-1, 2) # reshape to 2 cols
        f.close()
        try:
            txthdrpath = rstrip(self.path, '.din') + '.textheader'
            f = open(txthdrpath, 'rU') # use universal newline support
            self.textheader = f.read() # read it all in
            f.close()
        except IOError:
            print("WARNING: couldn't load text header associated with '%s'" % self.name)
            self.textheader = '' # set to empty

        treestr = self.level*TAB + self.name + '/'
        # print string to tree hierarchy and screen
        self.writetree(treestr + '\n')
        print(treestr)

        if self.textheader != '':
            # comment out all lines starting with "from dimstim"
            self.textheader = self.textheader.replace('from dimstim', '#from dimstim')
            # execute any remaining 'import' lines first, so that any modules imported
            # aren't artefactually detected as having been added to the namespace:
            for line in self.textheader.splitlines():
                if line.startswith('import'):
                    exec(line)
            thns = {} # textheader namespace
            # compiling to code and then executing that is supposed to be faster than directly
            # executing a string, according to
            # http://lucumr.pocoo.org/2011/2/1/exec-in-python/, but doesn't seem to make
            # a difference here:
            code = compile(self.textheader, "<string>", "exec")
            # don't exec in current namespace, load name:val pairs into thns instead:
            exec(code, None, thns)
            try:
                # dimstim up to ptc15 didn't have a version, neither did NVS display
                self.__version__ = thns['__version__']
            except KeyError:
                self.__version__ = 0.0
            if self.__version__ >= 0.16: # after major refactoring of dimstim
                for name, val in thns.items():
                    # bind each variable in the textheader as an attrib of self
                    self.__setattr__(name, val)
                # this doesn't work for textheaders generated by dimstim 0.16, since
                # xorigDeg and yorigDeg were accidentally omitted from all the experiment
                # scripts and hence the textheaders too:
                '''
                self.e.xorig = deg2pix(self.e.static.xorigDeg, self.I) + self.I.SCREENWIDTH / 2
                self.e.yorig = deg2pix(self.e.static.yorigDeg, self.I) + self.I.SCREENHEIGHT / 2
                '''
                self.REFRESHTIME = intround(1 / float(self.I.REFRESHRATE) * 1000000) # us
                # prevent replication of movie frame data in memory
                if type(self.e) == Movie:
                    fname = os.path.split(self.e.static.fname)[-1] # pathless fname
                    uns = get_ipython().user_ns
                    if fname not in uns['MOVIES']:
                        # add movie experiment, indexed according to movie data file name,
                        # to prevent from ever loading its frames more than once
                        uns['MOVIES'][fname] = self.e
            else:
                self.oldparams = dictattr()
                for name, val in thns.items():
                    # bind each variable in the textheader to oldparams
                    self.oldparams[name] = val
                self.loadptc15exp()
        else:
            # use the time difference between the first two din instead
            self.REFRESHTIME = self.din[1, 0] - self.din[0, 0]

        # add an extra refresh time after last din, that's when screen actually turns off
        self.trange = (self.din[0, 0], self.din[-1, 0] + self.REFRESHTIME)

        # these are static, no need for properties:
        self.dt = self.trange[1] - self.trange[0] # duration (us)
        self.dtsec = self.dt / 1e6
        self.dtmin = self.dtsec / 60
        self.dthour = self.dtmin / 60