allensdk.core.reference_space module¶
- class allensdk.core.reference_space.ReferenceSpace(structure_tree, annotation, resolution)[source]¶
Bases:
object
- static check_and_write(base_dir, structure_id, fn)[source]¶
A many_structure_masks callback that writes the mask to a nrrd file if the file does not already exist.
- check_coverage(structure_ids, domain_mask)[source]¶
Determines whether a spatial domain is completely covered by structures in a set.
- Parameters:
- structure_idslist of int
Specifies the set of structures to check.
- domain_masknumpy ndarray
Same shape as annotation. 1 inside the mask, 0 out. Specifies spatial domain.
- Returns:
- numpy ndarray
1 where voxels are missing from the candidate, 0 where the candidate exceeds the domain
- direct_voxel_counts()[source]¶
Determines the number of voxels directly assigned to one or more structures.
- Returns:
- dict
Keys are structure ids, values are the number of voxels directly assigned to those structures.
- property direct_voxel_map¶
- downsample(target_resolution)[source]¶
Obtain a smaller reference space by downsampling
- Parameters:
- target_resolutiontuple of numeric
Resolution in microns of the output space.
- interpolatorstring
Method used to interpolate the volume. Currently only ‘nearest’ is supported
- Returns:
- ReferenceSpace
A new ReferenceSpace with the same structure tree and a downsampled annotation.
- export_itksnap_labels(id_type=<class 'numpy.uint16'>, label_description_kwargs=None)[source]¶
Produces itksnap labels, remapping large ids if needed.
- Parameters:
- id_typenp.integer, optional
Used to determine the type of the output annotation and whether ids need to be remapped to smaller values.
- label_description_kwargsdict, optional
Keyword arguments passed to StructureTree.export_label_description
- Returns:
- np.ndarray
Annotation volume, remapped if needed
- pd.DataFrame
label_description dataframe
- get_slice_image(axis, position, cmap=None)[source]¶
Produce a AxBx3 RGB image from a slice in the annotation
- Parameters:
- axisint
Along which to slice the annotation volume. 0 is coronal, 1 is horizontal, and 2 is sagittal.
- positionint
In microns. Take the slice from this far along the specified axis.
- cmapdict, optional
Keys are structure ids, values are rgb triplets. Defaults to structure rgb_triplets.
- Returns:
- np.ndarray
RGB image array.
Notes
If you assign a custom colormap, make sure that you take care of the background in addition to the structures.
- make_structure_mask(structure_ids, direct_only=False)[source]¶
Return an indicator array for one or more structures
- Parameters:
- structure_idslist of int
Make a mask that indicates the union of these structures’ voxels
- direct_onlybool, optional
If True, only include voxels directly assigned to a structure in the mask. Otherwise include voxels assigned to descendants.
- Returns:
- numpy ndarray
Same shape as annotation. 1 inside mask, 0 outside.
- many_structure_masks(structure_ids, output_cb=None, direct_only=False)[source]¶
Build one or more structure masks and do something with them
- Parameters:
- structure_idslist of int
Specify structures to be masked
- output_cbfunction, optional
Must have the following signature: output_cb(structure_id, fn). On each requested id, fn will be curried to make a mask for that id. Defaults to returning the structure id and mask.
- direct_onlybool, optional
If True, only include voxels directly assigned to a structure in the mask. Otherwise include voxels assigned to descendants.
- Yields:
- Return values of output_cb called on each structure_id, structure_mask
- pair.
Notes
output_cb is called on every yield, so any side-effects (such as writing to a file) will be carried out regardless of what you do with the return values. You do actually have to iterate through the output, though.
- remove_unassigned(update_self=True)[source]¶
Obtains a structure tree consisting only of structures that have at least one voxel in the annotation.
- Parameters:
- update_selfbool, optional
If True, the contained structure tree will be replaced,
- Returns:
- list of dict
elements are filtered structures
- total_voxel_counts()[source]¶
Determines the number of voxels assigned to a structure or its descendants
- Returns:
- dict
Keys are structure ids, values are the number of voxels assigned to structures’ descendants.
- property total_voxel_map¶
- validate_structures(structure_ids, domain_mask)[source]¶
Determines whether a set of structures produces an exact and nonoverlapping tiling of a spatial domain
- Parameters:
- structure_idslist of int
Specifies the set of structures to check.
- domain_masknumpy ndarray
Same shape as annotation. 1 inside the mask, 0 out. Specifies spatial domain.
- Returns:
- set
Ids of structures that are the ancestors of other structures in the supplied set.
- numpy ndarray
Indicator for missing voxels.
- write_itksnap_labels(annotation_path, label_path, **kwargs)[source]¶
Generate a label file (nrrd) and a label_description file (csv) for use with ITKSnap
- Parameters:
- annotation_pathstr
write generated label file here
- label_pathstr
write generated label_description file here
- **kwargs
will be passed to self.export_itksnap_labels