dfsp-spirit / fsbrain

R library for structural neuroimaging. Provides high-level functions to access (read and write) and visualize surface-based brain morphometry data for individuals and groups.
Other
64 stars 13 forks source link

Tight layout with 9 view inflated #50

Closed mattsodoma closed 1 year ago

mattsodoma commented 1 year ago

I am trying to get a tight layout with the inflated brain on the 9 view. I was reading the FAQ which pointed me to use vislayout.from.coloredmeshes and to use shift_hemis_apart so the hemispheres on inflated don't overlap. My issue, is that when I use export, it recognizes the rglaction correctly and the hemispheres are seperated. However, when I use vislayout.from.coloredmeshes it does not separate the hemispheres. On the other hand, when I use the vislayout.from.coloredmeshes, I get the type of spacing that I would like whereas export has a lot of white space. Wondering if I am doing something wrong in my vislayout call or export calls. Pictures and code below:

Export image: combined loglate YMb_inflated

vislayout.from.coloredmeshes image

combined loglate YMb_inflated2

code: `x<-vis.symmetric.data.on.subject(subjects_dir, subject_id, lh_clust, rh_clust, bg="curv", surface = "inflated", rglactions = list('shift_hemis_apart'=TRUE), views = NULL)

export(x, img_only = TRUE, output_img = output_saveinflated,rglactions = list('shift_hemis_apart'=TRUE),view_angles=c("t9"),colorbar_legend= legendname)

vislayout.from.coloredmeshes(x,output_img = output_saveinflated2, view_angles = get.view.angle.names(angle_set = "t9"),rglactions = list('shift_hemis_apart'=TRUE))`

dfsp-spirit commented 1 year ago

This definitely should not happen. I will try to reproduce locally and let you know.

Which environment and version of fsbrain are you using?

Environment:

dfsp-spirit commented 1 year ago

Okay, I can reproduce this locally with the latest official release version of fsbrain. Confirmed as a bug. I will look into it.

mattsodoma commented 1 year ago

Hi Tim,

Thank you for looking into it. Not sure if this information is still helpful, but it was present on both my work and home desktop. Work: R version 4.2.2 MacOS Ventura 13.2.1 fsbrain 0.5.3

Home (not sure of specifics right now but its fairly recent reinstall of windows so everything is newer updates) Windows 11 R version 4.1+ fsbrain likely 0.5.3

Thank you, Matt

dfsp-spirit commented 1 year ago

Thanks for the additional info!

dfsp-spirit commented 1 year ago

Hi Matthew (@mattsodoma),

I have rolled out a fix for this on the master branch. The fix is not yet on CRAN, but it will go there with the next fsbrain release. To use the fixed version, you will have to install via remotes:

install.packages("remotes")
remotes::install_github("dfsp-spirit/fsbrain")

IMPORTANT: If you did this in a session that already had fsbrain loaded, you will have to completely restart R. Clicking Session -> New Session in RStudio is not enough! To be sure, just restart RStudio completely. If you do not do this, you will not be using the freshly installed package version, but the old broken one.

Then you can try this:

fsbrain::download_optional_data();
    fsbrain::download_fsaverage(accept_freesurfer_license = TRUE);
    subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
    subject_id = 'fsaverage';

    lh_demo_cluster_file = system.file("extdata", "lh.clusters_fsaverage.mgz", package = "fsbrain", mustWork = TRUE);
    rh_demo_cluster_file = system.file("extdata", "rh.clusters_fsaverage.mgz", package = "fsbrain", mustWork = TRUE);

    lh_clust = freesurferformats::read.fs.morph(lh_demo_cluster_file);   # contains a single positive cluster (activation, group difference), the other values are 0
    rh_clust = freesurferformats::read.fs.morph(rh_demo_cluster_file);   # contains two negative clusters

    cm = fsbrain::vis.symmetric.data.on.subject(subjects_dir, subject_id, lh_clust, rh_clust, surface="inflated", bg="curv_light", rglactions = list('shift_hemis_apart'=TRUE), views = NULL);

    fsbrain::export(cm, img_only = TRUE, output_img = "fsbrain_issue50_export.png", rglactions = list('shift_hemis_apart'=TRUE), view_angles=fsbrain::get.view.angle.names(angle_set = "t9"), colorbar_legend= "issue50 test");

fsbrain_issue50_export

dfsp-spirit commented 1 year ago

Please let me know whether this fixes your problem.

mattsodoma commented 1 year ago

Hi Tim, I just tested this on my home computer (windows) and it worked as expected! Appreciate the help. Matt

dfsp-spirit commented 1 year ago

Great to hear to that!