Esempio n. 1
0
def get_cell(n_seg=4):
    cell = lfp.CellGeometry(x=np.array([[0.] * 2] * n_seg),
                            y=np.array([[0.] * 2] * n_seg),
                            z=np.array([[1. * x, 1. * (x + 1)]
                                        for x in range(n_seg)]),
                            d=np.array([1.] * n_seg))
    return cell
Esempio n. 2
0
    def test_RecMEAElectrode_03(self):
        '''test_position_shifted_slice'''
        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'z_shift': -200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11) - 100,
            'method': "pointsource",
            'squeeze_cell_factor': None,
        }

        stick = lfp.CellGeometry(x=np.array([[-17.5, 17.5], [0., 23.],
                                             [23., 46.], [46.,
                                                          69.], [69., 92.],
                                             [92., 115.], [115., 125.],
                                             [125., 135.], [135., 145.],
                                             [145., 155.], [155., 165.],
                                             [115., 118.33333333],
                                             [118.33333333, 121.66666667],
                                             [121.66666667, 125.]]),
                                 y=np.array([[0., 0.], [0., 0.], [0., 0.],
                                             [0., 0.], [0., 0.], [0., 0.],
                                             [0., 4.], [4., 8.], [8., 12.],
                                             [12., 16.], [16., 20.], [0., 0.],
                                             [0., 0.], [0., 0.]]),
                                 z=np.array([[0, 0], [0, 0], [0, 0], [0, 0],
                                             [0, 0], [0, 0], [0, 0], [10, 20],
                                             [20, 30], [30, 40], [40, 50],
                                             [0, -10], [-10, -20], [-20,
                                                                    -30]]),
                                 d=np.zeros(14))
        stick.z = stick.z - 100

        MEA = lfp.RecMEAElectrode(stick, **electrodeParams)
        MEA._test_cell_extent()
Esempio n. 3
0
    def test_RecMEAElectrode_02(self):
        '''test return_comp_outside_slice'''
        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11),
            'method': "pointsource",
            'squeeze_cell_factor': None,
        }

        stick = lfp.CellGeometry(x=np.array([[-17.5, 17.5], [0., 23.],
                                             [23., 46.], [46.,
                                                          69.], [69., 92.],
                                             [92., 115.], [115., 125.],
                                             [125., 135.], [135., 145.],
                                             [145., 155.], [155., 165.],
                                             [115., 118.33333333],
                                             [118.33333333, 121.66666667],
                                             [121.66666667, 125.]]),
                                 y=np.array([[0., 0.], [0., 0.], [0., 0.],
                                             [0., 0.], [0., 0.], [0., 0.],
                                             [0., 4.], [4., 8.], [8., 12.],
                                             [12., 16.], [16., 20.], [0., 0.],
                                             [0., 0.], [0., 0.]]),
                                 z=np.array([[0, 0], [0, 0], [0, 0], [0, 0],
                                             [0, 0], [0, 0], [0, 0], [10, 20],
                                             [20, 30], [30, 40], [40, 50],
                                             [0, -10], [-10, -20], [-20,
                                                                    -30]]),
                                 d=np.zeros(14))
        stick.z = stick.z + 100
        MEA = lfp.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._return_comp_outside_slice)
        true_bad_comp = np.array([2, 3, 6])

        stick.z[true_bad_comp, 0] = 1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zstart above")
        np.testing.assert_equal(true_bad_comp,
                                np.arange(stick.totnsegs)[bad_comp])
        stick.z[true_bad_comp, 0] = 100

        stick.z[true_bad_comp, 0] = -1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zstart below")
        np.testing.assert_equal(true_bad_comp,
                                np.arange(stick.totnsegs)[bad_comp])
        stick.z[true_bad_comp, 0] = 100

        stick.z[true_bad_comp, -1] = 1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zend above")
        np.testing.assert_equal(true_bad_comp,
                                np.arange(stick.totnsegs)[bad_comp])
        stick.z[true_bad_comp, -1] = 100

        stick.z[true_bad_comp, -1] = -1000
        bad_comp, reason = MEA._return_comp_outside_slice()
        np.testing.assert_equal(reason, "zend below")
        np.testing.assert_equal(true_bad_comp,
                                np.arange(stick.totnsegs)[bad_comp])
        stick.z[true_bad_comp, -1] = 100
Esempio n. 4
0
    def test_RecMEAElectrode_01(self):
        '''test _test_cell_extent method w/wo. squeeze along z-axis'''
        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11),
            'method': "pointsource",
            'squeeze_cell_factor': None,
            'verbose': False
        }

        stick = lfp.CellGeometry(x=np.array([[-17.5, 17.5], [0., 23.],
                                             [23., 46.], [46.,
                                                          69.], [69., 92.],
                                             [92., 115.], [115., 125.],
                                             [125., 135.], [135., 145.],
                                             [145., 155.], [155., 165.],
                                             [115., 118.33333333],
                                             [118.33333333, 121.66666667],
                                             [121.66666667, 125.]]),
                                 y=np.array([[0., 0.], [0., 0.], [0., 0.],
                                             [0., 0.], [0., 0.], [0., 0.],
                                             [0., 4.], [4., 8.], [8., 12.],
                                             [12., 16.], [16., 20.], [0., 0.],
                                             [0., 0.], [0., 0.]]),
                                 z=np.array([[0, 0], [0, 0], [0, 0], [0, 0],
                                             [0, 0], [0, 0], [0, 0], [10, 20],
                                             [20, 30], [30, 40], [40, 50],
                                             [0, -10], [-10, -20], [-20,
                                                                    -30]]),
                                 d=np.zeros(14))

        stick.z = stick.z + 1
        MEA = lfp.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)

        stick.z = stick.z + 198.
        MEA = lfp.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)

        electrodeParams = {
            'sigma_T': 0.3,
            'sigma_S': 1.5,
            'sigma_G': 0.0,
            'h': 200,
            'x': np.linspace(0, 1000, 11),
            'y': np.zeros(11),
            'z': np.zeros(11),
            'method': "pointsource",
            'squeeze_cell_factor': 0.1,
        }

        stick.z = stick.z - 200
        MEA = lfp.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)

        stick.z = np.zeros_like(stick.z) + 202
        MEA = lfp.RecMEAElectrode(stick, **electrodeParams)
        np.testing.assert_raises(RuntimeError, MEA._test_cell_extent)
Esempio n. 5
0
def setupRecordDipole():
    """
    Function for/to <short description of `netpyne.sim.setup.setupRecordDipole`>


    """

    from .. import sim
    import lfpykit

    saveSteps = int(np.ceil(sim.cfg.duration / sim.cfg.recordStep))
    sim.simData['dipoleSum'] = np.zeros((saveSteps, 3))

    if sim.cfg.saveDipoleCells:
        if sim.cfg.saveDipoleCells == True:
            cellsRecordDipole = utils.getCellsList(['all'])  # record all cells
        elif isinstance(sim.cfg.saveDipoleCells, list):
            cellsRecordDipole = utils.getCellsList(sim.cfg.saveDipoleCells)
        for c in cellsRecordDipole:
            sim.simData['dipoleCells'][c.gid] = np.zeros((saveSteps, 3))

    if sim.cfg.saveDipolePops:
        if sim.cfg.saveDipolePops == True:
            popsRecordDipole = list(sim.net.pops.keys())  # record all pops
        elif isinstance(sim.cfg.saveDipolePops, list):
            popsRecordDipole = [
                p for p in sim.cfg.saveDipolePops
                if p in list(sim.net.pops.keys())
            ]  # only pops that exist
            sim.net.popForEachGid = {}
            for pop in popsRecordDipole:
                sim.net.popForEachGid.update(
                    {gid: pop
                     for gid in sim.net.pops[pop].cellGids})
        for pop in popsRecordDipole:
            sim.simData['dipolePops'][pop] = np.zeros((saveSteps, 3))

    if not sim.net.params.defineCellShapes:
        sim.net.defineCellShapes(
        )  # convert cell shapes (if not previously done already)
    sim.net.calcSegCoords()  # calculate segment coords for each cell

    if sim.cfg.createNEURONObj:
        for cell in sim.net.compartCells:
            lfpykitCell = lfpykit.CellGeometry(
                x=np.array([[p0, p1] for p0, p1 in zip(
                    cell._segCoords['p0'][0], cell._segCoords['p1'][0])]),
                y=np.array([[p0, p1] for p0, p1 in zip(
                    cell._segCoords['p0'][1], cell._segCoords['p1'][1])]),
                z=np.array([[p0, p1] for p0, p1 in zip(
                    cell._segCoords['p0'][2], cell._segCoords['p1'][2])]),
                d=np.array([[d0, d1] for d0, d1 in zip(
                    cell._segCoords['d0'], cell._segCoords['d1'])]))

            cdm = lfpykit.CurrentDipoleMoment(cell=lfpykitCell)
            cell.M = cdm.get_transformation_matrix()

            # set up recording of membrane currents (duplicate with setupRecordLFP -- unifiy and avoid calling twice)
            nseg = cell._segCoords['p0'].shape[1]
            cell.imembPtr = h.PtrVector(nseg)  # pointer vector
            cell.imembPtr.ptr_update_callback(
                cell.setImembPtr
            )  # used for gathering an array of  i_membrane values from the pointer vector
            cell.imembVec = h.Vector(nseg)

        sim.cvode.use_fast_imem(True)  # make i_membrane_ a range variable
        sim.cfg.use_fast_imem = True
Esempio n. 6
0
p = arbor.place_pwlin(morphology)
x, y, z, d = [np.array([], dtype=float).reshape((0, 2))] * 4
CV_ind = np.array([], dtype=int)  # tracks which CV owns segment
for i, m in enumerate(I_m_meta):
    segs = p.segments([m])
    for j, seg in enumerate(segs):
        x = np.row_stack([x, [seg.prox.x, seg.dist.x]])
        y = np.row_stack([y, [seg.prox.y, seg.dist.y]])
        z = np.row_stack([z, [seg.prox.z, seg.dist.z]])
        d = np.row_stack([d, [seg.prox.radius * 2, seg.dist.radius * 2]])
        CV_ind = np.r_[CV_ind, i]

###############################################################################
# compute extracellular potential using segment information
###############################################################################
cell_geometry = lfpykit.CellGeometry(x=x, y=y, z=z, d=d)

# membrane voltages, transmemrbane current and corresponding times
cell_geometry.V_m = V_m  # mV
# nA, sum stimulation and transmembrane current to mimic sinusoid synapse
cell_geometry.I_m = I_m + I_c
cell_geometry.time = time  # ms

# locations where extracellular potential is predicted
dx = 1
dz = 1
axis = np.round([x.min() - 10, x.max() + 10, y.min() - 10, y.max() + 10])
# axis = np.round(axis)
X, Y = np.meshgrid(
    np.linspace(axis[0], axis[1],
                int(np.diff(axis[:2]) // dx) + 1),