mne-tools / mne-tools/mne-python
Facilitate export to XArray
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
Describe the problem
XArray is very convenient when doing data exploration as it often allows for a more transparent code by using dimension names rather than indexes. It would be very useful if MNE was providing XArray export functions where it already provides exports to NumPy array. For example, whereas someone would currently use
ica.get_sources(epochs).get_data().mean(2).mean(0)
by adding a to_xarray() method, we could use the following alternative code
ica.get_sources(epochs).to_xarray().mean(["time", "epochs"])
# or ica.get_sources(epochs).to_xarray().mean("time").mean("epochs")
Personally, I found the second version much easier to understand. With the first version, I would typically have to print the shape of the data to infer what axis corresponds to what to understand what operation is being performed. The first form (with dimension indexes) is also much more error-prone because all sorts of things can affect the axes ordering whereas dimension names and coordinates generally remain consistent and generate much more transparent errors when they don't.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing ica.get_sources(epochs).get_data() export path and the other NumPy export entry points referred to in the issue. Define the scope of the proposed to_xarray() methods and identify the relevant tests; done should provide equivalent data with stable named dimensions and coordinates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100