ibllib.atlas.plots

Module that has convenience plotting functions for 2D atlas slices

Functions

compute_volume_from_points

Creates a 3D volume with xyz points placed in corresponding voxel in volume.

plot_points_on_slice

Plot xyz points on slice.

plot_scalar_on_barplot

plot_scalar_on_flatmap

Function to plot scalar value per allen region on flatmap slice

plot_scalar_on_slice

Function to plot scalar value per allen region on histology slice

plot_volume_on_slice

Plot slice at through volume

prepare_lr_data

Prepare data in format needed for plotting when providing different region values per hemisphere

reorder_data

Reorder list of acronyms and values to match the Allen ordering

prepare_lr_data(acronyms_lh, values_lh, acronyms_rh, values_rh)[source]

Prepare data in format needed for plotting when providing different region values per hemisphere

Parameters
  • acronyms_lh – array of acronyms on left hemisphere

  • values_lh – values for each acronym on left hemisphere

  • acronyms_rh – array of acronyms on right hemisphere

  • values_rh – values for each acronym on left hemisphere

Returns

combined acronyms and two column array of values

reorder_data(acronyms, values, brain_regions=None)[source]

Reorder list of acronyms and values to match the Allen ordering

Parameters
  • acronyms – array of acronyms

  • values – array of values

  • brain_regions – BrainRegions object

Returns

ordered array of acronyms and values

plot_scalar_on_slice(regions, values, coord=-1000, slice='coronal', mapping='Allen', hemisphere='left', background='image', cmap='viridis', clevels=None, show_cbar=False, brain_atlas=None, ax=None)[source]

Function to plot scalar value per allen region on histology slice

Parameters
  • regions – array of acronyms of Allen regions

  • values – array of scalar value per acronym. If hemisphere is ‘both’ and different values want to be shown on each

hemispheres, values should contain 2 columns, 1st column for LH values, 2nd column for RH values :param coord: coordinate of slice in um (not needed when slice=’top’) :param slice: orientation of slice, options are ‘coronal’, ‘sagittal’, ‘horizontal’, ‘top’ (top view of brain) :param mapping: atlas mapping to use, options are ‘Allen’, ‘Beryl’ or ‘Cosmos’ :param hemisphere: hemisphere to display, options are ‘left’, ‘right’, ‘both’ :param background: background slice to overlay onto, options are ‘image’ or ‘boundary’ :param cmap: colormap to use :param clevels: min max color levels [cmin, cmax] :param show_cbar: whether or not to add colorbar to axis :param brain_atlas: AllenAtlas object :param ax: optional axis object to plot on :return:

plot_scalar_on_flatmap(regions, values, depth=0, flatmap='dorsal_cortex', mapping='Allen', hemisphere='left', background='boundary', cmap='viridis', clevels=None, show_cbar=False, flmap_atlas=None, ax=None)[source]

Function to plot scalar value per allen region on flatmap slice

Parameters
  • regions – array of acronyms of Allen regions

  • values – array of scalar value per acronym. If hemisphere is ‘both’ and different values want to be shown on each

hemispheres, values should contain 2 columns, 1st column for LH values, 2nd column for RH values :param depth: depth in flatmap in um :param flatmap: name of flatmap (currently only option is ‘dorsal_cortex’) :param mapping: atlas mapping to use, options are ‘Allen’, ‘Beryl’ or ‘Cosmos’ :param hemisphere: hemisphere to display, options are ‘left’, ‘right’, ‘both’ :param background: background slice to overlay onto, options are ‘image’ or ‘boundary’ :param cmap: colormap to use :param clevels: min max color levels [cmin, cmax] :param show_cbar: whether to add colorbar to axis :param flmap_atlas: FlatMap object :param ax: optional axis object to plot on :return:

plot_volume_on_slice(volume, coord=-1000, slice='coronal', mapping='Allen', background='boundary', cmap='Reds', clevels=None, show_cbar=False, brain_atlas=None, ax=None)[source]

Plot slice at through volume

Parameters
  • volume – 3D array of volume (must be same shape as brain_atlas object)

  • coord – coordinate of slice in um

  • slice – orientation of slice, options are ‘coronal’, ‘sagittal’, ‘horizontal’

  • mapping – atlas mapping to use, options are ‘Allen’, ‘Beryl’ or ‘Cosmos’

  • background – background slice to overlay onto, options are ‘image’ or ‘boundary’

  • cmap – colormap to use

  • clevels – min max color levels [cmin, cmax]

  • show_cbar – whether or not to add colorbar to axis

  • brain_atlas – AllenAtlas object

  • ax – optional axis object to plot on

Returns

plot_points_on_slice(xyz, values=None, coord=-1000, slice='coronal', mapping='Allen', background='boundary', cmap='Reds', clevels=None, show_cbar=False, aggr='mean', fwhm=100, brain_atlas=None, ax=None)[source]

Plot xyz points on slice. Points that lie in the same voxel within slice are aggregated according to method specified. A 3D Gaussian smoothing kernel with distance specified by fwhm is applied to images.

Parameters
  • xyz – 3 column array of xyz coordinates of points in metres

  • values – array of values per xyz coordinates, if no values are given the sum of xyz points in each voxel is

returned :param coord: coordinate of slice in um (not needed when slice=’top’) :param slice: orientation of slice, options are ‘coronal’, ‘sagittal’, ‘horizontal’, ‘top’ (top view of brain) :param mapping: atlas mapping to use, options are ‘Allen’, ‘Beryl’ or ‘Cosmos’ :param background: background slice to overlay onto, options are ‘image’ or ‘boundary’ :param cmap: colormap to use :param clevels: min max color levels [cmin, cmax] :param show_cbar: whether or not to add colorbar to axis :param aggr: aggregation method. Options are sum, count, mean, std, median, min and max. Can also give in custom function (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binned_statistic.html) :param fwhm: fwhm distance of gaussian kernel in um :param brain_atlas: AllenAtlas object :param ax: optional axis object to plot on

Returns

compute_volume_from_points(xyz, values=None, aggr='sum', fwhm=100, ba=None)[source]

Creates a 3D volume with xyz points placed in corresponding voxel in volume. Points that fall into the same voxel within the volume are aggregated according to the method specified in aggr. Gaussian smoothing with a 3D kernel with distance specified by fwhm (full width half max) argument is applied. If fwhm = 0, no gaussian smoothing is applied.

Parameters
  • xyz – 3 column array of xyz coordinates of points in metres

  • values – 1 column array of values per xyz coordinates, if no values are given the sum of xyz points in each voxel is

returned :param aggr: aggregation method. Options are sum, count, mean, std, median, min and max. Can also give in custom function (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binned_statistic.html) :param fwhm: full width at half maximum of gaussian kernel in um :param ba: AllenAtlas object :return:

plot_scalar_on_barplot(acronyms, values, errors=None, order=True, ylim=None, ax=None, brain_regions=None)[source]