2d disk connectivity plot from script

Hi everyone,

I'm wondering if anyone knows how to invoke the connectivity >2d disk plot from script? I have a .mat file with the granger connectivity matrices for separate classes and I would like to plot the topography like I can do it in the brainstorm GUI.

The reason I wish to do this is because I wish to visualize the granger topography at each frequency and also create a gif out of it.

Hi!

The "Connectivity [1xN] -> 2D Disc" Display option calls the following function:

view_topography(fileName, [], '2DDisc')

where fileName is the relative path to your Brainstorm file inside your protocol folder, i.e. "SubjectX/ConditionY/timefreq_connectn_[...].mat"

I hope this helps!
Martin

The thing is I created my granger connectivity matrix from script by calling the function bst_spectral_granger.m. Is there a way to utilize this .mat file? It is a 14channel x 14 channel x 60 frequencies matrix. I don't think the brainstorm GUI produces this kind of matrix, just from seeing the figures and images.

The display and the database are tightly integrated, it is difficult to call the display functions without having the files in the database.

For showing a flat topography of the distribution of the connectivity values between one electrode and all the others (2DDisc or 2DSensorCap), this is possible with view_topography:
[hFig, iDS, iFig] = view_topography(DataFile, Modality, TopoType, F)
You still need to have one reference file registered in the database, but you can replace its values with the values you want by passing them as the F matrix ([Nelectrodes x 1]). Read the header of the function for additional help.

If what you want is the circular graph plot, this would be very difficult. The corresponding function is this one:

I'm trying the view_topography function with the dataset generated through the GUI, and I'm confronting some issues. When I call [hFig,iDS,iFig]=view_topography(fn,'EEG','2ddisc',TF), i get the following error.

Insufficient number of outputs from right hand side of equal sign to satisfy assignment.

Error in bst_memory>GetTimefreqMaximum (line 2388)
RowNames = GlobalData.DataSet(iDS).Timefreq(iTimefreq).RowNames;

Error in bst_memory (line 72)
eval(macro_method);

Error in figure_topo>UpdateTopoPlot (line 126)
Fall = bst_memory('GetTimefreqMaximum', iDS, iTf, TfInfo.Function);

Error in figure_topo>PlotFigure (line 651)
UpdateTopoPlot(iDS, iFig);

Error in figure_topo (line 27)
eval(macro_method);

Error in view_topography (line 379)
isOk = figure_topo('PlotFigure', iDS, iFig, 1);

I think the issue is that the variable, iTimefreq is an empty array, even though in a previous part of the script iTimefreq is assigned a value.

The easier for you to find the correct input parameters is maybe to use the Matlab debugger to explore dynamically how the function view_topograhy is called.
Place a breakpoint at the beginning of view_topography (eg. line 47) by clicking on the little dash next to the line number. Then display the file the way you want using the GUI. When the debugger stops, you can explore the contents of all the variables in input.

Then you should be able to simply add the values you want to show as the F parameter.
Note that this has to be a flat vector of values (Nelectrodes x 1), not a time-frequency or a connectivity matrix.

There might be some things that do not well when combining this extra parameter F with a time-frequency or connectivity file (I don't think I've ever tried this). If you think there is a bug somewhere, please give me as much info as possible to try to reproduce your problem (screen capture of your database explorer showing the files, what you have in your fn and TF variables, etc).

Even when I use the granger connectivity matrix created through the GUI, I still get errors when calling that .mat file from script with view_topography.

[hFig, iDS, iFig] = view_topography('gca.mat',[], '2ddisc',TF, 1, 'NewFigure', RefRowNames)
Error using view_topography (line 241)
This files contains information about cortical sources or regions of interest.
Cannot display it as a sensor topography.

even if I use the file formed through the brainstorm GUI, when I use file_gettype(filename), the answer is 'unknown'. I feel like this is the issue. How do I get the filetype 'timefreq'?

Or what is the valid data type for a granger connectivity matrix such that I can use view_topography and see a 2d disc layout?

[EDIT]: I have changed the file name so that it could be recognized as timefreq. This is fine, but it keeps saying File is not registered in database..

[EDIT2]: Even when I'm using the data produced by the brainstorm gui, I cannot seem to call the function view_topography properly.. if I insert: [hfig,ids,ifig]=view_topography(fn,[],'2ddisc'), then I get an error saying:
Output argument "RowNames" (and maybe others) not assigned during call to "figure_timefreq>GetFigureData".

Error in figure_timefreq (line 28)
eval(macro_method);

Error in figure_topo>GetFigureData (line 336)
[Time, Freqs, TfInfo, TF, RowNames] = figure_timefreq('GetFigureData', hFig, TimeDef);

Error in figure_topo>UpdateTopoPlot (line 101)
[DataToPlot, Time, selChan, overlayLabels, dispNames, StatThreshUnder, StatThreshOver] = GetFigureData(iDS, iFig, 0);

Error in figure_topo>PlotFigure (line 651)
UpdateTopoPlot(iDS, iFig);

Error in figure_topo (line 27)
eval(macro_method);

Error in view_topography (line 379)
isOk = figure_topo('PlotFigure', iDS, iFig, 1);

if I insert [hFig, iDS, iFig] = view_topography(fn, 'EEG', '2ddisc', TF(:,:,1), 1, 'NewFigure', RefRowNames)
I get the error:

Insufficient number of outputs from right hand side of equal sign to satisfy assignment.

Error in bst_memory>GetTimefreqMaximum (line 2388)
RowNames = GlobalData.DataSet(iDS).Timefreq(iTimefreq).RowNames;

Error in bst_memory (line 72)
eval(macro_method);

Error in figure_topo>UpdateTopoPlot (line 126)
Fall = bst_memory('GetTimefreqMaximum', iDS, iTf, TfInfo.Function);

Error in figure_topo>PlotFigure (line 651)
UpdateTopoPlot(iDS, iFig);

Error in figure_topo (line 27)
eval(macro_method);

Error in view_topography (line 379)
isOk = figure_topo('PlotFigure', iDS, iFig, 1);

[EDIT3] I believe the issue is in function bst_memory('GetDataSetTimeFreq',TfInfo.FileName). the iDS and iTimeFreq variables are all turning out blank.

**[EDIT4]: nevermind people! I think i've figured it out :slight_smile: sorry for the commotion

My question now is how do I iterate the figure over the frequencies? (in script)

Even when I use the granger connectivity matrix created through the GUI, I still get errors when calling that .mat file from script with view_topography.

Your files are not created from the interface ('gca.mat' is not created by Brainstorm). Generate the files from the process.

[hFig, iDS, iFig] = view_topography('gca.mat',[], '2ddisc',TF, 1, 'NewFigure', RefRowNames)
Error using view_topography (line 241)
This files contains information about cortical sources or regions of interest.
Cannot display it as a sensor topography.

Are you trying to display sensor-level data, or a connectivity matrix computed from ROIs in source space?

My question now is how do I iterate the figure over the frequencies?

Once the figure is opened, you can change the current frequency with this function:

panel_freq('SetCurrentFreq', freq, 0);  % Select the closest frequency bin available in the file
panel_freq('SetCurrentFreq', iFreq, 0);  % Select the frequency bin #iFreq from the current file

Hmm it doesn't seem to be working.

I think it is best if I do snapshot>Frequency contact sheet:figure.

For this I have a few questions. When I do a frequency resolution of 0.1Hz in the process GUI, I obtain 983 frequency bins between 0 and 60Hz. However, when I call this function in script (0:0.1:60) I get significantly fewer elements. Why is the process' frequency bins greater in number?

I am not sure if this is the core of the issue, but when I load my data (not from process GUI) and try to do frequency contact sheet, nothing changes. Nothing changes when I utilize the slider also.

[EDIT]: the gca.mat was just a name I gave. I understand that this is not the way to do things. I have view_topography working

Also, as a side question, how do I enable contour, channel labels, channel markers in script?

Can you describe/illustrate better what you did in one and the other cases?

Also, as a side question, how do I enable contour, channel labels, channel markers in script?

Use the functions (check the code for help):
figure_topo.m > SetTopoLayoutOptions
figure_3d.m > ViewSensors

Hi there,

I am calling the view_topography.m function from script. I have managed to plot them across frequencies, but I am unable to hold onto the display of sensors and labels. Is there a function I can call to continuously produce the sensors and labels (and contours) on the 2DSensorCap map (or 2ddisc)?

Hey @moon94

**[EDIT4]: nevermind people! I think i've figured it out :slight_smile: sorry for the commotion

Could you explain your solution, please? I've get the error "Insufficient number of outputs from right hand side of equal sign to satisfy assignment. etc"

OK.
I found the solution:

FileName='Group_analysis/S2210-S2110/timefreq_200128_1349.mat';

[hFig, iDS, iFig] = view_topography(FileName, 'EEG', '2DDisc', [], 0, [])