iblviewer.mouse_brain
Classes
This overwrites the constructor of AllenAtlas that is not designed to be used for the public, that is people outside of IBL. |
|
IBL Atlas is a wrapper for the Allen Atlas with added features. |
|
This is your entry point to International Brain Laboratory data visualization |
- class AllenAtlasExt(res_um=25, brainmap='Allen', scaling=array([1, 1, 1]), image_file_path=None, label_file_path=None)[source]
Bases:
ibllib.atlas.atlas.AllenAtlas
This overwrites the constructor of AllenAtlas that is not designed to be used for the public, that is people outside of IBL. Typically, you’d want to display the Allen volume data in this viewer and perform additional tasks (such as loading your own extra data) with other libraries. Dev note: I’m forced to copy and modify the whole constructor in this case.
Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution using the IBL Bregma and coordinate system
- remap_atlas(local_file_path, regions=None, ibregma=None)[source]
Remap the atlas label into a usable volume
- lateralize(label, regions=None, ibregma=None)[source]
Breaks the symmetry in regions labels in the Allen Mouse Atlas where the id of a region in the left hemisphere is the same as the same region in the right hemisphere. But if we want to map recordings to the brain, we need separate ids.
- Parameters
label – Segmented volume
- Returns
Modified volume
- class IBLAtlasModel(origin: numpy.ndarray = array([5739, 5400, 332]), atlas: Optional[ibllib.atlas.atlas.AllenAtlas] = None, atlas_lut: Optional[iblviewer.volume.LUTModel] = None, atlas_mapping_ids: Optional[list] = None, ibl_back_end: bool = True, atlas_volume: Optional[iblviewer.volume.VolumeModel] = None, dwi_volume: Optional[iblviewer.volume.VolumeModel] = None)[source]
Bases:
object
IBL Atlas is a wrapper for the Allen Atlas with added features. The volume is also modified such that it fits functional needs.
- origin: numpy.ndarray = array([5739, 5400, 332])
- atlas: ibllib.atlas.atlas.AllenAtlas = None
- atlas_lut: iblviewer.volume.LUTModel = None
- atlas_mapping_ids: list = None
- ibl_back_end: bool = True
- IBL_TRANSPOSE = (1, 0, 2)
- atlas_volume: iblviewer.volume.VolumeModel = None
- dwi_volume: iblviewer.volume.VolumeModel = None
- initialize(resolution=None, ibl_back_end=True)[source]
Get Allen Atlas metadata (.csv file that is copied into ibllib.atlas) and volume files
- Parameters
resolution – Volume resolution in microns
- get_atlas_model(atlas_mapping=None)[source]
Get a VolumeModel instance that represents the atlas (segmented) volume
- Parameters
atlas_mapping – IBL Mapping that we want to use on this atlas. See ibllib.atlas.AllenAtlas.regions.mappings.keys()
- Returns
VolumeModel
- get_value_from_scalar_map(scalar)[source]
Reverse look-up in array to find a corresponding value
- Parameters
scalar – Scalar value
- Returns
Raw volume value
- get_mapped_data(value)[source]
Given a value from the segmented volume, we retrieve useful info
- Parameters
value – Value from the volume
- Returns
Dictionary of corresponding data
- remap(ids, source='Allen', dest='Beryl')[source]
Remap ids/scalar values from source to destination Function by Olivier Winter
- Parameters
ids – List of ids
source – Source mapping
dest – Destination mapping
- get_allen_volume_file_name(resolution, raw_image=False)[source]
Get the Allen volume file name given its resolution
- Parameters
resolution – Resolution of the volume
raw_image – Whether we want the raw volume file name or the segmented one
- Returns
String
- get_allen_volume_url(resolution, raw_image=False)[source]
Construct a URL with which we can download data sets
- Parameters
resolution – Volume resolution, either 10, 25, 50 or 100 (um)
raw_image – Whether the volume is the segmented one (aka the atlas) or the DWI
- Returns
String
- load_volume(file_path, remap_scalars=False, mapping=None, make_current=True)[source]
Load a volume data file. Supports NRRD and many other formats thanks to vedo/VTK
- Parameters
file_path – Volume file path. Could support other file types easily.
remap_scalars – Whether scalar values in the volume are replaced by their row id from a mapping that stores. This is necessary in the case of segmented volumes with regions that have a discontinuous id.
mapping – Pandas Series or a Dictionary
make_current – Set the volume data as the current one
- Returns
3D array
- get_mapped_volume(volume, atlas_mapping=None, ibl_back_end=True)[source]
Set the volume data according to a mapping
- Parameters
volume – Given volume to display
atlas_mapping – Mapping, either a string for the name of the mapping or an integer.
ibl_back_end – If you are not using ibllib and want to load your own volume, set this to False so that there will be no transposition of the volume (needed for the ones from IBL)
- Returns
Volume nd array
- get_region_and_row_id(acronym)[source]
Get region and row id given an acronym
- Parameters
acronym – Acronym of a brain region
- Returns
Region id and row id
- get_regions_mask(region_ids, alpha_map=None)[source]
Build an alpha map that reveals only the given region ids
- Parameters
region_ids – List or numpy array of region ids
alpha_map – Optional alpha map that will be modified. If None provided, the method will attempt to use the current active alpha map
- Returns
2D numpy array with region ids and corresponding alpha values
- class MouseBrainViewer[source]
Bases:
iblviewer.application.Viewer
This is your entry point to International Brain Laboratory data visualization
- initialize(resolution=25, mapping='Beryl', add_atlas=True, add_dwi=False, dwi_color_map='viridis', dwi_alpha_map=None, local_allen_volumes_path=None, offscreen=False, jupyter=False, embed_ui=False, embed_font_size=15, plot=None, plot_window_id=0, num_windows=1, render=False, dark_mode=False)[source]
Initialize the controller, main entry point to the viewer
- Parameters
resolution – Resolution of the atlas volume. Possible values are 10 (requires a lot of RAM), 25, 50, 100. Units are in microns
mapping – Optional mapping value. In the context of IBL, there is ‘Allen’ for the standard Allen map and ‘Beryl’ (random name) which aggregates cortical layers as one.
add_atlas – Whether the Atlas is included in the viewer
add_dwi – Whether the diffusion weighted imaging is loaded in the viewer (same boundaries as atlas)
context – Context of the visualization
embed_ui – Whether the UI is embed within the VTK window
embed_font_size – Embed font size. Defaults to 16 points. You might need larger values in case you have a small screen with high dpi (but VTK methods fail to detect that).
jupyter – Whether we’re running from a jupyter notebook or not
plot – A vedo Plotter instance. You can either create it by yourself before hand, in case you want to have multiple windows with other stats or let the controller create a new one
plot_window_id – Sub-window id where the 3D visualization will be displayed
num_windows – Number of subwindows, in case you want to display your own stuff later
dark_mode – Whether the viewer is in dark mode
- add_atlas_dwi(color_map, alpha_map)[source]
Add the Allen Atlas diffusion weighted image
- Parameters
color_map – Color map for the volume
alpha_map – Alpha map for the volume
- load_bounding_mesh(add_to_scene=False, alpha_on_scene=0.3)[source]
Load the bounding mesh of the mouse brain that represents its approximate pial limit
- find_region(term)[source]
Find a region with a substring
- Parameters
term – Search term
- Returns
List of matching entries and the corresponding mask
- get_selection_info(line_length=40, precision=5)[source]
Get information about the current selection
- Parameters
line_length – Region name line length after what it’s word-wrapped
precision – Scalar value floating precision displayed
- Returns
Preformatted multiline text and a dictionary of extra data
- add_many_points_test(positions, point_radius=2, auto_xy_rotate=True, add_to_scene=True)[source]
Test method that validates that VTK is fast enough for displaying 10 million points interactively (and it is :)
- add_spheres(positions, radius=10, values=None, color_map='Accent', name='Spheres', use_origin=True, add_to_scene=True, noise_amount=0, trim_outliers=True, bounding_mesh=None, ibl_flip_yz=True, **kwargs)[source]
Add new spheres
- Parameters
positions – 3D array of coordinates
radius – List same length as positions of radii. The default size is 5um, or 5 pixels in case as_spheres is False.
values – 1D array of values, one per neuron or a time series of such 1D arrays (numpy format)
color_map – A color map, it can be a color map built by IBLViewer or a color map name (see vedo documentation), or a list of values, etc.
name – All point neurons are grouped into one object, you can give it a custom name
use_origin – Whether the origin is added as offset to the given positions
add_to_scene – Whether the new lines are added to scene/plot and rendered
noise_amount – Amount of 3D random noise applied to each point. Defaults to 0
trim_outliers – If bounding_mesh param is given, then the spheres will be trimmed, only the ones inside the bounding mesh will be kept
bounding_mesh – A closed manifold surface mesh used for trimming segments. If None, the current self.bounding_mesh is used (if it exists)
ibl_flip_yz – If you have an IBL data set, its 3D coordinates will be multiplied by -1 on Y and Z axes in order to match Allen Brain Atlas volume and how it’s stored by IBL.
- Returns
objects.Points
- add_points(positions, radius=10, values=None, color_map='Accent', name='Points', screen_space=False, use_origin=True, add_to_scene=True, noise_amount=0, trim_outliers=True, bounding_mesh=None, ibl_flip_yz=True, **kwargs)[source]
Add new points
- Parameters
positions – 3D array of coordinates
radius – List same length as positions of radii. The default size is 5um, or 5 pixels in case as_spheres is False.
values – 1D array of values, one per neuron or a time series of such 1D arrays (numpy format)
color_map – A color map, it can be a color map built by IBLViewer or a color map name (see vedo documentation), or a list of values, etc.
name – All point neurons are grouped into one object, you can give it a custom name
screen_space – Type of point, if True then the points are static screen-space points. If False, then the points are made to scale in 3D, ie you see them larger when you zoom closer to them, while this is not the case with screen-space points. Defaults to False.
use_origin – Whether the origin is added as offset to the given positions
add_to_scene – Whether the new lines are added to scene/plot and rendered
noise_amount – Amount of 3D random noise applied to each point. Defaults to 0
trim_outliers – If bounding_mesh param is given, then the spheres will be trimmed, only the ones inside the bounding mesh will be kept
bounding_mesh – A closed manifold surface mesh used for trimming segments. If None, the current self.bounding_mesh is used (if it exists)
ibl_flip_yz – If you have an IBL data set, its 3D coordinates will be multiplied by -1 on Y and Z axes in order to match Allen Brain Atlas volume and how it’s stored by IBL.
- Returns
objects.Points
- add_segments(points, end_points=None, line_width=2, values=None, color_map='Accent', name='Segments', use_origin=True, add_to_scene=True, relative_end_points=False, spherical_angles=None, radians=True, trim_outliers=True, bounding_mesh=None, ibl_flip_yz=True)[source]
Add a set of segments
- Parameters
points – 3D numpy array of points of length n
end_points – 3D numpy array of points of length n
line_width – Line width, defaults to 2px
values – 1D list of length n, for one scalar value per line
color_map – A color map, it can be a color map built by IBLViewer or a color map name (see vedo documentation), or a list of values, etc.
name – Name to give to the object
use_origin – Whether the current origin (not necessarily absolute 0) is used as offset
add_to_scene – Whether the new lines are added to scene/plot and rendered
relative_end_points – Whether the given end point is relative to the start point. False by default, except is spherical coordinates are given
spherical_angles – 3D numpy array of spherical angle data of length n In case end_points is None, this replaces end_points by finding the relative coordinate to each start point with the given radius/depth, theta and phi
radians – Whether the given spherical angle data is in radians or in degrees
trim_outliers – Whether segments are cropped by the bounding mesh
bounding_mesh – A closed manifold surface mesh used for trimming segments. If None, the current self.bounding_mesh is used (if it exists)
ibl_flip_yz – If you have an IBL data set, its 3D coordinates will be multiplied by -1 on Y and Z axes in order to match Allen Brain Atlas volume and how it’s stored by IBL.
- Returns
objects.Lines
- add_lines(points, line_width=2, values=None, color_map='Accent', name='Lines', use_origin=True, add_to_scene=True, trim_outliers=True, bounding_mesh=None, ibl_flip_yz=True)[source]
Create a set of lines with given point sets
- Parameters
points – List of lists of 3D coordinates
line_width – Line width, defaults to 2px
values – 1D list of length n, for one scalar value per line
color_map – A color map, it can be a color map built by IBLViewer or a color map name (see vedo documentation), or a list of values, etc.
name – Name to give to the object
use_origin – Whether the current origin (not necessarily absolute 0) is used as offset
add_to_scene – Whether the new lines are added to scene/plot and rendered
trim_outliers – Whether segments that are out of the brain envelope are trimmed or not. True by default
bounding_mesh – A closed manifold surface mesh used for trimming lines. If None, the current self.bounding_mesh is used (if it exists)
ibl_flip_yz – If you have an IBL data set, its 3D coordinates will be multiplied by -1 on Y and Z axes in order to match Allen Brain Atlas volume and how it’s stored by IBL.
- Returns
objects.Lines
- add_volume(data=None, resolution=None, file_path=None, color_map='viridis', alpha_map=None, select=False, add_to_scene=True, transpose=None)[source]
Add a volume to the viewer with box clipping and slicing enabled by default
- Parameters
data – Volume image data or a file_path
resolution – Resoluton of the volume
file_path – File path of the volume. If you don’t provide an image volume data, then the file_path will be used to load the volume data
color_map – Color map for the volume
alpha_map – Alpha map for the volume. If None, it will assume that 0 values are transparent and maximum values are opaque
select – Whether the volume is selected
add_to_scene – Whether the volume is added to scene
transpose – Transposition parameter. If None. nothing happens. If True, then the default IBL transposition is applied. You can provide your own, that is, a list of 3 elements to reorder the volume as desired.
- Returns
VolumeController