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

NaNs encountered during tag-control differencing #10

Open
markushs opened this issue Mar 2, 2022 · 2 comments
Open

NaNs encountered during tag-control differencing #10

markushs opened this issue Mar 2, 2022 · 2 comments

Comments

@markushs
Copy link

markushs commented Mar 2, 2022

Hi! We've collected some pilot data using the HCP-PCASL sequence and stumbled upon this repo when investigating how to integrate the ASL-analysis with the other parts of the HCP-pipeline.

With a few edits I managed to run our data through most of the pipeline. Was struggling a bit with NaNs, affecting the calculations here

B_perf = (Y_odd - Y_even) / (X_odd - X_even)
B_baseline = (X_odd*Y_even - X_even*Y_odd) / (X_odd - X_even)

Which seems to be caused by the first M0 volume ("calib0") being used as calibration image throughout the pipeline

hcp-asl/hcpasl/utils.py

Lines 228 to 230 in 518593a

fslroi(str(mbpcasl), str(tis_name), 0, 86)
fslroi(str(mbpcasl), str(calib0_name), 88, 1)
fslroi(str(mbpcasl), str(calib1_name), 89, 1)

In our data (collected using the "official" HCP-PCASL sequence on a Prisma), the first of the two M0-images is dislocated anteriorly by one voxel relative to the tag/control images and the second M0-image. Is this, something you've observed in developing/running the hcp-asl pipeline?

Also, are you planning to develop the pipeline further, or do you consider it "production-ready"?

Thanks!

@FKennedyMcC
Copy link
Collaborator

FKennedyMcC commented Mar 3, 2022

Hi markushs!

Thanks for getting in touch. A few more details would help us to figure out what is going wrong.

Do you know which asl_differencing.py step is causing problems? This function is called twice in the pipeline:

  1. First to perform tag-control differencing with the data aligned with the 1st volume of the ASL time series (i.e. after motion correction but before the ASL data is aligned with the T1w image and distortion corrected). The ASL nifti that is input to this differencing step will be saved by the pipeline into: ${StudyFolder}/${Subject}/ASL/TIs/, and the resulting difference data will be saved at: ${StudyFolder}/${Subject}/ASL/TIs/Betas . This differencing step is done so that we can run oxford_asl to generate a perfusion-weighted image, which can be used as the basis for an improved registration to the T1w image. The calibration image is not used in this perfusion estimation step (neither calib0 nor calib1), but the ASL difference data is masked in oxford_asl using the mask at: ${StudyFolder}/${Subject}/ASL/TIs/aslfs_mask.nii.gz.
  2. Second to perform tag-control differencing with the data aligned with the T1w image (the tag-control data input to this differencing step is saved here: ${StudyFolder}/${Subject}/T1w/ASL/TIs/asl_corr.nii.gz) prior to the final perfusion analysis with oxford_asl. The resulting difference data will be saved at: ${StudyFolder}/${Subject}/T1w/ASL/TIs/Betas. This final oxford_asl perfusion analysis step is also brain masked, with: ${StudyFolder}/${Subject}/T1w/ASL/TIs/reg/ASL_FoV_brain_mask.nii.gz and the first M0 image is used in this analysis. The T1w-aligned (and distortion corrected) version of calib0, which is used at this point is saved as: ${StudyFolder}/${Subject}/T1w/ASL/Calib/Calib0/calib0_corr_aslt1w.nii.gz

Please can you:

  • Let us know the command that you are using to call the pipeline.
  • Make sure that the pipeline is getting as far as saving the ${StudyFolder}/${Subject}/T1w/ASL/Calib/Calib0/calib0_corr_aslt1w.nii.gz and ${StudyFolder}/${Subject}/T1w/ASL/TIs/asl_corr.nii.gz nifti files and check that these two images are in alignment with each other.
  • confirm which differencing step is causing problems - the first (done in alignment with the 1st ASL volume) or the second (done in alignment with the T1w image, which has been pre-processed with the HCP's minimal processing pipeline).
  • Let me know exactly which of your nifti files contains NaNs i.e. is it one of the pre-differencing tag-control niftis? Or are the NaNs being generated during the asl_differencing.py process and so appear inside the brain in one of the Betas nifti files (NaNs outside of the brain should be masked out during perfusion estimation)?
  • It might also be helpful to know which bits of the pipeline code you have edited.

We do have some plans to develop the pipeline further in future i.e. to produce a second version of the pipeline, but what we have on this repo at the moment is the "production-ready" first version of the pipeline, and has been run on the ASL data acquired by the HCP Lifespan studies. Do let us now if you have feedback or you find other issues when running the code.

Hopefully we can figure out what is causing the current issue that you have observed!
I look forward to hearing from you,
Flora

@markushs
Copy link
Author

markushs commented Mar 8, 2022

Hi @FKennedyMcC !
Thank you for the detailed response, and sorry for being slow at responding back. I am working on a computing cluster without internet access, so all editing/debugging must be done via singularity containers (== slow progress) ...

After some more debugging, it looks like the main issue was not NaNs following asl_differencing.py. That is, NaNs are present and produce some errors, but the files you asked me to look for (.../T1w/ASL/Calib/Calib0/calib0_corr_aslt1w.nii.gz and .../T1w/ASL/TIs/asl_corr.nii.gz) do get produced and are in alignment with each other. The main issue actually seems to have been the invocation of fslpython in qc.py. I'm have a pre-compiled version of FSL 6.0.5.1 in my singularity image, and fslpython does not come with it. Simply replacing fslpython with python in qc.py, and installing the fslpy package solved the issue. Other than that, I just had some minor conflicts due to the ${RegName}-variable which was coded as MSMAll throughout the pipeline, but updating the relevant scripts to reflect the fact that we only have MSMSulc-registered data solved those issues as well.

So in the end it looks like the pipeline works fine on our data as well! Sorry for perhaps asking for help prematurely, but your helpful comments speeded up the process of finding the correct adjustments massively. The "unaligned" first M0-volume in our data is still a bit puzzling, but I'm in the process of discussing that with the HCP-community.

In case it can be of any help in further developments of the pipeline, the observed NaN-errors occur early on during the first run of oxford_asl, during BET skullstripping, i.e. before masking with aslfs_mask.nii.gz:

image

This error is due to NaNs in the beta_perf.nii.gz used as input to oxford_asl. In fact, both niftis in the .../ASL/TIs/Betas directory have a fluctuating border of NaNs in the periphery of the bounding box. No NaNs are found in the images entering the function tag_control_differencing. I see the same for the niftis in ´.../T1w/ASL/TIs/Betas`.

Again, thanks so much for your help. Now looking forward to start investigating the o�utputs!
Markus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants