def true_lam_csd(cell, dr=<NUM_LIT:100>, z=None):
if type(z) != type(np.ndarray(shape=<NUM_LIT:0>)):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>dz = abs(z[<NUM_LIT:1>] - z[<NUM_LIT:0>])<EOL>CSD = np.zeros((z.size, cell.tvec.size,))<EOL>r_end = np.sqrt(cell.xend**<NUM_LIT:2> + cell.yend**<NUM_LIT:2>)<EOL>r_start = np.sqrt(cell.xstart**<NUM_LIT:2> + cell.ystart**<NUM_LIT:2>)<EOL>volume = dz * np.pi * dr**<NUM_LIT:2><EOL>for i in range(len(z)):<EOL><INDENT>aa0 = cell.zstart < z[i] + dz/<NUM_LIT:2><EOL>aa1 = cell.zend < z[i] + dz/<NUM_LIT:2><EOL>bb0 = cell.zstart >= z[i] - dz/<NUM_LIT:2><EOL>bb1 = cell.zend >= z[i] - dz/<NUM_LIT:2><EOL>cc0 = r_start < dr<EOL>cc1 = r_end < dr<EOL>ii = aa0 & bb0 & cc0 <EOL>jj = aa1 & bb1 & cc1 <EOL>for j in range(cell.zstart.size):<EOL><INDENT>if ii[j] and jj[j]:<EOL><INDENT>CSD[i,] = CSD[i, ] + cell.imem[j, ] / volume<EOL><DEDENT>elif ii[j] and not jj[j]: <EOL><INDENT>z0 = cell.zstart[j]<EOL>r0 = r_start[j]<EOL>z1 = cell.zend[j]<EOL>r1 = r_end[j]<EOL>if r0 == r1:<EOL><INDENT>frac = -(z0 - z[i]-dz/<NUM_LIT:2>) / (z1 - z0)<EOL><DEDENT>else:<EOL><INDENT>L2 = (r1 - r0)**<NUM_LIT:2> + (z1 - z0)**<NUM_LIT:2><EOL>z2 = [z[i]-dz/<NUM_LIT:2>, z[i]+dz/<NUM_LIT:2>, z[i]-dz/<NUM_LIT:2>]<EOL>r2 = [<NUM_LIT:0>, <NUM_LIT:0>, dr]<EOL>z3 = [z[i]-dz/<NUM_LIT:2>, z[i]+dz/<NUM_LIT:2>, z[i]+dz/<NUM_LIT:2>]<EOL>r3 = [dr, dr, dr]<EOL>P = []<EOL>for k in range(<NUM_LIT:3>):<EOL><INDENT>P.append(_PrPz(r0, z0, r1, z1, r2[k], z2[k], r3[k], z3[k]))<EOL>if P[k][<NUM_LIT:2>]:<EOL><INDENT>vL2 = (P[k][<NUM_LIT:0>] - r0)**<NUM_LIT:2> + (P[k][<NUM_LIT:1>] -z0)**<NUM_LIT:2><EOL>frac = np.sqrt(vL2 / L2)<EOL><DEDENT><DEDENT><DEDENT>CSD[i,] = CSD[i, ] + frac * cell.imem[j, ] / volume<EOL><DEDENT>elif jj[j] and not ii[j]: <EOL><INDENT>z0 = cell.zstart[j]<EOL>r0 = r_start[j]<EOL>z1 = cell.zend[j]<EOL>r1 = r_end[j]<EOL>if r0 == r1:<EOL><INDENT>frac = (z1 - z[i]+dz/<NUM_LIT:2>) / (z1 - z0)<EOL><DEDENT>else:<EOL><INDENT>L2 = (r1 - r0)**<NUM_LIT:2> + (z1 - z0)**<NUM_LIT:2><EOL>z2 = [z[i]-dz/<NUM_LIT:2>, z[i]+dz/<NUM_LIT:2>, z[i]-dz/<NUM_LIT:2>]<EOL>r2 = [<NUM_LIT:0>, <NUM_LIT:0>, dr]<EOL>z3 = [z[i]-dz/<NUM_LIT:2>, z[i]+dz/<NUM_LIT:2>, z[i]+dz/<NUM_LIT:2>]<EOL>r3 = [dr, dr, dr]<EOL>P = []<EOL>for k in range(<NUM_LIT:3>):<EOL><INDENT>P.append(_PrPz(r0, z0, r1, z1, r2[k], z2[k], r3[k], z3[k]))<EOL>if P[k][<NUM_LIT:2>]:<EOL><INDENT>vL2 = (r1 - P[k][<NUM_LIT:0>])**<NUM_LIT:2> + (z1 - P[k][<NUM_LIT:1>])**<NUM_LIT:2><EOL>frac = np.sqrt(vL2 / L2)<EOL><DEDENT><DEDENT><DEDENT>CSD[i,] = CSD[i, ] + frac * cell.imem[j, ] / volume<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>return CSD<EOL>
Return CSD from membrane currents as function along the coordinates
of the electrode along z-axis. 


Parameters
----------
cell : `LFPy.cell.Cell` or `LFPy.cell.TemplateCell` object.
    Cell.
dr : float
    Radius of the cylindrical CSD volume.
z : numpy.ndarray
    Z-coordinates of electrode.


Returns
----------
CSD : numpy.ndarray
    Current-source density (in pA * mum^-3).