gifti export

194 views
Skip to first unread message

John Griffiths

unread,
Oct 16, 2014, 2:49:57 PM10/16/14
to tvb-...@googlegroups.com

Is there any code knocking round for exporting tvb surfaces to gitfti (.gii) files? 

Chars. 

j


Marmaduke Woodman

unread,
Oct 17, 2014, 2:41:21 AM10/17/14
to tvb-...@googlegroups.com
On 10/16/2014 08:49 PM, John Griffiths wrote:
>
> Is there any code knocking round for exporting tvb surfaces to gitfti
> (.gii) files?

Assuming you've loaded the surfaces and have the vertices & faces
arrays, something like this should work


from nibabel.gifti import gifti, giftiio

# create image object
gi = gifti.GiftiImage()

# create gifti arrays for vertices & faces
gv = gifti.GiftiDataArray.from_array(vertices, 1008)
gf = gifti.GiftiDataArray.from_array(faces, 1009)

# add to image
gi.add_gifti_data_array(gv)
gi.add_gifti_data_array(gf)

# write to file
giftiio.write(gi, 'surf.gii')



What is the target of the export, if I may ask? BrainVISA, SPM..?


cheers,
Marmaduke

John Griffiths

unread,
Oct 17, 2014, 3:32:49 PM10/17/14
to tvb-...@googlegroups.com

Thanks. 

The target is SPM.

The conventional SPM approach is to warp a set of canonical standard space meshes (cortical surface, inner skull, outer skull, and skin) to native space, and compute the forward model (e.g. EEG BEM) from those. However it is possible to supply custom meshes.

We don't actually need SPM to compute the lead fields as (if we are supplying TVB with brainstorm/openMEEG outputs) we already have this. However I think the most straightforward way to match up M/EEG simulations in TVB and SPM is to let SPM compute a forward model from a custom cortical mesh (not sure if the others are necessary) and then simply replace the 'SPMgainmatrix...mat' file with the one used for the TVB sims. 

c.f. my recent post about this on the spm list 

Does that sound kosher to you? Am I missing anything?

  
j

Michael WOODMAN

unread,
Oct 17, 2014, 4:43:40 PM10/17/14
to tvb-...@googlegroups.com
Hi John,

If you have existing lead fields computed for the TVB mesh in a given head model with your preferred s/M/EEG sensors, and you've figured out how to get all that info into SPM, then you should be fine.

There are some other approaches if you run into trouble,
let us know,
Marmaduke

John Griffiths <j.davidg...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "TVB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael WOODMAN

unread,
Oct 17, 2014, 4:56:44 PM10/17/14
to tvb-...@googlegroups.com
Hi

I misread your post to the SPM list..

The approach you mentioned about just adapting the cortical mesh, and working from there is spot on. We had success doing this in Brainstorm with the colin 27 head, so I guess it should work in SPM.

cheers,
Marmaduke

John Griffiths

unread,
Oct 17, 2014, 5:57:00 PM10/17/14
to tvb-...@googlegroups.com, marmaduk...@univ-amu.fr

Thanks. 

Could you give me an example of the function calls you use to compute the lead fields with brainstorm (or OpenMEEG) ? 

Marmaduke Woodman

unread,
Oct 20, 2014, 2:35:21 AM10/20/14
to tvb-...@googlegroups.com
On 10/17/2014 11:57 PM, John Griffiths wrote:
>
> Thanks.
>
> Could you give me an example of the function calls you use to compute
> the lead fields with brainstorm (or OpenMEEG) ?
>

It depends: are you doing a generic subject just based on the TVB
cortical mesh or a specific subject's head model & cortex?


If the first is the case, the brainstorm db files are available here:

https://github.com/the-virtual-brain/tvb-data/tree/master/tvb_data/brainstorm


In the second case I can write up some instructions; it's not a one-liner..


cheers,
Marmaduke

John Griffiths

unread,
Oct 20, 2014, 3:28:50 PM10/20/14
to tvb-...@googlegroups.com

I'd like to know how to do it for any subject given their MRI and sensor layout. 

Marmaduke Woodman

unread,
Oct 21, 2014, 3:13:37 AM10/21/14
to tvb-...@googlegroups.com
On 10/20/2014 09:28 PM, John Griffiths wrote:
>
> I'd like to know how to do it for any subject given their MRI and sensor
> layout.

For a subject where you don't have a full DTI (connectivity) pipeline
run, you need to (in Brainstorm or something equally capable)

1) load and segment the MRI
2) load real MEG/EEG data to have the sensor positions/orientations
2.5) align MEG and MRI
3) load TVB cortex, align "correctly" within most inner BEM surface
4) generate lead fields
5) import these lead fields in TVB for simulation


Given that many researchers have T1 and M/EEG for subjects, but not
usually DTI, this is definitely an important workflow.

<speculation>
Step 3 could be semi-automated by noting LPA-RPA-nasion points in
coordinate system of the TVB cortex. When MEG-MRI alignment is done, an
affine transform for the TVB cortex could be applied automatically,
followed by some finer tuning to fit nicely inside the inner BEM surface.
</speculation>

Step 5 could be automated by a new importer in TVB, e.g. loading part or
all of a Brainstorm DB for a given subject.

If you try this, please let us know how it goes.


cheers,
Marmaduke

John Griffiths

unread,
Nov 3, 2014, 7:40:57 PM11/3/14
to tvb-...@googlegroups.com

So that does produce a gifti file that nibabel appears able to read stuff from. 

But freeview can't load it in.

Any idea what's missing?

Ta.



On Friday, 17 October 2014 02:41:21 UTC-4, marmaduke.woodman wrote:

John Griffiths

unread,
Nov 4, 2014, 5:03:46 PM11/4/14
to tvb-...@googlegroups.com

Marmaduke for your example above for writing to a gifti image with nibabel, does an affine registration matrix not need to be added?

From a quick scout I don't see much in the tvb code about affines and registration things. How are they dealt with when importing gifti images?

Ta. 

Marmaduke Woodman

unread,
Nov 5, 2014, 1:09:28 AM11/5/14
to tvb-...@googlegroups.com
On 04/11/2014 23:03, John Griffiths wrote:
>
> Marmaduke for your example above for writing to a gifti image with
> nibabel, does an affine registration matrix not need to be added?

probably a good idea, yes, but in the case of the generic cortex, I'm
not sure there is one. Easiest thing to do is to use an identity transform.

>
> From a quick scout I don't see much in the tvb code about affines and
> registration things. How are they dealt with when importing gifti images?

It's not really dealt with in TVB, the working (yet dubious) assumption
being that everything is aligned by the user before importing.


> On Monday, 3 November 2014 19:40:57 UTC-5, John Griffiths wrote:


> So that does produce a gifti file that nibabel appears able to read
> stuff from.
>
> But freeview can't load it in.
>
> Any idea what's missing?
>

Sorry, no I'm not sure, but I suppose the transform is one thing. Do you
ahve any error messages? (freeview doesn't run on my system..)

cheers,
Marmaduke

Reply all
Reply to author
Forward
0 new messages