Esempio n. 1
0
    def _loop_over_contacts(self, r_limit=None, timestep=None, t_indices=None):
        '''Loop over electrode contacts, and will return LFPs across channels'''
        if t_indices is not None:
            LFP_temp = np.zeros((self.x.size, t_indices.size))
        else:
            LFP_temp = np.zeros((self.x.size, self.cell.imem.shape[1]))

        for i in range(self.x.size):
            LFP_temp[i, :] = LFP_temp[i, :] + \
                    lfpcalc.calc_lfp_choose(self.cell,
                                            x = self.x[i],
                                            y = self.y[i],
                                            z = self.z[i],
                                            sigma = self.sigma,
                                            r_limit = r_limit,
                                            timestep = timestep,
                                            t_indices = t_indices,
                                            method = self.method,
                                            **self.kwargs)

        return LFP_temp
Esempio n. 2
0
        def loop_over_points(x_n, y_n, z_n):

            #loop over points on contact
            for j in range(self.n):
                tmp = lfpcalc.calc_lfp_choose(self.cell,
                                              x=x_n[j],
                                              y=y_n[j],
                                              z=z_n[j],
                                              r_limit=r_limit,
                                              sigma=self.sigma,
                                              t_indices=t_indices,
                                              method=self.method,
                                              **self.kwargs)

                if j == 0:
                    lfp_e = tmp
                else:
                    lfp_e = np.r_['0,2', lfp_e, tmp]

                #no longer needed
                del tmp

            return lfp_e.mean(axis=0)
Esempio n. 3
0
        def loop_over_points(x_n, y_n, z_n):

            #loop over points on contact
            for j in range(self.n):
                tmp = lfpcalc.calc_lfp_choose(self.cell,
                                                    x = x_n[j],
                                                    y = y_n[j],
                                                    z = z_n[j],
                                                    r_limit = r_limit,
                                                    sigma = self.sigma,
                                                    t_indices = t_indices,
                                                    method = self.method)

                
                if j == 0:
                    lfp_e = tmp
                else:
                    lfp_e = np.r_['0,2', lfp_e, tmp]
                
                #no longer needed
                del tmp
            
            return lfp_e.mean(axis=0)
Esempio n. 4
0
 def _loop_over_contacts(self,
                 r_limit=None,
                 timestep=None,
                 t_indices=None):
     '''Loop over electrode contacts, and will return LFPs across channels'''
     if t_indices is not None:
         LFP_temp = np.zeros((self.x.size, t_indices.size))
     else:
         LFP_temp = np.zeros((self.x.size, self.cell.imem.shape[1]))
         
     for i in range(self.x.size):
         LFP_temp[i, :] = LFP_temp[i, :] + \
                 lfpcalc.calc_lfp_choose(self.cell,
                                         x = self.x[i],
                                         y = self.y[i],
                                         z = self.z[i],
                                         sigma = self.sigma,
                                         r_limit = r_limit,
                                         timestep = timestep,
                                         t_indices = t_indices,
                                         method = self.method)
         
     return LFP_temp
Esempio n. 5
0
    def _lfp_el_pos_calc_dist(
        self,
        r_limit=None,
        m=50,
        t_indices=None,
    ):
        '''
        Calc. of LFP over an n-point integral approximation over flat
        electrode surface: circle of radius r or square of side r. The
        locations of these n points on the electrode surface are random,
        within the given surface. '''
        lfp_el_pos = np.zeros(self.LFP.shape)
        offsets = {}
        circle_circ = {}

        def create_crcl(m, i):
            '''make circumsize of contact point'''
            crcl = np.zeros((m, 3))
            for j in range(m):
                B = [(np.random.rand() - 0.5), (np.random.rand() - 0.5),
                     (np.random.rand() - 0.5)]
                crcl[j, ] = np.cross(self.N[i, ], B)
                crcl[j, ] = crcl[j, ] / np.sqrt(crcl[j, 0]**2 + crcl[j, 1]**2 +
                                                crcl[j, 2]**2) * self.r

            crclx = crcl[:, 0] + self.x[i]
            crcly = crcl[:, 1] + self.y[i]
            crclz = crcl[:, 2] + self.z[i]

            return crclx, crcly, crclz

        def create_sqr(m, i):
            '''make circle in which square contact is circumscribed'''
            sqr = np.zeros((m, 3))
            for j in range(m):
                B = [(np.random.rand() - 0.5), (np.random.rand() - 0.5),
                     (np.random.rand() - 0.5)]
                sqr[j, ] = np.cross(self.N[i, ], B) / np.linalg.norm(
                    np.cross(self.N[i, ], B)) * self.r * np.sqrt(2) / 2

            sqrx = sqr[:, 0] + self.x[i]
            sqry = sqr[:, 1] + self.y[i]
            sqrz = sqr[:, 2] + self.z[i]

            return sqrx, sqry, sqrz

        def calc_xyz_n(i):
            '''calculate some offsets'''
            #offsets and radii init
            offs = np.zeros((self.n, 3))
            r2 = np.zeros(self.n)

            #assert the same random numbers are drawn every time
            if self.seedvalue is not None:
                np.random.seed(self.seedvalue)

            if self.shape is 'circle':
                for j in range(self.n):
                    A = [(np.random.rand() - 0.5) * self.r * 2,
                         (np.random.rand() - 0.5) * self.r * 2,
                         (np.random.rand() - 0.5) * self.r * 2]
                    offs[j, ] = np.cross(self.N[i, ], A)
                    r2[j] = offs[j, 0]**2 + offs[j, 1]**2 + offs[j, 2]**2
                    while r2[j] > self.r**2:
                        A = [(np.random.rand() - 0.5) * self.r * 2,
                             (np.random.rand() - 0.5) * self.r * 2,
                             (np.random.rand() - 0.5) * self.r * 2]
                        offs[j, ] = np.cross(self.N[i, ], A)
                        r2[j] = offs[j, 0]**2 + offs[j, 1]**2 + offs[j, 2]**2
            elif self.shape is 'square':
                for j in range(self.n):
                    A = [(np.random.rand() - 0.5), (np.random.rand() - 0.5),
                         (np.random.rand() - 0.5)]
                    offs[j, ] = np.cross(self.N[i, ], A) * self.r
                    r2[j] = offs[j, 0]**2 + offs[j, 1]**2 + offs[j, 2]**2

            x_n = offs[:, 0] + self.x[i]
            y_n = offs[:, 1] + self.y[i]
            z_n = offs[:, 2] + self.z[i]

            return x_n, y_n, z_n

        def loop_over_points(x_n, y_n, z_n):

            #loop over points on contact
            for j in range(self.n):
                tmp = lfpcalc.calc_lfp_choose(self.cell,
                                              x=x_n[j],
                                              y=y_n[j],
                                              z=z_n[j],
                                              r_limit=r_limit,
                                              sigma=self.sigma,
                                              t_indices=t_indices,
                                              method=self.method,
                                              **self.kwargs)

                if j == 0:
                    lfp_e = tmp
                else:
                    lfp_e = np.r_['0,2', lfp_e, tmp]

                #no longer needed
                del tmp

            return lfp_e.mean(axis=0)

        #loop over contacts
        for i in range(len(self.x)):
            if self.n > 1:

                #fetch offsets:
                x_n, y_n, z_n = calc_xyz_n(i)

                #fill in with contact average
                lfp_el_pos[i] = loop_over_points(x_n, y_n,
                                                 z_n)  #lfp_e.mean(axis=0)

                ##no longer needed
                #del lfp_e

            else:
                lfp_el_pos[i] = lfpcalc.calc_lfp_choose(self.cell,
                                                        x=self.x[i],
                                                        y=self.y[i],
                                                        z=self.z[i],
                                                        r_limit=r_limit,
                                                        sigma=self.sigma,
                                                        t_indices=t_indices,
                                                        **self.kwargs)

            offsets[i] = {'x_n': x_n, 'y_n': y_n, 'z_n': z_n}

            #fetch circumscribed circle around contact
            if self.shape is 'circle':
                crcl = create_crcl(m, i)
                circle_circ[i] = {
                    'x': crcl[0],
                    'y': crcl[1],
                    'z': crcl[2],
                }
            elif self.shape is 'square':
                sqr = create_sqr(m, i)
                circle_circ[i] = {
                    'x': sqr[0],
                    'y': sqr[1],
                    'z': sqr[2],
                }

        return circle_circ, offsets, lfp_el_pos
Esempio n. 6
0
    def _lfp_el_pos_calc_dist(self,
                              r_limit=None,
                             m=50,
                             t_indices=None,
                             ):
        '''
        Calc. of LFP over an n-point integral approximation over flat
        electrode surface with radius r. The locations of these n points on
        the electrode surface are random,  within the given radius. '''
        lfp_el_pos = np.zeros(self.LFP.shape)
        offsets = {}
        circle = {}

        def create_crcl(m, i):
            '''make circumsize of contact point'''
            crcl = np.zeros((m, 3))
            for j in range(m):
                B = [(np.random.rand()-0.5),
                    (np.random.rand()-0.5),
                    (np.random.rand()-0.5)]
                crcl[j, ] = np.cross(self.N[i, ], B)
                crcl[j, ] = crcl[j, ]/np.sqrt(crcl[j, 0]**2 +
                                           crcl[j, 1]**2 + \
                                           crcl[j, 2]**2)*self.r

            crclx = crcl[:, 0] + self.x[i]
            crcly = crcl[:, 1] + self.y[i]
            crclz = crcl[:, 2] + self.z[i]
            
            return crclx, crcly, crclz

        def calc_xyz_n(i):
            '''calculate some offsets'''
            #offsets and radii init
            offs = np.zeros((self.n, 3))
            r2 = np.zeros(self.n)
            
            #assert the same random numbers are drawn every time
            if self.seedvalue is not None:
                np.random.seed(self.seedvalue)
            for j in range(self.n):
                A = [(np.random.rand()-0.5)*self.r*2,
                    (np.random.rand()-0.5)*self.r*2,
                    (np.random.rand()-0.5)*self.r*2]
                offs[j, ] = np.cross(self.N[i, ], A)
                r2[j] = offs[j, 0]**2 + offs[j, 1]**2 + offs[j, 2]**2
                while r2[j] > self.r**2:
                    A = [(np.random.rand()-0.5)*self.r*2,
                        (np.random.rand()-0.5)*self.r*2,
                        (np.random.rand()-0.5)*self.r*2]
                    offs[j, ] = np.cross(self.N[i, ], A)
                    r2[j] = offs[j, 0]**2 + offs[j, 1]**2 + offs[j, 2]**2

            x_n = offs[:, 0] + self.x[i]
            y_n = offs[:, 1] + self.y[i]
            z_n = offs[:, 2] + self.z[i]
            
            return x_n, y_n, z_n

        def loop_over_points(x_n, y_n, z_n):

            #loop over points on contact
            for j in range(self.n):
                tmp = lfpcalc.calc_lfp_choose(self.cell,
                                                    x = x_n[j],
                                                    y = y_n[j],
                                                    z = z_n[j],
                                                    r_limit = r_limit,
                                                    sigma = self.sigma,
                                                    t_indices = t_indices,
                                                    method = self.method)

                
                if j == 0:
                    lfp_e = tmp
                else:
                    lfp_e = np.r_['0,2', lfp_e, tmp]
                
                #no longer needed
                del tmp
            
            return lfp_e.mean(axis=0)

        #loop over contacts
        for i in range(len(self.x)):
            if self.n > 1:
            
                #fetch offsets:
                x_n, y_n, z_n = calc_xyz_n(i)
                
                

                
                #fill in with contact average
                lfp_el_pos[i] = loop_over_points(x_n, y_n, z_n) #lfp_e.mean(axis=0)
                
                ##no longer needed
                #del lfp_e
                
            else:
                lfp_el_pos[i] = lfpcalc.calc_lfp_choose(
                    self.cell, 
                    x=self.x[i],
                    y=self.y[i],
                    z=self.z[i],
                    r_limit = r_limit, 
                    sigma=self.sigma,
                    t_indices=t_indices)
                
            offsets[i] = {
                'x_n' : x_n,
                'y_n' : y_n,
                'z_n' : z_n
            }

            
            #fetch circle around contact
            crcl = create_crcl(m, i)
            circle[i] = {
                'x' : crcl[0],
                'y' : crcl[1],
                'z' : crcl[2],
            }
        
        return circle,  offsets,  lfp_el_pos