Example #1
0
    def test_GetElement(self):
        """Check if GetElement returns proper lists."""
        ldict = {'elements': 'iaf_neuron', 'rows': 4, 'columns': 5}
        nest.ResetKernel()
        l = topo.CreateLayer((ldict, ldict))
        checkpos = [[0, 0], [1, 1], [4, 3]]

        # single gid, single coord gives 1-elem gid list
        n1 = topo.GetElement(l[:1], checkpos[0])
        self.assertEqual(len(n1), 1)
        self.assertTrue(not nest.is_sequencetype(n1[0]))

        # multiple gid, single coord gives l-elem gid list
        n2 = topo.GetElement(l, checkpos[0])
        self.assertEqual(len(n2), len(l))
        self.assertTrue(all([nest.is_sequencetype(n) for n in n2]))

        # single gid, multiple coord gives len(checkpos)-elem gid list
        n3 = topo.GetElement(l[:1], checkpos)
        self.assertEqual(len(n3), len(checkpos))
        self.assertTrue(all([nest.is_sequencetype(n) for n in n3]))
        self.assertTrue(all([len(n) == 1 for n in n3]))

        # multiple gid, multiple coord gives l*len(cp)-elem gid list
        n4 = topo.GetElement(l, checkpos)
        self.assertEqual(len(n4), len(l))
        self.assertTrue(all([nest.is_sequencetype(n) for n in n4]))
        self.assertTrue(all([len(n) == len(checkpos) for n in n4]))
        self.assertTrue(all([nest.is_sequencetype(m) for n in n4 for m in n]))
Example #2
0
    def test_GetElement(self):
        """Check if GetElement returns proper lists."""
        ldict = {'elements': 'iaf_neuron',
                 'rows': 4, 'columns': 5}
        nest.ResetKernel()
        l = topo.CreateLayer((ldict,ldict))
        checkpos = [[0,0],[1,1],[4,3]]

        # single gid, single coord gives 1-elem gid list
        n1 = topo.GetElement(l[:1], checkpos[0])
        self.assertEqual(len(n1), 1)
        self.assertTrue(not nest.is_sequencetype(n1[0]))

        # multiple gid, single coord gives l-elem gid list
        n2 = topo.GetElement(l, checkpos[0])
        self.assertEqual(len(n2), len(l))
        self.assertTrue(all([nest.is_sequencetype(n) for n in n2]))
        
        # single gid, multiple coord gives len(checkpos)-elem gid list
        n3 = topo.GetElement(l[:1], checkpos)
        self.assertEqual(len(n3), len(checkpos))
        self.assertTrue(all([nest.is_sequencetype(n) for n in n3]))
        self.assertTrue(all([len(n) == 1 for n in n3]))

        # multiple gid, multiple coord gives l*len(cp)-elem gid list
        n4 = topo.GetElement(l, checkpos)
        self.assertEqual(len(n4), len(l))
        self.assertTrue(all([nest.is_sequencetype(n) for n in n4]))
        self.assertTrue(all([len(n) == len(checkpos) for n in n4]))
        self.assertTrue(all([nest.is_sequencetype(m) for n in n4 for m in n]))
Example #3
0
def load_spikedata_from_file(spikefile):
    """
    Loads spike data from spikefile and returns it as a numpy array

    Directly borrowed and trimmed from existing method in nest.raster_plot
    
    Returns:
        data    data is a matrix such that
                    data[:,0] is a vector of all gids and
                    data[:,1] a vector with the corresponding time stamps.
    """
    #try:
    if True:
        if nest.is_sequencetype(spikefile):
            data = None
            for f in fname:
                if data == None:
                    print "Using loadtxt"
                    data = np.loadtxt(f)
                else:
                    print "Using concatenate"
                    data = np.concatenate((data, np.loadtxt(f)))
        else:
            print "Loading spike data for file: %s" % spikefile
            data = np.loadtxt(spikefile)
        return data
        #except:
        print "Error with loading spike data for file: %s" % spikefile
        return None
Example #4
0
def from_file(fname, title=None, hist=False, hist_binwidth=5.0, grayscale=False):
    """
    Plot raster from file
    """

    if nest.is_sequencetype(fname):
        data = None
        for f in fname:
            if data is None:
                data = numpy.loadtxt(f)
            else:
                data = numpy.concatenate((data, numpy.loadtxt(f)))
    else:
        data = numpy.loadtxt(fname)

    return from_data(data, title, hist, hist_binwidth, grayscale)
Example #5
0
def from_file(fname,
              title=None,
              hist=False,
              hist_binwidth=5.0,
              grayscale=False):
    """
    Plot raster from file
    """

    if nest.is_sequencetype(fname):
        data = None
        for f in fname:
            if data is None:
                data = numpy.loadtxt(f)
            else:
                data = numpy.concatenate((data, numpy.loadtxt(f)))
    else:
        data = numpy.loadtxt(fname)

    return from_data(data, title, hist, hist_binwidth, grayscale)
Example #6
0
def from_file(fname, title=None, grayscale=False):

    if nest.is_sequencetype(fname):
        data = None
        for f in fname:
            if data is None:
                data = numpy.loadtxt(f)
            else:
                data = numpy.concatenate((data, numpy.loadtxt(f)))
    else:
        data = numpy.loadtxt(fname)

    if grayscale:
        line_style = "k"
    else:
        line_style = ""

    if len(data.shape) == 1:
        print "INFO: only found 1 column in the file. Assuming that only one neuron was recorded."
        plotid = pylab.plot(data, line_style)
        pylab.xlabel("Time (steps of length interval)")

    elif data.shape[1] == 2:
        print "INFO: found 2 columns in the file. Assuming them to be gid, pot."

        plotid = []
        data_dict = {}
        for d in data:
            if not d[0] in data_dict:
                data_dict[d[0]] = [d[1]]
            else:
                data_dict[d[0]].append(d[1])

        for d in data_dict:
            plotid.append(
                pylab.plot(data_dict[d], line_style, label="Neuron %i" % d))

        pylab.xlabel("Time (steps of length interval)")
        pylab.legend()

    elif data.shape[1] == 3:
        plotid = []
        data_dict = {}
        g = data[0][0]
        t = []
        for d in data:
            if not d[0] in data_dict:
                data_dict[d[0]] = [d[2]]
            else:
                data_dict[d[0]].append(d[2])
            if d[0] == g:
                t.append(d[1])

        for d in data_dict:
            plotid.append(
                pylab.plot(t, data_dict[d], line_style, label="Neuron %i" % d))

        pylab.xlabel("Time (ms)")
        pylab.legend()

    else:
        raise ValueError("Inappropriate data shape %i!" % data.shape)

    if not title:
        title = "Membrane potential from file '%s'" % fname

    pylab.title(title)
    pylab.ylabel("Membrane potential (mV)")
    pylab.draw()

    return plotid
def from_file(fname, title=None, grayscale=False):

    if nest.is_sequencetype(fname):
        data = None
        for f in fname:
            if data is None:
                data = numpy.loadtxt(f)
            else:
                data = numpy.concatenate((data, numpy.loadtxt(f)))
    else:
        data = numpy.loadtxt(fname)

    if grayscale:
        line_style = "k"
    else:
        line_style = ""

    if len(data.shape) == 1:
        print "INFO: only found 1 column in the file. Assuming that only one neuron was recorded."
        plotid = pylab.plot(data, line_style)
        pylab.xlabel("Time (steps of length interval)")

    elif data.shape[1] == 2:
        print "INFO: found 2 columns in the file. Assuming them to be gid, pot."

        plotid = []
        data_dict = {}
        for d in data:
            if not d[0] in data_dict:
                data_dict[d[0]] = [d[1]]
            else:
                data_dict[d[0]].append(d[1])

        for d in data_dict:
            plotid.append(pylab.plot(data_dict[d], line_style, label="Neuron %i" % d))

        pylab.xlabel("Time (steps of length interval)")
        pylab.legend()

    elif data.shape[1] == 3:
        plotid = []
        data_dict = {}
        g = data[0][0]
        t = []
        for d in data:
            if not d[0] in data_dict:
                data_dict[d[0]] = [d[2]]
            else:
                data_dict[d[0]].append(d[2])
            if d[0] == g:
                t.append(d[1])

        for d in data_dict:
            plotid.append(pylab.plot(t, data_dict[d], line_style, label="Neuron %i" % d))

        pylab.xlabel("Time (ms)")
        pylab.legend()

    else:
        raise ValueError("Inappropriate data shape %i!" % data.shape)

    if not title:
        title = "Membrane potential from file '%s'" % fname

    pylab.title(title)
    pylab.ylabel("Membrane potential (mV)")
    pylab.draw()

    return plotid