Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding write capabilities to pybids #646

Open
Remi-Gau opened this issue Aug 9, 2020 · 2 comments
Open

adding write capabilities to pybids #646

Remi-Gau opened this issue Aug 9, 2020 · 2 comments

Comments

@Remi-Gau
Copy link
Contributor

Remi-Gau commented Aug 9, 2020

Since I have been working on a couple of matlab functions to write some basics BIDS things while running experiments I figured I would open an issue here to see if similar features have their place in pybids or if they should be put somewhere else in another python package.

https://github.com/cpp-lln-lab/CPP_BIDS/blob/master/notebooks/basic_usage.ipynb
https://github.com/cpp-lln-lab/CPP_BIDS/blob/master/notebooks/more_on_saving.ipynb
https://github.com/cpp-lln-lab/CPP_BIDS/blob/master/notebooks/creating_BIDS_dataset.ipynb

Checking through the open issues I found these:

I guess one thing that could be done before anything else is finishing the PR #552 .

@tyarkoni
Copy link
Collaborator

Thanks for opening this @Remi-Gau; I think this kind of thing is definitely in scope for pybids, and it would be great to support it.

It's worth noting that there are already a bunch of functions in pybids that can probably do much of the work; e.g., theres a BIDSLayout.write_to_file() method that takes arbitrary contents as well as BIDS keyword/value pairs, and generates a valid path and writes to it. This is just a wrapper around some functions in bids.layout.writing, like build_path() and write_to_file(), which could also be invoked directly.

I think the approach I favor, long term, is to actually remove all writing functionality from the BIDSLayout class, and maybe create a separate class called something like BIDSWriter that handles all writing. The latter could still optionally take a BIDSLayout object at initialization, and use that to provide context where needed. But The layout module is already kind of unwieldy, and refactoring the writing functionality so it's all in one module would make sense to me.

That all said, we can defer the refactoring to some point in future. For now, if you want to take this on, I would suggest maybe going with a more minimalistic solution. Easiest would be to write some standalone functions much like your saveEventsFile() and createBoldJson() ones, and just put them in the bids.layout.writing module. (If you need access to the BIDSLayout instance, I would probably just take that as an (optional?) argument to those functions and use whatever you need from the layout that way).

Let me know if that doesn't make sense, or if you have any questions. (And no worries if you don't want to take this on yourself, Remi; we can just leave it open.)

@Remi-Gau
Copy link
Contributor Author

It's worth noting that there are already a bunch of functions in pybids that can probably do much of the work; e.g., theres a BIDSLayout.write_to_file() method that takes arbitrary contents as well as BIDS keyword/value pairs, and generates a valid path and writes to it. This is just a wrapper around some functions in bids.layout.writing, like build_path() and write_to_file(), which could also be invoked directly.

Thanks for the pointers.

I think the approach I favor, long term, is to actually remove all writing functionality from the BIDSLayout class, and maybe create a separate class called something like BIDSWriter that handles all writing.

Makes sense from a lay user point of view as well.

For now, if you want to take this on, I would suggest maybe going with a more minimalistic solution. Easiest would be to write some standalone functions much like your saveEventsFile() and createBoldJson() ones, and just put them in the bids.layout.writing module. (If you need access to the BIDSLayout instance, I would probably just take that as an (optional?) argument to those functions and use whatever you need from the layout that way).

OK I like the minimalistic approach. 👍

Let me know if that doesn't make sense, or if you have any questions.

Questions I will have for sure.

And no worries if you don't want to take this on yourself, Remi; we can just leave it open.

I will start working on this but progress will be slow at first. Limited bandwidth + writing anything in python usually has me google even the most trivial things (so expect some noob material coming from my general direction). 😆

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

No branches or pull requests

2 participants