Replies: 5 comments 10 replies
-
|
Hi, a very simple thing that might work (although I have not tested it myself), is to set Lemme know if that ends up working, otherwise I'll have another look :) |
Beta Was this translation helpful? Give feedback.
-
|
Hi Ben, this is unfortunately not a supported feature. I think the way to go is to use the graph backend for this:
Let me know if this works! All the best |
Beta Was this translation helpful? Give feedback.
-
|
Thanks so much @michaeldeistler and @jnsbck for your responses so far (and for being so responsive in general!).
|
Beta Was this translation helpful? Give feedback.
-
|
Hi Ben, thanks for the explanation, this helps a lot! I have thought about this a bit more. I think that option 1 will be very difficult to implement, whereas option 2 will be quite straightforward. A general note on computing the voltage at branchpoints and tipsBefore getting started: In This means that you will get the voltage at these points for free: your model does not have to contain compartments at the exact tips or at the exact branchpoints. For example, say you have the following branch, where x ++++ x ++++ x ++++ x By default, x ++++ x ++++ x ++++ x where Why option 1 is difficult to implementAgain, consider the following SWC file describing a single branch: x ++++ x ++++ x ++++ x In your case, we would want to place compartment such that the compartment center will be at the SWC points. The best we could do is: x ++++ x ++++ x ++++ x The means that the length of the The situation is even trickier at branchpoints though: At the branchpoint, each branch will have a "half-length" compartment (for example: How to implement Option 2Option 2, in contrast, is straightforward to implement in Jaxley. I think the core question here is whether interpolating the voltage of two compartments is actually a good. I did some quick experiments and it looked good. To implement it:
What I would recommendUnless you want to invest multiple days or weeks into making option 1 work, I would recommend option 2. Just choose a pretty high We could also have a quick zoom call if you think it would be useful. Michael |
Beta Was this translation helpful? Give feedback.
-
I don't really know what you mean --- there should be a 1:1 corresponence (except that Below is a sketch for how one can achieve this: import jaxley as jx
import numpy as np
fname = "../jaxley/tests/swc_files/morph_ca1_n120_250.swc"
cell = jx.read_swc(fname, ncomp=1)
# Reasonable default values for most models.
frequency = 100.0
d_lambda = 0.1 # Larger -> more coarse-grained.
for branch in cell.branches:
diameter = 2 * branch.nodes["radius"].to_numpy()[0]
c_m = branch.nodes["capacitance"].to_numpy()[0]
r_a = branch.nodes["axial_resistivity"].to_numpy()[0]
l = branch.nodes["length"].to_numpy()[0]
lambda_f = 1e5 * np.sqrt(diameter / (4 * np.pi * frequency * c_m * r_a))
ncomp = int((l / (d_lambda * lambda_f) + 0.9) / 2) * 2 + 1
branch.set_ncomp(ncomp, initialize=False)
cell.initialize()
################################################################
################################################################
################################################################
coords = np.loadtxt(fname)
row = 55
xyzr = coords[row, [2, 3, 4, 5]]
errors = []
for b in cell.branches:
dists = np.sum((xyzr - b.xyzr[0])**2, axis=1)
min_error = np.min(dists)
errors.append(min_error)
is_in_branch = np.argmin(errors)
xyz_in_branch = cell.branch(is_in_branch).xyzr[0][:, :3]
dists = np.sqrt(np.sum((xyz_in_branch[1:] - xyz_in_branch[:-1])**2, axis=1))
dists_to_swc = np.sum((xyzr[:3] - xyz_in_branch)**2, axis=1)
min_error = np.argmin(dists_to_swc)
cum_dists = np.cumsum(dists)
loc_along_branch = cum_dists[min_error] / np.max(cum_dists)
ncomps = cell.branch(is_in_branch).ncomp
locs_along_branch = np.linspace(1 / ncomps / 2, 1 - 1 / ncomps / 2, ncomps)
voltages = np.random.randn(ncomps)
v_at_swc = np.interp(loc_along_branch, locs_along_branch, voltages)This does not yet deal with branch points. I will open a PR to record the voltage at branch points asap. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We have a bit of an odd use case: we would like to import a .swc file and, for every line of the .swc file, we would like our simulation to report a voltage at that exact location in space. I think the right way to do this is to have a branch for each line of the .swc. Any chance there is a way to do this using existing functions? if not, I suppose it shouldn't be hard to write our own.
Beta Was this translation helpful? Give feedback.
All reactions