def plot_population(ax,<EOL>params,<EOL>aspect='<STR_LIT>',<EOL>isometricangle=<NUM_LIT:0>,<EOL>plot_somas = True, plot_morphos = False,<EOL>num_unitsE = <NUM_LIT:1>, num_unitsI=<NUM_LIT:1>,<EOL>clip_dendrites=False,<EOL>main_pops=True, <EOL>Y = None,<EOL>big=True,<EOL>title='<STR_LIT>',<EOL>rasterized=True):
name_to_id_mapping={'<STR_LIT>':(<NUM_LIT:3>,<NUM_LIT:0>),<EOL>'<STR_LIT>':(<NUM_LIT:3>,<NUM_LIT:1>),<EOL>'<STR_LIT>':(<NUM_LIT:2>,<NUM_LIT:0>),<EOL>'<STR_LIT>':(<NUM_LIT:2>,<NUM_LIT:1>),<EOL>'<STR_LIT>':(<NUM_LIT:1>,<NUM_LIT:0>),<EOL>'<STR_LIT>':(<NUM_LIT:1>,<NUM_LIT:1>),<EOL>'<STR_LIT>':(<NUM_LIT:0>,<NUM_LIT:0>),<EOL>'<STR_LIT>':(<NUM_LIT:0>,<NUM_LIT:1>)<EOL>} <EOL>ax.xaxis.set_ticks([])<EOL>ax.yaxis.set_ticks([])<EOL>if big:<EOL><INDENT>ax.plot(params.electrodeParams['<STR_LIT:x>'],<EOL>params.electrodeParams['<STR_LIT:z>'],<EOL>'<STR_LIT:.>', marker='<STR_LIT:o>', markersize=<NUM_LIT:2>, color='<STR_LIT:k>', zorder=<NUM_LIT:0>)<EOL><DEDENT>else: <EOL><INDENT>ax.plot(params.electrodeParams['<STR_LIT:x>'],<EOL>params.electrodeParams['<STR_LIT:z>'],<EOL>'<STR_LIT:.>', marker='<STR_LIT:o>', markersize=<NUM_LIT:0.5>, color='<STR_LIT:k>', zorder=<NUM_LIT:0>)<EOL><DEDENT>x_0 = params.electrodeParams['<STR_LIT>'][<NUM_LIT:1>, <NUM_LIT:1>:-<NUM_LIT:1>]<EOL>z_0 = params.electrodeParams['<STR_LIT>'][<NUM_LIT:0>, <NUM_LIT:1>:-<NUM_LIT:1>]<EOL>x = np.r_[x_0[-<NUM_LIT:1>], x_0[::-<NUM_LIT:1>], -x_0[<NUM_LIT:1>:], -x_0[-<NUM_LIT:1>]]<EOL>z = np.r_[<NUM_LIT:100>, z_0[::-<NUM_LIT:1>], z_0[<NUM_LIT:1>:], <NUM_LIT:100>]<EOL>ax.fill(x, z, fc='<STR_LIT:w>', lw=<NUM_LIT:0.1>, ec='<STR_LIT:k>', zorder=-<NUM_LIT:0.1>, clip_on=False)<EOL>r = params.populationParams['<STR_LIT>']['<STR_LIT>']<EOL>theta0 = np.linspace(<NUM_LIT:0>, np.pi, <NUM_LIT:20>)<EOL>theta1 = np.linspace(np.pi, <NUM_LIT:2>*np.pi, <NUM_LIT:20>)<EOL>zpos = np.r_[params.layerBoundaries[:, <NUM_LIT:0>],<EOL>params.layerBoundaries[-<NUM_LIT:1>, <NUM_LIT:1>]]<EOL>layers = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>for i, z in enumerate(params.layerBoundaries.mean(axis=<NUM_LIT:1>)):<EOL><INDENT>if big:<EOL><INDENT>ax.text(r, z, '<STR_LIT>' % layers[i], va='<STR_LIT>', ha='<STR_LIT:left>')<EOL><DEDENT><DEDENT>for i, zval in enumerate(zpos):<EOL><INDENT>if i == <NUM_LIT:0>:<EOL><INDENT>ax.plot(r*np.cos(theta0),<EOL>r*np.sin(theta0)*np.sin(isometricangle)+zval,<EOL>color='<STR_LIT:k>', zorder=-r, clip_on=False)<EOL>ax.plot(r*np.cos(theta1),<EOL>r*np.sin(theta1)*np.sin(isometricangle)+zval,<EOL>color='<STR_LIT:k>', zorder=r, clip_on=False)<EOL><DEDENT>else:<EOL><INDENT>ax.plot(r*np.cos(theta0),<EOL>r*np.sin(theta0)*np.sin(isometricangle)+zval,<EOL>color='<STR_LIT>', zorder=-r, clip_on=False)<EOL>ax.plot(r*np.cos(theta1),<EOL>r*np.sin(theta1)*np.sin(isometricangle)+zval,<EOL>color='<STR_LIT:k>', zorder=r, clip_on=False)<EOL><DEDENT><DEDENT>ax.plot([-r, -r], [zpos[<NUM_LIT:0>], zpos[-<NUM_LIT:1>]], '<STR_LIT:k>', zorder=<NUM_LIT:0>, clip_on=False)<EOL>ax.plot([r, r], [zpos[<NUM_LIT:0>], zpos[-<NUM_LIT:1>]], '<STR_LIT:k>', zorder=<NUM_LIT:0>, clip_on=False)<EOL>if big:<EOL><INDENT>ax.plot([<NUM_LIT:0>, r], [z_0.min()]*<NUM_LIT:2>, '<STR_LIT:k>', lw=<NUM_LIT:1>, zorder=<NUM_LIT:0>, clip_on=False)<EOL>ax.text(r / <NUM_LIT>, z_0.min()-<NUM_LIT:100>, '<STR_LIT>' % int(r), ha='<STR_LIT>')<EOL>ax.plot([-r]*<NUM_LIT:2>, [z_0.min()+<NUM_LIT:50>, z_0.min()-<NUM_LIT:50>],<EOL>'<STR_LIT:k>', lw=<NUM_LIT:1>, zorder=<NUM_LIT:0>, clip_on=False)<EOL>ax.text(-r, z_0.min(), r'<STR_LIT>', va='<STR_LIT>', ha='<STR_LIT:right>')<EOL><DEDENT>ax.set_yticks([])<EOL>ax.set_yticklabels([])<EOL>if big:<EOL><INDENT>for pos in zpos:<EOL><INDENT>ax.text(-r, pos, '<STR_LIT>' % int(pos), ha='<STR_LIT:right>', va='<STR_LIT>')<EOL><DEDENT>ax.set_title(title, va='<STR_LIT>')<EOL><DEDENT>axis = ax.axis(ax.axis(aspect))<EOL>def plot_pop_scatter(somapos, marker, colors, i):<EOL><INDENT>pitch = <NUM_LIT:100><EOL>for lower in np.arange(-<NUM_LIT>, <NUM_LIT>, pitch):<EOL><INDENT>upper = lower + pitch<EOL>inds = (somapos[:, <NUM_LIT:1>] >= lower) & (somapos[:, <NUM_LIT:1>] < upper)<EOL>if np.any(inds):<EOL><INDENT>if big:<EOL><INDENT>ax.scatter(somapos[inds, <NUM_LIT:0>],<EOL>somapos[inds, <NUM_LIT:2>] - somapos[inds, <NUM_LIT:1>] * np.sin(isometricangle),<EOL>s=<NUM_LIT:10>, facecolors=colors[i], edgecolors='<STR_LIT>', linewidths=<NUM_LIT:0.1>, zorder=lower,<EOL>marker = marker, clip_on=False, rasterized=rasterized)<EOL><DEDENT>else:<EOL><INDENT>ax.scatter(somapos[inds, <NUM_LIT:0>],<EOL>somapos[inds, <NUM_LIT:2>] - somapos[inds, <NUM_LIT:1>] * np.sin(isometricangle),<EOL>s=<NUM_LIT:3>, facecolors=colors[i], edgecolors='<STR_LIT>', linewidths=<NUM_LIT:0.1>, zorder=lower,<EOL>marker = marker, clip_on=False, rasterized=rasterized)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>pop = list(zip(*params.mapping_Yy))[<NUM_LIT:0>]<EOL>if plot_somas:<EOL><INDENT>if main_pops:<EOL><INDENT>colors = phlp.get_colors(np.unique(pop).size)<EOL>E, I = list(zip(*params.y_in_Y))<EOL>pops_ = []<EOL>if Y is None:<EOL><INDENT>for i in range(len(E)):<EOL><INDENT>pops_.append(E[i])<EOL>pops_.append(I[i])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ids = name_to_id_mapping[Y]<EOL>if ids[<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>pops_.append(E[ids[<NUM_LIT:0>]])<EOL><DEDENT>if ids[<NUM_LIT:1>] == <NUM_LIT:1>:<EOL><INDENT>pops_.append(I[ids[<NUM_LIT:0>]])<EOL><DEDENT><DEDENT>for i, pops in enumerate(pops_):<EOL><INDENT>layer = np.unique(pop)[i]<EOL>if layer.rfind('<STR_LIT:p>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT:E>') >= <NUM_LIT:0>:<EOL><INDENT>marker = '<STR_LIT>'<EOL><DEDENT>elif layer.rfind('<STR_LIT:b>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT:I>') >= <NUM_LIT:0>:<EOL><INDENT>marker = '<STR_LIT:*>'<EOL><DEDENT>elif layer.rfind('<STR_LIT>') >= <NUM_LIT:0>:<EOL><INDENT>marker = '<STR_LIT:o>'<EOL><DEDENT>else:<EOL><INDENT>raise Exception<EOL><DEDENT>somapos = []<EOL>for j, lname in enumerate(pops):<EOL><INDENT>fname = glob.glob(os.path.join(params.populations_path, '<STR_LIT>' % lname))[<NUM_LIT:0>]<EOL>if j == <NUM_LIT:0>:<EOL><INDENT>somapos = np.loadtxt(fname).reshape((-<NUM_LIT:1>, <NUM_LIT:3>))<EOL><DEDENT>else:<EOL><INDENT>somapos = np.r_['<STR_LIT>', somapos, np.loadtxt(fname).reshape((-<NUM_LIT:1>, <NUM_LIT:3>))]<EOL><DEDENT><DEDENT>somapos = somapos[::<NUM_LIT:5>, :]<EOL>if Y is None:<EOL><INDENT>plot_pop_scatter(somapos, marker, colors, i)<EOL><DEDENT>else:<EOL><INDENT>plot_pop_scatter(somapos, marker, colors, ids[<NUM_LIT:0>]*<NUM_LIT:2>+ids[<NUM_LIT:1>])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>colors = phlp.get_colors(len(pop))<EOL>i = <NUM_LIT:0><EOL>for layer, _, _, _ in params.y_zip_list:<EOL><INDENT>if layer.rfind('<STR_LIT:p>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT:E>') >= <NUM_LIT:0>:<EOL><INDENT>marker = '<STR_LIT>'<EOL><DEDENT>elif layer.rfind('<STR_LIT:b>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT:I>') >= <NUM_LIT:0>:<EOL><INDENT>marker = '<STR_LIT:*>'<EOL><DEDENT>elif layer.rfind('<STR_LIT>') >= <NUM_LIT:0>:<EOL><INDENT>marker = '<STR_LIT:x>'<EOL><DEDENT>else:<EOL><INDENT>raise Exception<EOL><DEDENT>fname = glob.glob(os.path.join(params.populations_path, '<STR_LIT>' % layer))[<NUM_LIT:0>]<EOL>somapos = np.loadtxt(fname).reshape((-<NUM_LIT:1>, <NUM_LIT:3>))<EOL>plot_pop_scatter(somapos, marker, colors, i)<EOL>i += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>if plot_morphos:<EOL><INDENT>if main_pops:<EOL><INDENT>colors = phlp.get_colors(np.unique(pop).size)<EOL>E, I = list(zip(*params.y_in_Y))<EOL>pops_ = []<EOL>for i in range(len(E)):<EOL><INDENT>pops_.append(E[i])<EOL>pops_.append(I[i])<EOL><DEDENT>for i, pops in enumerate(pops_):<EOL><INDENT>layer = np.unique(pop)[i]<EOL>somapos = []<EOL>for j, lname in enumerate(pops):<EOL><INDENT>fname = glob.glob(os.path.join(params.populations_path, '<STR_LIT>' % lname))[<NUM_LIT:0>]<EOL>if j == <NUM_LIT:0>:<EOL><INDENT>somapos = np.loadtxt(fname).reshape((-<NUM_LIT:1>, <NUM_LIT:3>))<EOL><DEDENT>else:<EOL><INDENT>somapos = np.r_['<STR_LIT>', somapos, np.loadtxt(fname).reshape((-<NUM_LIT:1>, <NUM_LIT:3>))]<EOL><DEDENT><DEDENT>if layer.rfind('<STR_LIT:p>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT:E>') >= <NUM_LIT:0>:<EOL><INDENT>num_units = num_unitsE<EOL><DEDENT>else:<EOL><INDENT>num_units = num_unitsI            <EOL><DEDENT>if num_units > somapos.shape[<NUM_LIT:0>]:<EOL><INDENT>n = somapos.shape[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>n = num_units<EOL><DEDENT>morphos = []<EOL>for fname in params.m_y:<EOL><INDENT>if fname.rfind(layer) >= <NUM_LIT:0>:<EOL><INDENT>morphos.append(fname)<EOL><DEDENT><DEDENT>for j in range(n):<EOL><INDENT>cell = LFPy.Cell(morphology=os.path.join(params.PATH_m_y,<EOL>np.random.permutation(morphos)[<NUM_LIT:0>]),<EOL>nsegs_method='<STR_LIT>',<EOL>lambda_f=<NUM_LIT:10>,<EOL>extracellular=False<EOL>)<EOL>cell.set_pos(somapos[j, <NUM_LIT:0>], somapos[j, <NUM_LIT:1>], somapos[j, <NUM_LIT:2>])<EOL>cell.set_rotation(z=np.random.rand()*np.pi*<NUM_LIT:2>)<EOL>zips = []<EOL>for x, z in cell.get_idx_polygons():<EOL><INDENT>zips.append(list(zip(x, z-somapos[j, <NUM_LIT:1>] * np.sin(isometricangle))))<EOL><DEDENT>polycol = PolyCollection(zips,<EOL>edgecolors=colors[i],<EOL>facecolors=colors[i],<EOL>linewidths=(<NUM_LIT:0.5>),<EOL>zorder=somapos[j, <NUM_LIT:1>],<EOL>clip_on=clip_dendrites,<EOL>rasterized=rasterized)<EOL>ax.add_collection(polycol)<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>colors = phlp.get_colors(len(pop))<EOL>i = <NUM_LIT:0><EOL>for layer, morpho, depth, size in params.y_zip_list:<EOL><INDENT>fname = glob.glob(os.path.join(params.populations_path, '<STR_LIT>' % layer))[<NUM_LIT:0>]<EOL>somapos = np.loadtxt(fname).reshape((-<NUM_LIT:1>, <NUM_LIT:3>))<EOL>if layer.rfind('<STR_LIT:p>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT>') >= <NUM_LIT:0> or layer.rfind('<STR_LIT:E>') >= <NUM_LIT:0>:<EOL><INDENT>num_units = num_unitsE<EOL><DEDENT>else:<EOL><INDENT>num_units = num_unitsI            <EOL><DEDENT>if num_units > somapos.shape[<NUM_LIT:0>]:<EOL><INDENT>n = somapos.shape[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>n = num_units<EOL><DEDENT>for j in range(n):<EOL><INDENT>cell = LFPy.Cell(morphology=os.path.join(params.PATH_m_y, morpho),<EOL>nsegs_method='<STR_LIT>',<EOL>lambda_f=<NUM_LIT:10>,<EOL>extracellular=False<EOL>)<EOL>cell.set_pos(somapos[j, <NUM_LIT:0>], somapos[j, <NUM_LIT:1>], somapos[j, <NUM_LIT:2>])<EOL>cell.set_rotation(z=np.random.rand()*np.pi*<NUM_LIT:2>)<EOL>zips = []<EOL>for x, z in cell.get_idx_polygons():<EOL><INDENT>zips.append(list(zip(x, z-somapos[j, <NUM_LIT:1>] * np.sin(isometricangle))))<EOL><DEDENT>polycol = PolyCollection(zips,<EOL>edgecolors=colors[i],<EOL>facecolors=colors[i],<EOL>linewidths=(<NUM_LIT:0.5>),<EOL>zorder=somapos[j, <NUM_LIT:1>],<EOL>clip_on=clip_dendrites,<EOL>rasterized=rasterized)<EOL>ax.add_collection(polycol)<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return axis<EOL>
Plot the geometry of the column model, optionally with somatic locations
and optionally with reconstructed neurons

kwargs:
::
    ax : matplotlib.axes.AxesSubplot
    aspect : str
        matplotlib.axis argument
    isometricangle : float
        pseudo-3d view angle
    plot_somas : bool
        plot soma locations
    plot_morphos : bool
        plot full morphologies
    num_unitsE : int
        number of excitatory morphos plotted per population
    num_unitsI : int
        number of inhibitory morphos plotted per population
    clip_dendrites : bool
        draw dendrites outside of axis
    mainpops : bool
        if True, plot only main pops, e.g. b23 and nb23 as L23I
    Y : None, or string
        if not None, plot only soma locations of Y
    big : bool
        if False: leave out labels and reduce marker size

return:
::
    axis : list
        the plt.axis() corresponding to input aspect