Sunday, May 26, 2013

A simple Python phylopic.org wrapper

PhyloPic.org is an online repository of species silhouettes. I love the idea, I think it could be very useful to jazz up figures, and they have a fantastic search feature and API. This morning I wrote up a simple Python wrapper of the API - enter one or more taxon names, download thumbnail images for each one.

In [1]:
import phylopic

phylopic.download_pics('Turdus migratorius', 'Anolis carolinensis', 'Panthera leo', img_format='thumb.png')
Downloading pic for Turdus migratorius... done!
Downloading pic for Anolis carolinensis... done!
Downloading pic for Panthera leo... done!
In [2]:
imshow(imread('Turdus migratorius.thumb.png'))
Out[2]:
<matplotlib.image.AxesImage at 0x37a6c10>
In [3]:
imshow(imread('Anolis carolinensis.thumb.png'))
Out[3]:
<matplotlib.image.AxesImage at 0x36cf250>
In [4]:
imshow(imread('Panthera leo.thumb.png'))
Out[4]:
<matplotlib.image.AxesImage at 0x36fc9d0>

Currently you can download either a low-res thumbnail or an SVG (the default, not so ugly and pixel-y, but I couldn't find a good way to embed it into an IPython notebook.)

Code available on GitHub

4 comments:

  1. Nice! R version started here: https://github.com/schamberlain/fylopic

    ReplyDelete
  2. Very cool!

    Note that the SVG file does not exist for all submissions. You can check whether there is one by using the Image method with the "svgFile" option. If you also use the "pngFiles" option, you could pick the largest PNG file if there is no SVG file.

    I need to update the Links page with a link to this and Scott's Fylopic.

    ReplyDelete
    Replies
    1. Thanks for the tip! I'll update my code to reflect this.

      I love what Scott has done with fylopic - the integration of phylopic images with R's plotting functions is very cool.

      Delete
  3. I began some work with phylopic before the API was ready. Here is my proof of concept for integrating silhouettes into a R ggplot legend. Didn't plan with Scott so I'll just merge my efforts into his work.

    ReplyDelete