iblatlas.streamlines.utils

Functions

get_mask

Generate a mask to plot results onto

project_points_onto_flatmap

Projects 3D points with associated values onto a 2D flatmap.

project_volume_onto_flatmap

Projects a 3D volume onto a 2D flatmap by aggregating values along streamline paths.

validate_aggr

Validates if the provided aggregation type is valid.

xyz_to_depth

For a given xyz coordinates return the depth from the surface of the cortex.

xyz_to_depth(xyz, per=True, res_um=25)[source]

For a given xyz coordinates return the depth from the surface of the cortex. The depth is returned as a percentage if per=True and in um if per=False. Note the lookup will only work for xyz cooordinates that are in the Isocortex of the Allen volume. If coordinates outside of this region are given then the depth is returned as nan.

Parameters:
  • xyz (numpy.array) – An (n, 3) array of Cartesian coordinates. The order is ML, AP, DV and coordinates should be given in meters relative to bregma.

  • per (bool) – Whether to do the lookup in percentage from the surface of the cortex or depth in um from the surface of the cortex.

  • res_um (float or int) – The resolution of the brain atlas to do the depth lookup

Returns:

  • numpy.array

  • The depths from the surface of the cortex for each cartesian coordinate. If the coordinate does not lie within

  • the Isocortex, depth value returned is nan

get_mask(volume='annotation', br=None)[source]

Generate a mask to plot results onto

Parameters:

volumestr, optional

The type of volume to project. Options are: - ‘image’: Projects the anatomical image using max intensity. - ‘annotation’: Projects the labeled regions and maps them to RGB colors. - ‘boundary’: Projects labeled regions and extracts anatomical boundaries. Default is ‘annotation’.

brBrainRegions, optional

An instance of the BrainRegions If None, a default BrainRegions is initialized.

Returns:

imgnp.ndarray

The resulting 2D flatmap projection image, either grayscale, RGB, or binary mask, depending on the selected volume type.

validate_aggr(aggr: str) None[source]

Validates if the provided aggregation type is valid.

Parameters:

aggrstr

The aggregation method to validate (e.g., ‘mean’, ‘sum’).

Raises:

AssertionError

If the aggregation type is not one of the allowed values.

project_volume_onto_flatmap(vol: ndarray, res_um: int = 25, aggr: str = 'mean', plot: bool = True, cmap: str = 'viridis', clevels: tuple = None, ax: Axes = None) ndarray[source]

Projects a 3D volume onto a 2D flatmap by aggregating values along streamline paths.

Parameters:

volnp.ndarray

A 3D numpy array representing the volume data to be projected.

res_umint

The resolution of the volume. Must be one of 10, 25 or 50.

aggrstr, optional

The aggregation method (‘sum’, ‘count’, ‘mean’, etc.), default is ‘mean’.

plotbool, optional

Whether to plot the resulting projection, default is True.

cmapstr, optional

The colormap to use for the plot, default is ‘viridis’.

clevelstuple, optional

The color limits to use for the plot, default is None.

axmatplotlib.axes.Axes, optional

The axes on which to plot, default is None.

Returns:

np.ndarray

The projected 2D array onto the flatmap.

matplotlib.figure.Figure

Matplotlib figure object if plot=True, otherwise None.

matplotlib.axes.Axes

Matplotlib axes object if plot=True, otherwise None.

project_points_onto_flatmap(xyz: ndarray, values: ndarray, res_um: int = 25, aggr: str = 'mean', plot: bool = True, cmap: str = 'viridis', clevels: tuple = None, ax: Axes = None) ndarray[source]

Projects 3D points with associated values onto a 2D flatmap.

Parameters:

xyznp.ndarray

An array containing xyz coordinates of the points to be projected. xyz values should be given in metres

valuesnp.ndarray

A 1D array of values to associate with the points.

resint

The resolution to load the corresponding streamline paths.

aggrstr, optional

The aggregation method (‘sum’, ‘count’, ‘mean’, etc.), default is ‘mean’.

plotbool, optional

Whether to plot the resulting projection, default is True.

cmapstr, optional

The colormap to use for the plot, default is ‘viridis’.

clevelstuple, optional

The color limits to use for the plot, default is None.

axmatplotlib.axes.Axes, optional

The axes on which to plot, default is None.

Returns:

np.ndarray

The projected 2D array onto the flatmap.

matplotlib.figure.Figure

Matplotlib figure object if plot=True, otherwise None.

matplotlib.axes.Axes

Matplotlib axes object if plot=True, otherwise None.