Last active
September 15, 2016 14:09
-
-
Save atarkowska/980caed8c1c26d09672e1f9d79277b4e to your computer and use it in GitHub Desktop.
Example of REST API usage. Load data from IDR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# put here project/screen ids | |
containers = (101,) | |
list_datasets_url = "http://idr-demo.openmicroscopy.org/webclient/api/datasets/?id={container_id}&page=0" | |
list_images_url = "http://idr-demo.openmicroscopy.org/webclient/api/images/?id={id}&page=1" | |
image_link = "http://idr-demo.openmicroscopy.org/webclient/?show=image-{id}" | |
image_viewer_link = "http://idr-demo.openmicroscopy.org/webclient/img_detail/{id}/" | |
thumbnail_url = "http://idr-demo.openmicroscopy.org/webclient/render_thumbnail/size/96/{id}/" | |
map_url = "http://idr-demo.openmicroscopy.org/webclient/api/annotations/?type=map&image={id}" | |
for c in containers: | |
print 'Container:', c | |
for d in requests.get(list_datasets_url.format(**{'container_id': c })).json()['datasets']: | |
_url = list_images_url.format(**d) | |
for i in requests.get(_url).json()['images']: | |
print 'image iD:', i['id'] | |
print "image link:", image_link.format(**i) | |
print "image viewer link:", image_viewer_link.format(**i) | |
print 'thumbnail URL:', thumbnail_url.format(**i) | |
for a in requests.get(map_url.format(**i)).json()['annotations']: | |
print 'Annotaitons:' | |
print a['values'] |
Thanks, Ola! This looks great, exactly what I need in the first place.
Do the project ids (i.e. 101) stay the same over data releases? I imagine that if you need to re-import all data these ids will change as well?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output looks like: