Skip to content

Conversation

@tsalo
Copy link
Collaborator

@tsalo tsalo commented Dec 4, 2025

Related to nipreps/fmriprep#3579.

This should add SpatialReference to volumetric, standard-space anatomical outputs.

@tsalo
Copy link
Collaborator Author

tsalo commented Dec 5, 2025

For TemplateFlow volumetric spaces, the SpatialReference field will just have a URL (e.g., "https://templateflow.s3.amazonaws.com/tpl-MNI152Lin/tpl-MNI152Lin_res-02_T1w.nii.gz"). For non-standard volumetric spaces, it will be the absolute path to the template (e.g., "/home/.cache/templateflow/tpl-MyTemplate/tpl-MyTemplate_T1w.nii.gz"). I can't think of a good way to make the latter into a BIDS URI without having dataset_links defined in the config object, which seems out of scope for sMRIPrep.

@effigies
Copy link
Member

effigies commented Dec 5, 2025

Does it make more sense to copy the BIDSURI functionality from fMRIPrep? I think threading a dataset_links dictionary through datasink workflows and anything that calls them is reasonable. I think I'd prefer that to one implementation for functional and a different one for structural derivatives.

@tsalo
Copy link
Collaborator Author

tsalo commented Dec 5, 2025

That makes sense. I can add that.

@tsalo
Copy link
Collaborator Author

tsalo commented Dec 5, 2025

I think it looks good now. Here's the value from ds054:

{
    "SpatialReference": "bids:templateflow:tpl-MNI152Lin/tpl-MNI152Lin_res-02_T1w.nii.gz"
}

@tsalo tsalo requested a review from effigies December 5, 2025 20:21
Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few thoughts. I'm not sure that they're enough to finish this off on, but LMK what you think, and we can talk this over next week maybe?

Comment on lines +967 to +970
spatial_reference = pe.Node(
TemplateFlowReference(),
name='spatial_reference',
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried this is going to interfere with passing dataset_links from fmriprep, since that maps TF_LAYOUT.root onto bids:templateflow: and accepts raw paths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should update fMRIPrep to point to the website when it's a built-in template, but I could pass the dataset_links into this node to use a local path if templateflow is a key in the dictionary and doesn't start with http.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason I was leaning toward the website is that the CIFTI SpatialReference dictionary uses the website. If we do commit to using the local templateflow location then we should change that as well.

Comment on lines +246 to +247
if template_name in tf.TF_LAYOUT.get_templates():
self._results['uri'] = f'{tf_url}/{str(rel_path)}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably this is going to return custom templates found in TF_LAYOUT, so I'm not sure that the else branch will ever get hit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... I had hoped that get_templates would only return built-in templates, but that makes sense. Is there any way to distinguish built-in templates from custom ones?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I suppose we could inspect the skeleton in the templateflow client.

import zipfile
import templateflow

templates = [
    tpl.name.removeprefix('tpl-')
    for tpl in zipfile.Path(templateflow.conf.load_data('templateflow-skel.zip')).iterdir()
]

That's very much unsupported API, but it's doable.

Co-authored-by: Chris Markiewicz <effigies@gmail.com>
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

Successfully merging this pull request may close these issues.

2 participants