Example #1
0
    def test_GetChildren(self):
        """GetChildren"""

        nest.ResetKernel()
        model = 'iaf_neuron'
        l = nest.LayoutNetwork(model, [2, 3])
        topKids = [2, 6]
        kids2 = [3, 4, 5]
        kids6 = [7, 8, 9]

        # test top level
        self.assertEqual(nest.GetChildren(l), [topKids])

        # test underlying level
        self.assertEqual(nest.GetChildren([2, 6]), [kids2, kids6])

        # test with empty dict
        self.assertEqual(nest.GetChildren(l, properties={}), [topKids])

        # local id of middle nodes
        self.assertEqual(nest.GetChildren([2, 6], properties={'local_id': 2}),
                         [[4], [8]])

        # selection by model type
        self.assertEqual(nest.GetChildren(l, properties={'model': 'subnet'}),
                         [topKids])
        self.assertEqual(nest.GetChildren([2], properties={'model': 'subnet'}),
                         [[]])
        self.assertEqual(nest.GetChildren([2], properties={'model': model}),
                         [kids2])
Example #2
0
    def test_GetChildren(self):
        """GetChildren"""

        nest.ResetKernel()
        model = 'iaf_psc_alpha'
        l = nest.LayoutNetwork(model, (2, 3))
        topKids = (2, 6)
        kids2 = (3, 4, 5)
        kids6 = (7, 8, 9)

        # test top level
        self.assertEqual(nest.GetChildren(l), (topKids, ))

        # test underlying level
        self.assertEqual(nest.GetChildren((2, 6)), (kids2, kids6))

        # test with empty dict
        self.assertEqual(nest.GetChildren(l, properties={}), (topKids, ))

        # local id of middle nodes
        self.assertEqual(nest.GetChildren(
            (2, 6), properties={'local_id': 2}), ((4, ), (8, )))

        # selection by model type
        self.assertEqual(nest.GetChildren(
            l, properties={'model': 'subnet'}), (topKids, ))
        self.assertEqual(nest.GetChildren(
            (2, ), properties={'model': 'subnet'}), (tuple(), ))
        self.assertEqual(nest.GetChildren(
            (2, ), properties={'model': model}), (kids2, ))
Example #3
0
def check_distance():
    layer = tp.CreateLayer(l3d_specs)
    tp.ConnectLayers(layer, layer, conn_dict1)

    nodes = nest.GetChildren(layer)[0]

    positions = tp.GetPosition(nodes)
    target_positions = tp.GetTargetPositions(nodes, layer)

    deltas = filter(
        lambda x: x > 0.35,
        [[get_delta(positions[i], pos2) for pos2 in target_positions[i]]
         for i in range(len(positions))])
    print len(deltas)
Example #4
0
def MyPlotLayer(layer, ax=None, nodecolor='b', nodesize=20):
    """
    Plot nodes in a layer.
    
    This function plots only top-level nodes, not the content of composite nodes.
    
    Note: You should not use this function in distributed simulations.
    
    Parameters
    ----------
    layer         GID of layer to plot (as single-element list)
    fig           Matplotlib figure to plot to. If not given, a new figure is created [optional].
    nodecolor     Color for nodes [optional].
    nodesize      Marker size for nodes [optional].

    Returns
    -------
    Matplotlib figure.
    
    See also
    --------
    PlotTargets
    """

    import matplotlib.pyplot as plt

    if len(layer) != 1:
        raise ValueError("layer must contain exactly one GID.")

    # get layer extent and center, x and y
    xext, yext = nest.GetStatus(layer, 'topology')[0]['extent'][:2]
    xctr, yctr = nest.GetStatus(layer, 'topology')[0]['center'][:2]

    # extract position information, transpose to list of x and y positions
    xpos, ypos = zip(*GetPosition(nest.GetChildren(layer)))

    if not ax:
        ax = pylab.subplot(111)

    ax.scatter(xpos, ypos, s=nodesize, facecolor=nodecolor, edgecolor='none')
    _draw_extent(ax, xctr, yctr, xext, yext)
Example #5
0
    random.uniform(-0.5, 0.5)
] for j in range(1000)]

l1 = topo.CreateLayer({
    'extent': [1.5, 1.5, 1.5],  # must specify 3d extent AND center
    'center': [0., 0., 0.],
    'positions': pos,
    'elements': 'iaf_neuron'
})

# visualize
#xext, yext = nest.GetStatus(l1, 'topology')[0]['extent']
#xctr, yctr = nest.GetStatus(l1, 'topology')[0]['center']

# extract position information, transpose to list of x, y and z positions
xpos, ypos, zpos = zip(*topo.GetPosition(nest.GetChildren(l1)[0]))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xpos, ypos, zpos, s=15, facecolor='b', edgecolor='none')

# Gaussian connections in full volume [-0.75,0.75]**3
topo.ConnectLayers(
    l1, l1, {
        'connection_type': 'divergent',
        'allow_autapses': False,
        'mask': {
            'volume': {
                'lower_left': [-0.75, -0.75, -0.75],
                'upper_right': [0.75, 0.75, 0.75]
            }
        },
Example #6
0
    'allow_multapses': False,
    'allow_autapses': False,
    'connection_type': 'convergent',
    'mask': {
        'rectangular': {
            'lower_left': [-0.5, -0.5],
            'upper_right': [0.5, 0.5]
        }
    },
    'kernel': 0.5,
    'sources': {
        'model': 'iaf_neuron'
    },
    'targets': {
        'model': 'iaf_neuron'
    }
}

tp.ConnectLayers(l, l, projections)
tp.ConnectLayers(l_dummy1, l, projections)
tp.ConnectLayers(l_dummy2, l, projections)

if nest.version() == 'NEST 2.0.0':
    sources = nest.GetChildren(l)
if nest.version() == 'NEST 2.2.1':
    sources = nest.GetChildren(l)[0]

t = time.time()
targets = tp.GetTargetNodes(sources, l)
print time.time() - t
Example #7
0
    'connection_type': 'convergent',
    'mask': {
        'rectangular': {
            'lower_left': [-0.5, -0.5],
            'upper_right': [0.5, 0.5]
        }
    },
    'kernel': 0.5,
    'sources': {
        'model': 'iaf_neuron'
    },
    'targets': {
        'model': 'iaf_neuron'
    }
}

tp.ConnectLayers(l, l, projections)
tp.ConnectLayers(l_dummy1, l, projections)
tp.ConnectLayers(l_dummy2, l, projections)
tp.ConnectLayers(l_dummy3, l, projections)
t = time.time()
targets = tp.GetTargetNodes(nest.GetChildren(l)[0], l)
m = []
for trg in targets:
    m.append(len(trg))

print time.time() - t
print len(m)
#print tp.FindCenterElement(l)
#print nest.GetChildren(l)
#print nest.GetLeaves(l)
Example #8
0
    GIDs and neuron positions are written to file.
    '''

    layer_in = tp.CreateLayer(layerdict_in)
    layer_ex = tp.CreateLayer(layerdict_ex)
    layer_stim = tp.CreateLayer(layerdict_stim)

    tp.DumpLayerNodes(
        layer_ex, os.path.join(spike_output_path, label_positions + '-0.dat'))
    tp.DumpLayerNodes(
        layer_in, os.path.join(spike_output_path, label_positions + '-1.dat'))
    tp.DumpLayerNodes(
        layer_stim, os.path.join(spike_output_path,
                                 label_positions + '-2.dat'))

    nodes_ex = nest.GetChildren(layer_ex)[0]  # nodes of ex/in neurons
    nodes_in = nest.GetChildren(layer_in)[0]
    nodes_stim = nest.GetChildren(layer_stim)[0]
    '''
    Distribute initial membrane voltages.
    '''

    for neurons in [nodes_ex, nodes_in]:
        for neuron in neurons:
            nest.SetStatus([neuron], {'V_m': theta * random.rand()})
    '''
    Create spike detectors for recording from the excitatory and the
    inhibitory populations and a poisson generator as noise source.
    The spike detectors are configured for writing to file.
    '''
Example #9
0
    random.uniform(-0.5, 0.5)
] for j in range(1000)]

l1 = topo.CreateLayer({
    'extent': [1.5, 1.5, 1.5],  # must specify 3d extent AND center
    'center': [0., 0., 0.],
    'positions': pos,
    'elements': 'iaf_psc_alpha'
})

# visualize
# xext, yext = nest.GetStatus(l1, 'topology')[0]['extent']
# xctr, yctr = nest.GetStatus(l1, 'topology')[0]['center']

# l1_children is a work-around until NEST 3.0 is released
l1_children = nest.GetChildren(l1)[0]

# extract position information, transpose to list of x, y and z positions
xpos, ypos, zpos = zip(*topo.GetPosition(l1_children))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xpos, ypos, zpos, s=15, facecolor='b', edgecolor='none')

# Gaussian connections in full volume [-0.75,0.75]**3
topo.ConnectLayers(
    l1, l1, {
        'connection_type': 'divergent',
        'allow_autapses': False,
        'mask': {
            'volume': {
                'lower_left': [-0.75, -0.75, -0.75],