In [ ]:
import pymaid
from pymaid import tiles

rm = pymaid.CatmaidInstance('https://www.your.catmaid-server.org' ,
                            api_token='YOURTOKEN',
                            http_user='user', # omit if not required
                            http_password='password' # omit if not required
                           )

In [2]:
# Get a neuron
n = pymaid.get_neuron(16)
# Pick a random synapse
center = n.connectors.sample(1).iloc[0][['x', 'y', 'z']].values
center


Out[2]:
array([379172, 146340, 184240])

In [3]:
min_co = center - 5000
max_co = center + 5000
bbox = [c for co in zip(min_co[:2], max_co[:2]) for c in co] + [center[2]]
bbox


Out[3]:
[374172, 384172, 141340, 151340, 184240]

In [4]:
job = tiles.TileLoader(bbox, stack_id=5, coords='NM')


INFO  : Fastest image mirror: https://flyemdev.mrc-lmb.cam.ac.uk/fafb-tiles/ (pymaid)
INFO  : Estimated memory usage: 75.50 Mb (pymaid)

In [5]:
job.load_in_memory()

In [6]:
job.img.shape


Out[6]:
(2500, 2500, 1)

In [7]:
import matplotlib.pyplot as plt

ax = job.render_im(figsize=(12,12))
plt.show()



In [8]:
# First render the image
ax = job.render_im(figsize=(12,12))

# Now add the nodes
job.render_nodes(ax, treenodes=True, connectors=False)

# Readjust the figure limits
ax.set_xlim(0,2500)
ax.set_ylim(0,2500)

plt.show()



In [9]:
# Get skeleton IDs of all uPNs
upn = pymaid.get_skids_by_annotation('uPN')

# Generate a random color for each uPN
from colorsys import hsv_to_rgb
cmap = {n: hsv_to_rgb(1/len(upn)*i, 1, 1) for i, n in enumerate(upn)}


INFO  : Looking for Annotation(s): uPN (pymaid)
INFO  : Found 149 skeletons with matching annotation(s) (pymaid)

In [10]:
# Render image
ax = job.render_im(slider=False, figsize=(12,12))

# Add treenodes
job.render_nodes(ax, 
                 treenodes=True,
                 connectors=True,
                 skid_include=upn, # show only uPNs
                 tn_color=cmap, # apply colormap
                 cn_kws={'s':500, # make connectors larger
                         'edgecolor':'w'} # make connectors white
                )

# Add 1um scalebar
job.scalebar(size=1000, ax=ax, label=False, line_kws={'color':'w', 'lw':5})

# Show
plt.show()



In [3]:
# This assumes a 40nm z resolution
z2 = 184240 + 40 * 10
bbox = [374172, 384172, 141340, 151340, 184240, z2]

job = tiles.TileLoader(bbox, stack_id=5, coords='NM')


INFO  : Image mirror: https://flyemdev.mrc-lmb.cam.ac.uk/fafb-tiles/ (pymaid)
INFO  : Estimated memory usage for loading all images: 830.47 Mb (pymaid)

In [5]:
job.load_and_save(filepath='/Users/philipps/Downloads/slices/')



In [8]:
from IPython.display import Image
Image(filename='/Users/philipps/Downloads/slices/10.jpg')


Out[8]: