from scipy import io import cPickle as pickle import os.path import sys if os.path.exists('/home/onerva/consistency-as-onion'): sys.path.insert(0,'/home/onerva/consistency-as-onion') else: sys.path.insert(0,'/home/onerva/projects/consistency-as-onion') import functions import onion_parameters as params allVoxelTsPath = params.testSubjectFolders[0] + params.ROIVoxelTsFileName ROIInfoFile = params.ROIInfoFile allVoxelTs = io.loadmat(allVoxelTsPath)['roi_voxel_data'][0]['roi_voxel_ts'][0] _,_,voxelCoordinates,ROIMaps = functions.readROICentroids(ROIInfoFile,readVoxels=True,fixCentroids=True) ROIIndices = [] for ROIMap in ROIMaps: indices = np.zeros(len(ROIMap),dtype=int) for i, voxel in enumerate(ROIMap): indices[i] = np.where((voxelCoordinates == voxel).all(axis=1)==1)[0][0] ROIIndices.append(indices) testROIs = ROIIndices[0:20] spatialConsistencies = functions.calculateSpatialConsistencyInParallel(testROIs,allVoxelTs)
if not visualizeOnly: subjectFolders = [ '/media/onerva/KINGSTON/test-data/010/', '/media/onerva/KINGSTON/test-data/011/' ] nSubjects = len(subjectFolders) roiInfoFile = '/media/onerva/KINGSTON/test-data/group_roi_mask-30-4mm_with_subcortl_and_cerebellum.mat' resolution = 4 distanceMatrixPath = params.distanceMatrixPath radiusRange = np.arange(1, 10, 2) nRadia = len(radiusRange) _, _, voxelCoords, _ = functions.readROICentroids( roiInfoFile, readVoxels=True ) # this returns the coordinates of all voxels belonging to ROIs nROIs = len(voxelCoords) correlations = np.zeros((nSubjects, nRadia, nROIs)) allVoxelTs = [] for i, subject in enumerate( subjectFolders ): # reading the data here and not inside the loop to save time voxelTsFilePath = subject + params.ROIVoxelTsFileName allVoxelTs.append( io.loadmat(voxelTsFilePath)['roi_voxel_data'][0]['roi_voxel_ts'] [0]) for j, radius in enumerate(radiusRange):
""" import functions import numpy as np testDefSphericalROIs = False testFindROIlessVoxels = False testFindROIlessNeighbors = False testUpdateROI = False testGrowROIs = False testConstructMultilayer = True # testing defSphericalROIs if testDefSphericalROIs: ROIPath = 'atlases/brainnetome/brainnetome_thr25_4mm_rois.mat' centroids, _, voxelCoords = functions.readROICentroids(ROIPath, readVoxels=True) # testcase 1: ROIs with radius < 1 should contain only ROI centroids spheres = functions.defineSphericalROIs(centroids, voxelCoords, 0) sphereMaps = [] for sphereMap in spheres['ROIMaps']: sphereMaps.append(sphereMap) sphereMaps = np.array(sphereMaps) diff = np.sum(np.abs(sphereMaps - centroids)) if diff == 0: print "defSphericalROIs: testcase 1/3 OK" # testcase 2: small example space space = np.zeros((4, 4, 4))
subjects = [params.testSubjectFolders[0]] originalROIInfoPath = params.originalROIInfoFile optimizedROIInfoFile = params.optimizedROIInfoFile allVoxelTsFile = params.ROIVoxelTsFileName optimizedConsistencySaveName = params.optimizedSpatialConsistencySaveName originalConsistencySavePath = params.originalSpatialConsistencySavePath optimizedCorrelationSaveName = params.optimizedCorrelationSaveName originalCorrelationSavePath = params.originalCorrelationSavePath figureSavePath = params.spatialConsistencyValidationPath fig = plt.figure() ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) originalCentroids, _, originalVoxelCoordinates, originalROIMaps = functions.readROICentroids( originalROIInfoPath, readVoxels=True, fixCentroids=True) centroidIndices = np.zeros(len(originalCentroids), dtype=int) for i, originalCentroid in enumerate(originalCentroids): centroidIndices[i] = np.where( (originalVoxelCoordinates == originalCentroid).all(axis=1) == 1)[0][0] for i, subject in enumerate(subjects): optimizedROIInfoPath = subject + optimizedROIInfoFile allVoxelTsPath = subject + allVoxelTsFile allVoxelTs = io.loadmat( allVoxelTsPath)['roi_voxel_data'][0]['roi_voxel_ts'][0] _, _, _, ROIMaps = functions.readROICentroids(optimizedROIInfoPath, readVoxels=True) ROIIndices = []
visualizeOnly = False consistencySavePath = params.consistencyVsRadiusPath figureSavePath = '/media/onerva/KINGSTON/test-data/outcome/consistency-vs-radius.pdf' if not visualizeOnly: subjectFolders = params.testSubjectFolders nSubjects = len(subjectFolders) roiInfoFile = '/media/onerva/KINGSTON/test-data/group_roi_mask-30-4mm_with_subcortl_and_cerebellum.mat' resolution = 4 distanceMatrixPath = params.distanceMatrixPath radiusRange = np.arange(1, 20, 2) nRadia = len(radiusRange) centroids, _, voxelCoords, _ = functions.readROICentroids(roiInfoFile, readVoxels=True) nROIs = len(centroids) consistencies = np.zeros((nSubjects, nRadia, nROIs)) allVoxelTs = [] for i, subject in enumerate( subjectFolders ): # reading the data here and not inside the loop to save time voxelTsFilePath = subject + params.ROIVoxelTsFileName allVoxelTs.append( io.loadmat(voxelTsFilePath)['roi_voxel_data'][0]['roi_voxel_ts'] [0]) for j, radius in enumerate(radiusRange):