{ "metadata": { "name": "", "signature": "sha256:ba16b152c30b16a9f74d23c0ea034bf747c7bc67eeaf09b0e5811988245c88d8" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Data Sharing\n", "\n", "* We can now warmly share data and get credits for it as a paper publication.\n", "* We are going to illustrate this process for the case of [Figshare](http://figshare.com).\n", "* Keep in mind that other data sharing sites may exist for your discipline." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Locate your Image\n", "\n", "* Find in your local filesystem the images that you just acquired.\n", "* We will upload on of these images to Figshare." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Log into Figshare\n", "\n", "* Log into your [Figshare account](http://figshare.com/account/my_data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Upload Image\n", "\n", "* Click on the [Upload](http://figshare.com/account/upload) link at the top of the page\n", "* Follow the instructions and browse to the location of your acquired images in your filesystem\n", "* Upload only one Image at this point" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Publish the Image\n", "\n", "* Go to the [My Data](http://figshare.com/account/my_data) link at the top of the page and find your new uploaded image in the list\n", "* On the Status column, click on the \"**DRAFT**\" button\n", " * Select a title for the image (use a serious and descriptive title)\n", " * This is important since the image will get a real [DOI](http://en.wikipedia.org/wiki/Digital_object_identifier), just like an article\n", " * Select a **Category**, from the dropdown menu\n", " * In our case, we could use \"Biological Techniques\"\n", " * Enter a serious description in the \"**Description**\" field.\n", " * Click on the \"**Public**\" button, on the bottom right, to make the image publicly available\n", " * **Save** the changes\n", " * Click on the \"**Publish**\" link, on the bottom right.\n", " * Answer the confirmation by clicking on the \"**Yes, publish**\" button\n", " * Click on \"**Preview**\" the article" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Find Reference to the Image\n", "\n", "We need to be able to refer programatically to this image.\n", "\n", "Here we do this with the [Figshare's REST API](http://api.figshare.com/docs/).\n", "\n", "### Do The Following\n", "\n", "* For your image, take note of its identifier:\n", " * For example: [http://figshare.com/articles/Tardigrades_Image_01/1050595]\n", " * Has the identifier: \"**1050595**\"\n", "* Use this identifier in the following URL to get the article metadata:\n", " * http://api.figshare.com/v1/articles/1050595\n", " * This will return a JSON structure similar to the following\n", "\n", "
\n",
      "    {\"count\": 1, \"items\": [{\"article_id\": 1050595, \"title\": \"Image 002\", \"figshare_url\": \"http://figshare.com/articles/Image_002/1050595\", \"views\": 1, \"downloads\": 0, \"shares\": 0, \"doi\": \"http://dx.doi.org/10.6084/m9.figshare.1050595\", \"publisher_doi\": \"\", \"publisher_citation\": \"\", \"master_publisher_id\": 0, \"defined_type\": \"figure\", \"status\": \"Public\", \"version\": 1, \"published_date\": \"23:09, Jun 14, 2014\", \"description\": \"

Image of Tardigrade acquired with a cell phone water drop microscope

\", \"description_nohtml\": \"Image of Tardigrade acquired with a cell phone water drop microscope\", \"total_size\": \"85.10 KB\", \"owner\": {\"id\": 97454, \"full_name\": \"Luis Ibanez\"}, \"authors\": [{\"first_name\": \"Luis\", \"last_name\": \"Ibanez\", \"id\": 97454, \"full_name\": \"Luis Ibanez\"}], \"tags\": [{\"id\": 247678, \"name\": \"diy microscopy\"}, {\"id\": 98329, \"name\": \"tardigrades\"}], \"categories\": [{\"id\": 12, \"name\": \"Cell Biology\"}, {\"id\": 8, \"name\": \"Microbiology\"}], \"files\": [{\"thumb\": \"http://previews.figshare.com/1526484/250_1526484.jpg\", \"download_url\": \"http://files.figshare.com/1526484/IMG_20140331_131717.jpeg\", \"name\": \"IMG_20140331_131717.jpeg\", \"id\": 1526484, \"mime_type\": \"image/jpeg\", \"size\": \"87 KB\"}], \"links\": []}]}\n", "
\n", "\n", "* Look for the \"download_url\" tag.\n", " * Is the sixth from the end of the JSON structure." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Test the Download\n", "\n", "* Now we can refer to to actual file by using the \"download_url\" as\n", " * http://files.figshare.com/1526484/IMG_20140331_131717.jpeg\n", " * Put the \"download_url\" of your image in a browser and verify that the image is downloaded" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Programatic Download\n", "\n", "We now use the urllib module to download the image.\n", "\n", "We do this in several stages" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get the Article's URL" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import urllib\n", "import json\n", "\n", "destination_file = '/tmp/myimage.jpg'\n", "\n", "figshare_id = '1066744'\n", "\n", "figshare_url = \"http://api.figshare.com/v1/articles/%s\" % figshare_id" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Request Article Details from Figshare \n", "\n", "We do this using the REST API\n", "\n", "The response comes in the form of a JSON structure" ] }, { "cell_type": "code", "collapsed": false, "input": [ "jsonresponse = urllib.urlopen(figshare_url)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Find the Download URL\n", "\n", "We can now load the JSON structure into an object" ] }, { "cell_type": "code", "collapsed": false, "input": [ "article_info = json.load(jsonresponse)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and extract the \"**download_url**\" from it" ] }, { "cell_type": "code", "collapsed": false, "input": [ "image_download_url = article_info['items'][0]['files'][0]['download_url']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Finally Download the Image\n", "\n", "Using this URL we now download the image into the local file system." ] }, { "cell_type": "code", "collapsed": false, "input": [ "urllib.urlretrieve(image_download_url, destination_file)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Check for the Image Presence\n", "\n", "Simly use the \"ls\" command and the expected destination of the file.\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "ls -l /tmp/myimage.jpg" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Hands On\n", "\n", "* Repeat this process with your image in Figshare\n", "* Print out the raw content of the JSON response\n", "* Verify that the file appears in your file system" ] } ], "metadata": {} } ] }