Skip to content

Latest commit

 

History

History
84 lines (72 loc) · 4.08 KB

values_on_parcels.md

File metadata and controls

84 lines (72 loc) · 4.08 KB

Populate surface parcels with arbitrary values

What is this snippet for?

Simple walkthrough and example code (python) to create a "template" surface pscalar, then to populate the Gordon 333 surface parcels with arbitrary values. (good for visualization of any metric or value you are computing using parcels.)

Why do we need this?

For one project I was identifying parcels of interest. To show the overlap across a group of subjects, I needed to place a number on each parcel, which represented how many times that parcel was a parcel of interest across all subjects in my group. This example code allows you to place arbitrary values on any parcel, which you can then bring into workbench viewer and make a nice figure including a color map for your results, etc.

This example will:

  1. Show you how to create a "blank" pscalar (parcellated scalar surface file) using a source surface scalar file and parcel set of your choosing.
  2. Explain the text file needed to place values onto each parcel in the set you've chosen.
  3. Place those values onto the template pscalar file you made and save it out as a new pscalar.nii file.

This file can then be brought into workbench view to make figures.

Code example!

Step I: Make TEMPLATE pscalar from original dlabel (this only needs to be done once really)

# any dscalar in the correct surface you want to use
hcp1200_dscalar_source = <PATH TO>'/S1200.sulc_MSMAll.32k_fs_LR.dscalar.nii' 
# whatever parcel set you want to use
gordon_dlabel = <PATH TO>'/Gordon333_Parcels_LR.dlabel.nii' 
# The template you want to put values onto going forward
out_pscalar_TEMPLATE = <PATH TO>'/Gordon333_TEMPLATE.pscalar.nii' 

# the wb_command
wb_comm = ' '.join(['wb_command',
                    '-cifti-parcellate',
                    hcp1200_dscalar_source,
                    gordon_dlabel,
                    'COLUMN',
                    out_pscalar_TEMPLATE
                   ])
subprocess.call(wb_comm, shell=True)

Step II: Make and save whatever values.

  • 333 vector (each line of text file is each parcel 1-333. careful of python 0 indexing)
  • Save out as text file, one value per line.
value_vect_out = <PATH TO>'/TEST_values.txt'
# making manual text file just for testing here
the_vect = np.zeros(333, dtype=np.int).tolist()
the_vect[0] = 1
the_vect[161] = 162
the_vect[116] = 117
the_vect[278] = 279
with open(value_vect_out, 'w') as f:
    for item in the_vect:
        f.write(str(item) + '\n')

Step III: Write that vector of value to a pscalar file for wb view!!

output_pscalar = <PATH TO>'/YOUR_OUTPUT_G333.pscalar.nii'
wb_comm = ' '.join(['wb_command',
                    '-cifti-convert',
                    '-from-text',
                    value_vect_out,
                    out_pscalar_TEMPLATE,
                    output_pscalar                    
                   ])
subprocess.call(wb_comm, shell=True)

Example Outputs