Changeset 95

Show
Ignore:
Timestamp:
06/07/07 09:54:45 (1 year ago)
Author:
apdavison
Message:

* Reinstated the ID.set() method, as this allows setting multiple parameters at once, which is not possible with __setattr()__.

  • Wrote/fixed a few unit tests.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/improved-ID/common.py

    r94 r95  
    5858            object.__setattr__(self,name,value) 
    5959        else: 
    60             return _abstractMethod(self
     60            return self.set(**{name:value}
    6161 
    6262    def _set_cellclass(self, cellclass): 
     
    6868    def _get_cellclass(self): 
    6969        if self.parent: 
    70             return self.parent.celltype 
     70            return self.parent.celltype.__class__ 
    7171        else: 
    7272            return self._cellclass 
     
    9696    position = property(_get_position, _set_position) 
    9797 
     98    def set(self,**parameters): 
     99        """Set cell parameters, given as a sequence of parameter=value arguments.""" 
     100        return _abstractMethod(self) 
    98101 
    99102# ============================================================================== 
  • branches/improved-ID/nest.py

    r94 r95  
    3939        return pynest.getDict([int(self)])[0][translated_name] 
    4040     
    41     def set(self,param,val=None): 
     41    def set(self,**parameters): 
    4242        # We perform a call to the low-level function set() of the API. 
    4343        # If the cellclass is not defined in the ID object : 
    44         if (self._cellclass == None): 
     44        if (self.cellclass == None): 
    4545            raise Exception("Unknown cellclass") 
    4646        else: 
    4747            # We use the one given by the user 
    48             set(self,self._cellclass,param,val) 
     48            set(self, self.cellclass, parameters)  
    4949 
    5050 
     
    294294    giving the parameter name, in which case val is the parameter value. 
    295295    cellclass must be supplied for doing translation of parameter names.""" 
    296          
     296    # we should just assume that cellclass has been defined and raise an Exception if it has not 
    297297    if val: 
    298298        param = {param:val} 
     
    891891        population is scaled to the size of the source population.""" 
    892892        dist = 0.0 
    893         src_position = src.getPosition() 
    894         tgt_position = tgt.getPosition() 
     893        src_position = src.position 
     894        tgt_position = tgt.position 
    895895        if (len(src_position) == len(tgt_position)): 
    896896            for i in xrange(len(src_position)): 
  • branches/improved-ID/test/nesttests.py

    r86 r95  
    482482        #assert (self.target33[0,2].get('tau_m') == 15.1) 
    483483         
    484     def testSetAndGetPositionID(self): 
    485         # Small test to see if the position of the ID class is working 
    486         self.target33[0,2].setPosition((0.5,1.5)) 
    487         assert (self.target33[0,2].getPosition() == (0.5,1.5)) 
    488          
    489484    def testrandomizeWeights(self): 
    490485        # The probability of having two consecutive weights vector that are equal should be 0 
     
    517512        nest.setup(max_delay=0.5) 
    518513        nest.Population.nPop = 0 
    519         self.pop = nest.Population((5,),nest.IF_curr_alpha,{'tau_m':10.0}) 
    520      
    521     def testIDSet(self): 
    522         self.pop[3].set('tau_m',20.0) 
    523         ifcell_params = nest.pynest.getDict([self.pop[3]])[0] 
     514        self.pop1 = nest.Population((5,),nest.IF_curr_alpha,{'tau_m':10.0}) 
     515        self.pop2 = nest.Population((5,4),nest.IF_curr_exp,{'v_reset':-60.0}) 
     516     
     517    def testIDSetAndGet(self): 
     518        self.pop1[3].tau_m = 20.0 
     519        self.pop2[3,2].v_reset = -70.0 
     520        ifcell_params = nest.pynest.getDict([self.pop1[3]])[0] 
    524521        self.assertEqual(20.0, ifcell_params['Tau']) 
    525         ifcell_params = nest.pynest.getDict([self.pop[1]])[0] 
    526         self.assertEqual(10.0, ifcell_params['Tau']) 
     522        self.assertEqual(20.0, self.pop1[3].tau_m) 
     523        self.assertEqual(10.0, self.pop1[0].tau_m) 
     524        self.assertEqual(-70.0, self.pop2[3,2].v_reset) 
     525        self.assertEqual(-60.0, self.pop2[0,0].v_reset) 
     526 
     527    def testGetCellClass(self): 
     528        self.assertEqual(nest.IF_curr_alpha, self.pop1[0].cellclass) 
     529        self.assertEqual(nest.IF_curr_exp, self.pop2[4,3].cellclass) 
     530         
     531    def testSetAndGetPosition(self): 
     532        self.assert_((self.pop2[0,2].position == (0.0,2.0,0.0)).all()) 
     533        new_pos = (0.5,1.5,0.0) 
     534        self.pop2[0,2].position = new_pos 
     535        self.assert_((self.pop2[0,2].position == (0.5,1.5,0.0)).all()) 
     536        new_pos = (-0.6,3.5,-100.0) # check that position is set-by-value from new_pos 
     537        self.assert_((self.pop2[0,2].position == (0.5,1.5,0.0)).all()) 
     538 
    527539 
    528540if __name__ == "__main__":