def to_json(self, fname='cluster.json', k=5, criterion='maxclust'):
""" Convert clustered neurons into json file that can be loaded into
CATMAID selection table.
Parameters
----------
fname : str, optional
Filename to save selection to
k : {int, float}
criterion : {'maxclust','distance'}, optional
If `maxclust`, `k` clusters will be formed. If `distance`,
clusters will be created at threshold `k`.
See Also
--------
:func:`pymaid.plot.plot3d`
Function called to generate 3d plot
"""
cmap = self.get_colormap(k=k, criterion=criterion)
# Convert to 0-255
cmap = { n : [ int(v*255) for v in cmap[n] ] for n in cmap }
data = [ dict(skeleton_id=int(n),
color="#{:02x}{:02x}{:02x}".format( cmap[n][0],cmap[n][1],cmap[n][2] ),
opacity=1
) for n in cmap ]
with open(fname, 'w') as outfile:
json.dump(data, outfile)
module_logger.info('Selection saved as %s in %s' % (fname, os.getcwd()))
return
评论列表
文章目录