Skip to content

Commit da2f777

Browse files
committed
write_precomputed: fix skeleton edges
1 parent 16b6656 commit da2f777

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

navis/io/precomputed_io.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def write_info_file(data, filepath, add_props={}):
500500
u = 1
501501
tr = np.zeros((4, 3), dtype=int)
502502
tr[:3, :3] = np.diag([u, u, u])
503-
info['transform'] = tr.flatten().tolist()
503+
info['transform'] = tr.T.flatten().tolist()
504504

505505
else:
506506
raise TypeError(f'Unable to write info file for data of type "{type(data)}"')
@@ -539,14 +539,15 @@ def _write_skeleton(x, filename, radius=False):
539539
# Below code modified from:
540540
# https://github.com/google/neuroglancer/blob/master/python/neuroglancer/skeleton.py#L34
541541
result = io.BytesIO()
542-
vertex_positions = x.nodes[['x', 'y', 'z']].values.astype('float32')
542+
vertex_positions = x.nodes[['x', 'y', 'z']].values.astype('float32', order='C')
543543
# Map edges node IDs to node indices
544544
node_ix = pd.Series(x.nodes.reset_index(drop=True).index, index=x.nodes.node_id)
545-
edges = x.edges.copy().astype('uint32')
545+
edges = x.edges.copy().astype('uint32', order='C')
546546
edges[:, 0] = node_ix.loc[edges[:, 0]].values
547547
edges[:, 1] = node_ix.loc[edges[:, 1]].values
548+
edges = edges[:, [1, 0]] # For some reason we have to switch direction
548549

549-
result.write(struct.pack('<II', vertex_positions.shape[0], edges.shape[0] // 2))
550+
result.write(struct.pack('<II', vertex_positions.shape[0], edges.shape[0]))
550551
result.write(vertex_positions.tobytes())
551552
result.write(edges.tobytes())
552553

0 commit comments

Comments
 (0)