Skip to content

Instantly share code, notes, and snippets.

@dyf
Last active January 6, 2017 01:01
Show Gist options
  • Save dyf/718abc95833fa6263be6dfe1a91ef32a to your computer and use it in GitHub Desktop.
Save dyf/718abc95833fa6263be6dfe1a91ef32a to your computer and use it in GitHub Desktop.
Download Aging ISH Images
from allensdk.config import enable_console_log
from allensdk.api.queries.rma_api import RmaApi
from allensdk.api.queries.image_download_api import ImageDownloadApi
# print download messages to your console
enable_console_log()
# instantiate api classes for downloading metadata/images
image_api = ImageDownloadApi()
rma_api = RmaApi()
# this is the aging ish product
product_name = "Aging Dementia TBI - ISH data"
# download 2000 image metadata records at a time
start_row = 0
num_rows = 2000
all_images = []
while True:
images = rma_api.model_query("SectionImage",
criteria="data_set(products[name$eq'%s'])" % product_name,
start_row=start_row,
num_rows=num_rows,
count=False)
all_images += images
start_row += len(images)
if len(images) == 0:
break
# download the images themselves
for i, image in enumerate(all_images):
file_path = "%d.jpg" % image["id"]
image_api.download_section_image(file_path=file_path, section_image_id=image["id"], quality=100)
print(i, file_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment