Utils
compute_children_indices(parents)
¶
Return all children indices of every branch.
Example:
parents = [-1, 0, 0]
compute_children_indices(parents) -> [[1, 2], [], []]
Source code in jaxley/utils/cell_utils.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
compute_coupling_cond(rad1, rad2, r_a1, r_a2, l1, l2)
¶
Return the coupling conductance between two compartments.
Equations taken from https://en.wikipedia.org/wiki/Compartmental_neuron_models
.
radius
: um
r_a
: ohm cm
length_single_compartment
: um
coupling_conds
: S * um / cm / um^2 = S / cm / um -> *10**7 -> mS / cm^2
Source code in jaxley/utils/cell_utils.py
223 224 225 226 227 228 229 230 231 232 233 234 |
|
compute_coupling_cond_branchpoint(rad, r_a, l)
¶
Return the coupling conductance between one compartment and a comp with l=0.
From https://en.wikipedia.org/wiki/Compartmental_neuron_models
If one compartment has l=0.0 then the equations simplify.
R_long = \sum_i r_a * L_i/2 / crosssection_i
with crosssection = pi * r**2
For a single compartment with L>0, this turns into: R_long = r_a * L/2 / crosssection
Then, g_long = crosssection * 2 / L / r_a
Then, the effective conductance is g_long / zylinder_area. So: g = pi * r**2 * 2 / L / r_a / 2 / pi / r / L g = r / r_a / L**2
Source code in jaxley/utils/cell_utils.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
compute_impact_on_node(rad, r_a, l)
¶
Compute the weight with which a compartment influences its node.
In order to satisfy Kirchhoffs current law, the current at a branch point must be
proportional to the crosssection of the compartment. We only require proportionality
here because the branch point equation reads:
g_1 * (V_1 - V_b) + g_2 * (V_2 - V_b) = 0.0
Because R_long = r_a * L/2 / crosssection, we get g_long = crosssection * 2 / L / r_a \propto rad**2 / L / r_a
This equation can be multiplied by any constant.
Source code in jaxley/utils/cell_utils.py
260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
compute_morphology_indices_in_levels(num_branchpoints, child_belongs_to_branchpoint, par_inds, child_inds)
¶
Return (row, col) to build the sparse matrix defining the voltage eqs.
This is run at init
, not during runtime.
Source code in jaxley/utils/cell_utils.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
convert_point_process_to_distributed(current, radius, length)
¶
Convert current point process (nA) to distributed current (uA/cm2).
This function gets called for synapses and for external stimuli.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current |
ndarray
|
Current in |
required |
radius |
ndarray
|
Compartment radius in |
required |
length |
ndarray
|
Compartment length in |
required |
Return
Current in uA/cm2
.
Source code in jaxley/utils/cell_utils.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
equal_segments(branch_property, nseg_per_branch)
¶
Generates segments where some property is the same in each segment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
branch_property |
list
|
List of values of the property in each branch. Should have
|
required |
Source code in jaxley/utils/cell_utils.py
13 14 15 16 17 18 19 20 21 |
|
get_num_neighbours(num_children, nseg_per_branch, num_branches)
¶
Number of neighbours of each compartment.
Source code in jaxley/utils/cell_utils.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
group_and_sum(values_to_sum, inds_to_group_by, num_branchpoints)
¶
Group values by whether they have the same integer and sum values within group.
This is used to construct the last diagonals at the branch points.
Written by ChatGPT.
Source code in jaxley/utils/cell_utils.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
index_of_loc(branch_ind, loc, nseg_per_branch)
¶
Returns the index of a segment given a loc in [0, 1] and the index of a branch.
This is used because we specify locations such as synapses as a value between 0 and 1. We have to convert this onto a discrete segment here.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
branch_ind |
int
|
Index of the branch. |
required |
loc |
float
|
Location (in [0, 1]) along that branch. |
required |
nseg_per_branch |
int
|
Number of segments of each branch. |
required |
Returns:
Type | Description |
---|---|
int
|
The index of the compartment within the entire cell. |
Source code in jaxley/utils/cell_utils.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
interpolate_xyz(loc, coords)
¶
Perform a linear interpolation between xyz-coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loc |
float
|
The location in [0,1] along the branch. |
required |
coords |
ndarray
|
Array containing the reconstructed xyzr points of the branch. |
required |
Return
Interpolated xyz coordinate at loc
, shape `(3,).
Source code in jaxley/utils/cell_utils.py
284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
linear_segments(initial_val, endpoint_vals, parents, nseg_per_branch)
¶
Generates segments where some property is linearly interpolated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_val |
float
|
The value at the tip of the soma. |
required |
endpoint_vals |
list
|
The value at the endpoints of each branch. |
required |
Source code in jaxley/utils/cell_utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
loc_of_index(global_comp_index, nseg)
¶
Return location corresponding to index.
Source code in jaxley/utils/cell_utils.py
216 217 218 219 220 |
|
merge_cells(cumsum_num_branches, cumsum_num_branchpoints, arrs, exclude_first=True)
¶
Build full list of which branches are solved in which iteration.
From the branching pattern of single cells, this “merges” them into a single ordering of branches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cumsum_num_branches |
List[int]
|
cumulative number of branches. E.g., for three cells with
10, 15, and 5 branches respectively, this will should be a list containing
|
required |
arrs |
List[List[ndarray]]
|
A list of a list of arrays that should be merged. |
required |
exclude_first |
bool
|
If |
True
|
Returns:
Type | Description |
---|---|
ndarray
|
A list of arrays which contain the branch indices that are computed at each |
ndarray
|
level (i.e., iteration). |
Source code in jaxley/utils/cell_utils.py
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 |
|
params_to_pstate(params, indices_set_by_trainables)
¶
Make outputs get_parameters()
conform with outputs of .data_set()
.
make_trainable()
followed by params=get_parameters()
does not return indices
because these indices would also be differentiated by jax.grad
(as soon as
the params
are passed to def simulate(params)
. Therefore, in jx.integrate
,
we run the function to add indices to the dict. The outputs of params_to_pstate
are of the same shape as the outputs of .data_set()
.
Source code in jaxley/utils/cell_utils.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
remap_to_consecutive(arr)
¶
Maps an array of integers to an array of consecutive integers.
E.g. [0, 0, 1, 4, 4, 6, 6] -> [0, 0, 1, 2, 2, 3, 3]
Source code in jaxley/utils/cell_utils.py
275 276 277 278 279 280 281 |
|
plot_morph(xyzr, dims=(0, 1), col='k', ax=None, type='line', morph_plot_kwargs={})
¶
Plot morphology.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dims |
Tuple[int]
|
Which dimensions to plot. 1=x, 2=y, 3=z coordinate. Must be a tuple of two of them. |
(0, 1)
|
type |
str
|
Either |
'line'
|
col |
str
|
The color for all branches. |
'k'
|
Source code in jaxley/utils/plot_utils.py
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 |
|
swc_to_jaxley(fname, max_branch_len=100.0, sort=True, num_lines=None)
¶
Read an SWC file and bring morphology into jaxley
compatible formats.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname |
str
|
Path to swc file. |
required |
max_branch_len |
float
|
Maximal length of one branch. If a branch exceeds this length,
it is split into equal parts such that each subbranch is below
|
100.0
|
num_lines |
Optional[int]
|
Number of lines of the SWC file to read. |
None
|
Source code in jaxley/utils/swc.py
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 |
|
nested_checkpoint_scan(f, init, xs, length=None, *, nested_lengths, scan_fn=jax.lax.scan, checkpoint_fn=jax.checkpoint)
¶
A version of lax.scan that supports recursive gradient checkpointing.
Code taken from: https://github.com/google/jax/issues/2139
The interface of nested_checkpoint_scan
exactly matches lax.scan, except for
the required nested_lengths
argument.
The key feature of nested_checkpoint_scan
is that gradient calculations
require O(max(nested_lengths)) memory, vs O(prod(nested_lengths)) for unnested
scans, which it achieves by re-evaluating the forward pass
len(nested_lengths) - 1
times.
nested_checkpoint_scan
reduces to lax.scan
when nested_lengths
has a
single element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Callable[[Carry, Dict[str, ndarray]], Tuple[Carry, Output]]
|
function to scan over. |
required |
init |
Carry
|
initial value. |
required |
xs |
Dict[str, ndarray]
|
scanned over values. |
required |
length |
Optional[int]
|
leading length of all dimensions |
None
|
nested_lengths |
Sequence[int]
|
required list of lengths to scan over for each level of
checkpointing. The product of nested_lengths must match length (if
provided) and the size of the leading axis for all arrays in |
required |
scan_fn |
function matching the API of lax.scan |
scan
|
|
checkpoint_fn |
Callable[[Func], Func]
|
function matching the API of jax.checkpoint. |
checkpoint
|
Source code in jaxley/utils/jax_utils.py
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 |
|
gather_synapes(number_of_compartments, post_syn_comp_inds, current_each_synapse_voltage_term, current_each_synapse_constant_term)
¶
Compute current at the post synapse.
All this does it that it sums the synaptic currents that come into a particular compartment. It returns an array of as many elements as there are compartments.
Source code in jaxley/utils/syn_utils.py
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 |
|