numfocus / project-summit-2024-sprints

This repository will be used to gather sprint pitches for Day 3 of the NF 2024 Project Summit
MIT License
0 stars 0 forks source link

Experimenting with xarray / Array API compatibility #3

Open effigies opened 1 month ago

effigies commented 1 month ago

NiBabel was written in the times of Python 2.4 or 2.5 and the world has changed. Nowadays we would probably write our images as a dataclass:

@dataclass
class Neuroimage:
    data: npt.ArrayLike
    affine: np.ndarray
    header: Mapping[str, np.ndarray]

A data array tagged with metadata and spatial axis information is the basic idea of xarray. I plan to spend some time experimenting with how much logic we can push back into xarray and how much we can remain agnostic to the kind of array we wrap. We have some initial work in https://github.com/matthew-brett/xibabel.

I expect others have similar problems and this could be a collaborative affair.

TomNicholas commented 1 month ago

Xarray dev here - anyone else who has questions about using xarray with your package (or anything to do with named/dimensional arrays) please reach out!