# Addressing a specific variable in SpatialNeuron

**URL:** <https://brian.discourse.group/t/addressing-a-specific-variable-in-spatialneuron/227>\
**Category:** Support\
**Tags:** multicompartment\
**Created:** [11 December 2020 14:20 UTC](https://brian.discourse.group/t/addressing-a-specific-variable-in-spatialneuron/227 "2020-12-11T14:20:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barbara-ge](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/barbara-ge/32/102_2.png) [@barbara-ge](https://brian.discourse.group/u/barbara-ge)\
**Post date:** [11 December 2020 14:20 UTC](https://brian.discourse.group/t/addressing-a-specific-variable-in-spatialneuron/227/1 "2020-12-11T14:20:46Z")

</div>

# Description of problem

Hi again,  
I have a SpatialNeuron with variable surface and volume between different compartments and I would like to specify that in the model equations. Meaning that I’d like that the model equation calls the right surface and volume based on which compartment is being evaluated.  
And I haven’t find a way to solve that.

I know how to specifically set the volume and area of just one of the compartment with the indexing.  
But what if I want that in each compartment the area and volume of the actual compartment is used?

I suspect the solution has to be easy., but I couldn’t find any yet. Any help would be appreciated.

Barbara

# Minimal code to reproduce problem

```auto
SVR = np.arange(1., 41., 6.7)/umeter
dicr = 2/SVR

morpho = Soma(diameter=90*um)

morpho.L = Section(diameter=dicr, length=[20, 20, 20, 20, 20]*um, n=5)

S_N = morpho.area
Vol_N = morpho.volume

model_eq = '''
.
some other code not relevant
.
dKi/dt = (-S_N/(F*Vol_N))*(IKd + IM - 2*IPump) : mmolar 
'''

```

Error I got:  
An error occurred when preparing an object. KeyError: ‘Variable S\_N was found in the namespace, but is not a scalar value’

# What you have already tried

Adding the indexing:

```auto
S_N = morpho.area[i]

```

# Full traceback of error (if relevant)

Error I got (as expected since the indexing was not defined anywhere):  
An error occurred when preparing an object. KeyError: ‘The identifier “S\_N” could not be resolved.’

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [11 December 2020 15:27 UTC](https://brian.discourse.group/t/addressing-a-specific-variable-in-spatialneuron/227/2 "2020-12-11T15:27:39Z")

</div>

Hi Barbara,  
it is very possible that we do not document this anywhere, but the equations `SpatialNeuron` have direct access to all the variables from the `Morphology`. So you can have your equations directly refer to `area`, `volume`, `diameter`, `length`, etc., and this will refer to the respective values for each compartment. The definition of external variables (as `S_N` in your example`) only works for scalar values. But again, no need to do anything to get access to these values, something like

```auto
dKi/dt = (-area/volume)*(IKd + IM - 2*IPump) : mmolar

```

should work.
