Downloading Images

The ImageDownloadApi class in the AllenSDK provides a Python interface for accessing image data produced by the Allen Institute for Brain Science.

Contents:

Reference Documentation:

Download this file in .ipynb format here.

We will want to look at the images we download in this notebook. Here are a couple of functions that do this:

Finally, we will need an instance of ImageDownloadApi and an instance of SvgApi:

Downloading a single Mouse Brain Section image

In this example, we will download a single section image from Mouse Brain Atlas experiment 71210895.

For now, we'll assume that we already know the id (unique integer identifier) of the image that we wish to download. In a later section, we'll use our ImageDownloadApi instance to find the ids of all the images from a particular experiment.

The raw images can be quite large, so we will download downsampled versions. The downsample keyword argument reduces the size of the obtained image by a factor of $2^{\text{downsample}}$ along each axis.

Now we download the image using our api object and view it in the notebook.

Downloading a single Mouse Connectivity image

In this example, we will download a single section image from Mouse Brain Connectivity experiment 297225422.

In order to clearly distinguish projection signal from background structure, it helps to window and rescale each channel. We have precomputed channelwise windows for each section data set in the connectivity atlas. You can obtain these window parameters using the ImageDownloadApi

Then simply pass them in via the range keyword argument.

If we set the projection keyword argument to True, we can download a mask which labels important features of the image, such as the injection site, detected projection signal, and the boundary of detectable tissue.

Downloading a single atlas image

If we know the id of the atlas image we want, we can download it directly. We'll use an image from the Adult Human Brain Reference Atlas for this example.

Atlas images consist of an annotation image layered over a biological specimen image. You can control which one you download via the annotation keyword argument.

Setting annotation to False will download the biological specimen (in this case, a Nissl section).

We can download the structure drawings and labels (instead of the nissl) by setting annotation=True

Downloading a single atlas svg

We make the atlas drawings available (sans textual labels) as SVG. We'll download and display the SVG for the above atlas image:

Listing images from an atlas (or section data set)

The ImageDownloadApi class can list the images in an atlas or section dataset. For an atlas (the same Human Brain reference atlas as above), this looks like:

The id column of this dataframe contains the ids of the images in this atlas - these are the same integer identifiers that we have been using to download single images.

Downloading all of the images from a section data set

Specifically, Brainspan ISH experiment 100147602.

We'll start with some parameters:

Now we need to get the image ids for all of the images in this data set:

and then iterate:

We should now have a directory containing the requested images.

Listing the section data sets in a product

Related experiments are grouped into products. The ImageDownloadApi has a method for listing the section data sets in a particular product.

Here we will use this method to list section data sets from the Human Brain ISH SubCortex Study (id=10 per the above link).