FZJ-INM1-BDA / siibra-python

Software interfaces for interacting with brain atlases - Python client
Apache License 2.0
48 stars 10 forks source link

Allen Connectivity Data / adding external data sources #223

Open PolarBean opened 1 year ago

PolarBean commented 1 year ago

I would like to create the ability for Siibra to interface with the allen connectivity API.

https://help.brain-map.org/display/mouseconnectivity/API

This API allows for users to query for the top projections to and from a region. And then retrieve a nrrd volume with the projection information. I have succesfully managed to transform and upload this data into siibra however I would like to integrate this functionality into the siibra regional information tab itself. Some things I would need to know are

Thank you in advance for help with these issues.

dickscheid commented 1 year ago

Dear Harry,

thanks for getting in touch.

the integration of new external resources is not yet a standardized procedure, but we are interesting in supporting such contributions. We are working on a major rewrite of the management of EBRAINs and other resources in siibra, and it would not make sense to invest much time in doing that with the current version. What is your time frame for this?

Could you be more specific what you mean by overlaying multiple volumes (in Python), and what a typical nrrd file looks like?

It might be helpful to have a chat together then.

Timo

PolarBean commented 1 year ago

Dear Timo,

Interesting, I have no specific time frame for this and can wait for the rewrite to be completed. Ultimately what I would want to build is the ability to overlay multiple volumes in the Siibra interactive atlas viewer. By this I mean load both dataset A and dataset B in the same view. The simplest way I can think of to do this is to create a mean of two volumes rather than loading both into the viewer so it's likely not an issue. I'm more than happy to meet and discuss this further you can contact me further at harry.carey@medisin.uio.no

all the best,

Harry

dickscheid commented 1 year ago

Dear Harry,

if you want to see two volumes superimposed in the viewer, it is not necessary to fuse the image volumes - siibra-explorer has the capabilities to do that. We have just not (yet) exposed easy ways to superimpose user data except for local NIfTI files which you can just drag and drop. In a way, this happens for hi-resolution volumes if you upload them to the VoluBA anchoring tool, from where you can then open them in siibra explorer. This is a workflow which still needs a bit of polishing and testing, but probably the way for you to go, and it is not necessary to do any modifications in siibra-python for this (except you want to automatize). I will connect you with Julia per email, who supports VoluBA developments on our side.

Timo

PolarBean commented 1 year ago

You can download a typical nrrd volume at the following link http://api.brain-map.org/grid_data/download_file/287495026??image=projection_density&resolution=25 Note the resolution indicates it has a voxel spacing of 25 microns though you can change this to 10 or 50 depending on your needs. See the following python script for transforming the resulting nrrd volume into a format which is readable by the siibra interactive atlas viewer.

import nrrd
import numpy as np
import nibabel as nib
path_to_volume = r"C:\Users\harry\Documents\GitHub//11_wks_coronal_287495026_25um_projection_density.nrrd"
volume, header = nrrd.read(path_to_volume)
volume = volume * 255
volume = volume.astype(np.uint8)
#reverse volume axis
volume = np.moveaxis(volume, [0, 1, 2], [1, 2, 0])
volume = volume[::-1, ::-1, ::-1]
# create nibabel image with volume
img = nib.Nifti1Image(volume, np.eye(4))
#set volume offset to half volume resolution
half_res = np.array(volume.shape) / 2
#hardcoded for 25 um resolution need to make dynamic
img.header['qoffset_x'] = -half_res[0] / 40
img.header['qoffset_y'] = -half_res[1] / 40
img.header['qoffset_z'] = -half_res[2] / 40
#set pixel spacing to 25 microns need to make dynamic
img.header['pixdim'][1:4]  = [0.025,0.025,0.025]
nib.save(img, "11_wks_coronal_287495026_25um_projection_density.nii.gz")
PolarBean commented 1 year ago

perhaps instead of creating mean volumes it would be better if i were able to create multichannel volumes. I've tried this (dataset one as R and dataset 2 as B) however Siibra web viewer won't open multichannel nii's. I can create a new issue for this but can Siibra handle multi channel volumes?

dickscheid commented 1 year ago

siibra-explorer can do mutli-channel under the hood, we recently fixed some issues with this and I am not sure if this is easily accessible already. the siibra-explorer GitHub would be the right place to discuss this.