Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Min/Max setting in plotting #19

Closed
rb643 opened this issue Feb 2, 2021 · 17 comments
Closed

Min/Max setting in plotting #19

rb643 opened this issue Feb 2, 2021 · 17 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@rb643
Copy link

rb643 commented Feb 2, 2021

I noticed I can set min/max values using limit_fun, but it seem that this is overridden by the actual min and max if they are smaller. I'm generating a series of plots and would ideally like them all to be on the same scale and also all symmetric, is there a way to do so? This is my rough code so far (where cc is simply the contrast I'm plotting in this loop and the colormap is a divergent RdBu map generated with colorbrewer):

  coloredmeshes = vis.symmetric.data.on.subject(subjects_dir,  subject_id,
                                              lh_clust, rh_clust, bg='sulc', rglactions=list( "trans_fun"=limit_fun(-4, 4),'no_vis'=T),
                                              makecmap_options = list('colFn'=colmap))
  img = vis.export.from.coloredmeshes(coloredmeshes, 
                                      colorbar_legend=paste0("Surface Area (t) - ", cc, " - s",smoothness), 
                                      output_img=paste0('./Figures/FS_adult/SA_',cc,'_FWMH',smoothness,'.png'))
@dfsp-spirit dfsp-spirit self-assigned this Feb 3, 2021
@dfsp-spirit
Copy link
Owner

dfsp-spirit commented Feb 3, 2021

Hi Richard,

I did not try it yet, but if I remember correctly there is a way to do this, mentioned in the docs for vis_group(). It could be that it works for other functions as well. Try adding a range parameter to makecmap_options:

makecmap_options = list('colFn'=colmap, 'range'=c(-4, 4))

If it does not work let me know and I will check why.

@dfsp-spirit dfsp-spirit added the documentation Improvements or additions to documentation label Feb 3, 2021
@rb643
Copy link
Author

rb643 commented Feb 4, 2021

Ah yes I did find that guide, but it didn't seem like this was an allowed input for make_cmap...? Or did I miss something

  coloredmeshes = vis.symmetric.data.on.subject(subjects_dir,  subject_id,
                                               lh_clust, rh_clust, bg='sulc', rglactions=list( "trans_fun"=limit_fun(-4, 4),'no_vis'=T),
                                               makecmap_options = list('colFn'=colmap,'range'=c(-5, 5),'symm'=TRUE))
Error in if (data_range[1] < min(x)) { : 
  missing value where TRUE/FALSE needed

@dfsp-spirit dfsp-spirit added the enhancement New feature or request label Feb 4, 2021
@dfsp-spirit
Copy link
Owner

You're right. I will have a look and see whether I can make that option available to all vis functions.

dfsp-spirit added a commit that referenced this issue Feb 9, 2021
@dfsp-spirit
Copy link
Owner

Could you check whether the fix in 6d83f24 solves your issue? All you have to do is install fsbrain from github to get the new version:

devtools::install_github('dfsp-spirit/fsbrain')

@rb643
Copy link
Author

rb643 commented Feb 10, 2021

Thanks for looking into this so quickly. It appears though that I am still getting the same error message..

@rb643
Copy link
Author

rb643 commented Feb 10, 2021

> packageVersion("fsbrain")
[1] ‘0.4.1’
> library(fsbrain)
>   coloredmeshes = vis.symmetric.data.on.subject(subjects_dir,  subject_id,
+                                               lh_clust, rh_clust, bg='sulc', rglactions=list( 'no_vis'=T),
+                                               makecmap_options = list('colFn'=colmap,'range'=c(-4, 4),'symm'=TRUE))
Error in if (data_range[1] < min(x)) { : 
  missing value where TRUE/FALSE needed

@dfsp-spirit
Copy link
Owner

Is this fsaverage data? If so, could you attach it here or, if you'd rather not, send via email to my email (maintainer address)?

@dfsp-spirit
Copy link
Owner

dfsp-spirit commented Feb 10, 2021

If it is data computed in R, you can use freesurferformats::write.fs.curv to save it to a file. (1 per hemi)

@rb643
Copy link
Author

rb643 commented Feb 10, 2021

I'm plotting a sig.mgh result this way for a number of output (at varying smoothness levels for various group). Full code:

library(fsbrain)

#fsbrain::download_optional_data();
subjects_dir = '/Applications/freesurfer/7.1.1/subjects/'
sjl = read.md.subjects.from.fsgd("./Output/FSGD_Adult_Subgroup.fsgd");
subject_id = 'fsaverage';

colmap = colorRampPalette(RColorBrewer::brewer.pal(11, name="RdBu"))

for (ss in c('5','10','15')){
  for (cc in c("Both-Neither")){
  
  tryCatch({
 
  lh_demo_cluster_file = paste0('Output/freesurfer_adult_subgroup_etiv/lh.area.',ss,'.glmdir/',cc,'/sig.mgh')
  rh_demo_cluster_file = paste0('Output/freesurfer_adult_subgroup_etiv/rh.area.',ss,'.glmdir/',cc,'/sig.mgh')
  lh_clust = freesurferformats::read.fs.morph(lh_demo_cluster_file); 
  rh_clust = freesurferformats::read.fs.morph(rh_demo_cluster_file);   

  print((sum(lh_clust)+sum(rh_clust)))
  coloredmeshes = vis.symmetric.data.on.subject(subjects_dir,  subject_id,
                                              lh_clust, rh_clust, bg='sulc', rglactions=list( 'no_vis'=T),
                                              makecmap_options = list('colFn'=colmap,'range'=c(-4, 4)))
  img = vis.export.from.coloredmeshes(coloredmeshes, 
                                      colorbar_legend=paste0("Surface Area (t) - ", cc, " - s",ss), 
                                      output_img=paste0('./Figures/FS_adult/SA_',cc,'_FWMH',ss,'.png'))
  # close all windows
  while (rgl.cur() > 0) { rgl.close() }
  })
  }
}

All these left and right hemisphere sig.mgh files should be in fsaverage, I can email you an example, but I'm looping through a stack of results here and trying individual ones all throw the same error. Did I miss something? I added one example set here.
sig.zip

@dfsp-spirit
Copy link
Owner

Thanks for the zip, that will do.

@dfsp-spirit
Copy link
Owner

Hm, I think you you do not have the correct fsbrain version yet, or you did not restart the R interpreter after installing it. I am getting this plot with the following code and your unzipped data in the same directory:

library('fsbrain')

subjects_dir = file.path(find.freesurferhome()$found_at, "subjects")
subject_id = 'fsaverage';
colmap = colorRampPalette(RColorBrewer::brewer.pal(11, name="RdBu"))

lh_clust = freesurferformats::read.fs.morph('./lh_sig.mgh'); 
rh_clust = freesurferformats::read.fs.morph('./rh_sig.mgh');



coloredmeshes = vis.symmetric.data.on.subject(subjects_dir,  subject_id,
                                              lh_clust, rh_clust, bg='sulc', rglactions=list( 'no_vis'=T),
                                              makecmap_options = list('colFn'=colmap,'range'=c(-4, 4)))

output_img = "./plot.png";
img = vis.export.from.coloredmeshes(coloredmeshes, 
                                    colorbar_legend=paste0("Surface Area (t)"), 
                                    output_img=output_img);

plot

@dfsp-spirit
Copy link
Owner

issue19_fsbrain.zip

Here is a zip with my script, your data and the produced output.

@rb643
Copy link
Author

rb643 commented Feb 10, 2021

For some reason I just needed to restart my X11 as well, its working now! Thanks for sorting this out so quickly and efficiently!

@dfsp-spirit
Copy link
Owner

You're welcome!

@wjddyd66
Copy link

Thank you very much.

It was the same problem as above, but it has been resolved.

If you currently install it with R install.package, it will be installed as 0.4.1 Version as above, and the above problem will occur.

devtools::install_github('dfsp-spirit/fsbrain')

As I reinstalled and ran it, it ran without any problems.

@dfsp-spirit
Copy link
Owner

Great! I will release a new version with the fix on CRAN soon, it seems many people need this feature.

dfsp-spirit added a commit that referenced this issue Mar 27, 2021
@dfsp-spirit dfsp-spirit added bug Something isn't working and removed enhancement New feature or request labels Mar 27, 2021
@dfsp-spirit
Copy link
Owner

This fix is part of CRAN release 0.4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants