Skip to content

get_sample_pts_euclidean: interpolation weights appear swapped #22

Closed

Description

@tatsuookubo

Summary

When get_sample_pts_euclidean samples points along an SWC edge, the interpolation appears to place each point at the mirrored location on that edge. In a simple 3-node chain, this changes the actual distances from the root returned by the sampler, not just their order.

I’m including:


Minimal reproducible example

  • Save the following as demo.swc. The example neuron has 3 nodes on the x-axis at x = [0, 3, 10].
# id type x  y  z  radius parent
1  1    0  0  0  1     -1
2  3    3  0  0  1      1
3  3   10  0  0  1      2
  • Run:
python sampling_with_demo_swc.py
  • Observe output:
expected: [ 0.  2.  4.  6.  8. 10.]
got     : [0. 1. 3. 5. 7. 9.]

Potential fix

In get_sample_pts_euclidean inside src/cajal/sample_swc.py, interpolation currently uses:

(root_triple * x) + (child_triple * (1 - x))

If sampled points are intended to be measured from the parent/root along the edge, the weights seem swapped. A possible change would be:

(root_triple * (1 - x)) + (child_triple * x)
  • sampling_potential_fix.py demonstrates the output before and after swapping these weights, again using the 3-node example above.

Activity

  1. pcamara commented on Mar 19, 2026

    @pcamara
    Contributor

    Hi @tatsuookubo ,

    Thanks so much for catching this. You are right that the interpolation was inverted and I agree with your fix. It should not affect morphological distances substantially, since GW does not require uniform sampling, but it is more accurate.

    Please feel free to open a pull request, and I will merge it. Alternatively, if you prefer that we implement the fix on our end, just let me know.

  2. tatsuookubo commented on Mar 23, 2026

    @tatsuookubo
    ContributorAuthor

    Thank you very much for taking a look!
    In our hands, this had very little effect on the resulting intra-cellular distance matrices, but I just wanted to bring it up in case it helps make the implementation consistent with the documented behavior.
    I've opened a pull request with a proposed fix: #23.

    Overall, this CAJAL package is very inspiring and well implemented, and we have learned a great deal from it. Thank you to your group for this nice contribution to the field!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions