<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Example 10
Step1:  Create some dictionarys with parameters for cell
Step2:  Create an helper function to instantiate a cell object given a set of parameters
Step3:  Instantiate a LFPy.Cell object
Step4:  Create an electrode using a commercially available design from Neuronexus
Step5:  Rotate the probe and move it so that it is in the xz plane and 50 $\mu$m away from the soma
Step6:  Create a pulse stimulation current
Step7:  Create LFPy electrode object
Step8:  Enable extracellular stimulation for the cell using stimulating currents of the electrode object
Step9:  Run the simulation with electrode as input to cell.simulate()
Step10:  Then plot the somatic potential, the extracellular field and the LFP
from electrode object
Step11:  Positive pulses close to the soma location cause an hyperpolarization in the cell. Let's try something else!
Step12:  Use the probe field in the electrode object created before to overwrite currents
Step13:  Now the membrane potential is depolarizing, but stimulation is not strong enough to elicit an action potential.
Try to crank up the stimulation current to 50$\mu A$
Step14:  Finally we got two spikes. We can maybe get the same effect with smaller currents and higher stimulation frequencies / number of pulses / pulse width. Try to increase the pulse width
<ASSISTANT_TASK:>
Python Code:
import LFPy
import MEAutility as mu
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
Explanation: Example 10: Extracellular stimulation of neurons
This is an example of LFPy running in an Jupyter notebook. To run through this example code and produce output, press &lt;shift-Enter&gt; in each code block below.
First step is to import LFPy and other packages for analysis and plotting:
End of explanation
cellParameters = {
    'morphology' : 'morphologies/L5_Mainen96_LFPy.hoc',
    'tstart' : -50, # ignore startup transients
    'tstop' : 100,
    'dt' : 2**-4,
    'v_init' : -60, 
    'passive' : False,
}
Explanation: Create some dictionarys with parameters for cell:
End of explanation
def instantiate_cell(cellParameters):
    cell = LFPy.Cell(**cellParameters, delete_sections=True)
    cell.set_pos(x=0, y=0, z=0)
    cell.set_rotation(x=4.98919, y=-4.33261, z=np.pi) # Align apical dendrite with z-axis
    # insert hh mechanism in everywhere, reduced density elsewhere
    for sec in cell.allseclist:
        sec.insert('hh')
        if not 'soma' in sec.name():
            # reduce density of Na- and K-channels to 5% in dendrites
            sec.gnabar_hh = 0.006
            sec.gkbar_hh = 0.0018
            
    return cell
def plot_results(cell, electrode):
    fig = plt.figure(figsize=(10, 6))
    gs = GridSpec(2, 2)
    ax = fig.add_subplot(gs[0, 1])
    im = ax.pcolormesh(np.array(cell.t_ext), cell.z.mean(axis=-1), np.array(cell.v_ext),
                       cmap='RdBu', vmin=-100, vmax=100,
                       shading='auto')
    ax.set_title('Applied extracellular potential')
    ax.set_ylabel('z (um)', labelpad=0)
    rect = np.array(ax.get_position().bounds)
    rect[0] += rect[2] + 0.01
    rect[2] = 0.01
    cax = fig.add_axes(rect)
    
    cbar = fig.colorbar(im, cax=cax, extend='both')
    cbar.set_label('(mV)', labelpad=0)
    ax = fig.add_subplot(gs[1, 1], sharex=ax)
    ax.plot(cell.tvec, cell.somav, 'k')
    ax.set_title('somatic voltage')
    ax.set_ylabel('(mV)', labelpad=0)
    ax.set_xlabel('t (ms)')
    ax.set_ylim([-90, 20])
    ax.set_xlim(cell.tvec[0], cell.tvec[-1])
    ax = fig.add_subplot(gs[:, 0])
    for sec in cell.allseclist:
        idx = cell.get_idx(sec.name())
        ax.plot(cell.x[idx], cell.z[idx],
                color='k')
        if 'soma' in sec.name():
            ax.plot(cell.x[idx], cell.z[idx], color='b', lw=5)
    ax.plot(electrode.x, electrode.z, marker='o', color='g', markersize=3)
    ax.plot(electrode.x[stim_elec], electrode.z[stim_elec], marker='o', color='r', markersize=5)
    ax.axis([-500, 500, -400, 1200])
Explanation: Create an helper function to instantiate a cell object given a set of parameters:
End of explanation
cell = instantiate_cell(cellParameters)
Explanation: Instantiate a LFPy.Cell object:
End of explanation
probe = mu.return_mea('Neuronexus-32')
Explanation: Create an electrode using a commercially available design from Neuronexus:
End of explanation
probe.rotate(axis=[0, 0, 1], theta=90)
probe.move([0, 100, 0])
Explanation: Rotate the probe and move it so that it is in the xz plane and 50 $\mu$m away from the soma:
End of explanation
amp = 20000
n_pulses = 2
interpulse = 10
width = 2
dt = cell.dt
t_stop = cell.tstop
t_start = 20
stim_elec = 15
current, t_ext = probe.set_current_pulses(el_id=stim_elec, amp1=amp, width1=width, dt=dt, t_stop=t_stop,
                                          t_start=t_start, n_pulses=n_pulses, interpulse=interpulse)
plt.figure(figsize=(10, 6))
plt.plot(t_ext, current)
plt.title("Stimulating current")
plt.xlabel('t (ms)')
plt.ylabel('(nA)')
plt.xlim(0, cell.tstop)
Explanation: Create a pulse stimulation current:
End of explanation
electrode = LFPy.RecExtElectrode(cell=cell, probe=probe)
Explanation: Create LFPy electrode object:
End of explanation
v_ext = cell.enable_extracellular_stimulation(electrode, t_ext=t_ext) 
Explanation: Enable extracellular stimulation for the cell using stimulating currents of the electrode object:
End of explanation
cell.simulate(probes=[electrode], rec_vmem=True)
Explanation: Run the simulation with electrode as input to cell.simulate()
End of explanation
plot_results(cell, electrode)
Explanation: Then plot the somatic potential, the extracellular field and the LFP
from electrode object:
End of explanation
cell = instantiate_cell(cellParameters)
Explanation: Positive pulses close to the soma location cause an hyperpolarization in the cell. Let's try something else!
End of explanation
amp = -20000
n_pulses = 2
interpulse = 10
width = 2
dt = cell.dt
t_stop = cell.tstop
t_start = 20
stim_elec = 15
electrode = LFPy.RecExtElectrode(cell=cell, probe=probe)
current, t_ext = electrode.probe.set_current_pulses(el_id=stim_elec, amp1=amp, width1=width, dt=dt, 
                                                    t_stop=t_stop, t_start=t_start, n_pulses=n_pulses,
                                                    interpulse=interpulse)
v_ext = cell.enable_extracellular_stimulation(electrode, t_ext=t_ext) 
cell.simulate(probes=[electrode], rec_vmem=True)
plot_results(cell, electrode)
Explanation: Use the probe field in the electrode object created before to overwrite currents:
End of explanation
amp = -75000
electrode = LFPy.RecExtElectrode(cell=cell, probe=probe)
current, t_ext = electrode.probe.set_current_pulses(el_id=stim_elec, amp1=amp, width1=width, dt=dt, 
                                                    t_stop=t_stop, t_start=t_start, n_pulses=n_pulses,
                                                    interpulse=interpulse)
cell = instantiate_cell(cellParameters)
v_ext = cell.enable_extracellular_stimulation(electrode, t_ext=t_ext) 
cell.simulate(probes=[electrode], rec_vmem=True)
plot_results(cell, electrode)
Explanation: Now the membrane potential is depolarizing, but stimulation is not strong enough to elicit an action potential.
Try to crank up the stimulation current to 50$\mu A$
End of explanation
amp = -30000
n_pulses = 1
interpulse = 10
width = 15
dt = cell.dt
t_stop = cell.tstop
t_start = 20
stim_elec = 15
electrode = LFPy.RecExtElectrode(cell=cell, probe=probe)
current, t_ext = electrode.probe.set_current_pulses(el_id=stim_elec, amp1=amp, width1=width, dt=dt, 
                                                    t_stop=t_stop, t_start=t_start, n_pulses=n_pulses,
                                                    interpulse=interpulse)
cell = instantiate_cell(cellParameters)
v_ext = cell.enable_extracellular_stimulation(electrode, t_ext=t_ext) 
cell.simulate(probes=[electrode], rec_vmem=True)
plot_results(cell, electrode)
Explanation: Finally we got two spikes. We can maybe get the same effect with smaller currents and higher stimulation frequencies / number of pulses / pulse width. Try to increase the pulse width:
End of explanation
<END_TASK>