Skip to content

Instantly share code, notes, and snippets.

@j6k4m8
Last active January 29, 2016 15:53
Show Gist options
  • Save j6k4m8/4a6761a1ecbdb8bbc754 to your computer and use it in GitHub Desktop.
Save j6k4m8/4a6761a1ecbdb8bbc754 to your computer and use it in GitHub Desktop.
An ndio script to download a full dataset
# Jordan Matelsky (https://github.com/j6k4m8)
# uses ndio>=0.1.3
#
# Usage: python download-as-png.py token channel res startslice stopslice
# Example:
# python download-as-png.py kasthuri11 image 3 1100 1110
# (Will download slices 1100-1110 of the kasthuri11 dataset at resolution 3)
import ndio.remote.neurodata as ND
import ndio.convert.png as ndpng
import sys
nd = ND()
# get the information about the token:channel that we're downloading
# so that if it changes for some weird reason, we'll still download
# everything correctly.
if len(sys.argv) != 5:
raise ValueError("Usage: python download-as-png.py token channel res startslice stopslice")
token = sys.argv[1]
channel = sys.argv[2]
resolution = int(sys.argv[3])
img_size = nd.get_image_size(token, resolution=resolution)
img_offset = nd.get_image_offset(token, resolution=resolution)
start = int(sys.argv[4])
stop = int(sys.argv[5])
query = {
"token": token,
"channel": channel,
"x_start": img_offset[0],
"y_start": img_offset[1],
"z_start": start,
"x_stop": img_size[0],
"y_stop": img_size[1],
"z_stop": stop,
"resolution": resolution
}
vol = nd.get_cutout(**query)
ndpng.export_png_collection('png/*', vol, start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment