mcmodels.core.Mask¶
-
class
mcmodels.core.
Mask
(reference_space, structure_ids=None, hemisphere_id=None)[source]¶ Object for masking the grid data from allensdk.
This object is useful for masking grid data as well as reshaping/filling ‘masked’ arrays to be the shape of the annotation (CCF) from allensdk. Also, this object is useful for determining the location or structure id of a given voxel from the voxel-voxel connectivity matrix.
Parameters: - voxel_model_cache : VoxelModelCache object
This supplies the interface for pulling cached reference space, annotation, and structure tree objects.
- structure_ids : array-like, optional, shape (n_structure_ids,)
AllenSDK CCF Annotation structure ids to be included in the model
- Hemisphere : int
- hemisphere id to be included in the projection in the model.
- 1, left hemisphere
- 2, right hemisphere
- 3, both hemispheres
Examples
>>> from mcmodels.core import Mask, VoxelModelCache >>> cache = VoxelModelCache() >>> mask = Mask.from_cache(cache) >>> # what shape will a masked volume be >>> mask.masked_shape (448962,)
Attributes: - reference_space : reference_space object
see allensdk.reference_space
Methods
fill_volume_where_masked
(self, X, fill[, …])Fills a data volume where mask is valid. from_cache
(cache, \*\*kwargs)Parameters: get_flattened_voxel_index
(self, voxel_idx)Return the index of a givel voxel in the flattened mask. get_key
(self[, structure_ids, hemisphere_id])Returns flattened annotation key. get_structure_flattened_mask
(self[, …])Masks a structure_mask or union of structure_masks. get_structure_indices
(self[, structure_ids, …])Returns the indices of a masked structure_mask or union of structure_masks. map_masked_to_annotation
(self, y)Maps a masked vector y back to annotation volume. mask_volume
(self, X)Masks a given volume. Methods
__init__
(self, reference_space[, …])fill_volume_where_masked
(self, X, fill[, …])Fills a data volume where mask is valid. from_cache
(cache, \*\*kwargs)Parameters: get_flattened_voxel_index
(self, voxel_idx)Return the index of a givel voxel in the flattened mask. get_key
(self[, structure_ids, hemisphere_id])Returns flattened annotation key. get_structure_flattened_mask
(self[, …])Masks a structure_mask or union of structure_masks. get_structure_indices
(self[, structure_ids, …])Returns the indices of a masked structure_mask or union of structure_masks. map_masked_to_annotation
(self, y)Maps a masked vector y back to annotation volume. mask_volume
(self, X)Masks a given volume. -
assigned_structures
¶ List of resolved structures in annotation
-
coordinates
¶ Returns coordinates inside mask.
-
fill_volume_where_masked
(self, X, fill, inplace=True)[source]¶ Fills a data volume where mask is valid.
Parameters: - X : array, shape (x_ccf, y_ccf, z_ccf)
Array to be filled where mask is valid.
- fill : int or array, shape=(masked_shape)
Fill value or array.
- inplace : boolean
If True, X is filled in place, else a copy is returned.
Returns: - array - shape (x_ccf, y_ccf, z_ccf)
Filled array.
-
classmethod
from_cache
(cache, **kwargs)[source]¶ Parameters: - cache : caching object
MCC or RSC or VMC
-
get_flattened_voxel_index
(self, voxel_idx)[source]¶ Return the index of a givel voxel in the flattened mask.
Parameters: - voxel_idx : array
coordinates of voxel of which the flattened index position is wanted
Returns: - int
idx of voxel_idx in flattened mask
-
get_key
(self, structure_ids=None, hemisphere_id=None)[source]¶ Returns flattened annotation key.
Useful in performing structure specific computations on the voxel-voxel array.
Parameters: - structure_ids : list, optional (default=None)
Ids of structures which to include in the key. If None, the structure_ids used to make the Mask object will be used.
- hemisphere_id : int, optional (default=None)
Hemisphere to include in the key. If None, the hemisphere used to mask the Mask object will be used.
Returns: - key = array, shape (masked_shape,), type np.int
Key mapping an element in a masked data volume to its structure id in the annotation. Each element in key is a structure_id.
-
get_structure_flattened_mask
(self, structure_ids=None, hemisphere_id=None)[source]¶ Masks a structure_mask or union of structure_masks.
Parameters: - structure_ids : array-like, optional (default = None)
A list of structure ids with which to construct a structure union mask. If None, the object’s structure_ids are used.
- hemisphere_id : int, optional (default = None)
The hemisphere to which the structure union mask will be additionally masked to. If None, the object’s hemisphere_id is used.
Returns: - array - shape (masked_shape)
Masked structure union mask.
-
get_structure_indices
(self, structure_ids=None, hemisphere_id=None)[source]¶ Returns the indices of a masked structure_mask or union of structure_masks.
Parameters: - structure_ids : array-like, optional (default = None)
A list of structure ids with which to construct a structure union mask. If None, the object’s structure_ids are used.
- hemisphere_id : int, optional (default = None)
The hemisphere to which the structure union mask will be additionally masked to. If None, the object’s hemisphere_id is used.
Returns: - array - shape (masked_nonzero,)
The indices of the masked structure union mask that are nonzero
-
map_masked_to_annotation
(self, y)[source]¶ Maps a masked vector y back to annotation volume.
Parameters: - y : array, shape (masked_shape)
Array to be mapped into where mask is valid.
Returns: - y_volume : shape (x_ccf, y_ccf, z_ccf)
Array same shape as annotation, filled with input parameter y where mask is valid
-
mask
¶ Boolean mask defining ‘interesting’ voxels.
-
mask_volume
(self, X)[source]¶ Masks a given volume.
Parameters: - X - array, shape (x_ccf, y_ccf, z_ccf)
Data volume to be masked. Must be same shape as self.reference_space.annotation.shape
Returns: - array - shape (masked_shape)
Masked data volume.
-
masked_shape
¶ Shape a data volume would become after masking.