allensdk.api.queries.image_download_api module

class allensdk.api.queries.image_download_api.ImageDownloadApi(base_uri=None)[source]

Bases: allensdk.api.queries.rma_template.RmaTemplate

HTTP Client to download whole or partial two-dimensional images from the Allen Institute with the SectionImage, AtlasImage and ProjectionImage Download Services.

See Downloading an Image for more documentation.

COLORMAPS = {'aba': 8, 'aibsmap_alt': 9, 'blue': 6, 'colormap': 10, 'expression': 4, 'gray': 0, 'green': 7, 'hotmetal': 1, 'jet': 2, 'projection': 11, 'red': 5, 'redtemp': 3}
atlas_image_query(self, atlas_id, image_type_name=None)[source]

List atlas images belonging to a specified atlas

Parameters:
atlas_id : integer, optional

Find images from this atlas.

image_type_name : string, optional

Restrict response to images of this type. If not provided, the query will get it from the atlas id.

Returns:
list of dict :

Each element is an AtlasImage record.

Notes

See Downloading Atlas Images and Graphics for additional documentation. allensdk.api.queries.ontologies_api.OntologiesApi.get_atlases() can also be used to list atlases along with their ids.

download_atlas_image(self, atlas_image_id, file_path=None, **kwargs)[source]
download_image(self, image_id, file_path=None, endpoint=None, **kwargs)[source]

Download whole or partial two-dimensional images from the Allen Institute with the SectionImage or AtlasImage service.

Parameters:
image_id : integer

SubImage to download.

file_path : string, optional

where to put it, defaults to image_id.jpg

downsample : int, optional

Number of times to downsample the original image.

quality : int, optional

jpeg quality of the returned image, 0 to 100 (default)

expression : boolean, optional

Request the expression mask for the SectionImage.

view : string, optional

‘expression’, ‘projection’, ‘tumor_feature_annotation’ or ‘tumor_feature_boundary’

top : int, optional

Index of the topmost row of the region of interest.

left :int, optional

Index of the leftmost column of the region of interest.

width : int, optional

Number of columns in the output image.

height : int, optional

Number of rows in the output image.

range : list of ints, optional

Filter to specify the RGB channels. low,high,low,high,low,high

colormap : list of floats, optional

Filter to specify the RGB channels. [lower_threshold,colormap] gain 0-1, colormap id is a string from ImageDownloadApi.COLORMAPS

rgb : list of floats, optional

Filter to specify the RGB channels. [red,green,blue] 0-1

contrast : list of floats, optional

Filter to specify contrast parameters. [gain,bias] 0-1

annotation : boolean, optional

Request the annotated AtlasImage

atlas : int, optional

Specify the desired Atlas’ annotations.

projection : boolean, optional

Request projection for the specified image.

downsample_dimensions : boolean, optional

Indicates if the width and height should be adjusted to account for downsampling.

Returns:
None

the file is downloaded and saved to the path.

Notes

By default, an unfiltered full-sized image with the highest quality is returned as a download if no parameters are provided.

‘downsample=1’ halves the number of pixels of the original image both horizontally and vertically. range_list = kwargs.get(‘range’, None)

Specifying ‘downsample=2’ quarters the height and width values.

Quality must be an integer from 0, for the lowest quality, up to as high as 100. If it is not specified, it defaults to the highest quality.

Top is specified in full-resolution (largest tier) pixel coordinates. SectionImage.y is the default value.

Left is specified in full-resolution (largest tier) pixel coordinates. SectionImage.x is the default value.

Width is specified in tier-resolution (desired tier) pixel coordinates. SectionImage.width is the default value. It is automatically adjusted when downsampled.

Height is specified in tier-resolution (desired tier) pixel coordinates. SectionImage.height is the default value. It is automatically adjusted when downsampled.

The range parameter consists of 6 comma delimited integers that define the lower (0) and upper (4095) bound for each channel in red-green-blue order (i.e. “range=0,1500,0,1000,0,4095”). The default range values can be determined by referring to the following fields on the Equalization model associated with the SectionDataSet: red_lower, red_uppper, green_lower, green_upper, blue_lower, blue_upper. For more information, see the Image Controls section of the Allen Mouse Brain Connectivity Atlas: Projection Dataset help topic. See: `Image Download Service `<http://help.brain-map.org/display/api/Downloading+an+Image>_

download_projection_image(self, projection_image_id, file_path=None, **kwargs)[source]
download_section_image(self, section_image_id, file_path=None, **kwargs)[source]
get_section_data_sets_by_product(self, product_ids, include_failed=False, num_rows='all', count=False, **kwargs)[source]

List all of the section data sets produced as part of one or more products

Parameters:
product_ids : list of int

Integer specifiers for Allen Institute products. A product is a set of related data.

include_failed : bool, optional

If True, find both failed and passed datasets. Default is False

num_rows : int, optional

how many records to retrieve. Default is ‘all’.

count : bool, optional

If True, return a count of the lines found by the query. Default is False.

Returns:
list of dict :

Each returned element is a section data set record.

Notes

See http://api.brain-map.org/api/v2/data/query.json?criteria=model::Product for a list of products.

get_section_image_ranges(self, section_image_ids, num_rows='all', count=False, as_lists=True, **kwargs)[source]

Section images from the Mouse Connectivity Atlas are displayed on connectivity.brain-map.org after having been linearly windowed and leveled. This method obtains parameters defining channelwise upper and lower bounds of the windows used for one or more images.

Parameters:
section_image_ids : list of int

Each element is a unique identifier for a section image.

num_rows : int, optional

how many records to retrieve. Default is ‘all’.

count : bool, optional

If True, return a count of the lines found by the query. Default is False.

as_lists : bool, optional

If True, return the window parameters in a list, rather than a dict (this is the format of the range parameter on ImageDownloadApi.download_image). Default is False.

Returns:
list of dict or list of list :

For each section image id provided, return the window bounds for each channel.

rma_templates = {'image_queries': [{'name': 'section_image_ranges', 'description': 'see name', 'model': 'Equalization', 'num_rows': 'all', 'count': False, 'only': ['blue_lower', 'blue_upper', 'red_lower', 'red_upper', 'green_lower', 'green_upper'], 'criteria': 'section_data_set(section_images[id$in{{ section_image_ids }}])', 'criteria_params': ['section_image_ids']}, {'name': 'section_images_by_data_set_id', 'description': 'see name', 'model': 'SectionImage', 'num_rows': 'all', 'count': False, 'criteria': '[data_set_id$eq{{ data_set_id }}]', 'criteria_params': ['data_set_id']}, {'name': 'section_data_sets_by_product_id', 'description': 'see name', 'model': 'SectionDataSet', 'num_rows': 'all', 'count': False, 'criteria': '[failed$in{{failed}}],products[id$in{{ product_ids }}]', 'criteria_params': ['product_ids', 'failed']}]}
section_image_query(self, section_data_set_id, num_rows='all', count=False, **kwargs)[source]

List section images belonging to a specified section data set

Parameters:
atlas_id : integer, optional

Find images from this section data set.

num_rows : int

how many records to retrieve. Default is ‘all’

count : bool

If True, return a count of the lines found by the query.

Returns:
list of dict :

Each element is an SectionImage record.

Notes

The SectionDataSet model is used to represent single experiments which produce an array of images. This includes Mouse Connectivity and Mouse Brain Atlas experiments, among other projects. You may see references to the ids of experiments from those projects. These are the same as section data set ids.