Guest User

Untitled

a guest
Jan 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import json
  2. import pandas as pd
  3. import pyxnat
  4.  
  5. c = pyxnat.Interface(config='/home/grg/.xnat_bsc.cfg')
  6.  
  7. # Collect experiments
  8. experiments = json.load(open('/home/grg/Downloads/mri_list.json'))
  9.  
  10. # Querying FreeSurfer resource -if any- from each experiment
  11. tables = [[], [], []]
  12. for e in experiments:
  13. s = c.array.experiments(experiment_id=e, columns=['subject_label']).data[0]['subject_label']
  14. r = c.select.experiment(e).resource('FREESURFER6')
  15. if not r.exists(): continue
  16. volumes = [r.hippoSfVolumes(), r.aseg(), r.aparc()]
  17.  
  18. for each, table in zip(volumes, tables):
  19. each['subject'] = s
  20. table.append(each)
  21.  
  22. # Convert to dataframes
  23. hippoSfVolumes = pd.concat(tables[0]).set_index('subject').sort_index()
  24. aseg = pd.concat(tables[1]).set_index('subject').sort_index()
  25. aparc = pd.concat(tables[2]).set_index('subject').sort_index()
  26.  
  27. # Creating pivot tables
  28. aparc.to_excel('/tmp/aparc_JH.xlsx')
  29.  
  30. import pandas as pd
  31. t = pd.read_excel('/tmp/aparc_JH.xlsx').set_index('subject')
  32. pd.pivot_table(t,
  33. values='value',
  34. columns='region',
  35. index=t.index).head()
Add Comment
Please, Sign In to add comment