Example #1
0
    def loadptc15exp(self):
        ## TODO: - fake a .e dimstim.Experiment object, to replace what used to be the
        ## .stims object for movie experiments
        '''           - self.movie = self.experiment.stims[0]
                - need to convert sweeptimeMsec to sweepSec
                   - assert len(self.experiment.stims) == 1
                   - self.movie = self.experiment.stims[0]
                   - self.movie.load() # ensure the movie's data is loaded

            if self.movie.oname == 'mseq32':
                frameis = frameis[frameis != 65535] # remove all occurences of 65535
            elif self.movie.oname == 'mseq16':
                frameis = frameis[frameis != 16383] # remove all occurences of 16383
        '''
        # Add .static and .dynamic params to fake dimstim experiment
        self.e = dictattr()
        self.I = dictattr()  # fake InternalParams object
        self.e.static = dictattr()  # fake StaticParams object
        self.e.dynamic = dictattr()  # fake DynamicParams object
        # maps ptc15 param names to dimstim 0.16 param types and names, wherever possible
        ## TODO: fill in params for experiment types other than Movie??
        _15to16 = {
            'EYE': ('I', 'EYE'),
            'PIXPERCM': ('I', 'PIXPERCM'),
            'REFRESHRATE': ('I', 'REFRESHRATE'),
            'SCREENDISTANCECM': ('I', 'SCREENDISTANCECM'),
            'SCREENHEIGHT': ('I', 'SCREENHEIGHT'),
            'SCREENHEIGHTCM': ('I', 'SCREENHEIGHTCM'),
            'SCREENWIDTH': ('I', 'SCREENWIDTH'),
            'SCREENWIDTHCM': ('I', 'SCREENWIDTHCM'),
            'fname': ('static', 'fname'),
            'preexpSec': ('static', 'preexpSec'),
            'postexpSec': ('static', 'postexpSec'),
            'orioff': ('static', 'orioff'),
            'regionwidthDeg': ('static', 'widthDeg'),
            'regionheightDeg': ('static', 'heightDeg'),
            'mask': ('static', 'mask'),
            'diameterDeg': ('static', 'diameterDeg'),
            'GAMMA': ('static', 'gamma'),
            'framei': ('dynamic', 'framei'),
            'ori': ('dynamic', 'ori'),
            'polarity': ('dynamic', 'invert'),
            'bgbrightness': ('dynamic', 'bgbrightness'),
            'sweeptimeMsec': ('dynamic', 'sweepSec'),
            'postsweepMsec': ('dynamic', 'postsweepSec'),
        }

        # collect any ptc15 movie attribs and add them to self.oldparams
        try:
            # can't really handle more than 1 movie, since dimstim 0.16 doesn't
            assert len(np.unique(self.oldparams.playlist)) == 1
            # bind it, movie was the only possible stim object anyway in ptc15
            self.movie = self.oldparams.playlist[0]
            # returns dict of name:val pair attribs excluding __ and methods:
            movieparams = self.oldparams[self.movie.oname].__dict__
            self.oldparams.update(movieparams)
        except AttributeError:
            # no playlist, no movies, and therefore no movie attribs to deal with
            pass

        # convert ptc15 params to dimstim 0.16
        for oldname, val in self.oldparams.items():
            if 'msec' in oldname.lower():
                val = val / 1000.  # convert to sec
            elif oldname == 'polarity':
                val = bool(val)  # convert from 0/1 to boolean
            if oldname == 'origDeg':  # split old origDeg into new separate xposDeg and yposDeg
                self.e.dynamic.xposDeg = val[0]
                self.e.dynamic.yposDeg = val[1]
            else:
                try:
                    paramtype, newname = _15to16[oldname]
                    if paramtype == 'I':
                        # bind InternalParams directly to self, not to self.e:
                        self.I[newname] = val
                    self.e[paramtype][newname] = val
                except KeyError:  # oldname doesn't have a newname equivalent
                    pass

        try:
            m = self.movie
        except AttributeError:
            m = None

        if m:
            # make fake dimstim experiment a ptc15 Movie object, bind all of the attribs of
            # the existing fake dimstim experiment
            old_e = self.e
            self.e = m
            for name, val in old_e.__dict__.items():
                # bind each variable in the textheader as an attrib of self
                self.e.__setattr__(name, val)
            # deal with movie filename:
            # didn't have a chance to pass this exp as the parent in the movie init,
            # so just set the attribute manually:
            m.e = self
            # if fname refers to a movie whose local name is different, rename it to match
            # the local movie name
            old2new = {'mseq16.m': 'MSEQ16', 'mseq32.m': 'MSEQ32'}
            try:
                m.fname = old2new[m.fname]
            except KeyError:
                pass  # old name not in old2new, leave it be
            self.e.static.fname = m.fname  # update fake dimstim experiment's fname too
            # extensionless fname, fname should've been defined in the textheader
            m.name = os.path.splitext(m.fname)[0]
            uns = get_ipython().user_ns
            if m.name not in uns['MOVIES']:
                # and it very well may not be, cuz the textheader inits movies with no args,
                # leaving fname==None at first, which prevents it from being added to
                # MOVIES
                uns['MOVIES'][m.name] = m  # add m to MOVIES dictattr
            # Search self.e.moviepath string (from textheader) for 'Movies' word. Everything
            # after that is the relative path to your base movies folder. Eg, if
            # self.e.moviepath = 'C:\\Desktop\\Movies\\reliability\\e\\single\\', then set
            # self.e.relpath = '\\reliability\\e\\single\\'
            spath = self.oldparams.moviepath.split(
                '\\')  # ptc15 has purely MS path separators
            matchi = spath.index('Movies')
            relpath = joinpath(spath[matchi + 1::])
            MOVIEPATH = get_ipython().user_ns['MOVIEPATH']
            path = os.path.join(MOVIEPATH, relpath)
            m.fname = os.path.join(path, m.fname)
            self.e.static.fname = m.fname  # update
        try:
            self.REFRESHTIME = intround(1 / float(self.oldparams.REFRESHRATE) *
                                        1000000)  # us
        except AttributeError:
            pass
Example #2
0
    def loadCat15exp(self):
        ## TODO: - fake a .e dimstim.Experiment object, to replace what used to be the
        ## .stims object for movie experiments
        '''           - self.movie = self.experiment.stims[0]
                - need to convert sweeptimeMsec to sweepSec
                   - assert len(self.experiment.stims) == 1
                   - self.movie = self.experiment.stims[0]
                   - self.movie.load() # ensure the movie's data is loaded

            if self.movie.oname == 'mseq32':
                frameis = frameis[frameis != 65535] # remove all occurences of 65535
            elif self.movie.oname == 'mseq16':
                frameis = frameis[frameis != 16383] # remove all occurences of 16383
        '''
        # Add .static and .dynamic params to fake dimstim experiment
        self.e = dictattr()
        self.I = dictattr() # fake InternalParams object
        self.e.static = dictattr() # fake StaticParams object
        self.e.dynamic = dictattr() # fake DynamicParams object
        # maps Cat 15 param names to dimstim 0.16 param types and names, wherever possible
        ## TODO: fill in params for experiment types other than Movie??
        _15to16 = {'EYE': ('I', 'EYE'),
                   'PIXPERCM': ('I', 'PIXPERCM'),
                   'REFRESHRATE': ('I', 'REFRESHRATE'),
                   'SCREENDISTANCECM': ('I', 'SCREENDISTANCECM'),
                   'SCREENHEIGHT': ('I', 'SCREENHEIGHT'),
                   'SCREENHEIGHTCM': ('I', 'SCREENHEIGHTCM'),
                   'SCREENWIDTH': ('I', 'SCREENWIDTH'),
                   'SCREENWIDTHCM': ('I', 'SCREENWIDTHCM'),

                   'fname': ('static', 'fname'),
                   'preexpSec': ('static', 'preexpSec'),
                   'postexpSec': ('static', 'postexpSec'),
                   'orioff': ('static', 'orioff'),
                   'regionwidthDeg': ('static', 'widthDeg'),
                   'regionheightDeg': ('static', 'heightDeg'),
                   'mask': ('static', 'mask'),
                   'diameterDeg': ('static', 'diameterDeg'),
                   'GAMMA': ('static', 'gamma'),

                   'framei': ('dynamic', 'framei'),
                   'ori': ('dynamic', 'ori'),
                   'polarity': ('dynamic', 'invert'),
                   'bgbrightness': ('dynamic', 'bgbrightness'),
                   'sweeptimeMsec': ('dynamic', 'sweepSec'),
                   'postsweepMsec': ('dynamic', 'postsweepSec'),
                   }

        # collect any Cat 15 movie attribs and add them to self.oldparams
        try:
            # can't really handle more than 1 movie, since dimstim 0.16 doesn't
            assert len(np.unique(self.oldparams.playlist)) == 1
            # bind it, movie was the only possible stim object anyway in Cat 15
            self.movie = self.oldparams.playlist[0]
            # returns dict of name:val pair attribs excluding __ and methods:
            movieparams = self.oldparams[self.movie.oname].__dict__
            self.oldparams.update(movieparams)
        except AttributeError:
            # no playlist, no movies, and therefore no movie attribs to deal with
            pass

        # convert Cat 15 params to dimstim 0.16
        for oldname, val in self.oldparams.items():
            if 'msec' in oldname.lower():
                val = val / 1000. # convert to sec
            elif oldname == 'polarity':
                val = bool(val) # convert from 0/1 to boolean
            if oldname == 'origDeg': # split old origDeg into new separate xposDeg and yposDeg
                self.e.dynamic.xposDeg = val[0]
                self.e.dynamic.yposDeg = val[1]
            else:
                try:
                    paramtype, newname = _15to16[oldname]
                    if paramtype == 'I':
                        # bind InternalParams directly to self, not to self.e:
                        self.I[newname] = val
                    self.e[paramtype][newname] = val
                except KeyError: # oldname doesn't have a newname equivalent
                    pass

        try:
            m = self.movie
        except AttributeError:
            m = None

        if m:
            # make fake dimstim experiment a Cat15Movie object, bind all of the attribs of
            # the existing fake dimstim experiment
            old_e = self.e
            self.e = m
            for name, val in old_e.__dict__.items():
                # bind each variable in the textheader as an attrib of self
                self.e.__setattr__(name, val)
            # deal with movie filename:
            # didn't have a chance to pass this exp as the parent in the movie init,
            # so just set the attribute manually:
            m.e = self
            # if fname refers to a movie whose local name is different, rename it to match
            # the local movie name
            _old2new = {'mseq16.m': MSEQ16, 'mseq32.m': MSEQ32}
            try:
                m.fname = _old2new[m.fname]
            except KeyError:
                pass # old name not in _old2new, leave it be
            self.e.static.fname = m.fname # update fake dimstim experiment's fname too
            # extensionless fname, fname should've been defined in the textheader
            m.name = os.path.splitext(m.fname)[0]
            if m.name not in _MOVIES:
                # and it very well may not be, cuz the textheader inits movies with no args,
                # leaving fname==None at first, which prevents it from being added to
                # _MOVIES
                _MOVIES[m.name] = m # add m to _MOVIES dictattr
            # Search self.e.moviepath string (from textheader) for 'Movies' word. Everything
            # after that is the relative path to your base movies folder. Eg, if
            # self.e.moviepath = 'C:\\Desktop\\Movies\\reliability\\e\\single\\', then set
            # self.e.relpath = '\\reliability\\e\\single\\'
            spath = self.oldparams.moviepath.split('\\') # Cat15 has purely windows seperators
            matchi = spath.index('Movies')
            relpath = joinpath(spath[matchi+1 ::])
            MOVIEPATH = get_ipython().user_ns['MOVIEPATH']
            path = os.path.join(MOVIEPATH, relpath)
            m.fname = os.path.join(path, m.fname)
            self.e.static.fname = m.fname # update

            # Generate the sweeptable:
            # dict of lists, ie sweeptable={'ori':[0,45,90], 'sfreq':[1,1,1]}, so you index
            # into it with self.sweeptable['var'][sweepi]
            #self.sweeptable = {[]}
            #vars = self.sweeptable.keys()
            # need to check if varlist exists, if so use it (we're dealing with Cat 15),
            # if not, use revamped dimstim.SweepTable class
            varvals = {} # init a dictionary that will contain variable values
            for var in m.varlist:
                # generate dict with var:val entries, to pass to buildSweepTable
                varvals[var] = eval('m.' + var)
            # pass varlist by reference, dim indices end up being modified:
            m.sweepTable = self.buildCat15SweepTable(m.varlist, varvals, m.nruns,
                                                     m.shuffleRuns, m.blankSweep,
                                                     m.shuffleBlankSweeps,
                                                     makeSweepTableText=0)[0]
        else: # this is a simple stim (not object oriented movie)
            varvals = {} # init a dictionary that will contain variable values
            for var in self.oldparams.varlist:
                # generate dict with var:val entries, to pass to buildSweepTable
                varvals[var] = eval('self.oldparams.' + var)
            # pass varlist by reference, dim indices end up being modified:
            self.sweepTable = self.buildCat15SweepTable(self.oldparams.varlist, varvals,
                                                        self.oldparams.nruns,
                                                        self.oldparams.shuffleRuns,
                                                        self.oldparams.blankSweep,
                                                        self.oldparams.shuffleBlankSweeps,
                                                        makeSweepTableText=0)[0]
        try:
            self.REFRESHTIME = intround(1 / float(self.oldparams.REFRESHRATE) * 1000000) # us
        except AttributeError:
            pass