netneurolab / neuromaps

A toolbox for comparing brain maps
https://netneurolab.github.io/neuromaps
Other
246 stars 55 forks source link

Problem generating a null model with two MNI152 images #157

Closed BAshinoff closed 6 months ago

BAshinoff commented 7 months ago

Description of issue

Hi,

First, thank you for such a great toolbox! I am running into an issue and was hoping to get some advice.

I have written some python code that I'm running in a jupyter notebook to compare 'tmap' to all maps in the annotations by looping through the annotations.

For the code I am sharing below, I am using aghorian2017 as 'tmap' as a stand-in for a map I have which is also in MNI 152 space.

First, I take the tmap and resample it into the space/density of the annotation from the current loop, then I generate null models based on the resampled t-map, then I calculate the r and p values.

Below the code, I have included a screen shot of the error code I get that there is a problem identifying the 'sphere' variable in the alexander_bloch function. I have also included a screen shot of the alexander_bloch function that seems to fail. This only seems to happen though for iterations where the annotation is in MNI152 space, which matches tmap.

Just to note, I realize in this example it's crashing on the annotation that is identical to the tmap, but this happens for any annotation that starts in MNI152 space, but the code works with no issues for any annotation that starts in any of the other spaces.

Any advice to fix this error is appreciated.

Cheers, Brandon

from neuromaps import datasets, resampling, nulls, stats

tmap = datasets.fetch_annotation(source='aghourian2017')
annotations = datasets.fetch_annotation(source='all')

Results_array = []

for key, value in annotations.items():

  # Process the key and value
  trg_source, trg_desc, trg_space, trg_den_res = key
  filenames = value
  print('')

  print(key) 
  print("Start: Resampling")

  tmap_rs, trg_rs = resampling.resample_images(tmap,  filenames, 
  'MNI152', trg_space, 
  method='linear', 
  hemi=None, 
  resampling='transform_to_trg',
  alt_spec=None)

  print("Start: Generate Null Distribution")
  null_gen = nulls.alexander_bloch(tmap_rs, atlas=trg_space, density=trg_den_res,
                  n_perm=100, seed=1234)
  print("Finish: Generate Null Distribution")

  print("Start: Compare Images")

  r,p,nulldist = stats.compare_images(tmap_rs,trg_rs,nulls=null_gen,return_nulls=True)

  temp_data = [r,p,trg_source, trg_desc, trg_space, trg_den_res]
  Results_array.append(temp_data)
  print('rho = ' + str(r) + ', pspin = ' +str(p))
  print("Finish: Compare Images")
  print("Finish")
  print(key)

image

image

Code of Conduct

justinehansen commented 7 months ago

Hi Brandon, thanks for reaching out. This error happens because it's not possible to run spin tests on volumes (e.g. MNI152 maps). Spin tests are the version of spatial null where the cortical surface is projected to a sphere and spun, but this requires that your data exists on a cortical surface, which isn't the case for volumetric data. You have some options:

Hope that helps!

Justine

BAshinoff commented 7 months ago

Thanks Justine for the quick response!

This is extremely helpful, as was the workshop you ran that's on youtube!