Beispiel #1
0
    def _register_item(self, item, name):
        "adds item to experiment and returns unique id"
        # check name
        test = name.format(i=0, c='x', p='x')
        test_attr_name(test)
        
        # format name
        if '{c}' in name:
            name = name.format(i='{i}', c=item.__class__.__name__)
        if '{i}' in name:
            i = 0
            while hasattr(self, name.format(i=i)):
                i += 1
            name = name.format(i=i)
        else:
            if hasattr(self, name):
                raise ValueError("Experiment already has attribute named %r"
                                 % name)
        
        setattr(self, name, item)

        # get ID
        ID = max(set([-1]).union(self._itemIDs)) + 1
        self._itemIDs.add(ID)
        self._item_names[ID] = name
        
        return ID, name
Beispiel #2
0
 def rename_item(self, item, name):
     "rename an ExperimentItem"
     if hasattr(self, name):
         raise ValueError("Experiment already has an attribute named %r" % name)
     else:
         test_attr_name(name)
     
     delattr(self, item.name)
     setattr(self, name, item)
     setattr(item, 'name', name)
Beispiel #3
0
 def __setitem__(self, chan, value):
     chan = self._key_from_index(chan)
     
     # fill tuple
     if isinstance(value, basestring):
         value = (value, 'uts')
     while len(value) < 4:
         value = value + (None,)
     
     # check properties
     name, conversion, arg1, arg2 = value
     test_attr_name(name)
     assert conversion in ['uts', 'evt', 'topo']
     if conversion == 'evt':
         if arg1 is not None:
             assert np.isscalar(arg1)
         if arg2 is not None:
             assert np.iterable(arg2)
     elif conversion =='topo':
         assert isinstance(chan, tuple)
         if arg1 is not None:
             n_s = arg1.n
             start, stop = chan
             if start == None:
                 start = 0
             if stop == None:
                 stop = self._n
             
             n_chan = stop - start
             if n_chan != n_s:
                 raise ValueError("Number of Channels mismatch between "
                                  "Channel selection (%i) and sensor Net "
                                  "(%i)" % (n_chan, n_s))
     
     # set new value
     self._value[chan] = value
     self._changed()