[3/3] Fastgraph: Plot Fastgraphs#916
Conversation
- Adds `subtightplot.m`, A wrapper function for `subplot`. Adds the ability to define the gap between neighbouring subplots. - `subplot` prior to R2019b lacked this functionality, and the gap between subplots can reach 40% of figure area, which is pretty lavish. - In 2019b, MATLAB introduced `tiledLayout` and `nexttile` that can achieve the same but for backward compatibility it would be good to just stick to this external module.
Required for plotting Fastgraph as it uses the anatomical labels based on the atlas chosen by the user
|
@chinmaychinara91, To be reviewed, this PR should updated to be compatible with the changes in PR #911 and PR #912 |
- Rename processes as per the changes in PR brainstorm-tools#911 and brainstorm-tools#912 - Adding `ODD` and `EVEN` events not part of the tutorial (left at user's discretion with a note added to the tutorial about it). As recommended by @jcmosher.
rcassani
left a comment
There was a problem hiding this comment.
Please address the comments and perform the required changes.
There was a problem hiding this comment.
There is code to do this in Brainstorm. There is no need to add this external code.
See it in: figure_timefreq('GetLayoutPositions'). This is called when TF maps for all channels.
There was a problem hiding this comment.
Need to update the header comments
|
|
||
| % Process: Remove drift EMD | ||
| sFilesStimStartEmd = bst_process('CallProcess', 'process_remove_drift_emd', sFilesStimStartRmSpes, [], ... | ||
| 'cutoff', 2); % in ms |
| sProcess.options.label5.Comment = '<U><B>Select method to sort the data:</U></B>'; | ||
| sProcess.options.label5.Type = 'label'; | ||
| sProcess.options.sortmethod.Comment = {'Root Mean Square', 'Max Absolute'}; | ||
| sProcess.options.sortmethod.Type = 'radio'; |
| sProcess.options.label3.Comment = '<U><B>Select region(s) to include:</U></B>'; | ||
| sProcess.options.label3.Type = 'label'; | ||
| sProcess.options.regionprefrontal.Comment = '1: Prefrontal'; | ||
| sProcess.options.regionprefrontal.Type = 'checkbox'; | ||
| sProcess.options.regionprefrontal.Value = 1; | ||
| sProcess.options.regionfrontal.Comment = '2: Frontal'; | ||
| sProcess.options.regionfrontal.Type = 'checkbox'; | ||
| sProcess.options.regionfrontal.Value = 1; | ||
| sProcess.options.regioncentral.Comment = '3: Central'; | ||
| sProcess.options.regioncentral.Type = 'checkbox'; | ||
| sProcess.options.regioncentral.Value = 1; | ||
| sProcess.options.regionparietal.Comment = '4: Parietal'; | ||
| sProcess.options.regionparietal.Type = 'checkbox'; | ||
| sProcess.options.regionparietal.Value = 1; | ||
| sProcess.options.regiontemporal.Comment = '5: Temporal'; | ||
| sProcess.options.regiontemporal.Type = 'checkbox'; | ||
| sProcess.options.regiontemporal.Value = 1; | ||
| sProcess.options.regionoccipital.Comment = '6: Occipital'; | ||
| sProcess.options.regionoccipital.Type = 'checkbox'; | ||
| sProcess.options.regionoccipital.Value = 1; | ||
| sProcess.options.regionlimbic.Comment = '7: Limbic'; | ||
| sProcess.options.regionlimbic.Type = 'checkbox'; | ||
| sProcess.options.regionlimbic.Value = 1; |
There was a problem hiding this comment.
Use either list_vertical or list_horizontal, example in:
https://github.com/thuy-n/bst-neuromaps/blob/main/process/process_nmp_fetch_maps.m
In FastGraph case it is simpler as they regions are hard coded, there is no need of dynamic regions
Why do we need the numbers in the regions?
| plotWindowIdx = OPTIONS.PlotWindow(1) + 101 : OPTIONS.PlotWindow(2) + 101; | ||
| timeMs = seegData{iSubplot}.Time(plotWindowIdx) * 1000; | ||
|
|
||
| fprintf('\n===== Fastgraph %d/%d: Stimulation site "%s" =====\n', iSubplot, numel(sInputs), sInputs(iSubplot).Comment) |
| % Capture image | ||
| img = out_figure_image(hFigSurf); | ||
| % Crop background | ||
| bgColor = img(1,1,:); | ||
| mask = (img(:,:,1) == bgColor(1)) & ... | ||
| (img(:,:,2) == bgColor(2)) & ... | ||
| (img(:,:,3) == bgColor(3)); | ||
| goodRows = any(~mask, 2); | ||
| goodCols = any(~mask, 1); | ||
| imgCortex = img(goodRows, goodCols, :); |
There was a problem hiding this comment.
Change the background in the figure, then get the image 😉
| subtightplot(nRows, nCols, iSubplot+1, gap, horzMargin, vertMargin); | ||
| % Plot the reference panel with the cortex snapshot and axis labels | ||
| axSubplots(iSubplot+1) = gca; | ||
| PlotLegend(axSubplots(iSubplot+1), imgCortex, round(axSubplots(1).XLim), [0 1], 'Time (ms)', 'Voltage (mV)'); |
There was a problem hiding this comment.
Axis labels, and the L/R indicator should be for every figure, except for the "legend" on. Not the the opposite
|
|
||
| %% ===== ADD 'L/R' HEMISPHERE LABELS IN THE LEGEND ===== | ||
| % Add 'L/R' hemisphere labels to the legend axes | ||
| function AddLegendHemisphereLabels(axSubplotLegend, xRange, yRange) |
There was a problem hiding this comment.
This functions is way simpler by using normalized units for the place of the L/R labels in the figure
| % Keep the original axes limits fixed so the image does not alter them | ||
| axis(axSubplotLegend, 'manual'); | ||
| % Initial placement | ||
| UpdateLegendImage(axSubplotLegend, axImg, brainImg); |
There was a problem hiding this comment.
There are tools in Brainstorm to do these changes, no need to reinvent the wheel.
- Set the lateral view
- Apply zoom
See figure_3d.m
|
@chinmaychinara91, the file |
|
@chinmaychinara91, any update on this PR? |
|
@rcassani apologies for the delay. I will have it ready by end of this week. |
This PR is the 3rd and final part required for Fastgraph. It implements Fastgraph plotting, where each Fastgraph is a stacked area plot showing the distribution of stimulation-evoked responses across anatomical brain regions.
As the name suggests, Fastgraph stands for Functional-Anatomical STacked area graph. Each plot represents how stimulation of one site affects activity across other regions of the brain.
Prerequisite: Follow steps in PR #912
The GUI
Inputs
Regionuses the region colors for the plot, andLabeluses the above selected atlas label colors.RMSorMax Abs).20mmis considered close as the contacts close to the stim site will always give very high response so it needs to be ignored.Steps to use
Follow steps as in PR [2/3] Fastgraph: Remove SPES artifacts using EMD #912
Drag the artifact removed blocks (

| rm spes | emd) toProcess1tab >Run > Import > Import recordings > Import MEG/EEG: Events. Set event name asSTIMand epoch time-100to900ms. For this sample data, we will be importing all theSTIMevents with a 1s epoch. The reason we chose this is due to the range of latencies (early, middle, late) mentioned above. Also note that appending the per session (represented by#1,#2) stim site info to theSTIMevents of the stimulation block earlier now helps in creating separate groups, else all would have clustered under one.Drag the

STIMgroups toProcess1tab and average them by trial to get as under.Ideally do it for all the stimulation blocks, but above just shows a sample of the data where

A11-A12shows low response andB3-B4andB'3-B'4show high response. To see the results, just drag the averaged trials toProcess1tab >Run > FAST graph > Plot Fastgraphsand set the values as shown in the process GUI image above to get the plot as under.RMS).Avg: STIM B'3-B'4 #1Fastgraph, theparahippocampal Lgave the highest response, inAvg: STIM B3-B4 #1it wasparahippocampal Rand inAvg: STIM A11-A12 #1it wassuperiortemporal RLandRindicating above the x-axis represent the left hemisphere responses and below it represents the right hemisphere responses.Some more examples
Color by

Region| Select region(s) to include:FrontalandTemporalColor by

Label| Select region(s) to include: Select allColor by

Label| Select region(s) to include:FrontalandTemporalSelect scouts:

parahippocampal L,parahippocampal R,superiortemporal R| Color byRegion| Select region(s) to include: Select allSelect scouts:

parahippocampal L,parahippocampal R,superiortemporal R| Color byLabel| Select region(s) to include: Select allAssociated PRs
Checklist
For now good first draft for testing the end-to-end results, but might need changes based on the tutorial page.The tutorial data is here.@jcmosher @Nastaranlotfi @yashvakilna