MEG monitor - gain matrix

82 views
Skip to first unread message

JESUS CABRERA ALVAREZ

unread,
Apr 12, 2021, 1:00:19 PM4/12/21
to TVB Users
Dear all,

I am carrying out region simulations and trying to obtain MEG output. I computed a forward model for a surface mesh of 15.000 vertex approx. 

I tried with the whole lead field matrix [310 channels x  ~15.000 vertex] as input:

pr = projections.ProjectionSurfaceMEG.from_file("projection_surface_15k_MEG306.txt") 
rm = region_mapping.RegionMapping.from_file("region_mapping_N35_AAL2red.txt")
ss = sensors.SensorsMEG.from_file(LCCN_folder+"sensors_MEG306.txt")
mon = (monitors.Raw(), monitors.MEG(projection=pr, sensors=ss, region_mapping=rm, period=1))

But, I got this error message:

"""
    self._state += self.gain.dot(state[self.voi].sum(axis=-1).T)
ValueError: shapes (306,14779) and (92,4) not aligned: 14779 (dim 1) != 92 (dim 0)
"""

So, I thought that for my region simulation I had to do the gain matrix for each of my ROIs, as a gain matrix of [306 channels x 92 ROIs]. If I use this, my matrix is somehow modified to [306 channels x 102 ROIS]:

"""
>> sim.configure()
   INFO  Projection configured gain shape (306, 102)
>> sim.run()
    self._state += self.gain.dot(state[self.voi].sum(axis=-1).T)
ValueError: shapes (306,102) and (92,4) not aligned: 102 (dim 1) != 92 (dim 0)
"""

So, I went to the breakpoint: line 522, 

"""
def sample(self, step, state):
"Record state, returning sample at sampling frequency / period."
522  self._state += self.gain.dot(state[self.voi].sum(axis=-1).T)
if step % self._period_in_steps == 0:
time = (step - self._period_in_steps / 2.0) * self.dt
sample = self._state.copy() / self._period_in_steps
"""

I added before this line:
# self.gain=self.projection.projection_data 

To set my gain matrix to what I computed and avoid the error, but I guess this is not the best method to fix the problem. 

Could you help me?
Jesús Cabrera-Álvarez

WOODMAN Michael

unread,
Apr 13, 2021, 1:47:58 AM4/13/21
to tvb-...@googlegroups.com

Hi,


Do you have subcortical ROIs in your connectivity?  Does sim.connectivity.cortical.sum() return 82?  If so, you might temporarily set sim.connectivity.cortical[:] = True to avoid this bug.


cheers,

Marmaduke


From: tvb-...@googlegroups.com <tvb-...@googlegroups.com> on behalf of JESUS CABRERA ALVAREZ <jesc...@ucm.es>
Sent: Monday, April 12, 2021 7:00:19 PM
To: TVB Users
Subject: [TVB] MEG monitor - gain matrix
 
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/1d7d9bd5-2f86-4358-902e-da93a0c32603n%40googlegroups.com.

ja.sta...@gmail.com

unread,
Mar 24, 2022, 3:11:59 PM3/24/22
to TVB Users
Hi Marmaduke, Hi Jesus,
did you manage to solve this problem permanently? I am struggling with the same issue with the default 192 connectivity provided by the TVB and the same error pops up.
How do I avoid it and could you help me understand where does it come from? My parcellation for sure has subcortical regions.
Analogous to Jesus problem:
 'INFO Projection configured gain shape (276, 424)' - gives me a shape that I am having issues making sense of.
my error says: 'shapes (276,424) and (192,4) not aligned: 424 (dim 1) != 192 (dim 0)'

Where does the 424 come from if 276 is my number of MEG sensors?

And another question: If I wanted to perform a region-wise simulation with an MEG monitor (with a forward solution from region to sensors) would that be possible?
or do I need to perform surface simulation for MEG? I would be grateful for your help. Jan Stasinski


Julie Courtiol

unread,
Mar 27, 2022, 7:19:20 AM3/27/22
to tvb-...@googlegroups.com
Hi Jan,

I suggest you to add the following line:
>> con.cortical[:] = True     # To avoid adding analytical gain matrix for subcortical sources

Then, you should have this portion:
>> mon_MEG = monitors.MEG.from_file(sensors_fname='meg_brainstorm_276.txt', 
                                                                  projection_fname='projection_meg_276_surface_16k.npy',
                                                                  rm_f_name='regionMapping_16k_192.txt',
                                                                  period=1
                                                                  )


And to answer your question, yes, you can perform a region-based simulation for MEG monitors.

Best,
Julie
---
Best regards,

Dr. Julie Courtiol




Jan Stasiński

unread,
Mar 27, 2022, 7:54:13 AM3/27/22
to tvb-...@googlegroups.com
Thank you Julie! 

On Mar 27, 2022, at 13:19, Julie Courtiol <courtio...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages