OHBA-analysis / osl-dynamics

Methods for studying dynamic functional brain activity in neuroimaging data.
https://osl-dynamics.readthedocs.io/
MIT License
58 stars 18 forks source link

structural parcellation file #245

Closed sunflower-smile closed 2 months ago

sunflower-smile commented 5 months ago
  1. When I try to calculate power_maps and coh_maps using EEG data after source localization (using the Schaefer2018_200Parcels template), ”Importing Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm.nii.gz results in a 'file not found' error."

  2. In the FAQ section "Can I use a structural parcellation (e.g. AAL or Desikan-Killiany atlas)?" ,it is mentioned that having too many parcels from source localization can also have an impact.

Is there any problem with my understanding? If you can solve the above doubts, thank you very much.

cgohil8 commented 5 months ago

Have you already source localised / parcellated your data? Now you'd like to plot a power map for the source localised data?

  1. The available parcellations (that come with the packages) are listed here: https://osl-dynamics.readthedocs.io/en/latest/autoapi/osl_dynamics/files/parcellation/index.html. If you're using these then you can pass just the name, e.g.

    power.save(
    ...
    parcellation_file="fMRI_parcellation_ds8mm.nii.gz",
    ...
    )

    However, if it's not on the list, you can pass the full path to the file on your computer instead, e.g. if the parcellation was in my "Desktop" directory, i can pass:

    power.save(
    ...
    parcellation_file="/Users/cgohil/Desktop/fMRI_parcellation_ds8mm.nii.gz",
    ...
    )

    Note, this parcellation files must be a 4D image containing the masks for each parcel.

  2. There's nothing stopping you running the code, i.e. you can calculate the source activity at a large number of parcels. However, you will find that the activity of nearby parcels is very similar (due to volume conduction). If you calculated a network, you will find high connectivity ('ghost interactions'). You can only remove these ghost interactions if you have a small number of parcels. There's nothing stopping you from using a high density parcellation as long as you are aware of this issue and don't over interpret the connectivity. If you're only interested in power, then this might not be a problem and you can use a high density parcellation..

sunflower-smile commented 5 months ago

Thank you very much for your reply. I did use DyNeMo model and TDE-HMM model to explore the hidden state fireworks dynamics of EEG data after locating the source of EEG data through brainstorm. However, according to your reply, I will:

# Source reconstruction files used to create the source space data
mask_file = "E:/JupyterNoteBook/osl/osl/source_recon/parcellation/files/MNI152_T1_1mm_Brain.nii.gz"
parcellation_file = (
"E:/JupyterNoteBook/osl/osl/source_recon/parcellation/files/Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm.nii.gz "
)

However, the following problems were encountered:

IndexError: boolean index did not match indexed array along dimension 0;  dimension is 39676 but corresponding boolean dimension is 7221032

You mentioned "Note, this parcellation files must be a 4D image containing the masks for each parcel." So is this the main reason for the error? Or what should I do about it?

sunflower-smile commented 5 months ago

Thank you very much for your reply! The code for the DyNeMoC model is not publicly available on your team's home page. With all due respect, would you consider releasing the code for this model?

cgohil8 commented 5 months ago
IndexError: boolean index did not match indexed array along dimension 0;  dimension is 39676 but corresponding boolean dimension is 7221032

I would resample the parcellation file to match MNI152_T1_1mm_Brain.nii.gz with FSL flirt:

flirt -in Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm.nii.gz -ref MNI152_T1_1mm_Brain.nii.gz -out Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm_resampled.nii.gz -applyisoxfm 1

and use Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm_resampled.nii.gz to parcellate your data. Please close this issue if this resolves your issue.

The code for the DyNeMoC model is not publicly available on your team's home page. With all due respect, would you consider releasing the code for this model?

Unfortunately DyNeMoC's not supported in this repo. Note, it's a simple extension to take the inferred alphas and/or mode/state covariances (or means) and use these in a machine learning predictor with sklearn.

sunflower-smile commented 5 months ago

I'm sorry for the continued issue despite resampling the brain region file as per your guidance. Additionally, I appreciate your assistance with DyNeMoC-related inquiries. I'll delve deeper into these models to enhance my understanding.

cgohil8 commented 5 months ago

Okay, resampling both they should definitely match i think:

flirt -in MNI152_T1_1mm_Brain.nii.gz -ref MNI152_T1_1mm_Brain.nii.gz -out MNI152_T1_1mm_Brain_resampled.nii.gz -applyisoxfm 1
flirt -in Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm.nii.gz -ref MNI152_T1_1mm_Brain.nii.gz -out Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm_resampled.nii.gz -applyisoxfm 1

What do you get for dim1-dim4 when you do:

fslinfo MNI152_T1_1mm_Brain_resampled.nii.gz
fslinfo Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm_resampled.nii.gz

Note, you need to recompute your source reconstruction with this new parcellation file then pass

mask_file="MNI152_T1_1mm_Brain_resampled.nii.gz",
parcellation_file="Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm_resampled.nii.gz",

when you plot.

sunflower-smile commented 4 months ago

I am truly sorry that despite re-sampling the brain region file according to your instructions, the problem still exists.

# Source reconstruction files mask_file = "E:/JupyterNoteBook/osl-dynamics-main/osl_dynamics/files/mask/MNI152_T1_1mm_Brain_resampled.nii.gz" parcellation_file = "E:/JupyterNoteBook/osl-dynamics-main/osl_dynamics/files/parcellation/Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm_resampled.nii.gz""

IndexError: boolean index did not match indexed array along dimension 0; dimension is 39676 but corresponding boolean dimension is 7221032

其中: miss@DESKTOP-9FIJ8CQ:~$ fslinfo MNI152_T1_1mm_Brain_resampled.nii.gz data_type FLOAT32 dim1 182 dim2 218 dim3 182 dim4 1 datatype 16 pixdim1 1.000000 pixdim2 1.000000 pixdim3 1.000000 pixdim4 1.000000 cal_max 0.000000 cal_min 0.000000 file_type NIFTI-1+

miss@DESKTOP-9FIJ8CQ:~$ fslinfo Schaefer2018_200Parcels_7Networks_order_FSLMNI152_1mm_resampled.nii.gz data_type FLOAT32 dim1 182 dim2 218 dim3 182 dim4 1 datatype 16 pixdim1 1.000000 pixdim2 1.000000 pixdim3 1.000000 pixdim4 0.000000 cal_max 0.000000 cal_min 0.000000 file_type NIFTI-1+

I have also checked the parcellation file of schaefer200MNI, and there is still the same problem. I don't know what the problem is except for the problem. I'm really sorry to bother you for so long.

cgohil8 commented 3 months ago

Apologies for the delay. Is this still an issue?

sunflower-smile commented 2 months ago

I apologize, but the data source has been reconstructed through alternative means. Following this, the DyNeMo model was employed to learn the latent variables from EEG data.

Despite trying various approaches, I've been unable to integrate a classification layer into the DyNeMo network architecture for training on classification tasks. I am uncertain if this is due to a problem with my code. In your previous response, you mentioned, 'Unfortunately, DyNeMoC is not supported in this repository. However, it is straightforward to extend the use of the inferred alphas and/or the covariances (or means) of the modes/states with a machine learning predictor using sklearn.' Does this imply that I should seek alternative methods to leverage the learned alphas and/or the covariances (or means) of the modes/states for subsequent classification or prediction tasks? I would greatly appreciate any detailed guidance you could offer.

cgohil8 commented 2 months ago

We would recommend:

  1. Train the HMM/DyNeMo on the data, get your alphas.
  2. Calculate any metrics you want from the alphas as summary statistics for dynamics. You do this for each subject.
  3. Dual estimate the covariances for each subject.
  4. Use the subject-specific summary statistics and covariances in your classifier.

You might find these examples useful: https://github.com/OHBA-analysis/osl-dynamics/tree/main/examples/decoding/hmm.

cgohil8 commented 2 months ago

Can you send me your parcellation file: chetan.gohil@psych.ox.ac.uk. I will try and see if I can plot a brain surface map.

sunflower-smile commented 2 months ago

Thank you very much from the bottom of my heart!

cgohil8 commented 2 months ago

The issue was osl-dynamics was expecting a 4D binary parcellation, whereas the one you have is 3D. I added code to handle 3D parcellations in the plotting: https://github.com/OHBA-analysis/osl-dynamics/pull/265.