1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
.. _secspec:
.. _CurrentlyAccessedSection:
Section and Segment Selection
=============================
Dot notation for properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Since sections share property names eg. a length called :data:`L`
it is always necessary to specify *which* section is being discussed;
this is done using dot notation, e.g.
.. code-block::
python
dendrite[2].L = dendrite[1].L + dendrite[0].L
axon.v = soma.v
print(soma.gnabar)
axon.nseg *= 3
This notation is necessary when one needs to refer to more than
one section within a single statement.
sec= for functions
~~~~~~~~~~~~~~~~~~
Many NEURON functions refer to a specific Section. In recent versions of NEURON,
most of these either are available as section methods or take a section or segment
directly. For older code or for the remaining exceptions, the active section may
be specified using a ``sec=`` keyword argument.
For example:
.. code-block::
python
my_iclamp = h.IClamp(0.25, sec=soma) # better to use h.IClamp(soma(0.25)) though
num_pts_3d = h.n3d(sec=apical) # could get the same value as an int via apical.n3d()
Default section
~~~~~~~~~~~~~~~
If no ``sec=`` keyword argument is specified, the functions will use NEURON's
default Section (sometimes called the *currently accessed section*),
which can be identified via ``h.cas()``.
The default Section is controlled by a stack; it is initially
the first Section created but entries may be pushed onto or popped off of the
stack by the following commands. *Use this only as a last resort.*
.. function:: pop_section
Syntax:
``h.pop_section()``
Description:
Take the currently accessed section off the section stack. This can only be used after
a function which pushes a section on the section stack such as
``point_process.getloc()``.
Example:
.. code-block::
python
from neuron import h
soma = h.Section(name='soma')
apical = h.Section(name='apical')
stims = [h.IClamp(soma(i / 4.)) for i in range(5)] + [h.IClamp(apical(0.5))]
for stim in stims:
x = stim.get_loc()
print("location of %s is %s(%g)" % (stim, h.secname(), x))
h.pop_section()
(Note: in this example as ``nseg=1``, the current clamps will either be at position 0, 0.5, or 1.)
(Note: a more Pythonic way to get the location of the point-process ``stim`` is to use ``seg = stim.get_segment()``,
but this is shown as an example of using ``h.pop_section()``.)
----
.. function:: push_section
Syntax:
``h.push_section(number)``
``h.push_section(section_name)``
Description:
This function, along with ``h.pop_section()`` should only be used as a last resort.
It will place a specified section on the top of the section stack,
becoming the current section to which all operations apply. It is
probably always better to use :class:`SectionRef`
or :class:`SectionList` .
:samp:`push_section({number})`
Push the section identified by the number returned by
``h.this_section()``, etc. which you desire to be the currently accessed
section. Any section pushed must have a corresponding ``h.pop_section()``
later or else the section stack will be corrupted. The number is
not guaranteed to be the same across separate invocations of NEURON.
:samp:`push_section({section_name})`
Push the section identified by the name obtained
from sectionname(*strdef*). Note: at this time the implementation
iterates over all sections to find the proper one; so do not use
in loops.
Example:
.. code-block::
python
from neuron import h
soma = h.Section(name='soma')
apical = h.Section(name='apical')
# get a number to allow pushing by number
soma_id = h.this_section(sec=soma)
# push by name
h.push_section('apical')
# push by number
h.push_section(soma_id)
# RuntimeError -- no such section
h.push_section('basal')
.. seealso::
:class:`SectionRef`
|