mne-tools / mne-bids

MNE-BIDS is a Python package that allows you to read and write BIDS-compatible datasets with the help of MNE-Python.
https://mne.tools/mne-bids/
BSD 3-Clause "New" or "Revised" License
131 stars 85 forks source link

Columns of scan.tsv are not accessible #965

Open JojoVh opened 2 years ago

JojoVh commented 2 years ago

Dear mne_bids team.

I am an inexperienced user, but I found out that this has not been reported yet to the best of my knowledge: In the scans.tsv the filename and acq_time are being read in correctly. However, additional columns with (optional) recording-specific information are so far being ignored, despite this being a BIDS feature (https://bids-specification.readthedocs.io/en/stable/03-modality-agnostic-files.html#scans-file). Columns could be "medication_status", "UPDRS" or other custom-column names relevant to the experiment.

The cause of this unexpected behavior I found to be originating here:

https://mne.tools/mne-bids/stable/_modules/mne_bids/read.html

in the source code for mne_bids.read under the definition _handle_scans_reading(scans_fname, raw, bids_path) I noticed that the acq_time is extracted, but no further extractions are made.

My small suggestion would be to create a new property: raw.set_scans_info( )

Thank you very much in advance for your help Best wishes Jonathan Vanhoecke ICN lab - Charité Berlin

welcome[bot] commented 2 years ago

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

hoechenberger commented 2 years ago

Hello @JonathanVHoecke and thanks for getting in touch!

The issue here is that, like you said, all additional columns are kind of arbitrary – the standard allows users to name them however they like. Hence, we wouldn't really know where and how to store that info.

What I'd therefore recommend is simply using pandas to read the information contained in this file. Would that be sufficient for your use case?

My small suggestion would be to create a new property: raw.set_scans_info( )

Could you elaborate on what you'd imagine this command to do? I thought you were only asking about reading scans.tsv before, no?

Best wishes,

Richard

hoechenberger commented 2 years ago

@sappelhoff Do you think we should have a property BIDSPath.scans that returns a DataFrame of scans.tsv?

Edit: No, actually, it should only return a Series or dict with the data from the scans.tsv line that applies to the current recording, right?

sappelhoff commented 2 years ago

I generally agree that a consistent way to access extra columns in BIDS TSV files would be a good idea (not just, but also scans.tsv) :+1:

adam2392 commented 2 years ago

Perhaps BIDSPath.as_data_frame()?

Where it only works for tsv files?

hoechenberger commented 2 years ago

Since scans.tsv provides metadata that's specific to individual recordings, I think the BIDSPath of an individual recording should allow easy access to those metadata (i.e., one row of scans.tsv)

There can (and probably should) of course be a separate generic "give me $FILENAME.tsv contents` function, too