Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Linearize the voxel coordinates, and put them into two scipy.sparse.sparse.csc matrices. </p> <p>Let v be the number of voxels, m the number of masks, and t the number of tracks.<br> Let M be the mask csc matrix, size (m x v), where a 1 at (i,j) means mask i overlaps voxel j.<br> Let T be the track csc matrix, size (t x v), where a 1 at (k,j) means track k overlaps voxel j. </p> <pre><code>Overlap = (M * T.transpose() &gt; 0) # track T overlaps mask M Connected = (Overlap * Overlap.tranpose() &gt; 0) # Connected masks Density[mask_idx] = numpy.take(T, nonzero(Overlap[mask_idx, :])[0], axis=0).sum(axis=0) </code></pre> <p>I might be wrong on the last one, and I'm not sure css_matrices can be operated on by nonzero &amp; take. You might need to pull out each column in a loop and convert it to a full matrix.</p> <hr> <p>I ran some experiments trying to simulate what I thought was a reasonable amount of data. The code below takes about 2 minutes on a 2-year old MacBook. If you use csr_matrices, it takes about 4 minutes. There is probably a tradeoff depending on how long each track is. </p> <pre><code>from numpy import * from scipy.sparse import csc_matrix nvox = 1000000 ntracks = 300000 nmask = 100 # create about 100 entries per track tcoords = random.uniform(0, ntracks, ntracks * 100).astype(int) vcoords = random.uniform(0, nvox, ntracks * 100).astype(int) d = ones(ntracks * 100) T = csc_matrix((d, vstack((tcoords, vcoords))), shape=(ntracks, nvox), dtype=bool) # create around 10000 entries per mask mcoords = random.uniform(0, nmask, nmask * 10000).astype(int) vcoords = random.uniform(0, nvox, nmask * 10000).astype(int) d = ones(nmask * 10000) M = csc_matrix((d, vstack((mcoords, vcoords))), shape=(nmask, nvox), dtype=bool) Overlap = (M * T.transpose()).astype(bool) # mask M overlaps track T Connected = (Overlap * Overlap.transpose()).astype(bool) # mask M1 and M2 are connected Density = Overlap * T.astype(float) # number of tracks overlapping mask M summed across voxels </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload