def populate_hagmann_density(self, WM_img, ROI_img): """Populate hagmann density.""" def inverse_sum(elements): inverse_elements = [] for element in elements: inverse_elements.append( 1.0 / element ) from math import fsum return fsum(inverse_elements) # get surface areas for ROIs import images surface_area = images.surface_area_for_rois(ROI_img, WM_img) # make sure our surface areas are well formed, this means an # entry for every key epsilon = 0.00000000001 for n in self.nodes(): try: surface_area[n] except KeyError: surface_area[n] = epsilon except Exception as e: raise e # for every edge... for i,j in self.edges_iter(): calc_hd = ( ( 2.0 / ( surface_area[i] + surface_area[j] ) ) * \ inverse_sum( self[i][j]['streamlines_length'] ) ) self[i][j]['hagmann_density'] = calc_hd
def populate_hagmann_density(self, WM_img, ROI_img): """Populate hagmann density.""" def inverse_sum(elements): inverse_elements = [] for element in elements: inverse_elements.append(1.0 / element) from math import fsum return fsum(inverse_elements) # get surface areas for ROIs import images surface_area = images.surface_area_for_rois(ROI_img, WM_img) # make sure our surface areas are well formed, this means an # entry for every key epsilon = 0.00000000001 for n in self.nodes(): try: surface_area[n] except KeyError: surface_area[n] = epsilon except Exception as e: raise e # for every edge... for i, j in self.edges_iter(): calc_hd = ( ( 2.0 / ( surface_area[i] + surface_area[j] ) ) * \ inverse_sum( self[i][j]['streamlines_length'] ) ) self[i][j]['hagmann_density'] = calc_hd
def test_can_get_surface_areas(self): # the following compares images and test images that are known # to satisfy the condition that an ROI w/ label n will have n # voxels that border white matter... labels in these images # are defined for 1:10 roiImage = images.TNImage(filename = 'test_data/images/ROI_50x50x50.nii.gz') maskImage = images.TNImage(filename = 'test_data/images/ROI_WM_MASK_50x50x50.nii.gz') result = images.surface_area_for_rois(roiImage, maskImage) for label in range(1,11): # 1:10 assert result[label] == label
def test_can_get_surface_areas(self): # the following compares images and test images that are known # to satisfy the condition that an ROI w/ label n will have n # voxels that border white matter... labels in these images # are defined for 1:10 roiImage = images.TNImage( filename='test_data/images/ROI_50x50x50.nii.gz') maskImage = images.TNImage( filename='test_data/images/ROI_WM_MASK_50x50x50.nii.gz') result = images.surface_area_for_rois(roiImage, maskImage) for label in range(1, 11): # 1:10 assert result[label] == label
def extract_hagmann_density(connectome, roi_img, wm_img): """Populate hagmann density for given connectome""" def inverse_sum(elements): inverse_elements = [] for element in elements: inverse_elements.append( 1.0 / element ) from math import fsum return fsum(inverse_elements) # get surface areas for ROIs import images surface_area = images.surface_area_for_rois(roi_img, wm_img) # for every edge... for i,j in connectome.edges_iter(): calc_hd = ( ( 2.0 / ( surface_area[i] + surface_area[j] ) ) * \ inverse_sum( connectome[i][j]['streamlines_length'] ) ) connectome[i][j]['hagmann_density'] = calc_hd
def populate_hagmann_density(self, WM_img, ROI_img): """Populate hagmann density.""" def inverse_sum(elements): inverse_elements = [] for element in elements: inverse_elements.append( 1.0 / element ) from math import fsum return fsum(inverse_elements) # get surface areas for ROIs import images surface_area = images.surface_area_for_rois(ROI_img, WM_img) # for every edge... for i,j in self.edges_iter(): calc_hd = ( ( 2.0 / ( surface_area[i] + surface_area[j] ) ) * \ inverse_sum( self[i][j]['streamlines_length'] ) ) self[i][j]['hagmann_density'] = calc_hd